2 #include "vtkMPR3DDataViewer.h"
5 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
7 _visiblePosition[0]=false;
8 _visiblePosition[1]=false;
9 _visiblePosition[2]=false;
24 //-------------------------------------------------------------------
25 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
27 if(_outlineData) {_outlineData-> Delete();}
28 if(_mapOutline) {_mapOutline-> Delete();}
29 if(_outline) {_outline-> Delete();}
31 // if (_bwLut) _bwLut->Delete();
32 // if (_hueLut) _hueLut->Delete();
33 // if (_satLut) _satLut->Delete();
34 if (_ctfun) _ctfun->Delete();
35 if (_saggitalColors) _saggitalColors ->Delete();
36 if (_saggital) _saggital->Delete();
37 if (_axialColors) _axialColors->Delete();
38 if (_axial) _axial->Delete();
39 if (_coronalColors) _coronalColors->Delete();
40 if (_coronal) _coronal->Delete();
43 //-------------------------------------------------------------------
44 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
48 //-------------------------------------------------------------------
49 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
51 vtkImageActor *tmpVtkActor=NULL;
53 tmpVtkActor = GetvtkActor_saggital();
56 tmpVtkActor = GetvtkActor_coronal();
59 tmpVtkActor = GetvtkActor_axial();
63 //-------------------------------------------------------------------
64 void vtkMPR3DDataViewer::Refresh()
66 int x = (int)(_vtkmprbasedata->GetX());
67 int y = (int)(_vtkmprbasedata->GetY());
68 int z = (int)(_vtkmprbasedata->GetZ());
73 //-------------------------------------------------------------------
74 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
76 _vtkmprbasedata=vtkmprbasedata;
78 //-------------------------------------------------------------------
79 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
81 return _vtkmprbasedata;
83 //-------------------------------------------------------------------
85 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
89 //-------------------------------------------------------------------
91 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
93 return &_ctFunVectorPoint;
95 //-------------------------------------------------------------------
96 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
98 return &_ctFunVectorRed;
101 //-------------------------------------------------------------------
102 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
104 return &_ctFunVectorGreen;
107 //-------------------------------------------------------------------
108 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
110 return &_ctFunVectorBlue;
113 //-------------------------------------------------------------------
114 void vtkMPR3DDataViewer::Configure()
117 // Start by creatin a black/white lookup table.
118 _bwLut = vtkLookupTable::New();
119 _bwLut->SetTableRange (0, 2000);
120 _bwLut->SetSaturationRange (0, 0);
121 _bwLut->SetHueRange (0, 0);
122 _bwLut->SetValueRange (0, 1);
124 // Now create a lookup table that consists of the full hue circle
126 _hueLut = vtkLookupTable::New();
127 _hueLut->SetTableRange (0, 2000);
128 _hueLut->SetHueRange (0, 1);
129 _hueLut->SetSaturationRange (1, 1);
130 _hueLut->SetValueRange (1, 1);
132 // Finally, create a lookup table with a single hue but having a range
133 // in the saturation of the hue.
134 _satLut = vtkLookupTable::New();
135 _satLut->SetTableRange (0, 2000);
136 _satLut->SetHueRange (.6, .6);
137 _satLut->SetSaturationRange (0, 1);
138 _satLut->SetValueRange (1, 1);
145 if(_vtkmprbasedata->GetImageData())
147 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
148 delta = range[1]-range[0];
151 _ctFunVectorPoint.clear();
152 _ctFunVectorPoint.push_back( range[0] + delta*0/4 );
153 _ctFunVectorPoint.push_back( range[0] + delta*1/4 );
154 _ctFunVectorPoint.push_back( range[0] + delta*2/4 );
155 _ctFunVectorPoint.push_back( range[0] + delta*3/4 );
156 _ctFunVectorPoint.push_back( range[0] + delta*4/4 );
158 _ctFunVectorRed.clear();
159 _ctFunVectorRed.push_back(0.0);
160 _ctFunVectorRed.push_back(1.0);
161 _ctFunVectorRed.push_back(0.0);
162 _ctFunVectorRed.push_back(0.0);
163 _ctFunVectorRed.push_back(0.0);
165 _ctFunVectorGreen.clear();
166 _ctFunVectorGreen.push_back(0.0);
167 _ctFunVectorGreen.push_back(0.0);
168 _ctFunVectorGreen.push_back(0.0);
169 _ctFunVectorGreen.push_back(1.0);
170 _ctFunVectorGreen.push_back(0.2);
172 _ctFunVectorBlue.clear();
173 _ctFunVectorBlue.push_back(0.0);
174 _ctFunVectorBlue.push_back(0.0);
175 _ctFunVectorBlue.push_back(1.0);
176 _ctFunVectorBlue.push_back(0.0);
177 _ctFunVectorBlue.push_back(0.0);
182 _ctfun = vtkColorTransferFunction::New();
184 _ctfun->RemoveAllPoints();
186 int i,size=_ctFunVectorPoint.size();
189 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
193 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
194 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
195 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
196 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
198 // void *p=this; // JPRx
200 // Create the first of the three planes. The filter vtkImageMapToColors
201 // maps the data through the corresponding lookup table created above. The
202 // vtkImageActor is a type of vtkProp and conveniently displays an image on
203 // a single quadrilateral plane. It does this using texture mapping and as
204 // a result is quite fast. (Note: the input image has to be unsigned char
205 // values, which the vtkImageMapToColors produces.) Note also that by
206 // specifying the DisplayExtent, the pipeline requests data of this extent
207 // and the vtkImageMapToColors only processes a slice of data.
209 if(_saggitalColors==NULL){
210 _saggitalColors = vtkImageMapToColors::New();
212 _saggitalColors->RemoveAllInputs();
213 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
215 // _saggitalColors->SetLookupTable(_bwLut);
217 _saggitalColors->SetLookupTable(_ctfun);
221 _saggital = vtkImageActor::New();
222 _saggital->SetInput(_saggitalColors->GetOutput());
224 //_saggitalColors->Update();
228 // Create the second (axial) plane of the three planes. We use the
229 // same approach as before except that the extent differs.
232 if(_axialColors==NULL){
233 _axialColors = vtkImageMapToColors::New();
236 _axialColors->RemoveAllInputs();
237 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
238 // _axialColors->SetLookupTable(_hueLut);
239 _axialColors->SetLookupTable(_ctfun);
242 _axial = vtkImageActor::New();
243 _axial->SetInput(_axialColors->GetOutput());
246 //_axialColors->Update();
249 // Create the third (coronal) plane of the three planes. We use
250 // the same approach as before except that the extent differs.
251 if(_coronalColors==NULL){
252 _coronalColors = vtkImageMapToColors::New();
254 _coronalColors->RemoveAllInputs();
255 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
256 // _coronalColors->SetLookupTable(_satLut);
257 _coronalColors->SetLookupTable(_ctfun);
260 _coronal = vtkImageActor::New();
261 _coronal->SetInput(_coronalColors->GetOutput());
266 // An outline provides context around the data.
268 if(_outlineData==NULL){
269 _outlineData = vtkOutlineFilter::New();
271 _outlineData->RemoveAllInputs();
272 if(_vtkmprbasedata->GetImageData()){
273 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
276 if(_mapOutline==NULL){
277 _mapOutline = vtkPolyDataMapper::New();
278 _mapOutline->SetInput(_outlineData->GetOutput());
280 _mapOutline->Update();
281 //_mapOutline->RemoveAllInputs();
284 _outline = vtkActor::New();
285 _outline->SetMapper(_mapOutline);
286 _outline->GetProperty()->SetColor(0,0,0);
297 //_vtkmprbasedata->GetImageData()->GetExtent(ext);
304 //-------------------------------------------------------------------
305 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
309 //-------------------------------------------------------------------
310 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
314 //-------------------------------------------------------------------
315 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
320 //------------------------------------------------------------------------
321 void vtkMPR3DDataViewer::SetPositionX(int pos){
322 int x1,x2,y1,y2,z1,z2;
323 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
326 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
329 //------------------------------------------------------------------------
330 void vtkMPR3DDataViewer::SetPositionY(int pos){
331 int x1,x2,y1,y2,z1,z2;
332 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
335 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
338 //------------------------------------------------------------------------
339 void vtkMPR3DDataViewer::SetPositionZ(int pos){
340 int x1,x2,y1,y2,z1,z2;
341 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
344 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
347 //-------------------------------------------------------------------
348 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
350 _visiblePosition[idPosition]=visible;
352 //-------------------------------------------------------------------
353 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
355 return _visiblePosition[idPosition];
358 void vtkMPR3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
361 _saggitalColors->SetLookupTable(colortable);
362 _coronalColors->SetLookupTable(colortable);
363 _axialColors->SetLookupTable(colortable);