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>
18 //------------------------------------------------------------------------
19 //------------------------------------------------------------------------
20 //------------------------------------------------------------------------
22 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera {
24 vtkInteractorStyle3DMaracas();
25 ~vtkInteractorStyle3DMaracas();
27 virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
28 static vtkInteractorStyle3DMaracas *New(){
29 return new vtkInteractorStyle3DMaracas();
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 () ;
44 //------------------------------------------------------------------------
45 //------------------------------------------------------------------------
46 //------------------------------------------------------------------------
49 class vtkMaracasImageViewer2Callback : public vtkCommand
52 vtkMaracasImageViewer2Callback() {} ;
53 ~vtkMaracasImageViewer2Callback() {} ;
54 static vtkMaracasImageViewer2Callback *New() {
55 return new vtkMaracasImageViewer2Callback();
58 virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
60 void Execute(vtkObject *caller,
62 void *vtkNotUsed(callData))
64 if (this->IV->GetInput() == NULL)
71 if (event == vtkCommand::ResetWindowLevelEvent)
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]));
86 if (event == vtkCommand::StartWindowLevelEvent)
88 this->InitialWindow = this->IV->GetColorWindow();
89 this->InitialLevel = this->IV->GetColorLevel();
93 // Adjust the window level here
95 vtkInteractorStyleImage *isi =
96 static_cast<vtkInteractorStyleImage *>(caller);
98 int *size = this->IV->GetRenderWindow()->GetSize();
99 double window = this->InitialWindow;
100 double level = this->InitialLevel;
102 // Compute normalized delta
105 (isi->GetWindowLevelCurrentPosition()[0] -
106 isi->GetWindowLevelStartPosition()[0]) / size[0];
108 (isi->GetWindowLevelStartPosition()[1] -
109 isi->GetWindowLevelCurrentPosition()[1]) / size[1];
111 // Scale by current values
113 if (fabs(window) > 0.01)
119 dx = dx * (window < 0 ? -0.01 : 0.01);
121 if (fabs(level) > 0.01)
127 dy = dy * (level < 0 ? -0.01 : 0.01);
130 // Abs so that direction does not flip
141 // Compute new window level
143 double newWindow = dx + window;
145 newLevel = level - dy;
147 // Stay away from zero and really
149 if (fabs(newWindow) < 0.01)
151 newWindow = 0.01*(newWindow < 0 ? -1 : 1);
153 if (fabs(newLevel) < 0.01)
155 newLevel = 0.01*(newLevel < 0 ? -1 : 1);
158 this->IV->SetColorWindow(newWindow);
159 this->IV->SetColorLevel(newLevel);
164 double InitialWindow;
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 ~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_