]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVTKRenderWindowInteractorEditContour.h
8fe719b8804b052c52e31034105a2350e5f9a768
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVTKRenderWindowInteractorEditContour.h
1 #ifndef _wxVTKRenderWindowInteractorEditContour_h_
2 #define _wxVTKRenderWindowInteractorEditContour_h_
3
4
5 #include <wxVTKRenderWindowInteractor.h>
6
7 #include <vtkCommand.h> 
8 #include <vtkImageData.h> 
9 //#include <vtkRenderWindow.h> 
10 #include <vtkImageViewer2.h> 
11
12 #include <vtkInteractorStyleTrackballCamera.h> 
13 #include <vtkInteractorStyleImage.h> 
14
15
16
17 //------------------------------------------------------------------------
18 //------------------------------------------------------------------------
19 //------------------------------------------------------------------------
20
21 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera    {
22 public:
23         vtkInteractorStyle3DMaracas();
24         ~vtkInteractorStyle3DMaracas();
25
26         virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
27         static vtkInteractorStyle3DMaracas *New(){
28                                         return new vtkInteractorStyle3DMaracas();
29                                 }
30
31         virtual void  OnMouseMove () ;
32         virtual void  OnLeftButtonDown (); 
33         virtual void  OnLeftButtonUp () ;
34         virtual void  OnMiddleButtonDown (); 
35         virtual void  OnMiddleButtonUp () ;
36         virtual void  OnRightButtonDown () ;
37         virtual void  OnRightButtonUp () ;
38
39 private:
40
41 };
42
43 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
46
47
48 class vtkMaracasImageViewer2Callback : public vtkCommand
49 {
50 public:
51   vtkMaracasImageViewer2Callback() {} ;
52   ~vtkMaracasImageViewer2Callback() {} ;
53   static vtkMaracasImageViewer2Callback *New() {
54      return new vtkMaracasImageViewer2Callback(); 
55   }
56
57   virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
58   
59   void Execute(vtkObject *caller, 
60                unsigned long event, 
61                void *vtkNotUsed(callData))
62     {
63       if (this->IV->GetInput() == NULL)
64         {
65         return;
66         }
67
68       // Reset
69
70       if (event == vtkCommand::ResetWindowLevelEvent)
71         {
72         this->IV->GetInput()->UpdateInformation();
73         this->IV->GetInput()->SetUpdateExtent
74           (this->IV->GetInput()->GetWholeExtent());
75         this->IV->GetInput()->Update();
76         double *range = this->IV->GetInput()->GetScalarRange();
77         this->IV->SetColorWindow(range[1] - range[0]);
78         this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
79         this->IV->Render();
80         return;
81         }
82
83       // Start
84
85       if (event == vtkCommand::StartWindowLevelEvent)
86         {
87         this->InitialWindow = this->IV->GetColorWindow();
88         this->InitialLevel = this->IV->GetColorLevel();
89         return;
90         }
91       
92       // Adjust the window level here
93
94       vtkInteractorStyleImage *isi = 
95         static_cast<vtkInteractorStyleImage *>(caller);
96
97       int *size = this->IV->GetRenderWindow()->GetSize();
98       double window = this->InitialWindow;
99       double level = this->InitialLevel;
100       
101       // Compute normalized delta
102
103       double dx = 4.0 * 
104         (isi->GetWindowLevelCurrentPosition()[0] - 
105          isi->GetWindowLevelStartPosition()[0]) / size[0];
106       double dy = 4.0 * 
107         (isi->GetWindowLevelStartPosition()[1] - 
108          isi->GetWindowLevelCurrentPosition()[1]) / size[1];
109       
110       // Scale by current values
111
112       if (fabs(window) > 0.01)
113         {
114         dx = dx * window;
115         }
116       else
117         {
118         dx = dx * (window < 0 ? -0.01 : 0.01);
119         }
120       if (fabs(level) > 0.01)
121         {
122         dy = dy * level;
123         }
124       else
125         {
126         dy = dy * (level < 0 ? -0.01 : 0.01);
127         }
128       
129       // Abs so that direction does not flip
130
131       if (window < 0.0) 
132         {
133         dx = -1*dx;
134         }
135       if (level < 0.0) 
136         {
137         dy = -1*dy;
138         }
139       
140       // Compute new window level
141
142       double newWindow = dx + window;
143       double newLevel;
144       newLevel = level - dy;
145       
146       // Stay away from zero and really
147
148       if (fabs(newWindow) < 0.01)
149         {
150         newWindow = 0.01*(newWindow < 0 ? -1 : 1);
151         }
152       if (fabs(newLevel) < 0.01)
153         {
154         newLevel = 0.01*(newLevel < 0 ? -1 : 1);
155         }
156       
157       this->IV->SetColorWindow(newWindow);
158       this->IV->SetColorLevel(newLevel);
159       this->IV->Render();
160     }
161   
162   vtkImageViewer2 *IV;
163   double InitialWindow;
164   double InitialLevel;
165 };
166
167 class wxVTKRenderWindowInteractor;
168
169 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
170 public:
171         vtkInteractorStyle2DMaracas();
172         ~vtkInteractorStyle2DMaracas();
173
174         virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
175         static vtkInteractorStyle2DMaracas *New(){
176                                         return new vtkInteractorStyle2DMaracas();
177                                 }
178
179         virtual void  OnMouseMove () ;
180         virtual void  OnLeftButtonDown (); 
181         virtual void  OnLeftButtonUp () ;
182         virtual void  OnMiddleButtonDown (); 
183         virtual void  OnMiddleButtonUp () ;
184         virtual void  OnRightButtonDown () ;
185         virtual void  OnRightButtonUp () ;
186         void  SetObserver( vtkCommand *obs );
187
188 private:
189         vtkCommand *_obs;
190 };
191
192
193 //-----------------------------------------------------------------------------
194
195
196
197
198 class wxVTKRenderWindowInteractorEditContour : public wxVTKRenderWindowInteractor {
199
200 public:
201
202     wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id); 
203     virtual ~wxVTKRenderWindowInteractorEditContour(); 
204
205     virtual void OnButtonDown(wxMouseEvent &event);
206     virtual void OnButtonUp(wxMouseEvent &event);
207     virtual void OnButtonDouble(wxMouseEvent &event);
208     virtual void OnMotion(wxMouseEvent &event);
209     virtual void OnKeyDown(wxKeyEvent &event);
210
211     void SetState(int state);
212     int  GetState();
213     void SetObserver(vtkCommand *obs);
214
215 private:
216     int        _state;
217     vtkCommand *_obs;
218 };
219
220
221 #endif //_wxVTKRenderWindowInteractorEditContour_h_