]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVTKRenderWindowInteractorEditContour.h
virtual desctructors
[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
22 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera    {
23 public:
24         vtkInteractorStyle3DMaracas();
25         ~vtkInteractorStyle3DMaracas();
26
27         virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
28         static vtkInteractorStyle3DMaracas *New(){
29                                         return new vtkInteractorStyle3DMaracas();
30                                 }
31
32         virtual void  OnMouseMove () ;
33         virtual void  OnLeftButtonDown (); 
34         virtual void  OnLeftButtonUp () ;
35         virtual void  OnMiddleButtonDown (); 
36         virtual void  OnMiddleButtonUp () ;
37         virtual void  OnRightButtonDown () ;
38         virtual void  OnRightButtonUp () ;
39
40 private:
41
42 };
43
44 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
47
48
49 class vtkMaracasImageViewer2Callback : public vtkCommand
50 {
51 public:
52   vtkMaracasImageViewer2Callback() {} ;
53   ~vtkMaracasImageViewer2Callback() {} ;
54   static vtkMaracasImageViewer2Callback *New() {
55      return new vtkMaracasImageViewer2Callback(); 
56   }
57
58   virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
59   
60   void Execute(vtkObject *caller, 
61                unsigned long event, 
62                void *vtkNotUsed(callData))
63     {
64       if (this->IV->GetInput() == NULL)
65         {
66         return;
67         }
68
69       // Reset
70
71       if (event == vtkCommand::ResetWindowLevelEvent)
72         {
73         this->IV->GetInput()->UpdateInformation();
74         this->IV->GetInput()->SetUpdateExtent
75           (this->IV->GetInput()->GetWholeExtent());
76         this->IV->GetInput()->Update();
77         double *range = this->IV->GetInput()->GetScalarRange();
78         this->IV->SetColorWindow(range[1] - range[0]);
79         this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
80         this->IV->Render();
81         return;
82         }
83
84       // Start
85
86       if (event == vtkCommand::StartWindowLevelEvent)
87         {
88         this->InitialWindow = this->IV->GetColorWindow();
89         this->InitialLevel = this->IV->GetColorLevel();
90         return;
91         }
92       
93       // Adjust the window level here
94
95       vtkInteractorStyleImage *isi = 
96         static_cast<vtkInteractorStyleImage *>(caller);
97
98       int *size = this->IV->GetRenderWindow()->GetSize();
99       double window = this->InitialWindow;
100       double level = this->InitialLevel;
101       
102       // Compute normalized delta
103
104       double dx = 4.0 * 
105         (isi->GetWindowLevelCurrentPosition()[0] - 
106          isi->GetWindowLevelStartPosition()[0]) / size[0];
107       double dy = 4.0 * 
108         (isi->GetWindowLevelStartPosition()[1] - 
109          isi->GetWindowLevelCurrentPosition()[1]) / size[1];
110       
111       // Scale by current values
112
113       if (fabs(window) > 0.01)
114         {
115         dx = dx * window;
116         }
117       else
118         {
119         dx = dx * (window < 0 ? -0.01 : 0.01);
120         }
121       if (fabs(level) > 0.01)
122         {
123         dy = dy * level;
124         }
125       else
126         {
127         dy = dy * (level < 0 ? -0.01 : 0.01);
128         }
129       
130       // Abs so that direction does not flip
131
132       if (window < 0.0) 
133         {
134         dx = -1*dx;
135         }
136       if (level < 0.0) 
137         {
138         dy = -1*dy;
139         }
140       
141       // Compute new window level
142
143       double newWindow = dx + window;
144       double newLevel;
145       newLevel = level - dy;
146       
147       // Stay away from zero and really
148
149       if (fabs(newWindow) < 0.01)
150         {
151         newWindow = 0.01*(newWindow < 0 ? -1 : 1);
152         }
153       if (fabs(newLevel) < 0.01)
154         {
155         newLevel = 0.01*(newLevel < 0 ? -1 : 1);
156         }
157       
158       this->IV->SetColorWindow(newWindow);
159       this->IV->SetColorLevel(newLevel);
160       this->IV->Render();
161     }
162   
163   vtkImageViewer2 *IV;
164   double InitialWindow;
165   double InitialLevel;
166 };
167
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         ~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_