]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVTKRenderWindowInteractorEditContour.h
#3471 Doxygen OFF in CMake AND wx.h conflict
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVTKRenderWindowInteractorEditContour.h
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 #ifndef _wxVTKRenderWindowInteractorEditContour_h_
27 #define _wxVTKRenderWindowInteractorEditContour_h_
28
29 #include <creawxVTKRenderWindowInteractor.h>
30
31 #include <vtkCommand.h> 
32 #include <vtkImageData.h> 
33 //#include <vtkRenderWindow.h> 
34 #include <vtkImageViewer2.h> 
35
36 #include <vtkInteractorStyleTrackballCamera.h> 
37 #include <vtkInteractorStyleImage.h> 
38
39
40
41 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
43 //------------------------------------------------------------------------
44
45 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera    {
46 public:
47         vtkInteractorStyle3DMaracas();
48         ~vtkInteractorStyle3DMaracas();
49
50         virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
51         static vtkInteractorStyle3DMaracas *New(){
52                                         return new vtkInteractorStyle3DMaracas();
53                                 }
54
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 () ;
62
63 private:
64
65 };
66
67 //------------------------------------------------------------------------
68 //------------------------------------------------------------------------
69 //------------------------------------------------------------------------
70
71
72 class vtkMaracasImageViewer2Callback : public vtkCommand
73 {
74 public:
75   vtkMaracasImageViewer2Callback() {} ;
76   ~vtkMaracasImageViewer2Callback() {} ;
77   static vtkMaracasImageViewer2Callback *New() {
78      return new vtkMaracasImageViewer2Callback(); 
79   }
80
81   virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
82   
83   void Execute(vtkObject *caller, 
84                unsigned long event, 
85                void *vtkNotUsed(callData))
86     {
87       if (this->IV->GetInput() == NULL)
88         {
89         return;
90         }
91
92       // Reset
93
94       if (event == vtkCommand::ResetWindowLevelEvent)
95         {
96
97
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();
104 #else
105         //..
106 #endif
107
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]));
111         this->IV->Render();
112         return;
113         }
114
115       // Start
116
117       if (event == vtkCommand::StartWindowLevelEvent)
118         {
119         this->InitialWindow = this->IV->GetColorWindow();
120         this->InitialLevel = this->IV->GetColorLevel();
121         return;
122         }
123       
124       // Adjust the window level here
125
126       vtkInteractorStyleImage *isi = 
127         static_cast<vtkInteractorStyleImage *>(caller);
128
129       int *size = this->IV->GetRenderWindow()->GetSize();
130       double window = this->InitialWindow;
131       double level = this->InitialLevel;
132       
133       // Compute normalized delta
134
135       double dx = 4.0 * 
136         (isi->GetWindowLevelCurrentPosition()[0] - 
137          isi->GetWindowLevelStartPosition()[0]) / size[0];
138       double dy = 4.0 * 
139         (isi->GetWindowLevelStartPosition()[1] - 
140          isi->GetWindowLevelCurrentPosition()[1]) / size[1];
141       
142       // Scale by current values
143
144       if (fabs(window) > 0.01)
145         {
146         dx = dx * window;
147         }
148       else
149         {
150         dx = dx * (window < 0 ? -0.01 : 0.01);
151         }
152       if (fabs(level) > 0.01)
153         {
154         dy = dy * level;
155         }
156       else
157         {
158         dy = dy * (level < 0 ? -0.01 : 0.01);
159         }
160       
161       // Abs so that direction does not flip
162
163       if (window < 0.0) 
164         {
165         dx = -1*dx;
166         }
167       if (level < 0.0) 
168         {
169         dy = -1*dy;
170         }
171       
172       // Compute new window level
173
174       double newWindow = dx + window;
175       double newLevel;
176       newLevel = level - dy;
177       
178       // Stay away from zero and really
179
180       if (fabs(newWindow) < 0.01)
181         {
182         newWindow = 0.01*(newWindow < 0 ? -1 : 1);
183         }
184       if (fabs(newLevel) < 0.01)
185         {
186         newLevel = 0.01*(newLevel < 0 ? -1 : 1);
187         }
188       
189       this->IV->SetColorWindow(newWindow);
190       this->IV->SetColorLevel(newLevel);
191       this->IV->Render();
192     }
193   
194   vtkImageViewer2 *IV;
195   double InitialWindow;
196   double InitialLevel;
197 };
198
199 //class crea::wxVTKRenderWindowInteractor;
200
201 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
202 public:
203         vtkInteractorStyle2DMaracas();
204         ~vtkInteractorStyle2DMaracas();
205
206         virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
207         static vtkInteractorStyle2DMaracas *New(){
208                                         return new vtkInteractorStyle2DMaracas();
209                                 }
210
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 );
219
220 private:
221         vtkCommand *_obs;
222 };
223
224
225 //-----------------------------------------------------------------------------
226
227
228
229
230 class wxVTKRenderWindowInteractorEditContour : public crea::wxVTKRenderWindowInteractor {
231
232 public:
233
234     wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id); 
235     virtual ~wxVTKRenderWindowInteractorEditContour(); 
236
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);
242
243     void SetState(int state);
244     int  GetState();
245     void SetObserver(vtkCommand *obs);
246
247 private:
248     int        _state;
249     vtkCommand *_obs;
250 };
251
252
253 #endif //_wxVTKRenderWindowInteractorEditContour_h_