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 #ifndef _wxVTKRenderWindowInteractorEditContour_h_
27 #define _wxVTKRenderWindowInteractorEditContour_h_
30 #include <creawxVTKRenderWindowInteractor.h>
32 #include <vtkCommand.h>
33 #include <vtkImageData.h>
34 //#include <vtkRenderWindow.h>
35 #include <vtkImageViewer2.h>
37 #include <vtkInteractorStyleTrackballCamera.h>
38 #include <vtkInteractorStyleImage.h>
42 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
46 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera {
48 vtkInteractorStyle3DMaracas();
49 ~vtkInteractorStyle3DMaracas();
51 virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
52 static vtkInteractorStyle3DMaracas *New(){
53 return new vtkInteractorStyle3DMaracas();
56 virtual void OnMouseMove () ;
57 virtual void OnLeftButtonDown ();
58 virtual void OnLeftButtonUp () ;
59 virtual void OnMiddleButtonDown ();
60 virtual void OnMiddleButtonUp () ;
61 virtual void OnRightButtonDown () ;
62 virtual void OnRightButtonUp () ;
68 //------------------------------------------------------------------------
69 //------------------------------------------------------------------------
70 //------------------------------------------------------------------------
73 class vtkMaracasImageViewer2Callback : public vtkCommand
76 vtkMaracasImageViewer2Callback() {} ;
77 ~vtkMaracasImageViewer2Callback() {} ;
78 static vtkMaracasImageViewer2Callback *New() {
79 return new vtkMaracasImageViewer2Callback();
82 virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
84 void Execute(vtkObject *caller,
86 void *vtkNotUsed(callData))
88 if (this->IV->GetInput() == NULL)
95 if (event == vtkCommand::ResetWindowLevelEvent)
99 //EED 2017-01-01 Migration VTK7
100 #if VTK_MAJOR_VERSION <= 5
101 this->IV->GetInput()->UpdateInformation();
102 this->IV->GetInput()->SetUpdateExtent
103 (this->IV->GetInput()->GetWholeExtent());
104 this->IV->GetInput()->Update();
109 double *range = this->IV->GetInput()->GetScalarRange();
110 this->IV->SetColorWindow(range[1] - range[0]);
111 this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
118 if (event == vtkCommand::StartWindowLevelEvent)
120 this->InitialWindow = this->IV->GetColorWindow();
121 this->InitialLevel = this->IV->GetColorLevel();
125 // Adjust the window level here
127 vtkInteractorStyleImage *isi =
128 static_cast<vtkInteractorStyleImage *>(caller);
130 int *size = this->IV->GetRenderWindow()->GetSize();
131 double window = this->InitialWindow;
132 double level = this->InitialLevel;
134 // Compute normalized delta
137 (isi->GetWindowLevelCurrentPosition()[0] -
138 isi->GetWindowLevelStartPosition()[0]) / size[0];
140 (isi->GetWindowLevelStartPosition()[1] -
141 isi->GetWindowLevelCurrentPosition()[1]) / size[1];
143 // Scale by current values
145 if (fabs(window) > 0.01)
151 dx = dx * (window < 0 ? -0.01 : 0.01);
153 if (fabs(level) > 0.01)
159 dy = dy * (level < 0 ? -0.01 : 0.01);
162 // Abs so that direction does not flip
173 // Compute new window level
175 double newWindow = dx + window;
177 newLevel = level - dy;
179 // Stay away from zero and really
181 if (fabs(newWindow) < 0.01)
183 newWindow = 0.01*(newWindow < 0 ? -1 : 1);
185 if (fabs(newLevel) < 0.01)
187 newLevel = 0.01*(newLevel < 0 ? -1 : 1);
190 this->IV->SetColorWindow(newWindow);
191 this->IV->SetColorLevel(newLevel);
196 double InitialWindow;
200 class crea::wxVTKRenderWindowInteractor;
202 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
204 vtkInteractorStyle2DMaracas();
205 ~vtkInteractorStyle2DMaracas();
207 virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
208 static vtkInteractorStyle2DMaracas *New(){
209 return new vtkInteractorStyle2DMaracas();
212 virtual void OnMouseMove () ;
213 virtual void OnLeftButtonDown ();
214 virtual void OnLeftButtonUp () ;
215 virtual void OnMiddleButtonDown ();
216 virtual void OnMiddleButtonUp () ;
217 virtual void OnRightButtonDown () ;
218 virtual void OnRightButtonUp () ;
219 void SetObserver( vtkCommand *obs );
226 //-----------------------------------------------------------------------------
231 class wxVTKRenderWindowInteractorEditContour : public crea::wxVTKRenderWindowInteractor {
235 wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id);
236 virtual ~wxVTKRenderWindowInteractorEditContour();
238 virtual void OnButtonDown(wxMouseEvent &event);
239 virtual void OnButtonUp(wxMouseEvent &event);
240 virtual void OnButtonDouble(wxMouseEvent &event);
241 virtual void OnMotion(wxMouseEvent &event);
242 virtual void OnKeyDown(wxKeyEvent &event);
244 void SetState(int state);
246 void SetObserver(vtkCommand *obs);
254 #endif //_wxVTKRenderWindowInteractorEditContour_h_