1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkInteractorStyleCutter.cxx,v $
6 Date: $Date: 2009/05/14 13:54:57 $
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();
62 //----------------------------------------------------------------------------
63 vtkInteractorStyleCutter::~vtkInteractorStyleCutter()
65 this->Points->Delete();
66 this->BboxActor->Delete();
67 this->Lines->Delete();
68 this->LoopPoints->Delete();
71 //----------------------------------------------------------------------------
72 void vtkInteractorStyleCutter::OnMouseMove()
74 if (!this->Interactor || !this->Moving)
79 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
80 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
83 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
84 this->CurrentPosition[1], 0);
86 this->Interactor->Render();
89 //----------------------------------------------------------------------------
90 void vtkInteractorStyleCutter::OnLeftButtonDown()
92 if (!this->Interactor)
97 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
98 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
104 //Call this before accessing CurrentRenderer
105 this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]);
106 this->CurrentRenderer->AddProp( BboxActor );
111 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
112 this->CurrentPosition[1], 0);
113 this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0],
114 this->CurrentPosition[1], 0);
116 this->Lines->InsertCellPoint( this->PointID );
117 this->Lines->UpdateCellCount( this->PointID + 1 );
118 this->BboxActor->VisibilityOn();
120 this->Interactor->Render();
123 //----------------------------------------------------------------------------
124 void vtkInteractorStyleCutter::OnRightButtonDown()
126 if (!this->Interactor || !this->Moving)
132 this->Points->GetPoint( 0, xyz );
133 this->Points->SetPoint(this->PointID, xyz);
138 this->Interactor->Render();
142 //----------------------------------------------------------------------------
143 void vtkInteractorStyleCutter::Initialize()
145 this->Points->Reset();
146 this->Lines->Reset();
148 this->PointID = this->Points->InsertNextPoint( 0, 0, 0);
149 this->Lines->InsertNextCell( 1 );
150 this->Lines->InsertCellPoint( 0 );
152 //----------------------------------------------------------------------------
153 void vtkInteractorStyleCutter::EndLoop()
156 int numPts = this->Points->GetNumberOfPoints()-1;
157 this->LoopPoints->SetNumberOfPoints( numPts );
158 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
159 int state = camera->GetParallelProjection ();
160 camera->ParallelProjectionOn();
162 for (int i=0; i < numPts; i++)
164 this->Points->GetPoint(i, pi);
165 this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0);
166 this->CurrentRenderer->DisplayToWorld();
168 this->CurrentRenderer->GetWorldPoint( fpi );
175 this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] );
178 //Set direction of extrusion, should save this state before camera moves
179 camera->GetDirectionOfProjection( this->Direction );
180 //camera->SetParallelProjection( state );
182 //----------------------------------------------------------------------------
184 void vtkInteractorStyleCutter::VisibilityOff()
186 this->BboxActor->VisibilityOff();
188 //----------------------------------------------------------------------------
189 void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent)
191 this->Superclass::PrintSelf(os, indent);