]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualInteractorWindowLevel.cxx
#3155 creaMaracasVisu Feature New Normal - ViewerPlane ComplexBox
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualInteractorWindowLevel.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 #include "manualInteractorWindowLevel.h"
28 #include "wxVtk2DBaseView.h"
29 //-------------------------------------------------------------------
30 //-------------------------------------------------------------------
31 //-------------------------------------------------------------------
32
33 manualInteractorWindowLevel::manualInteractorWindowLevel()
34 {
35         _stateWindowLevel       =       false;
36         _backPx                         =       0;
37         _backPy                         =       0;
38         _backWindow                     =       -1;
39         _backLevel                      =       -1;
40 }
41
42 //-------------------------------------------------------------------
43
44 manualInteractorWindowLevel::~manualInteractorWindowLevel()
45 {
46 }
47
48 //-------------------------------------------------------------------
49
50 bool manualInteractorWindowLevel::OnMouseMove()                 // virtual 
51 {
52         if (_stateWindowLevel==true)
53         {
54                 int tmpPx,tmpPy;
55                 wxVTKRenderWindowInteractor *wxVTKiren;
56                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
57                 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
58                 double colorWin;
59                 double colorLev;
60                 vtkImageData* imgrange = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->GetVtkBaseData()->GetImageData();
61                 if(imgrange != NULL)
62                 {
63                         double* scalarrange = imgrange->GetScalarRange();
64                         double scalarr;
65                         if (scalarrange[1] == scalarrange[0])
66                         {
67                                 scalarr=scalarrange[1];
68                                 if (scalarrange[1]==0) {scalarr=100;}
69                         } else {
70                                 scalarr = scalarrange[1] - scalarrange[0];
71                         }
72                         //std::cout<<"scalar r="<<scalarr<<std::endl;
73                         int w, h;
74                         ((wxWindow*)wxVTKiren)->GetSize(&w, &h);                        
75                         double dw=w,dh=h;
76                         double dx = (scalarr*( _backPx - tmpPx ))/dw;
77                         double dy = (scalarr*( _backPy - tmpPy ))/dh;
78                         //colorWin=_backWindow - (scalarr)*( _backPx - tmpPx );
79                         colorWin=_backWindow - dx;
80                         colorLev=_backLevel  + dy;
81                 } else {
82                         colorWin=_backWindow - 2*( _backPx - tmpPx );
83                         colorLev=_backLevel  + 2*( _backPy - tmpPy );
84                 }
85                 if (colorWin<0)
86                 { 
87                         colorWin=0;
88                 }
89                 if (colorWin>100000)
90                 { 
91                         colorWin=100000;
92                 }       
93 //EED 2 Nov 2012  This lets see negative values with the interaction of Window-Level Color
94 //              if (colorLev<0)
95 //              { 
96 //                      colorLev=0;
97 //              }       
98                 if (colorLev>100000)
99                 { 
100                         colorLev=100000;
101                 }
102                 wxVtk2DBaseView *wxvtk2Dbaseview        = (wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
103                 vtkBaseData *vtkbasedata                        = wxvtk2Dbaseview->GetVtkBaseData();
104 //EED Borrame
105 //              vtkImageViewer2 *vtkimageviewer2        = wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();              
106 //              vtkimageviewer2->SetColorWindow(colorWin);
107 //              vtkimageviewer2->SetColorLevel(colorLev);
108                 vtkbasedata->SetColorWindow(colorWin);
109                 vtkbasedata->SetColorLevel(colorLev);           
110                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
111 //              vtkimageviewer2->Render();
112         }
113         return true;
114 }
115
116 //-------------------------------------------------------------------
117
118 bool manualInteractorWindowLevel::OnMiddleButtonDown()  // virtual 
119 {
120         if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
121                 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ){
122                 _stateWindowLevel       = true;
123                 wxVTKRenderWindowInteractor *wxVTKiren;
124                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
125                 wxVTKiren->GetEventPosition( _backPx , _backPy );
126                 _backWindow = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorWindow();
127                 _backLevel  = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorLevel();
128         }
129         return true;
130 }
131
132 //-------------------------------------------------------------------
133
134 bool manualInteractorWindowLevel::OnMiddleButtonUp()            // virtual
135 {
136         if (_stateWindowLevel==true)
137         {
138                 _stateWindowLevel=false;
139         }
140         return true;
141 }