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;
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;
78 tmpVtkActor = GetvtkActor_saggital();
81 tmpVtkActor = GetvtkActor_coronal();
84 tmpVtkActor = GetvtkActor_axial();
88 //-------------------------------------------------------------------
89 void vtkMPR3DDataViewer::Refresh()
91 int x = (int)(_vtkmprbasedata->GetX());
92 int y = (int)(_vtkmprbasedata->GetY());
93 int z = (int)(_vtkmprbasedata->GetZ());
98 //-------------------------------------------------------------------
99 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
101 _vtkmprbasedata=vtkmprbasedata;
103 //-------------------------------------------------------------------
104 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
106 return _vtkmprbasedata;
108 //-------------------------------------------------------------------
110 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
114 //-------------------------------------------------------------------
116 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
118 return &_ctFunVectorPoint;
120 //-------------------------------------------------------------------
121 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
123 return &_ctFunVectorRed;
126 //-------------------------------------------------------------------
127 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
129 return &_ctFunVectorGreen;
132 //-------------------------------------------------------------------
133 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
135 return &_ctFunVectorBlue;
138 //-------------------------------------------------------------------
139 void vtkMPR3DDataViewer::Configure()
142 // Start by creatin a black/white lookup table.
143 _bwLut = vtkLookupTable::New();
144 _bwLut->SetTableRange (0, 2000);
145 _bwLut->SetSaturationRange (0, 0);
146 _bwLut->SetHueRange (0, 0);
147 _bwLut->SetValueRange (0, 1);
149 // Now create a lookup table that consists of the full hue circle
151 _hueLut = vtkLookupTable::New();
152 _hueLut->SetTableRange (0, 2000);
153 _hueLut->SetHueRange (0, 1);
154 _hueLut->SetSaturationRange (1, 1);
155 _hueLut->SetValueRange (1, 1);
157 // Finally, create a lookup table with a single hue but having a range
158 // in the saturation of the hue.
159 _satLut = vtkLookupTable::New();
160 _satLut->SetTableRange (0, 2000);
161 _satLut->SetHueRange (.6, .6);
162 _satLut->SetSaturationRange (0, 1);
163 _satLut->SetValueRange (1, 1);
170 if(_vtkmprbasedata->GetImageData())
172 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
173 delta = range[1]-range[0];
176 _ctFunVectorPoint.clear();
177 _ctFunVectorPoint.push_back( range[0] + delta*0/4 );
178 _ctFunVectorPoint.push_back( range[0] + delta*1/4 );
179 _ctFunVectorPoint.push_back( range[0] + delta*2/4 );
180 _ctFunVectorPoint.push_back( range[0] + delta*3/4 );
181 _ctFunVectorPoint.push_back( range[0] + delta*4/4 );
183 _ctFunVectorRed.clear();
184 _ctFunVectorRed.push_back(0.0);
185 _ctFunVectorRed.push_back(1.0);
186 _ctFunVectorRed.push_back(0.0);
187 _ctFunVectorRed.push_back(0.0);
188 _ctFunVectorRed.push_back(0.0);
190 _ctFunVectorGreen.clear();
191 _ctFunVectorGreen.push_back(0.0);
192 _ctFunVectorGreen.push_back(0.0);
193 _ctFunVectorGreen.push_back(0.0);
194 _ctFunVectorGreen.push_back(1.0);
195 _ctFunVectorGreen.push_back(0.2);
197 _ctFunVectorBlue.clear();
198 _ctFunVectorBlue.push_back(0.0);
199 _ctFunVectorBlue.push_back(0.0);
200 _ctFunVectorBlue.push_back(1.0);
201 _ctFunVectorBlue.push_back(0.0);
202 _ctFunVectorBlue.push_back(0.0);
207 _ctfun = vtkColorTransferFunction::New();
209 _ctfun->RemoveAllPoints();
211 int i,size=_ctFunVectorPoint.size();
214 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
218 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
219 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
220 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
221 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
223 // void *p=this; // JPRx
225 // Create the first of the three planes. The filter vtkImageMapToColors
226 // maps the data through the corresponding lookup table created above. The
227 // vtkImageActor is a type of vtkProp and conveniently displays an image on
228 // a single quadrilateral plane. It does this using texture mapping and as
229 // a result is quite fast. (Note: the input image has to be unsigned char
230 // values, which the vtkImageMapToColors produces.) Note also that by
231 // specifying the DisplayExtent, the pipeline requests data of this extent
232 // and the vtkImageMapToColors only processes a slice of data.
234 if(_saggitalColors==NULL){
235 _saggitalColors = vtkImageMapToColors::New();
237 _saggitalColors->RemoveAllInputs();
238 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
240 // _saggitalColors->SetLookupTable(_bwLut);
242 _saggitalColors->SetLookupTable(_ctfun);
246 _saggital = vtkImageActor::New();
247 _saggital->SetInput(_saggitalColors->GetOutput());
249 //_saggitalColors->Update();
253 // Create the second (axial) plane of the three planes. We use the
254 // same approach as before except that the extent differs.
257 if(_axialColors==NULL){
258 _axialColors = vtkImageMapToColors::New();
261 _axialColors->RemoveAllInputs();
262 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
263 // _axialColors->SetLookupTable(_hueLut);
264 _axialColors->SetLookupTable(_ctfun);
267 _axial = vtkImageActor::New();
268 _axial->SetInput(_axialColors->GetOutput());
271 //_axialColors->Update();
274 // Create the third (coronal) plane of the three planes. We use
275 // the same approach as before except that the extent differs.
276 if(_coronalColors==NULL){
277 _coronalColors = vtkImageMapToColors::New();
279 _coronalColors->RemoveAllInputs();
280 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
281 // _coronalColors->SetLookupTable(_satLut);
282 _coronalColors->SetLookupTable(_ctfun);
285 _coronal = vtkImageActor::New();
286 _coronal->SetInput(_coronalColors->GetOutput());
291 // An outline provides context around the data.
293 if(_outlineData==NULL){
294 _outlineData = vtkOutlineFilter::New();
296 _outlineData->RemoveAllInputs();
297 if(_vtkmprbasedata->GetImageData()){
298 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
301 if(_mapOutline==NULL){
302 _mapOutline = vtkPolyDataMapper::New();
303 _mapOutline->SetInput(_outlineData->GetOutput());
305 _mapOutline->Update();
306 //_mapOutline->RemoveAllInputs();
309 _outline = vtkActor::New();
310 _outline->SetMapper(_mapOutline);
311 _outline->GetProperty()->SetColor(0,0,0);
322 //_vtkmprbasedata->GetImageData()->GetExtent(ext);
329 //-------------------------------------------------------------------
330 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
334 //-------------------------------------------------------------------
335 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
339 //-------------------------------------------------------------------
340 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
345 //------------------------------------------------------------------------
346 void vtkMPR3DDataViewer::SetPositionX(int pos){
347 int x1,x2,y1,y2,z1,z2;
348 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
351 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
354 //------------------------------------------------------------------------
355 void vtkMPR3DDataViewer::SetPositionY(int pos){
356 int x1,x2,y1,y2,z1,z2;
357 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
360 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
363 //------------------------------------------------------------------------
364 void vtkMPR3DDataViewer::SetPositionZ(int pos){
365 int x1,x2,y1,y2,z1,z2;
366 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
369 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
372 //-------------------------------------------------------------------
373 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
375 _visiblePosition[idPosition]=visible;
377 //-------------------------------------------------------------------
378 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
380 return _visiblePosition[idPosition];
383 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
386 _saggitalColors->SetLookupTable(colortable);
387 _coronalColors->SetLookupTable(colortable);
388 _axialColors->SetLookupTable(colortable);