]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
e43df9aa9ca1882dcb6e674f76ae7ab745037440
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / vtkMPR3DDataViewer.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 "vtkMPR3DDataViewer.h"
28
29
30 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
31 {
32         _visiblePosition[0]=false;
33         _visiblePosition[1]=false;
34         _visiblePosition[2]=false;
35         _ctfun                  = NULL;
36         _vtkmprbasedata = NULL;
37
38         _ctfun                  = NULL;
39         _saggitalColors = NULL;
40         _saggital               = NULL;
41         _axialColors    = NULL;
42         _axial                  = NULL;
43         _coronalColors  = NULL;
44         _coronal                = NULL;
45         _mapOutline             = NULL;
46         _outline                = NULL;
47         _outlineData    = NULL;
48 }
49 //-------------------------------------------------------------------
50 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
51 {
52         if(_outlineData) {_outlineData-> Delete();}
53         if(_mapOutline)  {_mapOutline-> Delete();}
54         if(_outline)     {_outline-> Delete();}
55
56 //      if (_bwLut)                             _bwLut->Delete();
57 //      if (_hueLut)                    _hueLut->Delete();
58 //      if (_satLut)                    _satLut->Delete();
59         if (_ctfun)                             _ctfun->Delete();
60         if (_saggitalColors)    _saggitalColors ->Delete();
61         if (_saggital)                  _saggital->Delete();
62         if (_axialColors)               _axialColors->Delete();
63         if (_axial)                             _axial->Delete();
64         if (_coronalColors)             _coronalColors->Delete();
65         if (_coronal)                   _coronal->Delete();
66
67 }
68 //-------------------------------------------------------------------
69 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
70 {
71         return _outline;
72 }
73 //-------------------------------------------------------------------
74 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
75 {
76         vtkImageActor *tmpVtkActor=NULL;
77         if (id==0)
78         {
79                 tmpVtkActor = GetvtkActor_saggital();
80         }
81         if (id==1)
82         {
83                 tmpVtkActor = GetvtkActor_coronal();
84         }
85         if (id==2)
86         {
87                 tmpVtkActor = GetvtkActor_axial();
88         }
89         return tmpVtkActor;
90 }
91
92 //-------------------------------------------------------------------
93 void vtkMPR3DDataViewer::Refresh()
94 {
95         int x = (int)(_vtkmprbasedata->GetX());
96         int y = (int)(_vtkmprbasedata->GetY());
97         int z = (int)(_vtkmprbasedata->GetZ());
98         SetPositionX( x );
99         SetPositionY( y );
100         SetPositionZ( z );
101 }
102 //-------------------------------------------------------------------
103 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
104 {
105         _vtkmprbasedata=vtkmprbasedata;
106 }
107 //-------------------------------------------------------------------
108 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
109 {
110         return _vtkmprbasedata;
111 }
112 //-------------------------------------------------------------------
113
114 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
115 {
116         return _ctfun;
117 }
118 //-------------------------------------------------------------------
119
120 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
121 {
122         return &_ctFunVectorPoint;
123 }
124 //-------------------------------------------------------------------
125 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorRed()
126 {
127         return &_ctFunVectorRed;
128 }
129
130 //-------------------------------------------------------------------
131 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorGreen()
132 {
133         return &_ctFunVectorGreen;
134 }
135
136 //-------------------------------------------------------------------
137 std::vector<double>*     vtkMPR3DDataViewer::GetctFunVectorBlue()
138 {
139         return &_ctFunVectorBlue;
140 }
141
142 //-------------------------------------------------------------------
143 void vtkMPR3DDataViewer::SetImage()
144 {
145 //EED 2017-01-01 Migration VTK7
146 #if VTK_MAJOR_VERSION <= 5
147         _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
148         _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
149         _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
150 #else
151         _saggitalColors->SetInputData( _vtkmprbasedata->GetImageData() );
152         _axialColors->SetInputData( _vtkmprbasedata->GetImageData() );
153         _coronalColors->SetInputData( _vtkmprbasedata->GetImageData() );
154 #endif
155 }
156
157 //-------------------------------------------------------------------
158 void vtkMPR3DDataViewer::Configure()
159 {
160 /*
161   // Start by creatin a black/white lookup table.
162         _bwLut = vtkLookupTable::New();
163     _bwLut->SetTableRange (0, 2000);
164     _bwLut->SetSaturationRange (0, 0);
165     _bwLut->SetHueRange (0, 0);
166     _bwLut->SetValueRange (0, 1);
167
168   // Now create a lookup table that consists of the full hue circle
169   // (from HSV).
170         _hueLut = vtkLookupTable::New();
171     _hueLut->SetTableRange (0, 2000);
172     _hueLut->SetHueRange (0, 1);
173     _hueLut->SetSaturationRange (1, 1);
174     _hueLut->SetValueRange (1, 1);
175
176   // Finally, create a lookup table with a single hue but having a range
177   // in the saturation of the hue.
178         _satLut = vtkLookupTable::New();
179     _satLut->SetTableRange (0, 2000);
180     _satLut->SetHueRange (.6, .6);
181     _satLut->SetSaturationRange (0, 1);
182     _satLut->SetValueRange (1, 1);
183 */
184
185
186         double range[2];
187         double delta;
188         
189         if(_vtkmprbasedata->GetImageData())
190         {
191 //EED 2017-01-01 Migration VTK7
192 #if VTK_MAJOR_VERSION <= 5
193                 _vtkmprbasedata->GetImageData()->Update();
194 #else
195                 // ..
196 #endif
197                 _vtkmprbasedata->GetImageData()->Modified();
198                 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
199                 delta = range[1]-range[0];
200                 if (delta==0)
201                 {
202                         printf("EED vtkMPR3DDataViewer::Configure Warning!  image Range [0,0] -> changed to [0,1000] \n" );
203                         delta=1000;
204                 } // if delta                           
205
206                 _ctFunVectorPoint.clear();
207                 _ctFunVectorPoint.push_back( range[0] + delta*0/8 );
208                 _ctFunVectorPoint.push_back( range[0] + delta*1/8 );
209                 _ctFunVectorPoint.push_back( range[0] + delta*2/8 );
210                 _ctFunVectorPoint.push_back( range[0] + delta*3/8 );
211                 _ctFunVectorPoint.push_back( range[0] + delta*4/8 );
212                 _ctFunVectorPoint.push_back( range[0] + delta*5/8 );
213                 _ctFunVectorPoint.push_back( range[0] + delta*6/8 );
214                 _ctFunVectorPoint.push_back( range[0] + delta*7/8 );
215                 _ctFunVectorPoint.push_back( range[0] + delta*8/8 );
216
217                 _ctFunVectorRed.clear();
218                 _ctFunVectorRed.push_back(0.0);
219                 _ctFunVectorRed.push_back(0.0);
220                 _ctFunVectorRed.push_back(0.0);
221                 _ctFunVectorRed.push_back(0.0);
222                 _ctFunVectorRed.push_back(0.5);
223                 _ctFunVectorRed.push_back(1.0);
224                 _ctFunVectorRed.push_back(1.0);
225                 _ctFunVectorRed.push_back(1.0);
226                 _ctFunVectorRed.push_back(0.5);
227
228                 _ctFunVectorGreen.clear();
229                 _ctFunVectorGreen.push_back(0.0);
230                 _ctFunVectorGreen.push_back(0.0);
231                 _ctFunVectorGreen.push_back(0.5);
232                 _ctFunVectorGreen.push_back(1.0);
233                 _ctFunVectorGreen.push_back(1.0);
234                 _ctFunVectorGreen.push_back(1.0);
235                 _ctFunVectorGreen.push_back(0.5);
236                 _ctFunVectorGreen.push_back(0.0);
237                 _ctFunVectorGreen.push_back(0.0);
238
239                 _ctFunVectorBlue.clear();
240                 _ctFunVectorBlue.push_back(0.5);
241                 _ctFunVectorBlue.push_back(1.0);
242                 _ctFunVectorBlue.push_back(1.0);
243                 _ctFunVectorBlue.push_back(1.0);
244                 _ctFunVectorBlue.push_back(0.5);
245                 _ctFunVectorBlue.push_back(0.0);
246                 _ctFunVectorBlue.push_back(0.0);
247                 _ctFunVectorBlue.push_back(0.0);
248                 _ctFunVectorBlue.push_back(0.0);
249
250                 if(_ctfun==NULL)
251                 {
252                         _ctfun = vtkColorTransferFunction::New();
253                 }
254                 _ctfun->RemoveAllPoints();
255
256                 int i,size=_ctFunVectorPoint.size();
257                 for (i=0;i<size;i++)
258                 {
259                         _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
260                         
261                 }
262         /*
263                 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
264                 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
265                 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
266                 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
267         */
268         //      void *p=this; // JPRx
269
270         // Create the first of the three planes. The filter vtkImageMapToColors
271         // maps the data through the corresponding lookup table created above.  The
272         // vtkImageActor is a type of vtkProp and conveniently displays an image on
273         // a single quadrilateral plane. It does this using texture mapping and as
274         // a result is quite fast. (Note: the input image has to be unsigned char
275         // values, which the vtkImageMapToColors produces.) Note also that by
276         // specifying the DisplayExtent, the pipeline requests data of this extent
277         // and the vtkImageMapToColors only processes a slice of data.
278                 
279                 if(_saggitalColors==NULL)
280                 {
281                         _saggitalColors = vtkImageMapToColors::New();
282                 }
283                 _saggitalColors->RemoveAllInputs();
284 //EED 2017-01-01 Migration VTK7
285 #if VTK_MAJOR_VERSION <= 5
286                 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
287 #else
288                 _saggitalColors->SetInputData( _vtkmprbasedata->GetImageData() );
289 #endif
290                 
291         //    _saggitalColors->SetLookupTable(_bwLut);
292                 
293                 _saggitalColors->SetLookupTable(_ctfun);
294                 
295
296                 if(_saggital==NULL)
297                 {
298                         _saggital = vtkImageActor::New();
299 //EED 2017-01-01 Migration VTK7
300 #if VTK_MAJOR_VERSION <= 5
301                         _saggital->SetInput(_saggitalColors->GetOutput());
302 #else
303                         _saggital->SetInputData(_saggitalColors->GetOutput());
304 #endif
305                 }       
306                 //_saggitalColors->Update();
307         
308
309
310         // Create the second (axial) plane of the three planes. We use the
311         // same approach as before except that the extent differs.
312
313                 
314                 if(_axialColors==NULL)
315                 {
316                         _axialColors = vtkImageMapToColors::New();
317                 }
318
319                 _axialColors->RemoveAllInputs();
320
321 //EED 2017-01-01 Migration VTK7
322 #if VTK_MAJOR_VERSION <= 5
323                 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
324 #else
325                 _axialColors->SetInputData( _vtkmprbasedata->GetImageData() );
326 #endif
327
328         //    _axialColors->SetLookupTable(_hueLut);
329                 _axialColors->SetLookupTable(_ctfun);
330
331                 if(_axial==NULL)
332                 {
333                         _axial = vtkImageActor::New();
334
335 //EED 2017-01-01 Migration VTK7
336 #if VTK_MAJOR_VERSION <= 5
337                         _axial->SetInput(_axialColors->GetOutput());
338 #else
339                         _axial->SetInputData(_axialColors->GetOutput());
340 #endif
341
342                 }
343                 
344                 //_axialColors->Update();
345         
346
347                 // Create the third (coronal) plane of the three planes. We use 
348         // the same approach as before except that the extent differs.
349                 if(_coronalColors==NULL)
350                 {
351                         _coronalColors = vtkImageMapToColors::New();
352                 }
353                 _coronalColors->RemoveAllInputs();
354
355 //EED 2017-01-01 Migration VTK7
356 #if VTK_MAJOR_VERSION <= 5
357                 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
358 #else
359                 _coronalColors->SetInputData( _vtkmprbasedata->GetImageData() );
360 #endif
361
362         //    _coronalColors->SetLookupTable(_satLut);
363                 _coronalColors->SetLookupTable(_ctfun);
364
365                 if(_coronal==NULL)
366                 {
367                         _coronal = vtkImageActor::New();
368
369 //EED 2017-01-01 Migration VTK7
370 #if VTK_MAJOR_VERSION <= 5
371                         _coronal->SetInput(_coronalColors->GetOutput());
372 #else
373                         _coronal->SetInputData(_coronalColors->GetOutput());
374 #endif
375
376                 } // if _coronal
377                 
378         
379
380         // An outline provides context around the data.
381         //
382                 if(_outlineData==NULL)
383                 {
384                         _outlineData = vtkOutlineFilter::New();
385                 } // if _outlineData
386                 _outlineData->RemoveAllInputs();
387                 if(_vtkmprbasedata->GetImageData())
388                 {
389 //EED 2017-01-01 Migration VTK7
390 #if VTK_MAJOR_VERSION <= 5
391                         _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
392 #else
393                         _outlineData->SetInputData((vtkDataSet *) _vtkmprbasedata->GetImageData() );
394 #endif
395                 } // if _image
396
397                 if(_mapOutline==NULL)
398                 {
399                         _mapOutline = vtkPolyDataMapper::New();
400
401 //EED 2017-01-01 Migration VTK7
402 #if VTK_MAJOR_VERSION <= 5
403                         _mapOutline->SetInput(_outlineData->GetOutput());
404 #else
405                         _mapOutline->SetInputData(_outlineData->GetOutput());
406 #endif
407
408                 }
409                 _mapOutline->Update();    
410                 //_mapOutline->RemoveAllInputs();
411         
412                 if(_outline==NULL)
413                 {
414                         _outline = vtkActor::New();
415                         _outline->SetMapper(_mapOutline);
416                         _outline->GetProperty()->SetColor(0,0,0);
417                 }
418         }
419         
420         //int ext[6];
421         //_vtkmprbasedata->GetImageData()->GetExtent(ext);
422 }
423
424 //-------------------------------------------------------------------
425 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
426 {
427         return _saggital;
428 }
429 //-------------------------------------------------------------------
430 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
431 {
432         return _coronal;
433 }
434 //-------------------------------------------------------------------
435 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
436 {
437         return _axial;
438 }
439
440 //------------------------------------------------------------------------
441 void vtkMPR3DDataViewer::SetPositionX(int pos)
442 {
443         int x1,x2,y1,y2,z1,z2;
444         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
445         if(_saggital)
446         {
447                 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
448 //EED 2016/02/19
449                 _saggital->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
450         }
451 }
452
453 //------------------------------------------------------------------------
454 void vtkMPR3DDataViewer::SetPositionY(int pos)
455 {
456         int x1,x2,y1,y2,z1,z2;
457         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
458         if(_coronal)
459         {
460                 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
461 //EED 2016/02/19
462                 _coronal->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
463         }
464 }
465 //------------------------------------------------------------------------
466 void vtkMPR3DDataViewer::SetPositionZ(int pos)
467 {
468         int x1,x2,y1,y2,z1,z2;
469         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
470         if(_axial)
471         {
472                 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
473 //EED 2016/02/19
474                 _axial->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
475         }
476 }
477 //-------------------------------------------------------------------
478 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
479 {
480         _visiblePosition[idPosition]=visible;
481 }
482 //-------------------------------------------------------------------
483 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
484 {
485         return _visiblePosition[idPosition];
486 }
487
488 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable)
489 {
490         if(_saggitalColors)
491         {
492                 _saggitalColors->SetLookupTable(colortable);
493                 _coronalColors->SetLookupTable(colortable);
494                 _axialColors->SetLookupTable(colortable);
495         }
496 }
497