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_
29 #include <creawxVTKRenderWindowInteractor.h>
31 #include <vtkCommand.h>
32 #include <vtkImageData.h>
33 //#include <vtkRenderWindow.h>
34 #include <vtkImageViewer2.h>
36 #include <vtkInteractorStyleTrackballCamera.h>
37 #include <vtkInteractorStyleImage.h>
41 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
45 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera {
47 vtkInteractorStyle3DMaracas();
48 ~vtkInteractorStyle3DMaracas();
50 virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
51 static vtkInteractorStyle3DMaracas *New(){
52 return new vtkInteractorStyle3DMaracas();
55 virtual void OnMouseMove () ;
56 virtual void OnLeftButtonDown ();
57 virtual void OnLeftButtonUp () ;
58 virtual void OnMiddleButtonDown ();
59 virtual void OnMiddleButtonUp () ;
60 virtual void OnRightButtonDown () ;
61 virtual void OnRightButtonUp () ;
67 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
69 //------------------------------------------------------------------------
72 class vtkMaracasImageViewer2Callback : public vtkCommand
75 vtkMaracasImageViewer2Callback() {} ;
76 ~vtkMaracasImageViewer2Callback() {} ;
77 static vtkMaracasImageViewer2Callback *New() {
78 return new vtkMaracasImageViewer2Callback();
81 virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
83 void Execute(vtkObject *caller,
85 void *vtkNotUsed(callData))
87 if (this->IV->GetInput() == NULL)
94 if (event == vtkCommand::ResetWindowLevelEvent)
98 //EED 2017-01-01 Migration VTK7
99 #if VTK_MAJOR_VERSION <= 5
100 this->IV->GetInput()->UpdateInformation();
101 this->IV->GetInput()->SetUpdateExtent
102 (this->IV->GetInput()->GetWholeExtent());
103 this->IV->GetInput()->Update();
108 double *range = this->IV->GetInput()->GetScalarRange();
109 this->IV->SetColorWindow(range[1] - range[0]);
110 this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
117 if (event == vtkCommand::StartWindowLevelEvent)
119 this->InitialWindow = this->IV->GetColorWindow();
120 this->InitialLevel = this->IV->GetColorLevel();
124 // Adjust the window level here
126 vtkInteractorStyleImage *isi =
127 static_cast<vtkInteractorStyleImage *>(caller);
129 int *size = this->IV->GetRenderWindow()->GetSize();
130 double window = this->InitialWindow;
131 double level = this->InitialLevel;
133 // Compute normalized delta
136 (isi->GetWindowLevelCurrentPosition()[0] -
137 isi->GetWindowLevelStartPosition()[0]) / size[0];
139 (isi->GetWindowLevelStartPosition()[1] -
140 isi->GetWindowLevelCurrentPosition()[1]) / size[1];
142 // Scale by current values
144 if (fabs(window) > 0.01)
150 dx = dx * (window < 0 ? -0.01 : 0.01);
152 if (fabs(level) > 0.01)
158 dy = dy * (level < 0 ? -0.01 : 0.01);
161 // Abs so that direction does not flip
172 // Compute new window level
174 double newWindow = dx + window;
176 newLevel = level - dy;
178 // Stay away from zero and really
180 if (fabs(newWindow) < 0.01)
182 newWindow = 0.01*(newWindow < 0 ? -1 : 1);
184 if (fabs(newLevel) < 0.01)
186 newLevel = 0.01*(newLevel < 0 ? -1 : 1);
189 this->IV->SetColorWindow(newWindow);
190 this->IV->SetColorLevel(newLevel);
195 double InitialWindow;
199 //class crea::wxVTKRenderWindowInteractor;
201 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
203 vtkInteractorStyle2DMaracas();
204 ~vtkInteractorStyle2DMaracas();
206 virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
207 static vtkInteractorStyle2DMaracas *New(){
208 return new vtkInteractorStyle2DMaracas();
211 virtual void OnMouseMove () ;
212 virtual void OnLeftButtonDown ();
213 virtual void OnLeftButtonUp () ;
214 virtual void OnMiddleButtonDown ();
215 virtual void OnMiddleButtonUp () ;
216 virtual void OnRightButtonDown () ;
217 virtual void OnRightButtonUp () ;
218 void SetObserver( vtkCommand *obs );
225 //-----------------------------------------------------------------------------
230 class wxVTKRenderWindowInteractorEditContour : public crea::wxVTKRenderWindowInteractor {
234 wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id);
235 virtual ~wxVTKRenderWindowInteractorEditContour();
237 virtual void OnButtonDown(wxMouseEvent &event);
238 virtual void OnButtonUp(wxMouseEvent &event);
239 virtual void OnButtonDouble(wxMouseEvent &event);
240 virtual void OnMotion(wxMouseEvent &event);
241 virtual void OnKeyDown(wxKeyEvent &event);
243 void SetState(int state);
245 void SetObserver(vtkCommand *obs);
253 #endif //_wxVTKRenderWindowInteractorEditContour_h_