]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
07c0ec1d1274530fcc15cc1ecedf00f33c688859
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkMPR3DDataViewer.cxx
1
2 #include "vtkMPR3DDataViewer.h"
3
4
5 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
6 {
7         _visiblePosition[0]=false;
8         _visiblePosition[1]=false;
9         _visiblePosition[2]=false;
10         _ctfun = NULL;
11         _vtkmprbasedata=NULL;
12
13         _ctfun=NULL;
14         _saggitalColors=NULL;
15         _saggital=NULL;
16         _axialColors=NULL;
17         _axial=NULL;
18         _coronalColors=NULL;
19         _coronal=NULL;
20         _mapOutline=NULL;
21         _outline=NULL;
22         _outlineData=NULL;
23 }
24 //-------------------------------------------------------------------
25 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
26 {
27         _outlineData-> Delete();
28         _mapOutline-> Delete();
29         _outline-> Delete();
30
31 //      if (_bwLut)             _bwLut->Delete();
32 //      if (_hueLut)            _hueLut->Delete();
33 //      if (_satLut)            _satLut->Delete();
34         if (_ctfun)             _ctfun->Delete();
35         if (_saggitalColors)    _saggitalColors ->Delete();
36         if (_saggital)          _saggital->Delete();
37         if (_axialColors)       _axialColors->Delete();
38         if (_axial)             _axial->Delete();
39         if (_coronalColors)     _coronalColors->Delete();
40         if (_coronal)           _coronal->Delete();
41
42 }
43 //-------------------------------------------------------------------
44 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
45 {
46         return _outline;
47 }
48 //-------------------------------------------------------------------
49 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
50 {
51         vtkImageActor *tmpVtkActor=NULL;
52         if (id==0){
53                 tmpVtkActor = GetvtkActor_saggital();
54         }
55         if (id==1){
56                 tmpVtkActor = GetvtkActor_coronal();
57         }
58         if (id==2){
59                 tmpVtkActor = GetvtkActor_axial();
60         }
61         return tmpVtkActor;
62 }
63 //-------------------------------------------------------------------
64 void vtkMPR3DDataViewer::Refresh()
65 {
66         int x = (int)(_vtkmprbasedata->GetX());
67         int y = (int)(_vtkmprbasedata->GetY());
68         int z = (int)(_vtkmprbasedata->GetZ());
69         SetPositionX( x );
70         SetPositionY( y );
71         SetPositionZ( z );
72 }
73 //-------------------------------------------------------------------
74 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
75 {
76         _vtkmprbasedata=vtkmprbasedata;
77 }
78 //-------------------------------------------------------------------
79 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
80 {
81         return _vtkmprbasedata;
82 }
83 //-------------------------------------------------------------------
84
85 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
86 {
87         return _ctfun;
88 }
89 //-------------------------------------------------------------------
90
91 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
92 {
93         return &_ctFunVectorPoint;
94 }
95 //-------------------------------------------------------------------
96 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorRed()
97 {
98         return &_ctFunVectorRed;
99 }
100
101 //-------------------------------------------------------------------
102 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorGreen()
103 {
104         return &_ctFunVectorGreen;
105 }
106
107 //-------------------------------------------------------------------
108 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorBlue()
109 {
110         return &_ctFunVectorBlue;
111 }
112
113 //-------------------------------------------------------------------
114 void vtkMPR3DDataViewer::Configure()
115 {
116 /*
117   // Start by creatin a black/white lookup table.
118         _bwLut = vtkLookupTable::New();
119     _bwLut->SetTableRange (0, 2000);
120     _bwLut->SetSaturationRange (0, 0);
121     _bwLut->SetHueRange (0, 0);
122     _bwLut->SetValueRange (0, 1);
123
124   // Now create a lookup table that consists of the full hue circle
125   // (from HSV).
126         _hueLut = vtkLookupTable::New();
127     _hueLut->SetTableRange (0, 2000);
128     _hueLut->SetHueRange (0, 1);
129     _hueLut->SetSaturationRange (1, 1);
130     _hueLut->SetValueRange (1, 1);
131
132   // Finally, create a lookup table with a single hue but having a range
133   // in the saturation of the hue.
134         _satLut = vtkLookupTable::New();
135     _satLut->SetTableRange (0, 2000);
136     _satLut->SetHueRange (.6, .6);
137     _satLut->SetSaturationRange (0, 1);
138     _satLut->SetValueRange (1, 1);
139 */
140
141
142         double range[2];
143         double max;
144         
145         if(_vtkmprbasedata->GetImageData()){
146                 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
147                 max = range[1];
148         }else{
149                 max = 1;
150         }
151         
152         
153         
154
155         _ctFunVectorPoint.clear();
156         _ctFunVectorPoint.push_back(max*0/4);
157         _ctFunVectorPoint.push_back(max*1/4);
158         _ctFunVectorPoint.push_back(max*2/4);
159         _ctFunVectorPoint.push_back(max*3/4);
160         _ctFunVectorPoint.push_back(max*4/4);
161
162         _ctFunVectorRed.clear();
163         _ctFunVectorRed.push_back(0.0);
164         _ctFunVectorRed.push_back(1.0);
165         _ctFunVectorRed.push_back(0.0);
166         _ctFunVectorRed.push_back(0.0);
167         _ctFunVectorRed.push_back(0.0);
168
169         _ctFunVectorGreen.clear();
170         _ctFunVectorGreen.push_back(0.0);
171         _ctFunVectorGreen.push_back(0.0);
172         _ctFunVectorGreen.push_back(0.0);
173         _ctFunVectorGreen.push_back(1.0);
174         _ctFunVectorGreen.push_back(0.2);
175
176         _ctFunVectorBlue.clear();
177         _ctFunVectorBlue.push_back(0.0);
178         _ctFunVectorBlue.push_back(0.0);
179         _ctFunVectorBlue.push_back(1.0);
180         _ctFunVectorBlue.push_back(0.0);
181         _ctFunVectorBlue.push_back(0.0);
182
183
184         if(_ctfun==NULL){
185                 _ctfun = vtkColorTransferFunction::New();
186         }
187         _ctfun->RemoveAllPoints();
188
189         int i,size=_ctFunVectorPoint.size();
190         for (i=0;i<size;i++)
191         {
192                 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
193                 
194         }
195 /*
196         _ctfun->AddRGBPoint( 100 ,0 ,0,0);
197         _ctfun->AddRGBPoint( 200 ,1 ,0,0);
198         _ctfun->AddRGBPoint( 300 ,0 ,1,0);
199         _ctfun->AddRGBPoint( 400 ,0 ,0,1);
200 */
201 //      void *p=this; // JPRx
202
203   // Create the first of the three planes. The filter vtkImageMapToColors
204   // maps the data through the corresponding lookup table created above.  The
205   // vtkImageActor is a type of vtkProp and conveniently displays an image on
206   // a single quadrilateral plane. It does this using texture mapping and as
207   // a result is quite fast. (Note: the input image has to be unsigned char
208   // values, which the vtkImageMapToColors produces.) Note also that by
209   // specifying the DisplayExtent, the pipeline requests data of this extent
210   // and the vtkImageMapToColors only processes a slice of data.
211         
212         if(_saggitalColors==NULL){
213                 _saggitalColors = vtkImageMapToColors::New();
214         }
215         _saggitalColors->RemoveAllInputs();
216         
217         if(_vtkmprbasedata->GetImageData()){
218                 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
219         }
220 //    _saggitalColors->SetLookupTable(_bwLut);
221         
222     _saggitalColors->SetLookupTable(_ctfun);
223         
224
225         if(_saggital==NULL){
226                 _saggital = vtkImageActor::New();
227                 _saggital->SetInput(_saggitalColors->GetOutput());
228         }       
229         //_saggitalColors->Update();
230     
231
232
233   // Create the second (axial) plane of the three planes. We use the
234   // same approach as before except that the extent differs.
235
236         
237         if(_axialColors==NULL){
238                 _axialColors = vtkImageMapToColors::New();
239         }
240
241         _axialColors->RemoveAllInputs();
242         if(_vtkmprbasedata->GetImageData()){
243                 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
244         }
245 //    _axialColors->SetLookupTable(_hueLut);
246     _axialColors->SetLookupTable(_ctfun);
247
248         if(_axial==NULL){
249                 _axial = vtkImageActor::New();
250                 _axial->SetInput(_axialColors->GetOutput());
251         }
252         
253         //_axialColors->Update();
254     
255
256         // Create the third (coronal) plane of the three planes. We use 
257   // the same approach as before except that the extent differs.
258         if(_coronalColors==NULL){
259                 _coronalColors = vtkImageMapToColors::New();
260         }
261         _coronalColors->RemoveAllInputs();
262         if(_vtkmprbasedata->GetImageData()){
263                 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
264         }
265 //    _coronalColors->SetLookupTable(_satLut);
266     _coronalColors->SetLookupTable(_ctfun);
267
268         if(_coronal==NULL){
269                 _coronal = vtkImageActor::New();
270                 _coronal->SetInput(_coronalColors->GetOutput());
271         }
272         
273     
274
275   // An outline provides context around the data.
276   //
277         if(_outlineData==NULL){
278                 _outlineData = vtkOutlineFilter::New();
279         }
280         _outlineData->RemoveAllInputs();
281         if(_vtkmprbasedata->GetImageData()){
282                 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
283         }
284
285         if(_mapOutline==NULL){
286                 _mapOutline = vtkPolyDataMapper::New();
287                 _mapOutline->SetInput(_outlineData->GetOutput());
288         }
289         _mapOutline->Update();    
290         //_mapOutline->RemoveAllInputs();
291     
292         if(_outline==NULL){
293                 _outline = vtkActor::New();
294                 _outline->SetMapper(_mapOutline);
295                 _outline->GetProperty()->SetColor(0,0,0);
296         }
297         
298     
299
300         //int ext[6];
301         //_vtkmprbasedata->GetImageData()->GetExtent(ext);
302
303         
304
305
306 }
307
308 //-------------------------------------------------------------------
309 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
310 {
311         return _saggital;
312 }
313 //-------------------------------------------------------------------
314 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
315 {
316         return _coronal;
317 }
318 //-------------------------------------------------------------------
319 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
320 {
321         return _axial;
322 }
323
324 //------------------------------------------------------------------------
325 void vtkMPR3DDataViewer::SetPositionX(int pos){
326         int x1,x2,y1,y2,z1,z2;
327         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
328         _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
329 }
330 //------------------------------------------------------------------------
331 void vtkMPR3DDataViewer::SetPositionY(int pos){
332         int x1,x2,y1,y2,z1,z2;
333         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
334         _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
335 }
336 //------------------------------------------------------------------------
337 void vtkMPR3DDataViewer::SetPositionZ(int pos){
338         int x1,x2,y1,y2,z1,z2;
339         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
340         _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
341 }
342 //-------------------------------------------------------------------
343 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
344 {
345         _visiblePosition[idPosition]=visible;
346 }
347 //-------------------------------------------------------------------
348 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
349 {
350         return _visiblePosition[idPosition];
351 }
352
353 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
354         _saggitalColors->SetLookupTable(colortable);
355          _coronalColors->SetLookupTable(colortable);
356         _axialColors->SetLookupTable(colortable);
357 }
358