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)
97 this->IV->GetInput()->UpdateInformation();
98 this->IV->GetInput()->SetUpdateExtent
99 (this->IV->GetInput()->GetWholeExtent());
100 this->IV->GetInput()->Update();
101 double *range = this->IV->GetInput()->GetScalarRange();
102 this->IV->SetColorWindow(range[1] - range[0]);
103 this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
110 if (event == vtkCommand::StartWindowLevelEvent)
112 this->InitialWindow = this->IV->GetColorWindow();
113 this->InitialLevel = this->IV->GetColorLevel();
117 // Adjust the window level here
119 vtkInteractorStyleImage *isi =
120 static_cast<vtkInteractorStyleImage *>(caller);
122 int *size = this->IV->GetRenderWindow()->GetSize();
123 double window = this->InitialWindow;
124 double level = this->InitialLevel;
126 // Compute normalized delta
129 (isi->GetWindowLevelCurrentPosition()[0] -
130 isi->GetWindowLevelStartPosition()[0]) / size[0];
132 (isi->GetWindowLevelStartPosition()[1] -
133 isi->GetWindowLevelCurrentPosition()[1]) / size[1];
135 // Scale by current values
137 if (fabs(window) > 0.01)
143 dx = dx * (window < 0 ? -0.01 : 0.01);
145 if (fabs(level) > 0.01)
151 dy = dy * (level < 0 ? -0.01 : 0.01);
154 // Abs so that direction does not flip
165 // Compute new window level
167 double newWindow = dx + window;
169 newLevel = level - dy;
171 // Stay away from zero and really
173 if (fabs(newWindow) < 0.01)
175 newWindow = 0.01*(newWindow < 0 ? -1 : 1);
177 if (fabs(newLevel) < 0.01)
179 newLevel = 0.01*(newLevel < 0 ? -1 : 1);
182 this->IV->SetColorWindow(newWindow);
183 this->IV->SetColorLevel(newLevel);
188 double InitialWindow;
192 class crea::wxVTKRenderWindowInteractor;
194 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
196 vtkInteractorStyle2DMaracas();
197 ~vtkInteractorStyle2DMaracas();
199 virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
200 static vtkInteractorStyle2DMaracas *New(){
201 return new vtkInteractorStyle2DMaracas();
204 virtual void OnMouseMove () ;
205 virtual void OnLeftButtonDown ();
206 virtual void OnLeftButtonUp () ;
207 virtual void OnMiddleButtonDown ();
208 virtual void OnMiddleButtonUp () ;
209 virtual void OnRightButtonDown () ;
210 virtual void OnRightButtonUp () ;
211 void SetObserver( vtkCommand *obs );
218 //-----------------------------------------------------------------------------
223 class wxVTKRenderWindowInteractorEditContour : public crea::wxVTKRenderWindowInteractor {
227 wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id);
228 virtual ~wxVTKRenderWindowInteractorEditContour();
230 virtual void OnButtonDown(wxMouseEvent &event);
231 virtual void OnButtonUp(wxMouseEvent &event);
232 virtual void OnButtonDouble(wxMouseEvent &event);
233 virtual void OnMotion(wxMouseEvent &event);
234 virtual void OnKeyDown(wxKeyEvent &event);
236 void SetState(int state);
238 void SetObserver(vtkCommand *obs);
246 #endif //_wxVTKRenderWindowInteractorEditContour_h_