]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRBaseData.cxx
Merge branch 'master' of ssh://git.creatis.insa-lyon.fr/creaMaracasVisu
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMPRBaseData.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
28 #include <vtkPlanes.h>
29 #include <vtkProperty.h> 
30 #include <vtkPolyData.h> 
31 #include <vtkDataSet.h> 
32 #include <vtkCellArray.h>
33 #include <vtkTransform.h>
34 #include <vtkTransformFilter.h>
35 #include <vtkDataSetReader.h>
36
37 #include "wxMPRBaseData.h"
38 #include "pPlotter/HistogramDialog.h"
39
40
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #endif
44 //-------------------------------------------------------------------
45 //-------------------------------------------------------------------
46 //-------------------------------------------------------------------
47
48
49 //-------------------------------------------------------------------
50 //-------------------------------------------------------------------
51 //-------------------------------------------------------------------
52 vtkMPRBaseData::vtkMPRBaseData()
53 {
54   _x=0;
55   _y=0;
56   _z=0;
57   _x1 = 0;
58   _x2 = 0;
59   _y1 = 0;
60   _y2 = 0;
61   _z1 = 0;
62   _z2 = 0;
63   _transformOrientation = NULL;
64   _marImageData = NULL;
65 }
66
67 //-------------------------------------------------------------------
68 vtkMPRBaseData::~vtkMPRBaseData()
69 {
70         if (_marImageData)                      delete _marImageData;
71         if (_transformOrientation)      _transformOrientation ->Delete();
72 }
73
74 //-------------------------------------------------------------------
75 void vtkMPRBaseData::Configure()
76 {
77         //EED 03nov2012
78         vtkBaseData::Configure();
79         
80         vtkImageData* img = _marImageData->GetImageData();
81         if(img !=NULL)
82         {
83                 img->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2);
84         //std::cout<<"vtkMPRBaseData::Configure() _x1= "<<_x1<<" _x2= "<<_x2<<" _y1= "<<_y1<<" _y2= "<<_y2<<" _z1= "<<_z1<<" _z2= "<<_z2<<std::endl;            
85         }
86         
87         if(_transformOrientation==NULL)
88         {
89                 _transformOrientation=vtkTransform::New();
90         }
91         
92         _transformOrientation->Identity();
93 }
94
95 //-------------------------------------------------------------------
96 void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2)
97 {
98         *x1=_x1;
99         *x2=_x2;
100         *y1=_y1;
101         *y2=_y2;
102         *z1=_z1;
103         *z2=_z2;
104 }
105
106
107 //------------------------------------------------------------------------
108 int vtkMPRBaseData::GetMaxPositionX( )
109 {
110         return _x2;
111 }
112 //------------------------------------------------------------------------
113 int vtkMPRBaseData::GetMaxPositionY( )
114 {
115         return _y2;
116 }
117 //------------------------------------------------------------------------
118 int vtkMPRBaseData::GetMaxPositionZ( )
119 {
120         return _z2;
121 }
122 //-------------------------------------------------------------------
123 double vtkMPRBaseData::GetX()
124 {
125
126         return _x;
127 }
128 //-------------------------------------------------------------------
129 double  vtkMPRBaseData::GetY()
130 {
131         return _y;
132 }
133 //-------------------------------------------------------------------
134 /**
135 **      Calculates the value of the slider and the layer in the image that is spouse to show
136 **/
137 void vtkMPRBaseData::SetX(double x)
138 {
139         //int dim[3];
140         int ext[6];
141         double* origin;
142         vtkImageData* img = _marImageData->GetImageData();
143         if(img!=NULL){
144                 /*img->GetDimensions(dim);
145                 if (x<0)
146                 {
147                         x=0;
148                 }
149                 if (x>=dim[0])
150                 {
151                         x=dim[0]-1;
152                 }
153                 _x=x;*/
154                 img->GetExtent(ext);
155                 origin = img->GetOrigin();
156                 if (x < ext[0])
157                 {
158                         x=ext[0] + origin[0];
159                 }
160                 if (x > ext[1])
161                 {
162                         x=ext[1] + origin[0];
163                 }
164                 
165                 _x=x;
166                 _observable->InvokeEvent(1);    
167         }
168 }
169 //-------------------------------------------------------------------
170 /**
171 **      Calculates the value of the slider and the layer in the image that is spouse to show
172 **/
173 void vtkMPRBaseData::SetY(double y)
174 {
175         //int dim[3];
176         int ext[6];
177         double* origin;
178         vtkImageData* img = _marImageData->GetImageData();
179         if(img!=NULL){
180                 /*img->GetDimensions(dim);
181                 if (y<0)
182                 {
183                         y=0;
184                 }
185                 if (y>=dim[1])
186                 {
187                         y=dim[1]-1;
188                 }
189                 _y=y;*/
190                 img->GetExtent(ext);
191                 origin = img->GetOrigin();
192                 if (y<ext[2])
193                 {
194                         y=ext[2] + origin[1];
195                 }
196                 if (y > ext[3])
197                 {
198                         y=ext[3] + origin[1];
199                 }
200                 _y=y;
201                 _observable->InvokeEvent(2);    
202         }
203 }
204 //-------------------------------------------------------------------
205 vtkTransform *vtkMPRBaseData::GetTransformOrientation()
206 {       
207         return _transformOrientation; 
208 }
209 //-------------------------------------------------------------------
210 void vtkMPRBaseData::SetNormal(double nx, double ny, double nz)
211 {
212         double alfa = atan2(ny,nx) * 180.0 / 3.1416;
213         double beta = atan2( nz, sqrt( nx*nx + ny*ny )  ) * 180.0 / 3.1416;
214         _transformOrientation->Identity();              
215         _transformOrientation->RotateWXYZ(alfa,0,0,1);
216         _transformOrientation->RotateWXYZ(-beta,0,1,0);
217 }
218 //-------------------------------------------------------------------
219 void vtkMPRBaseData::InitTransformOrientation(vtkTransform *trans)
220 {
221         _transformOrientation->SetMatrix( trans->GetMatrix() );
222 }
223
224
225
226 //-------------------------------------------------------------------
227 //-------------------------------------------------------------------
228 //-------------------------------------------------------------------
229