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::Configure()
146 // Start by creatin a black/white lookup table.
147 _bwLut = vtkLookupTable::New();
148 _bwLut->SetTableRange (0, 2000);
149 _bwLut->SetSaturationRange (0, 0);
150 _bwLut->SetHueRange (0, 0);
151 _bwLut->SetValueRange (0, 1);
153 // Now create a lookup table that consists of the full hue circle
155 _hueLut = vtkLookupTable::New();
156 _hueLut->SetTableRange (0, 2000);
157 _hueLut->SetHueRange (0, 1);
158 _hueLut->SetSaturationRange (1, 1);
159 _hueLut->SetValueRange (1, 1);
161 // Finally, create a lookup table with a single hue but having a range
162 // in the saturation of the hue.
163 _satLut = vtkLookupTable::New();
164 _satLut->SetTableRange (0, 2000);
165 _satLut->SetHueRange (.6, .6);
166 _satLut->SetSaturationRange (0, 1);
167 _satLut->SetValueRange (1, 1);
174 if(_vtkmprbasedata->GetImageData())
176 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
177 delta = range[1]-range[0];
180 _ctFunVectorPoint.clear();
181 _ctFunVectorPoint.push_back( range[0] + delta*0/4 );
182 _ctFunVectorPoint.push_back( range[0] + delta*1/4 );
183 _ctFunVectorPoint.push_back( range[0] + delta*2/4 );
184 _ctFunVectorPoint.push_back( range[0] + delta*3/4 );
185 _ctFunVectorPoint.push_back( range[0] + delta*4/4 );
187 _ctFunVectorRed.clear();
188 _ctFunVectorRed.push_back(0.0);
189 _ctFunVectorRed.push_back(1.0);
190 _ctFunVectorRed.push_back(0.0);
191 _ctFunVectorRed.push_back(0.0);
192 _ctFunVectorRed.push_back(0.0);
194 _ctFunVectorGreen.clear();
195 _ctFunVectorGreen.push_back(0.0);
196 _ctFunVectorGreen.push_back(0.0);
197 _ctFunVectorGreen.push_back(0.0);
198 _ctFunVectorGreen.push_back(1.0);
199 _ctFunVectorGreen.push_back(0.2);
201 _ctFunVectorBlue.clear();
202 _ctFunVectorBlue.push_back(0.0);
203 _ctFunVectorBlue.push_back(0.0);
204 _ctFunVectorBlue.push_back(1.0);
205 _ctFunVectorBlue.push_back(0.0);
206 _ctFunVectorBlue.push_back(0.0);
211 _ctfun = vtkColorTransferFunction::New();
213 _ctfun->RemoveAllPoints();
215 int i,size=_ctFunVectorPoint.size();
218 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
222 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
223 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
224 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
225 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
227 // void *p=this; // JPRx
229 // Create the first of the three planes. The filter vtkImageMapToColors
230 // maps the data through the corresponding lookup table created above. The
231 // vtkImageActor is a type of vtkProp and conveniently displays an image on
232 // a single quadrilateral plane. It does this using texture mapping and as
233 // a result is quite fast. (Note: the input image has to be unsigned char
234 // values, which the vtkImageMapToColors produces.) Note also that by
235 // specifying the DisplayExtent, the pipeline requests data of this extent
236 // and the vtkImageMapToColors only processes a slice of data.
238 if(_saggitalColors==NULL){
239 _saggitalColors = vtkImageMapToColors::New();
241 _saggitalColors->RemoveAllInputs();
242 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
244 // _saggitalColors->SetLookupTable(_bwLut);
246 _saggitalColors->SetLookupTable(_ctfun);
250 _saggital = vtkImageActor::New();
251 _saggital->SetInput(_saggitalColors->GetOutput());
253 //_saggitalColors->Update();
257 // Create the second (axial) plane of the three planes. We use the
258 // same approach as before except that the extent differs.
261 if(_axialColors==NULL){
262 _axialColors = vtkImageMapToColors::New();
265 _axialColors->RemoveAllInputs();
266 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
267 // _axialColors->SetLookupTable(_hueLut);
268 _axialColors->SetLookupTable(_ctfun);
271 _axial = vtkImageActor::New();
272 _axial->SetInput(_axialColors->GetOutput());
275 //_axialColors->Update();
278 // Create the third (coronal) plane of the three planes. We use
279 // the same approach as before except that the extent differs.
280 if(_coronalColors==NULL){
281 _coronalColors = vtkImageMapToColors::New();
283 _coronalColors->RemoveAllInputs();
284 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
285 // _coronalColors->SetLookupTable(_satLut);
286 _coronalColors->SetLookupTable(_ctfun);
289 _coronal = vtkImageActor::New();
290 _coronal->SetInput(_coronalColors->GetOutput());
295 // An outline provides context around the data.
297 if(_outlineData==NULL){
298 _outlineData = vtkOutlineFilter::New();
300 _outlineData->RemoveAllInputs();
301 if(_vtkmprbasedata->GetImageData()){
302 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
305 if(_mapOutline==NULL){
306 _mapOutline = vtkPolyDataMapper::New();
307 _mapOutline->SetInput(_outlineData->GetOutput());
309 _mapOutline->Update();
310 //_mapOutline->RemoveAllInputs();
313 _outline = vtkActor::New();
314 _outline->SetMapper(_mapOutline);
315 _outline->GetProperty()->SetColor(0,0,0);
326 //_vtkmprbasedata->GetImageData()->GetExtent(ext);
333 //-------------------------------------------------------------------
334 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
338 //-------------------------------------------------------------------
339 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
343 //-------------------------------------------------------------------
344 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
349 //------------------------------------------------------------------------
350 void vtkMPR3DDataViewer::SetPositionX(int pos)
352 int x1,x2,y1,y2,z1,z2;
353 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
356 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
358 _saggital->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
362 //------------------------------------------------------------------------
363 void vtkMPR3DDataViewer::SetPositionY(int pos)
365 int x1,x2,y1,y2,z1,z2;
366 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
369 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
371 _coronal->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
374 //------------------------------------------------------------------------
375 void vtkMPR3DDataViewer::SetPositionZ(int pos)
377 int x1,x2,y1,y2,z1,z2;
378 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
381 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
383 _axial->SetInterpolate( GetVtkMPRBaseData()->GetInterpolate() );
386 //-------------------------------------------------------------------
387 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
389 _visiblePosition[idPosition]=visible;
391 //-------------------------------------------------------------------
392 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
394 return _visiblePosition[idPosition];
397 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
400 _saggitalColors->SetLookupTable(colortable);
401 _coronalColors->SetLookupTable(colortable);
402 _axialColors->SetLookupTable(colortable);