2 #include "vtkClipping3DDataViewer.h"
3 #include "vtkDataSetReader.h"
4 #include "vtkProperty.h"
6 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
9 for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
10 _visibleTissue[i] = false;
11 _representationType[i] = true;
15 //-------------------------------------------------------------------
16 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
19 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
21 _tissueStripper[i]->Delete();
22 _tissueMapper[i]->Delete();
23 _tissuePlanes[i]->Delete();
24 _tissueClipper[i]->Delete();
26 _outlineData->Delete();
27 _mapOutline->Delete();
32 _compositeFunction->Delete();
33 _volumeMapper->Delete();
34 _volumeProperty->Delete();
36 _volumePlanes->Delete();
38 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
39 _tissue[i]-> Delete();
40 _observerS[i]-> Delete();
42 _observerV-> Delete();
44 //-------------------------------------------------------------------
45 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
49 //-------------------------------------------------------------------
50 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
52 return this->_tissueClipper[id];
54 //-------------------------------------------------------------------
55 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
57 return _tissueMapper[id];
59 //-------------------------------------------------------------------
60 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
62 return _tissuePlanes[id];
64 //-------------------------------------------------------------------
65 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
67 return _tissueStripper[id];
69 //-------------------------------------------------------------------
70 void vtkClipping3DDataViewer::Refresh()
72 // _volumeMapper->SetClippingPlanes(_volumePlanes);
74 // this->_volumeMapper->Update();
75 // this->_newvol->Update();
77 // _newvol->VisibilityOn();
80 // _volumeMapper = vtkVolumeRayCastMapper::New();
81 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
82 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
83 // _volumeMapper->SetClippingPlanes( _volumePlanes );
84 // _newvol->SetMapper(_volumeMapper );
88 //-------------------------------------------------------------------
89 void vtkClipping3DDataViewer::RefreshSurface()
92 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
94 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
95 // this->GetMCubes(i)->Update();
98 //-------------------------------------------------------------------
99 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
101 _vtkmprbasedata=vtkmprbasedata;
103 //-------------------------------------------------------------------
104 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
106 return _vtkmprbasedata;
110 //-------------------------------------------------------------------
111 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
113 _visibleTissue[idTissue]=visible;
115 //-------------------------------------------------------------------
116 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
117 return _visibleTissue[idTissue];
119 //-------------------------------------------------------------------
120 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
122 _representationType[idTissue]=representationType;
124 //-------------------------------------------------------------------
125 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
127 return _representationType[idTissue];
130 //-------------------------------------------------------------------
131 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
135 //-------------------------------------------------------------------
136 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
138 return _observerS[idObserverS];
140 //-------------------------------------------------------------------
141 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
146 //-------------------------------------------------------------------
147 bool vtkClipping3DDataViewer::GetVisibleVolume()
149 return _visibleVolume;
151 //-------------------------------------------------------------------
152 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
154 _visibleVolume = visiblevolume;
158 //-------------------------------------------------------------------
159 void vtkClipping3DDataViewer::Configure_Tissue()
164 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
165 // Visualisation - original volume
166 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
167 imagedata->GetScalarRange( range );
168 _mCubes[i] = vtkMarchingCubes::New( );
169 _mCubes[i]->SetInput( imagedata );
171 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
172 // _mCubes[i]->SetValue( 0, 1500 );
174 _tissueStripper[i] = vtkStripper::New();
175 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
179 _tissuePlanes[i] = vtkPlanes::New();
181 int x1,x2,y1,y2,z1,z2;
182 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
183 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
185 _tissueClipper[i] = vtkClipPolyData::New();
186 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
187 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
188 _tissueClipper[i]->InsideOutOn( );
190 _tissueMapper[i] = vtkPolyDataMapper::New( );
191 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
192 _tissueMapper[i]->ScalarVisibilityOff( );
193 // _tissueMapper[i]->Update();
200 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
202 _tissue[i] = vtkActor::New();
203 _tissue[i]->SetMapper( GetTissueMapper(i) );
204 float cr=1,cg=0.5,cb=0.5;
205 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
206 _tissue[i]->GetProperty()->SetSpecular(.3);
207 _tissue[i]->GetProperty()->SetSpecularPower(20);
208 _tissue[i]->GetProperty()->SetOpacity(0.5);
209 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
210 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
211 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
212 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
215 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
217 _observerS[i] = boxSurfaceObserver::New();
218 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
219 _observerS[i]->SetActor( _tissue[i] );
224 //-----------------------------------------------------------------------------
226 void vtkClipping3DDataViewer::Configure_Volume()
230 _tfun = vtkPiecewiseFunction::New();
231 _ctfun = vtkColorTransferFunction::New();
234 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
235 double max = range[1];
238 adding the poinst of the transference function
241 greyValuesTransferenceFVector.push_back(max * 0/2); // JPR ?? 0/2
242 greyValuesTransferenceFVector.push_back(max * 1/2); // JPR ?? division entiere?
243 greyValuesTransferenceFVector.push_back(max * 2/2);
245 intensityValuesTransferenceFVector.push_back(0.0);
246 intensityValuesTransferenceFVector.push_back(1.0);
247 intensityValuesTransferenceFVector.push_back(1.0);
249 _tfun->AddPoint(max * 0/2 , 0.0);
250 _tfun->AddPoint(max * 1/2 , 1.0);
251 _tfun->AddPoint(max * 2/2 , 1.0);
254 Adding the colors to the vectors
257 redColorsOfColorTransferenceFVector.push_back(0.0);
258 redColorsOfColorTransferenceFVector.push_back(1.0);
259 redColorsOfColorTransferenceFVector.push_back(0.0);
260 redColorsOfColorTransferenceFVector.push_back(0.0);
261 redColorsOfColorTransferenceFVector.push_back(0.0);
264 greenColorsOfColorTransferenceFVector.push_back(0.0);
265 greenColorsOfColorTransferenceFVector.push_back(0.0);
266 greenColorsOfColorTransferenceFVector.push_back(0.0);
267 greenColorsOfColorTransferenceFVector.push_back(1.0);
268 greenColorsOfColorTransferenceFVector.push_back(0.2);
271 blueColorsOfColorTransferenceFVector.push_back(0.0);
272 blueColorsOfColorTransferenceFVector.push_back(0.0);
273 blueColorsOfColorTransferenceFVector.push_back(1.0);
274 blueColorsOfColorTransferenceFVector.push_back(0.0);
275 blueColorsOfColorTransferenceFVector.push_back(0.0);
277 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
278 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
279 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
280 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
281 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
283 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
284 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
285 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
286 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
287 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
289 _volumePlanes = vtkPlanes::New();
290 // int x1,x2,y1,y2,z1,z2;
291 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
292 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
293 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
295 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
297 _volumeMapper = vtkVolumeRayCastMapper::New();
298 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
299 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
300 _volumeMapper->SetClippingPlanes( _volumePlanes );
301 _volumeMapper->AutoAdjustSampleDistancesOn();
303 _volumeProperty = vtkVolumeProperty::New();
304 _volumeProperty->SetColor(_ctfun);
305 _volumeProperty->SetScalarOpacity( _tfun );
307 _volumeProperty->SetInterpolationTypeToLinear();
308 _volumeProperty->ShadeOn();
309 _volumeProperty->DisableGradientOpacityOn();
311 // _volumeProperty->SetInterpolationTypeToNearest();
312 // _volumeProperty->ShadeOff();
313 // _volumeProperty->SetAmbient(0.3);
314 // _volumeProperty->SetDiffuse(0.1);
315 // _volumeProperty->SetSpecular(0.8);
316 // _volumeProperty->DisableGradientOpacityOn();
318 _newvol = vtkVolume::New();
319 _newvol->SetMapper(_volumeMapper );
320 _newvol->SetProperty(_volumeProperty );
322 _observerV = boxSurfaceObserver::New();
323 _observerV->SetPlanes( _volumePlanes );
324 _observerV->SetActor( _newvol );
325 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
329 //-------------------------------------------------------------------
330 void vtkClipping3DDataViewer::Configure()
335 // An outline provides context around the data.
337 _outlineData = vtkOutlineFilter::New();
338 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
339 _mapOutline = vtkPolyDataMapper::New();
340 _mapOutline->SetInput(_outlineData->GetOutput());
341 _outline = vtkActor::New();
342 _outline->SetMapper(_mapOutline);
343 _outline->GetProperty()->SetColor(0,0,0);
347 //-------------------------------------------------------------------
348 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
350 _mCubes[idTissue]->SetValue(0, isoValue);
352 //-------------------------------------------------------------------
353 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
355 return _mCubes[idTissue]->GetValue(0);
357 //-------------------------------------------------------------------
358 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
362 //-------------------------------------------------------------------
363 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
364 return _volumeMapper;
366 //-------------------------------------------------------------------
367 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
369 return _volumePlanes;
372 //-------------------------------------------------------------------
373 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
375 return _mCubes[idTissue];
377 //--------------------------------------------------------------------
378 //-------------------
380 //-------------------
382 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
384 return &greyValuesTransferenceFVector;
386 //--------------------------------------------------------------------
387 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
389 return &intensityValuesTransferenceFVector;
391 //--------------------------------------------------------------------
392 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
394 return &redColorsOfColorTransferenceFVector;
396 //--------------------------------------------------------------------
397 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
399 return &greenColorsOfColorTransferenceFVector;
401 //--------------------------------------------------------------------
402 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
404 return &blueColorsOfColorTransferenceFVector;
406 //--------------------------------------------------------------------
407 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
409 return &greyValueColorsOfColorTransferenceFVector;
411 //--------------------------------------------------------------------
412 //--------------------------------------
413 //Getters transference function
414 //and color of the transference function
415 //---------------------------------------
416 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
420 //--------------------------------------------------------------------
421 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
426 //-------------------------------------------------------------------
428 void vtkClipping3DDataViewer::ReadVolumeFunctions()
431 int i=0,xi,yi,r,g,b,gValue;
432 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
434 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
438 int tfSize=this->greyValuesTransferenceFVector.size();
442 hDlg->erasePointsTransferenceFunction();
445 double g=greyValuesTransferenceFVector[i];
446 double in=intensityValuesTransferenceFVector[i];
447 hDlg->addPointToTransferenceFunction(g,in*100);
453 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
459 double gr=greyValueColorsOfColorTransferenceFVector[i];
460 double r=redColorsOfColorTransferenceFVector[i];
461 double g=greenColorsOfColorTransferenceFVector[i];
462 double b=blueColorsOfColorTransferenceFVector[i];
463 hDlg->addColorPoint(gr,r*255,g*255,b*255);
467 //If it is smooth activate next line
468 //hDlg->updatePlotter();
469 //setting variables if the user wants to do refresh
470 hDlg->setCTF(_ctfun);
474 // when the user had changed the transference Function
476 if(hDlg->ShowModal()== wxID_OK )
478 // -- vtkPiecewiseFunction --
479 this->_tfun->RemoveAllPoints();
480 greyValuesTransferenceFVector.clear();
481 intensityValuesTransferenceFVector.clear();
483 int nTFPoints=hDlg->getSizeTransferenceFunction();
487 hDlg->getTransferenceFunctionPoint(i,xi,yi);
488 this->_tfun->AddPoint( xi , yi/100.0 );
489 greyValuesTransferenceFVector.push_back(xi);
490 intensityValuesTransferenceFVector.push_back(yi/100.0);
493 // -- vtkColorTransferFunction --
494 this->_ctfun->RemoveAllPoints ();
496 redColorsOfColorTransferenceFVector.clear();
497 greenColorsOfColorTransferenceFVector.clear();
498 blueColorsOfColorTransferenceFVector.clear();
499 greyValueColorsOfColorTransferenceFVector.clear();
501 int nCTFpoints=hDlg->getSizeBarColor();
505 hDlg->getDataBarColorPoint(i,xi,r,g,b);
506 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
507 redColorsOfColorTransferenceFVector.push_back(r/255.0);
508 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
509 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
510 greyValueColorsOfColorTransferenceFVector.push_back(xi);
514 this->_volumeMapper->Update();
515 this->_newvol->Update();
521 if(hDlg->getRefreshed())
524 //--Transference Function----
525 this->_tfun->RemoveAllPoints();
527 size=greyValuesTransferenceFVector.size();
530 double grey1=greyValuesTransferenceFVector[i];
531 double in2=intensityValuesTransferenceFVector[i];
532 this->_tfun->AddPoint( grey1 , in2 );
535 // -- vtkColorTransferFunction --
536 _ctfun->RemoveAllPoints ();
539 size=greyValueColorsOfColorTransferenceFVector.size();
542 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
543 double red =(redColorsOfColorTransferenceFVector)[i];
544 double green =(greenColorsOfColorTransferenceFVector)[i];
545 double blue = (blueColorsOfColorTransferenceFVector)[i];
546 _ctfun->AddRGBPoint(grey2,red,green,blue);
548 this->_volumeMapper->Update();
549 this->_newvol->Update();
557 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
564 FILE *ff = fopen ( namefile ,"r");
568 if (strcmp(tmp,"MAX")==0)
570 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
571 vtkimagedata->GetScalarRange(range);
572 max = (int) (range[1]);
577 fscanf(ff,"%s",tmp); // --
579 // -- vtkPiecewiseFunction --
580 this->_tfun->RemoveAllPoints();
582 while ( strcmp(tmp,"--")!=0 )
587 this->_tfun->AddPoint( x*max , val );
591 this->_ctfun->RemoveAllPoints ();
592 // -- vtkColorTransferFunction --
603 this->_ctfun->AddRGBPoint( x*max , r,g,b );
607 this->_volumeMapper->Update();
608 this->_newvol->Update();
615 //-------------------------------------------------------------------
617 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
619 vtkDataSetReader *reader = vtkDataSetReader::New();
620 reader->SetFileName(namefile);
622 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );
625 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
627 _volumeProperty->SetColor(colortable);