]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualInteractorWindowLevel.cxx
48b3a4ddeea7463afcb6af56b8256a1a242970ef
[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
53 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
54 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
55 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
56 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
57 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
58 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
59 printf("EED Warning manualInteractorWindowLevel::OnMouseMove    Clean this put in a specific class for camera Interaction ....\n");
60
61 // EED Mising in the wheal event  and the ctrl+MouseRight Event
62         wxVtk2DBaseView *wxvtk2Dbaseview        = (wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
63         vtkBaseData *vtkbasedata                        = wxvtk2Dbaseview->GetVtkBaseData();
64         double parallelscaling=wxvtk2Dbaseview->GetRenderer()->GetActiveCamera()->GetParallelScale();
65         vtkbasedata->SetCameraParallelScale( parallelscaling );
66         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
67 //-----------------
68
69
70         if (_stateWindowLevel==true)
71         {
72                 int tmpPx,tmpPy;
73                 crea::wxVTKRenderWindowInteractor *wxVTKiren;
74                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
75                 wxVTKiren->GetEventPosition( tmpPx , tmpPy );
76                 double colorWin;
77                 double colorLev;
78                 vtkImageData* imgrange = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->GetVtkBaseData()->GetImageData();
79                 if(imgrange != NULL)
80                 {
81                         double* scalarrange = imgrange->GetScalarRange();
82                         double scalarr;
83                         if (scalarrange[1] == scalarrange[0])
84                         {
85                                 scalarr=scalarrange[1];
86                                 if (scalarrange[1]==0) {scalarr=100;}
87                         } else {
88                                 scalarr = scalarrange[1] - scalarrange[0];
89                         }
90                         //std::cout<<"scalar r="<<scalarr<<std::endl;
91                         int w, h;
92                         ((wxWindow*)wxVTKiren)->GetSize(&w, &h);                        
93                         double dw=w,dh=h;
94                         double dx = (scalarr*( _backPx - tmpPx ))/dw;
95                         double dy = (scalarr*( _backPy - tmpPy ))/dh;
96                         //colorWin=_backWindow - (scalarr)*( _backPx - tmpPx );
97                         colorWin=_backWindow - dx;
98                         colorLev=_backLevel  + dy;
99                 } else {
100                         colorWin=_backWindow - 2*( _backPx - tmpPx );
101                         colorLev=_backLevel  + 2*( _backPy - tmpPy );
102                 }
103                 if (colorWin<0)
104                 { 
105                         colorWin=0;
106                 }
107                 if (colorWin>100000)
108                 { 
109                         colorWin=100000;
110                 }       
111 //EED 2 Nov 2012  This lets see negative values with the interaction of Window-Level Color
112 //              if (colorLev<0)
113 //              { 
114 //                      colorLev=0;
115 //              }       
116                 if (colorLev>100000)
117                 { 
118                         colorLev=100000;
119                 }
120                 wxVtk2DBaseView *wxvtk2Dbaseview        = (wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
121                 vtkBaseData *vtkbasedata                        = wxvtk2Dbaseview->GetVtkBaseData();
122 //EED Borrame
123 //              vtkImageViewer2 *vtkimageviewer2        = wxvtk2Dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();              
124 //              vtkimageviewer2->SetColorWindow(colorWin);
125 //              vtkimageviewer2->SetColorLevel(colorLev);
126                 vtkbasedata->SetColorWindow(colorWin);
127                 vtkbasedata->SetColorLevel(colorLev);           
128                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
129 //              vtkimageviewer2->Render();
130         }
131         return true;
132 }
133
134 //-------------------------------------------------------------------
135
136 bool manualInteractorWindowLevel::OnMiddleButtonDown()  // virtual 
137 {
138         if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
139                 (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ){
140                 _stateWindowLevel       = true;
141                 crea::wxVTKRenderWindowInteractor *wxVTKiren;
142                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
143                 wxVTKiren->GetEventPosition( _backPx , _backPy );
144                 _backWindow = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorWindow();
145                 _backLevel  = ((wxVtk2DBaseView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView())->_imageViewer2XYZ->GetVtkImageViewer2()->GetColorLevel();
146         }
147         return true;
148 }
149
150 //-------------------------------------------------------------------
151
152 bool manualInteractorWindowLevel::OnMiddleButtonUp()            // virtual
153 {
154         if (_stateWindowLevel==true)
155         {
156                 _stateWindowLevel=false;
157         }
158         return true;
159 }