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 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();
89 //----------------------------------------------------------------------------
90 vtkInteractorStyleCutter::~vtkInteractorStyleCutter()
92 this->Points->Delete();
93 this->BboxActor->Delete();
94 this->Lines->Delete();
95 this->LoopPoints->Delete();
98 //----------------------------------------------------------------------------
99 void vtkInteractorStyleCutter::OnMouseMove()
101 if (!this->Interactor || !this->Moving)
106 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
107 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
110 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
111 this->CurrentPosition[1], 0);
113 this->Interactor->Render();
116 //----------------------------------------------------------------------------
117 void vtkInteractorStyleCutter::OnLeftButtonDown()
119 if (!this->Interactor)
126 this->CurrentPosition[0] = this->Interactor->GetEventPosition()[0];
127 this->CurrentPosition[1] = this->Interactor->GetEventPosition()[1];
133 //Call this before accessing CurrentRenderer
134 this->FindPokedRenderer(this->CurrentPosition[0], this->CurrentPosition[1]);
135 this->CurrentRenderer->AddViewProp(BboxActor);
140 this->Points->SetPoint(this->PointID, this->CurrentPosition[0],
141 this->CurrentPosition[1], 0);
142 this->PointID = this->Points->InsertNextPoint( this->CurrentPosition[0],
143 this->CurrentPosition[1], 0);
145 this->Lines->InsertCellPoint( this->PointID );
146 this->Lines->UpdateCellCount( this->PointID + 1 );
147 this->BboxActor->VisibilityOn();
149 this->Interactor->Render();
152 //----------------------------------------------------------------------------
153 bool vtkInteractorStyleCutter::Finished()
158 //----------------------------------------------------------------------------
159 void vtkInteractorStyleCutter::OnRightButtonDown()
161 if (!this->Interactor || !this->Moving)
167 this->Points->GetPoint( 0, xyz );
168 this->Points->SetPoint(this->PointID, xyz);
173 this->Interactor->Render();
178 //----------------------------------------------------------------------------
179 void vtkInteractorStyleCutter::Initialize()
181 this->Points->Reset();
182 this->Lines->Reset();
184 this->PointID = this->Points->InsertNextPoint( 0, 0, 0);
185 this->Lines->InsertNextCell( 1 );
186 this->Lines->InsertCellPoint( 0 );
188 //----------------------------------------------------------------------------
189 void vtkInteractorStyleCutter::EndLoop()
192 int numPts = this->Points->GetNumberOfPoints()-1;
193 this->LoopPoints->SetNumberOfPoints( numPts );
194 vtkCamera *camera = this->CurrentRenderer->GetActiveCamera();
195 //int state = camera->GetParallelProjection ();
196 camera->ParallelProjectionOn();
198 for (int i=0; i < numPts; i++)
200 this->Points->GetPoint(i, pi);
201 this->CurrentRenderer->SetDisplayPoint(pi[0], pi[1], 0);
202 this->CurrentRenderer->DisplayToWorld();
204 this->CurrentRenderer->GetWorldPoint( fpi );
211 this->LoopPoints->SetPoint( i, fpi[0], fpi[1], fpi[2] );
214 //Set direction of extrusion, should save this state before camera moves
215 camera->GetDirectionOfProjection( this->Direction );
216 //camera->SetParallelProjection( state );
218 //----------------------------------------------------------------------------
220 void vtkInteractorStyleCutter::VisibilityOff()
222 this->BboxActor->VisibilityOff();
224 //----------------------------------------------------------------------------
225 void vtkInteractorStyleCutter::PrintSelf(ostream& os, vtkIndent indent)
227 this->Superclass::PrintSelf(os, indent);