]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
#3207 creaMaracasVisu Feature New Normal branch vtk7itk4wx3-mingw
[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         //    _saggitalColors->SetLookupTable(_bwLut);
285                 _saggitalColors->SetLookupTable(_ctfun);
286 //EED 2017-01-01 Migration VTK7
287 #if VTK_MAJOR_VERSION <= 5
288                 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
289 #else
290                 _saggitalColors->SetInputData( _vtkmprbasedata->GetImageData() );
291                 _saggitalColors->Update();
292 #endif
293                 
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         //    _axialColors->SetLookupTable(_hueLut);
321                 _axialColors->SetLookupTable(_ctfun);
322
323 //EED 2017-01-01 Migration VTK7
324 #if VTK_MAJOR_VERSION <= 5
325                 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
326 #else
327                 _axialColors->SetInputData( _vtkmprbasedata->GetImageData() );
328                 _axialColors->Update();
329 #endif
330
331
332                 if(_axial==NULL)
333                 {
334                         _axial = vtkImageActor::New();
335
336 //EED 2017-01-01 Migration VTK7
337 #if VTK_MAJOR_VERSION <= 5
338                         _axial->SetInput(_axialColors->GetOutput());
339 #else
340                         _axial->SetInputData(_axialColors->GetOutput());
341 #endif
342
343                 }
344                 
345                 //_axialColors->Update();
346         
347
348                 // Create the third (coronal) plane of the three planes. We use 
349         // the same approach as before except that the extent differs.
350                 if(_coronalColors==NULL)
351                 {
352                         _coronalColors = vtkImageMapToColors::New();
353                 }
354                 _coronalColors->RemoveAllInputs();
355         //    _coronalColors->SetLookupTable(_satLut);
356                 _coronalColors->SetLookupTable(_ctfun);
357
358 //EED 2017-01-01 Migration VTK7
359 #if VTK_MAJOR_VERSION <= 5
360                 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
361 #else
362                 _coronalColors->SetInputData( _vtkmprbasedata->GetImageData() );
363                 _coronalColors->Update();
364 #endif
365
366
367                 if(_coronal==NULL)
368                 {
369                         _coronal = vtkImageActor::New();
370
371 //EED 2017-01-01 Migration VTK7
372 #if VTK_MAJOR_VERSION <= 5
373                         _coronal->SetInput(_coronalColors->GetOutput());
374 #else
375                         _coronal->SetInputData(_coronalColors->GetOutput());
376 #endif
377
378                 } // if _coronal
379                 
380         
381
382         // An outline provides context around the data.
383         //
384                 if(_outlineData==NULL)
385                 {
386                         _outlineData = vtkOutlineFilter::New();
387                 } // if _outlineData
388                 _outlineData->RemoveAllInputs();
389                 if(_vtkmprbasedata->GetImageData())
390                 {
391 //EED 2017-01-01 Migration VTK7
392 #if VTK_MAJOR_VERSION <= 5
393                         _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
394 #else
395                         _outlineData->SetInputData((vtkDataSet *) _vtkmprbasedata->GetImageData() );
396                         _outlineData->Update();    
397 #endif
398                 } // if _image
399
400                 if(_mapOutline==NULL)
401                 {
402                         _mapOutline = vtkPolyDataMapper::New();
403
404 //EED 2017-01-01 Migration VTK7
405 #if VTK_MAJOR_VERSION <= 5
406                         _mapOutline->SetInput(_outlineData->GetOutput());
407 #else
408                         _mapOutline->SetInputData(_outlineData->GetOutput());
409 #endif
410
411                 }
412                 _mapOutline->Update();    
413                 //_mapOutline->RemoveAllInputs();
414         
415                 if(_outline==NULL)
416                 {
417                         _outline = vtkActor::New();
418                         _outline->SetMapper(_mapOutline);
419                         _outline->GetProperty()->SetColor(0,0,0);
420                 }
421         }
422         
423         //int ext[6];
424         //_vtkmprbasedata->GetImageData()->GetExtent(ext);
425 }
426
427 //-------------------------------------------------------------------
428 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
429 {
430         return _saggital;
431 }
432 //-------------------------------------------------------------------
433 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
434 {
435         return _coronal;
436 }
437 //-------------------------------------------------------------------
438 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
439 {
440         return _axial;
441 }
442
443 //------------------------------------------------------------------------
444 void vtkMPR3DDataViewer::SetPositionX(int pos)
445 {
446         int x1,x2,y1,y2,z1,z2;
447         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
448         if(_saggital)
449         {
450                 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
451 //EED 2016/02/19
452                 _saggital->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
453         }
454 }
455
456 //------------------------------------------------------------------------
457 void vtkMPR3DDataViewer::SetPositionY(int pos)
458 {
459         int x1,x2,y1,y2,z1,z2;
460         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
461         if(_coronal)
462         {
463                 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
464 //EED 2016/02/19
465                 _coronal->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
466         }
467 }
468 //------------------------------------------------------------------------
469 void vtkMPR3DDataViewer::SetPositionZ(int pos)
470 {
471         int x1,x2,y1,y2,z1,z2;
472         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
473         if(_axial)
474         {
475                 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
476 //EED 2016/02/19
477                 _axial->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
478         }
479 }
480 //-------------------------------------------------------------------
481 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
482 {
483         _visiblePosition[idPosition]=visible;
484 }
485 //-------------------------------------------------------------------
486 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
487 {
488         return _visiblePosition[idPosition];
489 }
490
491 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable)
492 {
493         if(_saggitalColors)
494         {
495                 _saggitalColors->SetLookupTable(colortable);
496                 _coronalColors->SetLookupTable(colortable);
497                 _axialColors->SetLookupTable(colortable);
498         }
499 }
500