wxVTKRenderWindowInteractorEditContour.h

Go to the documentation of this file.
00001 #ifndef _wxVTKRenderWindowInteractorEditContour_h_
00002 #define _wxVTKRenderWindowInteractorEditContour_h_
00003 
00004 
00005 #include <wxVTKRenderWindowInteractor.h>
00006 
00007 #include <vtkCommand.h> 
00008 #include <vtkImageData.h> 
00009 //#include <vtkRenderWindow.h> 
00010 #include <vtkImageViewer2.h> 
00011 
00012 #include <vtkInteractorStyleTrackballCamera.h> 
00013 #include <vtkInteractorStyleImage.h> 
00014 
00015 
00016 
00017 //------------------------------------------------------------------------
00018 //------------------------------------------------------------------------
00019 //------------------------------------------------------------------------
00020 
00021 class vtkInteractorStyle3DMaracas : public vtkInteractorStyleTrackballCamera    {
00022 public:
00023         vtkInteractorStyle3DMaracas();
00024         ~vtkInteractorStyle3DMaracas();
00025 
00026         virtual char const *GetClassName() const { return "vtkInteractorStyle3DMaracas";}
00027         static vtkInteractorStyle3DMaracas *New(){
00028                                         return new vtkInteractorStyle3DMaracas();
00029                                 }
00030 
00031         virtual void  OnMouseMove () ;
00032         virtual void  OnLeftButtonDown (); 
00033         virtual void  OnLeftButtonUp () ;
00034         virtual void  OnMiddleButtonDown (); 
00035         virtual void  OnMiddleButtonUp () ;
00036         virtual void  OnRightButtonDown () ;
00037         virtual void  OnRightButtonUp () ;
00038 
00039 private:
00040 
00041 };
00042 
00043 //------------------------------------------------------------------------
00044 //------------------------------------------------------------------------
00045 //------------------------------------------------------------------------
00046 
00047 
00048 class vtkMaracasImageViewer2Callback : public vtkCommand
00049 {
00050 public:
00051   vtkMaracasImageViewer2Callback() {} ;
00052   ~vtkMaracasImageViewer2Callback() {} ;
00053   static vtkMaracasImageViewer2Callback *New() {
00054      return new vtkMaracasImageViewer2Callback(); 
00055   }
00056 
00057   virtual char const *GetClassName() const { return "vtkMaracasImageViewer2Callback";}
00058   
00059   void Execute(vtkObject *caller, 
00060                unsigned long event, 
00061                void *vtkNotUsed(callData))
00062     {
00063       if (this->IV->GetInput() == NULL)
00064         {
00065         return;
00066         }
00067 
00068       // Reset
00069 
00070       if (event == vtkCommand::ResetWindowLevelEvent)
00071         {
00072         this->IV->GetInput()->UpdateInformation();
00073         this->IV->GetInput()->SetUpdateExtent
00074           (this->IV->GetInput()->GetWholeExtent());
00075         this->IV->GetInput()->Update();
00076         double *range = this->IV->GetInput()->GetScalarRange();
00077         this->IV->SetColorWindow(range[1] - range[0]);
00078         this->IV->SetColorLevel(0.5 * (range[1] + range[0]));
00079         this->IV->Render();
00080         return;
00081         }
00082 
00083       // Start
00084 
00085       if (event == vtkCommand::StartWindowLevelEvent)
00086         {
00087         this->InitialWindow = this->IV->GetColorWindow();
00088         this->InitialLevel = this->IV->GetColorLevel();
00089         return;
00090         }
00091       
00092       // Adjust the window level here
00093 
00094       vtkInteractorStyleImage *isi = 
00095         static_cast<vtkInteractorStyleImage *>(caller);
00096 
00097       int *size = this->IV->GetRenderWindow()->GetSize();
00098       double window = this->InitialWindow;
00099       double level = this->InitialLevel;
00100       
00101       // Compute normalized delta
00102 
00103       double dx = 4.0 * 
00104         (isi->GetWindowLevelCurrentPosition()[0] - 
00105          isi->GetWindowLevelStartPosition()[0]) / size[0];
00106       double dy = 4.0 * 
00107         (isi->GetWindowLevelStartPosition()[1] - 
00108          isi->GetWindowLevelCurrentPosition()[1]) / size[1];
00109       
00110       // Scale by current values
00111 
00112       if (fabs(window) > 0.01)
00113         {
00114         dx = dx * window;
00115         }
00116       else
00117         {
00118         dx = dx * (window < 0 ? -0.01 : 0.01);
00119         }
00120       if (fabs(level) > 0.01)
00121         {
00122         dy = dy * level;
00123         }
00124       else
00125         {
00126         dy = dy * (level < 0 ? -0.01 : 0.01);
00127         }
00128       
00129       // Abs so that direction does not flip
00130 
00131       if (window < 0.0) 
00132         {
00133         dx = -1*dx;
00134         }
00135       if (level < 0.0) 
00136         {
00137         dy = -1*dy;
00138         }
00139       
00140       // Compute new window level
00141 
00142       double newWindow = dx + window;
00143       double newLevel;
00144       newLevel = level - dy;
00145       
00146       // Stay away from zero and really
00147 
00148       if (fabs(newWindow) < 0.01)
00149         {
00150         newWindow = 0.01*(newWindow < 0 ? -1 : 1);
00151         }
00152       if (fabs(newLevel) < 0.01)
00153         {
00154         newLevel = 0.01*(newLevel < 0 ? -1 : 1);
00155         }
00156       
00157       this->IV->SetColorWindow(newWindow);
00158       this->IV->SetColorLevel(newLevel);
00159       this->IV->Render();
00160     }
00161   
00162   vtkImageViewer2 *IV;
00163   double InitialWindow;
00164   double InitialLevel;
00165 };
00166 
00167 class wxVTKRenderWindowInteractor;
00168 
00169 class vtkInteractorStyle2DMaracas : public vtkInteractorStyleImage{
00170 public:
00171         vtkInteractorStyle2DMaracas();
00172         ~vtkInteractorStyle2DMaracas();
00173 
00174         virtual char const *GetClassName() const { return "vtkInteractorStyle2DMaracas";}
00175         static vtkInteractorStyle2DMaracas *New(){
00176                                         return new vtkInteractorStyle2DMaracas();
00177                                 }
00178 
00179         virtual void  OnMouseMove () ;
00180         virtual void  OnLeftButtonDown (); 
00181         virtual void  OnLeftButtonUp () ;
00182         virtual void  OnMiddleButtonDown (); 
00183         virtual void  OnMiddleButtonUp () ;
00184         virtual void  OnRightButtonDown () ;
00185         virtual void  OnRightButtonUp () ;
00186         void  SetObserver( vtkCommand *obs );
00187 
00188 private:
00189         vtkCommand *_obs;
00190 };
00191 
00192 
00193 //-----------------------------------------------------------------------------
00194 
00195 
00196 
00197 
00198 class wxVTKRenderWindowInteractorEditContour : public wxVTKRenderWindowInteractor {
00199 
00200 public:
00201 
00202     wxVTKRenderWindowInteractorEditContour(wxWindow *parent,wxWindowID id); 
00203     virtual ~wxVTKRenderWindowInteractorEditContour(); 
00204 
00205     virtual void OnButtonDown(wxMouseEvent &event);
00206     virtual void OnButtonUp(wxMouseEvent &event);
00207     virtual void OnButtonDouble(wxMouseEvent &event);
00208     virtual void OnMotion(wxMouseEvent &event);
00209     virtual void OnKeyDown(wxKeyEvent &event);
00210 
00211     void SetState(int state);
00212     int  GetState();
00213     void SetObserver(vtkCommand *obs);
00214 
00215 private:
00216     int        _state;
00217     vtkCommand *_obs;
00218 };
00219 
00220 
00221 #endif //_wxVTKRenderWindowInteractorEditContour_h_

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1