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;
38 _saggitalColors = NULL;
42 _coronalColors = NULL;
48 //-------------------------------------------------------------------
49 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
51 if(_outlineData) {_outlineData -> Delete();}
52 if(_mapOutline) {_mapOutline -> Delete();}
53 if(_outline) {_outline -> Delete();}
54 // if (_bwLut) {_bwLut -> Delete();}
55 // if (_hueLut) {_hueLut -> Delete();}
56 // if (_satLut) {_satLut -> Delete();}
57 if (_ctfun) {_ctfun -> Delete();}
58 if (_saggitalColors) {_saggitalColors -> Delete();}
59 if (_saggital) {_saggital -> Delete();}
60 if (_axialColors) {_axialColors -> Delete();}
61 if (_axial) {_axial -> Delete();}
62 if (_coronalColors) {_coronalColors -> Delete();}
63 if (_coronal) {_coronal -> Delete();}
66 //-------------------------------------------------------------------
67 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
72 //-------------------------------------------------------------------
73 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
75 vtkImageActor *tmpVtkActor=NULL;
78 tmpVtkActor = GetvtkActor_saggital();
82 tmpVtkActor = GetvtkActor_coronal();
86 tmpVtkActor = GetvtkActor_axial();
91 //-------------------------------------------------------------------
92 void vtkMPR3DDataViewer::Refresh()
94 int x = (int)(_vtkmprbasedata->GetX());
95 int y = (int)(_vtkmprbasedata->GetY());
96 int z = (int)(_vtkmprbasedata->GetZ());
101 //-------------------------------------------------------------------
102 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
104 _vtkmprbasedata=vtkmprbasedata;
106 //-------------------------------------------------------------------
107 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
109 return _vtkmprbasedata;
111 //-------------------------------------------------------------------
113 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
117 //-------------------------------------------------------------------
119 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
121 return &_ctFunVectorPoint;
123 //-------------------------------------------------------------------
124 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
126 return &_ctFunVectorRed;
129 //-------------------------------------------------------------------
130 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
132 return &_ctFunVectorGreen;
135 //-------------------------------------------------------------------
136 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
138 return &_ctFunVectorBlue;
141 //-------------------------------------------------------------------
142 void vtkMPR3DDataViewer::SetImage()
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 _outlineData -> SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
151 _saggitalColors -> SetInputData( _vtkmprbasedata->GetImageData() );
152 _axialColors -> SetInputData( _vtkmprbasedata->GetImageData() );
153 _coronalColors -> SetInputData( _vtkmprbasedata->GetImageData() );
155 //EED 2020-01-27 this is to slow ??? how can we accelerated
156 // _saggitalColors -> Update();
157 // _axialColors -> Update();
158 // _coronalColors -> Update();
160 _outlineData -> SetInputData((vtkDataSet *) _vtkmprbasedata->GetImageData() );
165 //-------------------------------------------------------------------
166 void vtkMPR3DDataViewer::Configure()
169 // Start by creatin a black/white lookup table.
170 _bwLut = vtkLookupTable::New();
171 _bwLut->SetTableRange (0, 2000);
172 _bwLut->SetSaturationRange (0, 0);
173 _bwLut->SetHueRange (0, 0);
174 _bwLut->SetValueRange (0, 1);
176 // Now create a lookup table that consists of the full hue circle
178 _hueLut = vtkLookupTable::New();
179 _hueLut->SetTableRange (0, 2000);
180 _hueLut->SetHueRange (0, 1);
181 _hueLut->SetSaturationRange (1, 1);
182 _hueLut->SetValueRange (1, 1);
184 // Finally, create a lookup table with a single hue but having a range
185 // in the saturation of the hue.
186 _satLut = vtkLookupTable::New();
187 _satLut->SetTableRange (0, 2000);
188 _satLut->SetHueRange (.6, .6);
189 _satLut->SetSaturationRange (0, 1);
190 _satLut->SetValueRange (1, 1);
195 if(_vtkmprbasedata->GetImageData())
197 //EED 2017-01-01 Migration VTK7
198 #if VTK_MAJOR_VERSION <= 5
199 _vtkmprbasedata->GetImageData()->Update();
203 _vtkmprbasedata->GetImageData()->Modified();
204 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
205 delta = range[1]-range[0];
208 printf("EED vtkMPR3DDataViewer::Configure Warning! image Range [0,0] -> changed to [0,1000] \n" );
212 _ctFunVectorPoint.clear();
213 _ctFunVectorPoint.push_back( range[0] + delta*0/8 );
214 _ctFunVectorPoint.push_back( range[0] + delta*1/8 );
215 _ctFunVectorPoint.push_back( range[0] + delta*2/8 );
216 _ctFunVectorPoint.push_back( range[0] + delta*3/8 );
217 _ctFunVectorPoint.push_back( range[0] + delta*4/8 );
218 _ctFunVectorPoint.push_back( range[0] + delta*5/8 );
219 _ctFunVectorPoint.push_back( range[0] + delta*6/8 );
220 _ctFunVectorPoint.push_back( range[0] + delta*7/8 );
221 _ctFunVectorPoint.push_back( range[0] + delta*8/8 );
223 _ctFunVectorRed.clear();
224 _ctFunVectorRed.push_back(0.0);
225 _ctFunVectorRed.push_back(0.0);
226 _ctFunVectorRed.push_back(0.0);
227 _ctFunVectorRed.push_back(0.0);
228 _ctFunVectorRed.push_back(0.5);
229 _ctFunVectorRed.push_back(1.0);
230 _ctFunVectorRed.push_back(1.0);
231 _ctFunVectorRed.push_back(1.0);
232 _ctFunVectorRed.push_back(0.5);
234 _ctFunVectorGreen.clear();
235 _ctFunVectorGreen.push_back(0.0);
236 _ctFunVectorGreen.push_back(0.0);
237 _ctFunVectorGreen.push_back(0.5);
238 _ctFunVectorGreen.push_back(1.0);
239 _ctFunVectorGreen.push_back(1.0);
240 _ctFunVectorGreen.push_back(1.0);
241 _ctFunVectorGreen.push_back(0.5);
242 _ctFunVectorGreen.push_back(0.0);
243 _ctFunVectorGreen.push_back(0.0);
245 _ctFunVectorBlue.clear();
246 _ctFunVectorBlue.push_back(0.5);
247 _ctFunVectorBlue.push_back(1.0);
248 _ctFunVectorBlue.push_back(1.0);
249 _ctFunVectorBlue.push_back(1.0);
250 _ctFunVectorBlue.push_back(0.5);
251 _ctFunVectorBlue.push_back(0.0);
252 _ctFunVectorBlue.push_back(0.0);
253 _ctFunVectorBlue.push_back(0.0);
254 _ctFunVectorBlue.push_back(0.0);
258 _ctfun = vtkColorTransferFunction::New();
260 _ctfun->RemoveAllPoints();
262 int i,size=_ctFunVectorPoint.size();
265 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
269 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
270 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
271 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
272 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
274 // void *p=this; // JPRx
276 // Create the first of the three planes. The filter vtkImageMapToColors
277 // maps the data through the corresponding lookup table created above. The
278 // vtkImageActor is a type of vtkProp and conveniently displays an image on
279 // a single quadrilateral plane. It does this using texture mapping and as
280 // a result is quite fast. (Note: the input image has to be unsigned char
281 // values, which the vtkImageMapToColors produces.) Note also that by
282 // specifying the DisplayExtent, the pipeline requests data of this extent
283 // and the vtkImageMapToColors only processes a slice of data.
285 if(_saggitalColors==NULL)
287 _saggitalColors = vtkImageMapToColors::New();
289 _saggitalColors->RemoveAllInputs();
291 // _saggitalColors->SetLookupTable(_bwLut);
292 _saggitalColors->SetLookupTable(_ctfun);
293 //EED 2017-01-01 Migration VTK7
294 #if VTK_MAJOR_VERSION <= 5
295 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
297 _saggitalColors->SetInputData( _vtkmprbasedata->GetImageData() );
298 _saggitalColors->Update();
304 _saggital = vtkImageActor::New();
305 //EED 2017-01-01 Migration VTK7
306 #if VTK_MAJOR_VERSION <= 5
307 _saggital->SetInput(_saggitalColors->GetOutput());
309 _saggital->SetInputData(_saggitalColors->GetOutput());
312 //_saggitalColors->Update();
314 // Create the second (axial) plane of the three planes. We use the
315 // same approach as before except that the extent differs.
317 if(_axialColors==NULL)
319 _axialColors = vtkImageMapToColors::New();
321 _axialColors->RemoveAllInputs();
322 // _axialColors->SetLookupTable(_hueLut);
323 _axialColors->SetLookupTable(_ctfun);
326 //EED 2017-01-01 Migration VTK7
327 #if VTK_MAJOR_VERSION <= 5
328 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
330 _axialColors->SetInputData( _vtkmprbasedata->GetImageData() );
331 _axialColors->Update();
336 _axial = vtkImageActor::New();
338 //EED 2017-01-01 Migration VTK7
339 #if VTK_MAJOR_VERSION <= 5
340 _axial->SetInput(_axialColors->GetOutput());
342 _axial->SetInputData(_axialColors->GetOutput());
347 //_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);
359 //EED 2017-01-01 Migration VTK7
360 #if VTK_MAJOR_VERSION <= 5
361 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
363 _coronalColors->SetInputData( _vtkmprbasedata->GetImageData() );
364 _coronalColors->Update();
370 _coronal = vtkImageActor::New();
372 //EED 2017-01-01 Migration VTK7
373 #if VTK_MAJOR_VERSION <= 5
374 _coronal->SetInput(_coronalColors->GetOutput());
376 _coronal->SetInputData(_coronalColors->GetOutput());
381 // An outline provides context around the data.
383 if(_outlineData==NULL)
385 _outlineData = vtkOutlineFilter::New();
387 _outlineData->RemoveAllInputs();
388 if(_vtkmprbasedata->GetImageData())
390 //EED 2017-01-01 Migration VTK7
391 #if VTK_MAJOR_VERSION <= 5
392 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
394 _outlineData->SetInputData((vtkDataSet *) _vtkmprbasedata->GetImageData() );
395 _outlineData->Update();
399 if(_mapOutline==NULL)
401 _mapOutline = vtkPolyDataMapper::New();
403 //EED 2017-01-01 Migration VTK7
404 #if VTK_MAJOR_VERSION <= 5
405 _mapOutline->SetInput(_outlineData->GetOutput());
407 _mapOutline->SetInputData(_outlineData->GetOutput());
411 _mapOutline->Update();
412 //_mapOutline->RemoveAllInputs();
416 _outline = vtkActor::New();
417 _outline->SetMapper(_mapOutline);
418 _outline->GetProperty()->SetColor(0,0,0);
422 //_vtkmprbasedata->GetImageData()->GetExtent(ext);
425 //-------------------------------------------------------------------
426 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
430 //-------------------------------------------------------------------
431 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
435 //-------------------------------------------------------------------
436 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
441 //------------------------------------------------------------------------
442 void vtkMPR3DDataViewer::SetPositionX(int pos)
444 int x1,x2,y1,y2,z1,z2;
445 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
448 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
450 _saggital->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
454 //------------------------------------------------------------------------
455 void vtkMPR3DDataViewer::SetPositionY(int pos)
457 int x1,x2,y1,y2,z1,z2;
458 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
461 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
463 _coronal->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
466 //------------------------------------------------------------------------
467 void vtkMPR3DDataViewer::SetPositionZ(int pos)
469 int x1,x2,y1,y2,z1,z2;
470 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
473 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
475 _axial->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
478 //-------------------------------------------------------------------
479 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
481 _visiblePosition[idPosition]=visible;
483 //-------------------------------------------------------------------
484 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
486 return _visiblePosition[idPosition];
489 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable)
493 _saggitalColors->SetLookupTable(colortable);
494 _coronalColors->SetLookupTable(colortable);
495 _axialColors->SetLookupTable(colortable);