1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkInteractorStyleCutter.cxx,v $
6 Date: $Date: 2010/02/24 14:00:46 $
7 Version: $Revision: 1.1 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 #include "vtkInteractorStyleCutter.h"
20 #include <vtkPoints.h>
21 #include <vtkActor2D.h>
22 #include <vtkObjectFactory.h>
23 #include <vtkRenderer.h>
24 #include <vtkRenderWindowInteractor.h>
25 #include <vtkCellArray.h>
26 #include <vtkPolyData.h>
27 #include <vtkPolyDataMapper2D.h>
28 #include <vtkProperty2D.h>
29 #include <vtkCamera.h>
31 vtkCxxRevisionMacro(vtkInteractorStyleCutter, "$Revision: 1.1 $");
32 vtkStandardNewMacro(vtkInteractorStyleCutter);
34 //----------------------------------------------------------------------------
35 vtkInteractorStyleCutter::vtkInteractorStyleCutter()
37 this->CurrentPosition[0] = this->CurrentPosition[1] = 0;
38 this->Direction[0] = this->Direction[1] = this->Direction[2] = 0.;
41 this->Points = vtkPoints::New();
42 this->Lines = vtkCellArray::New();
43 this->LoopPoints = vtkPoints::New();
45 vtkPolyData *pd = vtkPolyData::New();
46 pd->SetPoints( Points );
47 pd->SetLines( Lines );
49 vtkPolyDataMapper2D *bboxMapper = vtkPolyDataMapper2D::New();
50 bboxMapper->SetInput( pd );
52 this->BboxActor = vtkActor2D::New();
53 this->BboxActor->SetMapper( bboxMapper );
54 this->BboxActor->GetProperty()->SetColor(1, 0, 0);
55 this->BboxActor->VisibilityOff();
64 //----------------------------------------------------------------------------
65 vtkInteractorStyleCutter::~vtkInteractorStyleCutter()
67 this->Points->Delete();
68 this->BboxActor->Delete();
69 this->Lines->Delete();
70 this->LoopPoints->Delete();
73 //----------------------------------------------------------------------------
74 void vtkInteractorStyleCutter::OnMouseMove()
76 if (!this->Interactor || !this->Moving)
81 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
82 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
85 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
86 this->CurrentPosition[1], 0);
88 this->Interactor->Render();
91 //----------------------------------------------------------------------------
92 void vtkInteractorStyleCutter::OnLeftButtonDown()
94 if (!this->Interactor)
101 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
102 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
108 //Call this before accessing CurrentRenderer
109 this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]);
110 this->CurrentRenderer->AddViewProp(BboxActor);
115 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
116 this->CurrentPosition[1], 0);
117 this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0],
118 this->CurrentPosition[1], 0);
120 this->Lines->InsertCellPoint( this->PointID );
121 this->Lines->UpdateCellCount( this->PointID + 1 );
122 this->BboxActor->VisibilityOn();
124 this->Interactor->Render();
127 //----------------------------------------------------------------------------
128 bool vtkInteractorStyleCutter::Finished()
133 //----------------------------------------------------------------------------
134 void vtkInteractorStyleCutter::OnRightButtonDown()
136 if (!this->Interactor || !this->Moving)
142 this->Points->GetPoint( 0, xyz );
143 this->Points->SetPoint(this->PointID, xyz);
148 this->Interactor->Render();
153 //----------------------------------------------------------------------------
154 void vtkInteractorStyleCutter::Initialize()
156 this->Points->Reset();
157 this->Lines->Reset();
159 this->PointID = this->Points->InsertNextPoint( 0, 0, 0);
160 this->Lines->InsertNextCell( 1 );
161 this->Lines->InsertCellPoint( 0 );
163 //----------------------------------------------------------------------------
164 void vtkInteractorStyleCutter::EndLoop()
167 int numPts = this->Points->GetNumberOfPoints()-1;
168 this->LoopPoints->SetNumberOfPoints( numPts );
169 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
170 //int state = camera->GetParallelProjection ();
171 camera->ParallelProjectionOn();
173 for (int i=0; i < numPts; i++)
175 this->Points->GetPoint(i, pi);
176 this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0);
177 this->CurrentRenderer->DisplayToWorld();
179 this->CurrentRenderer->GetWorldPoint( fpi );
186 this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] );
189 //Set direction of extrusion, should save this state before camera moves
190 camera->GetDirectionOfProjection( this->Direction );
191 //camera->SetParallelProjection( state );
193 //----------------------------------------------------------------------------
195 void vtkInteractorStyleCutter::VisibilityOff()
197 this->BboxActor->VisibilityOff();
199 //----------------------------------------------------------------------------
200 void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent)
202 this->Superclass::PrintSelf(os, indent);