1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
27 #include "vtkMPR3DDataViewer.h"
30 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
32 _visiblePosition[0]=false;
33 _visiblePosition[1]=false;
34 _visiblePosition[2]=false;
36 _vtkmprbasedata = NULL;
39 _saggitalColors = NULL;
43 _coronalColors = NULL;
49 //-------------------------------------------------------------------
50 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
52 if(_outlineData) {_outlineData-> Delete();}
53 if(_mapOutline) {_mapOutline-> Delete();}
54 if(_outline) {_outline-> Delete();}
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();
68 //-------------------------------------------------------------------
69 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
73 //-------------------------------------------------------------------
74 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
76 vtkImageActor *tmpVtkActor=NULL;
79 tmpVtkActor = GetvtkActor_saggital();
83 tmpVtkActor = GetvtkActor_coronal();
87 tmpVtkActor = GetvtkActor_axial();
92 //-------------------------------------------------------------------
93 void vtkMPR3DDataViewer::Refresh()
95 int x = (int)(_vtkmprbasedata->GetX());
96 int y = (int)(_vtkmprbasedata->GetY());
97 int z = (int)(_vtkmprbasedata->GetZ());
102 //-------------------------------------------------------------------
103 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
105 _vtkmprbasedata=vtkmprbasedata;
107 //-------------------------------------------------------------------
108 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
110 return _vtkmprbasedata;
112 //-------------------------------------------------------------------
114 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
118 //-------------------------------------------------------------------
120 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
122 return &_ctFunVectorPoint;
124 //-------------------------------------------------------------------
125 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
127 return &_ctFunVectorRed;
130 //-------------------------------------------------------------------
131 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
133 return &_ctFunVectorGreen;
136 //-------------------------------------------------------------------
137 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
139 return &_ctFunVectorBlue;
142 //-------------------------------------------------------------------
143 void vtkMPR3DDataViewer::SetImage()
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() );
151 _saggitalColors->SetInputData( _vtkmprbasedata->GetImageData() );
152 _axialColors->SetInputData( _vtkmprbasedata->GetImageData() );
153 _coronalColors->SetInputData( _vtkmprbasedata->GetImageData() );
157 //-------------------------------------------------------------------
158 void vtkMPR3DDataViewer::Configure()
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);
168 // Now create a lookup table that consists of the full hue circle
170 _hueLut = vtkLookupTable::New();
171 _hueLut->SetTableRange (0, 2000);
172 _hueLut->SetHueRange (0, 1);
173 _hueLut->SetSaturationRange (1, 1);
174 _hueLut->SetValueRange (1, 1);
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);
189 if(_vtkmprbasedata->GetImageData())
191 //EED 2017-01-01 Migration VTK7
192 #if VTK_MAJOR_VERSION <= 5
193 _vtkmprbasedata->GetImageData()->Update();
197 _vtkmprbasedata->GetImageData()->Modified();
198 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
199 delta = range[1]-range[0];
202 printf("EED vtkMPR3DDataViewer::Configure Warning! image Range [0,0] -> changed to [0,1000] \n" );
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 );
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);
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);
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);
252 _ctfun = vtkColorTransferFunction::New();
254 _ctfun->RemoveAllPoints();
256 int i,size=_ctFunVectorPoint.size();
259 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
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);
268 // void *p=this; // JPRx
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.
279 if(_saggitalColors==NULL)
281 _saggitalColors = vtkImageMapToColors::New();
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() );
290 _saggitalColors->SetInputData( _vtkmprbasedata->GetImageData() );
291 _saggitalColors->Update();
298 _saggital = vtkImageActor::New();
299 //EED 2017-01-01 Migration VTK7
300 #if VTK_MAJOR_VERSION <= 5
301 _saggital->SetInput(_saggitalColors->GetOutput());
303 _saggital->SetInputData(_saggitalColors->GetOutput());
306 //_saggitalColors->Update();
310 // Create the second (axial) plane of the three planes. We use the
311 // same approach as before except that the extent differs.
314 if(_axialColors==NULL)
316 _axialColors = vtkImageMapToColors::New();
319 _axialColors->RemoveAllInputs();
320 // _axialColors->SetLookupTable(_hueLut);
321 _axialColors->SetLookupTable(_ctfun);
323 //EED 2017-01-01 Migration VTK7
324 #if VTK_MAJOR_VERSION <= 5
325 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
327 _axialColors->SetInputData( _vtkmprbasedata->GetImageData() );
328 _axialColors->Update();
334 _axial = vtkImageActor::New();
336 //EED 2017-01-01 Migration VTK7
337 #if VTK_MAJOR_VERSION <= 5
338 _axial->SetInput(_axialColors->GetOutput());
340 _axial->SetInputData(_axialColors->GetOutput());
345 //_axialColors->Update();
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)
352 _coronalColors = vtkImageMapToColors::New();
354 _coronalColors->RemoveAllInputs();
355 // _coronalColors->SetLookupTable(_satLut);
356 _coronalColors->SetLookupTable(_ctfun);
358 //EED 2017-01-01 Migration VTK7
359 #if VTK_MAJOR_VERSION <= 5
360 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
362 _coronalColors->SetInputData( _vtkmprbasedata->GetImageData() );
363 _coronalColors->Update();
369 _coronal = vtkImageActor::New();
371 //EED 2017-01-01 Migration VTK7
372 #if VTK_MAJOR_VERSION <= 5
373 _coronal->SetInput(_coronalColors->GetOutput());
375 _coronal->SetInputData(_coronalColors->GetOutput());
382 // An outline provides context around the data.
384 if(_outlineData==NULL)
386 _outlineData = vtkOutlineFilter::New();
388 _outlineData->RemoveAllInputs();
389 if(_vtkmprbasedata->GetImageData())
391 //EED 2017-01-01 Migration VTK7
392 #if VTK_MAJOR_VERSION <= 5
393 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
395 _outlineData->SetInputData((vtkDataSet *) _vtkmprbasedata->GetImageData() );
396 _outlineData->Update();
400 if(_mapOutline==NULL)
402 _mapOutline = vtkPolyDataMapper::New();
404 //EED 2017-01-01 Migration VTK7
405 #if VTK_MAJOR_VERSION <= 5
406 _mapOutline->SetInput(_outlineData->GetOutput());
408 _mapOutline->SetInputData(_outlineData->GetOutput());
412 _mapOutline->Update();
413 //_mapOutline->RemoveAllInputs();
417 _outline = vtkActor::New();
418 _outline->SetMapper(_mapOutline);
419 _outline->GetProperty()->SetColor(0,0,0);
424 //_vtkmprbasedata->GetImageData()->GetExtent(ext);
427 //-------------------------------------------------------------------
428 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
432 //-------------------------------------------------------------------
433 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
437 //-------------------------------------------------------------------
438 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
443 //------------------------------------------------------------------------
444 void vtkMPR3DDataViewer::SetPositionX(int pos)
446 int x1,x2,y1,y2,z1,z2;
447 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
450 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
452 _saggital->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
456 //------------------------------------------------------------------------
457 void vtkMPR3DDataViewer::SetPositionY(int pos)
459 int x1,x2,y1,y2,z1,z2;
460 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
463 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
465 _coronal->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
468 //------------------------------------------------------------------------
469 void vtkMPR3DDataViewer::SetPositionZ(int pos)
471 int x1,x2,y1,y2,z1,z2;
472 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
475 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
477 _axial->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
480 //-------------------------------------------------------------------
481 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
483 _visiblePosition[idPosition]=visible;
485 //-------------------------------------------------------------------
486 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
488 return _visiblePosition[idPosition];
491 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable)
495 _saggitalColors->SetLookupTable(colortable);
496 _coronalColors->SetLookupTable(colortable);
497 _axialColors->SetLookupTable(colortable);