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