]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualInteractorWindowLevel.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualInteractorWindowLevel.cxx
1
2 #include "manualInteractorWindowLevel.h"
3 #include "wxVtk2DBaseView.h"
4 //-------------------------------------------------------------------
5 //-------------------------------------------------------------------
6 //-------------------------------------------------------------------
7
8 manualInteractorWindowLevel::manualInteractorWindowLevel()
9 {
10         _stateWindowLevel       =       false;
11         _backPx                         =       0;
12         _backPy                         =       0;
13         _backWindow                     =       -1;
14         _backLevel                      =       -1;
15 }
16
17 //-------------------------------------------------------------------
18
19 manualInteractorWindowLevel::~manualInteractorWindowLevel()
20 {
21 }
22
23 //-------------------------------------------------------------------
24
25 bool manualInteractorWindowLevel::OnMouseMove()                 // virtual 
26 {
27
28         if (_stateWindowLevel==true)
29         {
30                 int tmpPx,tmpPy;
31                 wxVTKRenderWindowInteractor *wxVTKiren;
32                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
33                 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
34
35                 double colorWin;
36                 double colorLev;
37                 
38                 vtkImageData* imgrange = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->GetVtkBaseData()->GetImageData();
39
40                 if(imgrange != NULL){
41                         double* scalarrange = imgrange->GetScalarRange();
42                         double scalarr = scalarrange[1] - scalarrange[0];
43                         //std::cout<<"scalar r="<<scalarr<<std::endl;
44                         int w, h;
45                         ((wxWindow*)wxVTKiren)->GetSize(&w, &h);                        
46
47                         double dw=w,dh=h;
48                         double dx = (scalarr*( _backPx - tmpPx ))/dw;
49                         double dy = (scalarr*( _backPy - tmpPy ))/dh;
50
51                         //colorWin=_backWindow - (scalarr)*( _backPx - tmpPx );
52                         colorWin=_backWindow - dx;
53                         colorLev=_backLevel  + dy;
54                 }else{
55                         colorWin=_backWindow - 2*( _backPx - tmpPx );
56                         colorLev=_backLevel  + 2*( _backPy - tmpPy );
57                 }
58
59                 if (colorWin<0)
60                 { 
61                         colorWin=0;
62                 }
63                 if (colorWin>100000)
64                 { 
65                         colorWin=100000;
66                 }       
67
68                 if (colorLev<0)
69                 { 
70                         colorLev=0;
71                 }
72                 if (colorLev>100000)
73                 { 
74                         colorLev=100000;
75                 }
76                 vtkImageViewer2 *vtkimageviewer2;
77                 vtkimageviewer2=((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2();
78                 vtkimageviewer2->SetColorWindow(colorWin);
79                 vtkimageviewer2->SetColorLevel(colorLev);
80 //              vtkimageviewer2->Render();
81         }
82         return true;
83 }
84
85 //-------------------------------------------------------------------
86
87 bool manualInteractorWindowLevel::OnMiddleButtonDown()  // virtual 
88 {
89         if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
90                 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ){
91                 _stateWindowLevel       = true;
92                 wxVTKRenderWindowInteractor *wxVTKiren;
93                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
94                 wxVTKiren->GetEventPosition( _backPx , _backPy );
95                 _backWindow = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorWindow();
96                 _backLevel  = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorLevel();
97         }
98         return true;
99 }
100
101 //-------------------------------------------------------------------
102
103 bool manualInteractorWindowLevel::OnMiddleButtonUp()            // virtual
104 {
105         if (_stateWindowLevel==true)
106         {
107                 _stateWindowLevel=false;
108         }
109         return true;
110 }