1 #ifndef _wxVTKRenderWindowInteractorEditContour_h_
2 #define _wxVTKRenderWindowInteractorEditContour_h_
5 #include <wxVTKRenderWindowInteractor.h>
7 #include <vtkCommand.h>
8 #include <vtkImageData.h>
9 //#include <vtkRenderWindow.h>
10 #include <vtkImageViewer2.h>
12 #include <vtkInteractorStyleTrackballCamera.h>
13 #include <vtkInteractorStyleImage.h>
17 //------------------------------------------------------------------------
18 //------------------------------------------------------------------------
19 //------------------------------------------------------------------------
21 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera {
23 vtkInteractorStyle3DMaracas();
24 ~vtkInteractorStyle3DMaracas();
26 virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
27 static vtkInteractorStyle3DMaracas *New(){
28 return new vtkInteractorStyle3DMaracas();
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 () ;
43 //------------------------------------------------------------------------
44 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
48 class vtkMaracasImageViewer2Callback : public vtkCommand
51 vtkMaracasImageViewer2Callback() {} ;
52 ~vtkMaracasImageViewer2Callback() {} ;
53 static vtkMaracasImageViewer2Callback *New() {
54 return new vtkMaracasImageViewer2Callback();
57 virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
59 void Execute(vtkObject *caller,
61 void *vtkNotUsed(callData))
63 if (this->IV->GetInput() == NULL)
70 if (event == vtkCommand::ResetWindowLevelEvent)
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]));
85 if (event == vtkCommand::StartWindowLevelEvent)
87 this->InitialWindow = this->IV->GetColorWindow();
88 this->InitialLevel = this->IV->GetColorLevel();
92 // Adjust the window level here
94 vtkInteractorStyleImage *isi =
95 static_cast<vtkInteractorStyleImage *>(caller);
97 int *size = this->IV->GetRenderWindow()->GetSize();
98 double window = this->InitialWindow;
99 double level = this->InitialLevel;
101 // Compute normalized delta
104 (isi->GetWindowLevelCurrentPosition()[0] -
105 isi->GetWindowLevelStartPosition()[0]) / size[0];
107 (isi->GetWindowLevelStartPosition()[1] -
108 isi->GetWindowLevelCurrentPosition()[1]) / size[1];
110 // Scale by current values
112 if (fabs(window) > 0.01)
118 dx = dx * (window < 0 ? -0.01 : 0.01);
120 if (fabs(level) > 0.01)
126 dy = dy * (level < 0 ? -0.01 : 0.01);
129 // Abs so that direction does not flip
140 // Compute new window level
142 double newWindow = dx + window;
144 newLevel = level - dy;
146 // Stay away from zero and really
148 if (fabs(newWindow) < 0.01)
150 newWindow = 0.01*(newWindow < 0 ? -1 : 1);
152 if (fabs(newLevel) < 0.01)
154 newLevel = 0.01*(newLevel < 0 ? -1 : 1);
157 this->IV->SetColorWindow(newWindow);
158 this->IV->SetColorLevel(newLevel);
163 double InitialWindow;
167 class wxVTKRenderWindowInteractor;
169 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
171 vtkInteractorStyle2DMaracas();
172 ~vtkInteractorStyle2DMaracas();
174 virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
175 static vtkInteractorStyle2DMaracas *New(){
176 return new vtkInteractorStyle2DMaracas();
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 );
193 //-----------------------------------------------------------------------------
198 class wxVTKRenderWindowInteractorEditContour : public wxVTKRenderWindowInteractor {
202 wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id);
203 virtual ~wxVTKRenderWindowInteractorEditContour();
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);
211 void SetState(int state);
213 void SetObserver(vtkCommand *obs);
221 #endif //_wxVTKRenderWindowInteractorEditContour_h_