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:16:20 $
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 //EED 2017-01-01 Migration VTK7
57 #if VTK_MAJOR_VERSION <= 5
58 vtkCxxRevisionMacro(vtkInteractorStyleCutter, "$Revision: 1.2 $");
62 vtkStandardNewMacro(vtkInteractorStyleCutter);
64 //----------------------------------------------------------------------------
65 vtkInteractorStyleCutter::vtkInteractorStyleCutter()
67 this->CurrentPosition[0] = this->CurrentPosition[1] = 0;
68 this->Direction[0] = this->Direction[1] = this->Direction[2] = 0.;
71 this->Points = vtkPoints::New();
72 this->Lines = vtkCellArray::New();
73 this->LoopPoints = vtkPoints::New();
75 vtkPolyData *pd = vtkPolyData::New();
76 pd->SetPoints( Points );
77 pd->SetLines( Lines );
79 vtkPolyDataMapper2D *bboxMapper = vtkPolyDataMapper2D::New();
80 //EED 2017-01-01 Migration VTK7
81 #if VTK_MAJOR_VERSION <= 5
82 bboxMapper->SetInput( pd );
84 bboxMapper->SetInputData( pd );
87 this->BboxActor = vtkActor2D::New();
88 this->BboxActor->SetMapper( bboxMapper );
89 this->BboxActor->GetProperty()->SetColor(1, 0, 0);
90 this->BboxActor->VisibilityOff();
99 //----------------------------------------------------------------------------
100 vtkInteractorStyleCutter::~vtkInteractorStyleCutter()
102 this->Points->Delete();
103 this->BboxActor->Delete();
104 this->Lines->Delete();
105 this->LoopPoints->Delete();
108 //----------------------------------------------------------------------------
109 void vtkInteractorStyleCutter::OnMouseMove()
111 if (!this->Interactor || !this->Moving)
116 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
117 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
120 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
121 this->CurrentPosition[1], 0);
123 this->Interactor->Render();
126 //----------------------------------------------------------------------------
127 void vtkInteractorStyleCutter::OnLeftButtonDown()
129 if (!this->Interactor)
136 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
137 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
143 //Call this before accessing CurrentRenderer
144 this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]);
145 this->CurrentRenderer->AddViewProp(BboxActor);
150 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
151 this->CurrentPosition[1], 0);
152 this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0],
153 this->CurrentPosition[1], 0);
155 this->Lines->InsertCellPoint( this->PointID );
156 this->Lines->UpdateCellCount( this->PointID + 1 );
157 this->BboxActor->VisibilityOn();
159 this->Interactor->Render();
162 //----------------------------------------------------------------------------
163 bool vtkInteractorStyleCutter::Finished()
168 //----------------------------------------------------------------------------
169 void vtkInteractorStyleCutter::OnRightButtonDown()
171 if (!this->Interactor || !this->Moving)
177 this->Points->GetPoint( 0, xyz );
178 this->Points->SetPoint(this->PointID, xyz);
183 this->Interactor->Render();
188 //----------------------------------------------------------------------------
189 void vtkInteractorStyleCutter::Initialize()
191 this->Points->Reset();
192 this->Lines->Reset();
194 this->PointID = this->Points->InsertNextPoint( 0, 0, 0);
195 this->Lines->InsertNextCell( 1 );
196 this->Lines->InsertCellPoint( 0 );
198 //----------------------------------------------------------------------------
199 void vtkInteractorStyleCutter::EndLoop()
202 int numPts = this->Points->GetNumberOfPoints()-1;
203 this->LoopPoints->SetNumberOfPoints( numPts );
204 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
205 //int state = camera->GetParallelProjection ();
206 camera->ParallelProjectionOn();
208 for (int i=0; i < numPts; i++)
210 this->Points->GetPoint(i, pi);
211 this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0);
212 this->CurrentRenderer->DisplayToWorld();
214 this->CurrentRenderer->GetWorldPoint( fpi );
221 this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] );
224 //Set direction of extrusion, should save this state before camera moves
225 camera->GetDirectionOfProjection( this->Direction );
226 //camera->SetParallelProjection( state );
228 //----------------------------------------------------------------------------
230 void vtkInteractorStyleCutter::VisibilityOff()
232 this->BboxActor->VisibilityOff();
234 //----------------------------------------------------------------------------
235 void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent)
237 this->Superclass::PrintSelf(os, indent);