1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /*=========================================================================
28 Program: Visualization Toolkit
29 Module: $RCSfile: vtkInteractorStyleCutter.cxx,v $
31 Date: $Date: 2012/11/15 14:15:18 $
32 Version: $Revision: 1.2 $
34 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
36 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
38 This software is distributed WITHOUT ANY WARRANTY; without even
39 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
40 PURPOSE. See the above copyright notice for more information.
42 =========================================================================*/
43 #include "vtkInteractorStyleCutter.h"
45 #include <vtkPoints.h>
46 #include <vtkActor2D.h>
47 #include <vtkObjectFactory.h>
48 #include <vtkRenderer.h>
49 #include <vtkRenderWindowInteractor.h>
50 #include <vtkCellArray.h>
51 #include <vtkPolyData.h>
52 #include <vtkPolyDataMapper2D.h>
53 #include <vtkProperty2D.h>
54 #include <vtkCamera.h>
56 vtkCxxRevisionMacro(vtkInteractorStyleCutter, "$Revision: 1.2 $");
57 vtkStandardNewMacro(vtkInteractorStyleCutter);
59 //----------------------------------------------------------------------------
60 vtkInteractorStyleCutter::vtkInteractorStyleCutter()
62 this->CurrentPosition[0] = this->CurrentPosition[1] = 0;
63 this->Direction[0] = this->Direction[1] = this->Direction[2] = 0.;
66 this->Points = vtkPoints::New();
67 this->Lines = vtkCellArray::New();
68 this->LoopPoints = vtkPoints::New();
70 vtkPolyData *pd = vtkPolyData::New();
71 pd->SetPoints( Points );
72 pd->SetLines( Lines );
74 vtkPolyDataMapper2D *bboxMapper = vtkPolyDataMapper2D::New();
75 bboxMapper->SetInput( pd );
77 this->BboxActor = vtkActor2D::New();
78 this->BboxActor->SetMapper( bboxMapper );
79 this->BboxActor->GetProperty()->SetColor(1, 0, 0);
80 this->BboxActor->VisibilityOff();
87 //----------------------------------------------------------------------------
88 vtkInteractorStyleCutter::~vtkInteractorStyleCutter()
90 this->Points->Delete();
91 this->BboxActor->Delete();
92 this->Lines->Delete();
93 this->LoopPoints->Delete();
96 //----------------------------------------------------------------------------
97 void vtkInteractorStyleCutter::OnMouseMove()
99 if (!this->Interactor || !this->Moving)
104 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
105 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
108 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
109 this->CurrentPosition[1], 0);
111 this->Interactor->Render();
114 //----------------------------------------------------------------------------
115 void vtkInteractorStyleCutter::OnLeftButtonDown()
117 if (!this->Interactor)
122 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
123 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
129 //Call this before accessing CurrentRenderer
130 this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]);
131 this->CurrentRenderer->AddProp( BboxActor );
136 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
137 this->CurrentPosition[1], 0);
138 this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0],
139 this->CurrentPosition[1], 0);
141 this->Lines->InsertCellPoint( this->PointID );
142 this->Lines->UpdateCellCount( this->PointID + 1 );
143 this->BboxActor->VisibilityOn();
145 this->Interactor->Render();
148 //----------------------------------------------------------------------------
149 void vtkInteractorStyleCutter::OnRightButtonDown()
151 if (!this->Interactor || !this->Moving)
157 this->Points->GetPoint( 0, xyz );
158 this->Points->SetPoint(this->PointID, xyz);
163 this->Interactor->Render();
167 //----------------------------------------------------------------------------
168 void vtkInteractorStyleCutter::Initialize()
170 this->Points->Reset();
171 this->Lines->Reset();
173 this->PointID = this->Points->InsertNextPoint( 0, 0, 0);
174 this->Lines->InsertNextCell( 1 );
175 this->Lines->InsertCellPoint( 0 );
177 //----------------------------------------------------------------------------
178 void vtkInteractorStyleCutter::EndLoop()
181 int numPts = this->Points->GetNumberOfPoints()-1;
182 this->LoopPoints->SetNumberOfPoints( numPts );
183 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
184 int state = camera->GetParallelProjection ();
185 camera->ParallelProjectionOn();
187 for (int i=0; i < numPts; i++)
189 this->Points->GetPoint(i, pi);
190 this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0);
191 this->CurrentRenderer->DisplayToWorld();
193 this->CurrentRenderer->GetWorldPoint( fpi );
200 this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] );
203 //Set direction of extrusion, should save this state before camera moves
204 camera->GetDirectionOfProjection( this->Direction );
205 //camera->SetParallelProjection( state );
207 //----------------------------------------------------------------------------
209 void vtkInteractorStyleCutter::VisibilityOff()
211 this->BboxActor->VisibilityOff();
213 //----------------------------------------------------------------------------
214 void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent)
216 this->Superclass::PrintSelf(os, indent);