]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/vtkMPR3DDataViewer.cxx
#3155 creaMaracasVisu Feature New Normal - ViewerPlane ComplexBox
[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         _saggitalColors -> SetInput( _vtkmprbasedata->GetImageData() );
145         _axialColors    -> SetInput( _vtkmprbasedata->GetImageData() );
146         _coronalColors  -> SetInput( _vtkmprbasedata->GetImageData() );
147         _outlineData    -> SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
148 }
149
150 //-------------------------------------------------------------------
151 void vtkMPR3DDataViewer::Configure()
152 {
153 /*
154   // Start by creatin a black/white lookup table.
155         _bwLut = vtkLookupTable::New();
156     _bwLut->SetTableRange (0, 2000);
157     _bwLut->SetSaturationRange (0, 0);
158     _bwLut->SetHueRange (0, 0);
159     _bwLut->SetValueRange (0, 1);
160
161   // Now create a lookup table that consists of the full hue circle
162   // (from HSV).
163         _hueLut = vtkLookupTable::New();
164     _hueLut->SetTableRange (0, 2000);
165     _hueLut->SetHueRange (0, 1);
166     _hueLut->SetSaturationRange (1, 1);
167     _hueLut->SetValueRange (1, 1);
168
169   // Finally, create a lookup table with a single hue but having a range
170   // in the saturation of the hue.
171         _satLut = vtkLookupTable::New();
172     _satLut->SetTableRange (0, 2000);
173     _satLut->SetHueRange (.6, .6);
174     _satLut->SetSaturationRange (0, 1);
175     _satLut->SetValueRange (1, 1);
176 */
177
178         double range[2];
179         double delta;
180         if(_vtkmprbasedata->GetImageData())
181         {
182                 _vtkmprbasedata->GetImageData()->Update();
183                 _vtkmprbasedata->GetImageData()->Modified();
184                 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
185                 delta = range[1]-range[0];
186                 if (delta==0)
187                 {
188                         printf("EED vtkMPR3DDataViewer::Configure Warning!  image Range [0,0] -> changed to [0,1000] \n" );
189                         delta=1000;
190                 } // if delta                           
191
192                 _ctFunVectorPoint.clear();
193                 _ctFunVectorPoint.push_back( range[0] + delta*0/8 );
194                 _ctFunVectorPoint.push_back( range[0] + delta*1/8 );
195                 _ctFunVectorPoint.push_back( range[0] + delta*2/8 );
196                 _ctFunVectorPoint.push_back( range[0] + delta*3/8 );
197                 _ctFunVectorPoint.push_back( range[0] + delta*4/8 );
198                 _ctFunVectorPoint.push_back( range[0] + delta*5/8 );
199                 _ctFunVectorPoint.push_back( range[0] + delta*6/8 );
200                 _ctFunVectorPoint.push_back( range[0] + delta*7/8 );
201                 _ctFunVectorPoint.push_back( range[0] + delta*8/8 );
202
203                 _ctFunVectorRed.clear();
204                 _ctFunVectorRed.push_back(0.0);
205                 _ctFunVectorRed.push_back(0.0);
206                 _ctFunVectorRed.push_back(0.0);
207                 _ctFunVectorRed.push_back(0.0);
208                 _ctFunVectorRed.push_back(0.5);
209                 _ctFunVectorRed.push_back(1.0);
210                 _ctFunVectorRed.push_back(1.0);
211                 _ctFunVectorRed.push_back(1.0);
212                 _ctFunVectorRed.push_back(0.5);
213
214                 _ctFunVectorGreen.clear();
215                 _ctFunVectorGreen.push_back(0.0);
216                 _ctFunVectorGreen.push_back(0.0);
217                 _ctFunVectorGreen.push_back(0.5);
218                 _ctFunVectorGreen.push_back(1.0);
219                 _ctFunVectorGreen.push_back(1.0);
220                 _ctFunVectorGreen.push_back(1.0);
221                 _ctFunVectorGreen.push_back(0.5);
222                 _ctFunVectorGreen.push_back(0.0);
223                 _ctFunVectorGreen.push_back(0.0);
224
225                 _ctFunVectorBlue.clear();
226                 _ctFunVectorBlue.push_back(0.5);
227                 _ctFunVectorBlue.push_back(1.0);
228                 _ctFunVectorBlue.push_back(1.0);
229                 _ctFunVectorBlue.push_back(1.0);
230                 _ctFunVectorBlue.push_back(0.5);
231                 _ctFunVectorBlue.push_back(0.0);
232                 _ctFunVectorBlue.push_back(0.0);
233                 _ctFunVectorBlue.push_back(0.0);
234                 _ctFunVectorBlue.push_back(0.0);
235
236                 if(_ctfun==NULL)
237                 {
238                         _ctfun = vtkColorTransferFunction::New();
239                 }
240                 _ctfun->RemoveAllPoints();
241
242                 int i,size=_ctFunVectorPoint.size();
243                 for (i=0;i<size;i++)
244                 {
245                         _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
246                         
247                 }
248         /*
249                 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
250                 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
251                 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
252                 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
253         */
254         //      void *p=this; // JPRx
255
256         // Create the first of the three planes. The filter vtkImageMapToColors
257         // maps the data through the corresponding lookup table created above.  The
258         // vtkImageActor is a type of vtkProp and conveniently displays an image on
259         // a single quadrilateral plane. It does this using texture mapping and as
260         // a result is quite fast. (Note: the input image has to be unsigned char
261         // values, which the vtkImageMapToColors produces.) Note also that by
262         // specifying the DisplayExtent, the pipeline requests data of this extent
263         // and the vtkImageMapToColors only processes a slice of data.
264                 
265                 if(_saggitalColors==NULL)
266                 {
267                         _saggitalColors = vtkImageMapToColors::New();
268                 }
269                 _saggitalColors->RemoveAllInputs();
270                 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
271         //    _saggitalColors->SetLookupTable(_bwLut);
272                 _saggitalColors->SetLookupTable(_ctfun);
273                 if(_saggital==NULL)
274                 {
275                         _saggital = vtkImageActor::New();
276                         _saggital->SetInput(_saggitalColors->GetOutput());
277                 }       
278                 //_saggitalColors->Update();
279         
280         // Create the second (axial) plane of the three planes. We use the
281         // same approach as before except that the extent differs.
282
283                 if(_axialColors==NULL)
284                 {
285                         _axialColors = vtkImageMapToColors::New();
286                 }
287                 _axialColors->RemoveAllInputs();
288                 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
289         //    _axialColors->SetLookupTable(_hueLut);
290                 _axialColors->SetLookupTable(_ctfun);
291                 if(_axial==NULL)
292                 {
293                         _axial = vtkImageActor::New();
294                         _axial->SetInput(_axialColors->GetOutput());
295                 }
296                 
297                 //_axialColors->Update();
298                 // Create the third (coronal) plane of the three planes. We use 
299         // the same approach as before except that the extent differs.
300                 if(_coronalColors==NULL)
301                 {
302                         _coronalColors = vtkImageMapToColors::New();
303                 }
304                 _coronalColors->RemoveAllInputs();
305                 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
306         //    _coronalColors->SetLookupTable(_satLut);
307                 _coronalColors->SetLookupTable(_ctfun);
308                 if(_coronal==NULL)
309                 {
310                         _coronal = vtkImageActor::New();
311                         _coronal->SetInput(_coronalColors->GetOutput());
312                 }
313                 
314         // An outline provides context around the data.
315         //
316                 if(_outlineData==NULL)
317                 {
318                         _outlineData = vtkOutlineFilter::New();
319                 }
320                 _outlineData->RemoveAllInputs();
321                 if(_vtkmprbasedata->GetImageData())
322                 {
323                         _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
324                 }
325
326                 if(_mapOutline==NULL)
327                 {
328                         _mapOutline = vtkPolyDataMapper::New();
329                         _mapOutline->SetInput(_outlineData->GetOutput());
330                 }
331                 _mapOutline->Update();    
332                 //_mapOutline->RemoveAllInputs();
333         
334                 if(_outline==NULL)
335                 {
336                         _outline = vtkActor::New();
337                         _outline->SetMapper(_mapOutline);
338                         _outline->GetProperty()->SetColor(0,0,0);
339                 }
340         }
341         //int ext[6];
342         //_vtkmprbasedata->GetImageData()->GetExtent(ext);
343 }
344
345 //-------------------------------------------------------------------
346 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
347 {
348         return _saggital;
349 }
350 //-------------------------------------------------------------------
351 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
352 {
353         return _coronal;
354 }
355 //-------------------------------------------------------------------
356 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
357 {
358         return _axial;
359 }
360
361 //------------------------------------------------------------------------
362 void vtkMPR3DDataViewer::SetPositionX(int pos)
363 {
364         int x1,x2,y1,y2,z1,z2;
365         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
366         if(_saggital)
367         {
368                 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
369 //EED 2016/02/19
370                 _saggital->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
371         }
372 }
373
374 //------------------------------------------------------------------------
375 void vtkMPR3DDataViewer::SetPositionY(int pos)
376 {
377         int x1,x2,y1,y2,z1,z2;
378         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
379         if(_coronal)
380         {
381                 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
382 //EED 2016/02/19
383                 _coronal->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
384         }
385 }
386 //------------------------------------------------------------------------
387 void vtkMPR3DDataViewer::SetPositionZ(int pos)
388 {
389         int x1,x2,y1,y2,z1,z2;
390         _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
391         if(_axial)
392         {
393                 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
394 //EED 2016/02/19
395                 _axial->SetInterpolate(  GetVtkMPRBaseData()->GetInterpolate() );
396         }
397 }
398 //-------------------------------------------------------------------
399 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
400 {
401         _visiblePosition[idPosition]=visible;
402 }
403 //-------------------------------------------------------------------
404 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
405 {
406         return _visiblePosition[idPosition];
407 }
408
409 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable)
410 {
411         if(_saggitalColors)
412         {
413                 _saggitalColors->SetLookupTable(colortable);
414                 _coronalColors->SetLookupTable(colortable);
415                 _axialColors->SetLookupTable(colortable);
416         }
417 }
418