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