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;
19 _volumeMapper = vtkVolumeRayCastMapper::New();
20 _newvol = vtkVolume::New();
21 _volumeProperty = vtkVolumeProperty::New();
22 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
23 _compositeFunctionMIP = vtkVolumeRayCastMIPFunction::New();
26 //-------------------------------------------------------------------
27 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
30 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
32 _tissueStripper[i]->Delete();
33 _tissueMapper[i]->Delete();
34 _tissuePlanes[i]->Delete();
35 _tissueClipper[i]->Delete();
37 _outlineData->Delete();
38 _mapOutline->Delete();
43 _compositeFunction->Delete();
44 _volumeMapper->Delete();
45 _volumeProperty->Delete();
47 _volumePlanes->Delete();
49 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
50 _tissue[i]-> Delete();
51 _observerS[i]-> Delete();
53 _observerV-> Delete();
55 //-------------------------------------------------------------------
56 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
60 //-------------------------------------------------------------------
61 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
63 return this->_tissueClipper[id];
65 //-------------------------------------------------------------------
66 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
68 return _tissueMapper[id];
70 //-------------------------------------------------------------------
71 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
73 return _tissuePlanes[id];
75 //-------------------------------------------------------------------
76 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
78 return _tissueStripper[id];
80 //-------------------------------------------------------------------
81 void vtkClipping3DDataViewer::Refresh()
83 // _volumeMapper->SetClippingPlanes(_volumePlanes);
85 // this->_volumeMapper->Update();
86 // this->_newvol->Update();
88 // _newvol->VisibilityOn();
91 // _volumeMapper = vtkVolumeRayCastMapper::New();
92 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
93 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
94 // _volumeMapper->SetClippingPlanes( _volumePlanes );
95 // _newvol->SetMapper(_volumeMapper );
99 //-------------------------------------------------------------------
100 void vtkClipping3DDataViewer::RefreshSurface()
103 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
105 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
106 // this->GetMCubes(i)->Update();
109 //-------------------------------------------------------------------
110 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
112 _vtkmprbasedata=vtkmprbasedata;
114 //-------------------------------------------------------------------
115 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
117 return _vtkmprbasedata;
121 //-------------------------------------------------------------------
122 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
124 _visibleTissue[idTissue]=visible;
126 //-------------------------------------------------------------------
127 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
128 return _visibleTissue[idTissue];
130 //-------------------------------------------------------------------
131 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
133 _representationType[idTissue]=representationType;
135 //-------------------------------------------------------------------
136 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
138 return _representationType[idTissue];
141 //-------------------------------------------------------------------
142 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
146 //-------------------------------------------------------------------
147 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
149 return _observerS[idObserverS];
151 //-------------------------------------------------------------------
152 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
157 //-------------------------------------------------------------------
158 bool vtkClipping3DDataViewer::GetVisibleVolume()
160 return _visibleVolume;
162 //-------------------------------------------------------------------
163 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
165 _visibleVolume = visiblevolume;
169 //-------------------------------------------------------------------
170 void vtkClipping3DDataViewer::Configure_Tissue()
175 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
176 // Visualisation - original volume
177 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
178 imagedata->GetScalarRange( range );
179 _mCubes[i] = vtkMarchingCubes::New( );
180 _mCubes[i]->SetInput( imagedata );
182 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
183 // _mCubes[i]->SetValue( 0, 1500 );
185 _tissueStripper[i] = vtkStripper::New();
186 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
190 _tissuePlanes[i] = vtkPlanes::New();
192 int x1,x2,y1,y2,z1,z2;
193 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
194 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
196 _tissueClipper[i] = vtkClipPolyData::New();
197 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
198 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
199 _tissueClipper[i]->InsideOutOn( );
201 _tissueMapper[i] = vtkPolyDataMapper::New( );
202 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
203 _tissueMapper[i]->ScalarVisibilityOff( );
204 // _tissueMapper[i]->Update();
211 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
213 _tissue[i] = vtkActor::New();
214 _tissue[i]->SetMapper( GetTissueMapper(i) );
215 float cr=1,cg=0.5,cb=0.5;
216 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
217 _tissue[i]->GetProperty()->SetSpecular(.3);
218 _tissue[i]->GetProperty()->SetSpecularPower(20);
219 _tissue[i]->GetProperty()->SetOpacity(0.5);
220 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
221 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
222 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
223 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
226 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
228 _observerS[i] = boxSurfaceObserver::New();
229 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
230 _observerS[i]->SetActor( _tissue[i] );
235 //-----------------------------------------------------------------------------
237 void vtkClipping3DDataViewer::Configure_Volume()
243 /** if(_newvol != NULL)
246 _volumeMapper->Delete();
247 _volumeProperty->Delete();
252 _tfun = vtkPiecewiseFunction::New();
253 _ctfun = vtkColorTransferFunction::New();
256 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
257 double max = range[1];
260 adding the poinst of the transference function
263 greyValuesTransferenceFVector.push_back(max * 0/2); // JPR ?? 0/2
264 greyValuesTransferenceFVector.push_back(max * 1/2); // JPR ?? division entiere?
265 greyValuesTransferenceFVector.push_back(max * 2/2);
267 intensityValuesTransferenceFVector.push_back(0.0);
268 intensityValuesTransferenceFVector.push_back(1.0);
269 intensityValuesTransferenceFVector.push_back(1.0);
271 _tfun->AddPoint(max * 0/2 , 0.0);
272 _tfun->AddPoint(max * 1/2 , 1.0);
273 _tfun->AddPoint(max * 2/2 , 1.0);
276 Adding the colors to the vectors
279 redColorsOfColorTransferenceFVector.push_back(0.0);
280 redColorsOfColorTransferenceFVector.push_back(1.0);
281 redColorsOfColorTransferenceFVector.push_back(0.0);
282 redColorsOfColorTransferenceFVector.push_back(0.0);
283 redColorsOfColorTransferenceFVector.push_back(0.0);
286 greenColorsOfColorTransferenceFVector.push_back(0.0);
287 greenColorsOfColorTransferenceFVector.push_back(0.0);
288 greenColorsOfColorTransferenceFVector.push_back(0.0);
289 greenColorsOfColorTransferenceFVector.push_back(1.0);
290 greenColorsOfColorTransferenceFVector.push_back(0.2);
293 blueColorsOfColorTransferenceFVector.push_back(0.0);
294 blueColorsOfColorTransferenceFVector.push_back(0.0);
295 blueColorsOfColorTransferenceFVector.push_back(1.0);
296 blueColorsOfColorTransferenceFVector.push_back(0.0);
297 blueColorsOfColorTransferenceFVector.push_back(0.0);
299 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
300 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
301 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
302 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
303 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
305 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
306 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
307 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
308 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
309 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
311 _volumePlanes = vtkPlanes::New();
312 // int x1,x2,y1,y2,z1,z2;
313 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
314 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
315 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
321 // _volumeMapper = vtkVolumeRayCastMapper::New();
322 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
326 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
329 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
333 _volumeMapper->SetClippingPlanes( _volumePlanes );
334 _volumeMapper->AutoAdjustSampleDistancesOn();
336 _volumeProperty->SetInterpolationTypeToNearest();
337 //_volumeProperty = vtkVolumeProperty::New();
338 _volumeProperty->SetColor(_ctfun);
339 _volumeProperty->SetScalarOpacity( _tfun );
343 _volumeProperty->DisableGradientOpacityOn();
353 // _volumeProperty->SetInterpolationTypeToNearest();
354 // _volumeProperty->ShadeOff();
355 // _volumeProperty->SetAmbient(0.3);
356 // _volumeProperty->SetDiffuse(0.1);
357 // _volumeProperty->SetSpecular(0.8);
358 // _volumeProperty->DisableGradientOpacityOn();
360 // _newvol = vtkVolume::New();
361 _newvol->SetMapper(_volumeMapper );
362 _newvol->SetProperty(_volumeProperty );
364 _observerV = boxSurfaceObserver::New();
365 _observerV->SetPlanes( _volumePlanes );
366 _observerV->SetActor( _newvol );
367 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
370 void vtkClipping3DDataViewer::updateVolume()
375 cout<<"JPRG::vtkClipping3DDataViewer::Configure_Volume::isRayCasting"<<endl;
376 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
380 cout<<"JPRG::vtkClipping3DDataViewer::Configure_Volume::isMIP"<<endl;
382 _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
387 _volumeProperty->SetInterpolationTypeToLinear();
391 _volumeProperty->SetInterpolationTypeToNearest();
396 _volumeProperty->ShadeOn();
400 _volumeProperty->ShadeOff();
405 //-------------------------------------------------------------------
406 void vtkClipping3DDataViewer::Configure()
411 // An outline provides context around the data.
413 _outlineData = vtkOutlineFilter::New();
414 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
415 _mapOutline = vtkPolyDataMapper::New();
416 _mapOutline->SetInput(_outlineData->GetOutput());
417 _outline = vtkActor::New();
418 _outline->SetMapper(_mapOutline);
419 _outline->GetProperty()->SetColor(0,0,0);
423 //-------------------------------------------------------------------
424 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
426 _mCubes[idTissue]->SetValue(0, isoValue);
428 //-------------------------------------------------------------------
429 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
431 return _mCubes[idTissue]->GetValue(0);
433 //-------------------------------------------------------------------
434 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
438 //-------------------------------------------------------------------
439 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
440 return _volumeMapper;
442 //-------------------------------------------------------------------
443 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
445 return _volumePlanes;
448 //-------------------------------------------------------------------
449 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
451 return _mCubes[idTissue];
453 //--------------------------------------------------------------------
454 //-------------------
456 //-------------------
458 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
460 return &greyValuesTransferenceFVector;
462 //--------------------------------------------------------------------
463 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
465 return &intensityValuesTransferenceFVector;
467 //--------------------------------------------------------------------
468 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
470 return &redColorsOfColorTransferenceFVector;
472 //--------------------------------------------------------------------
473 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
475 return &greenColorsOfColorTransferenceFVector;
477 //--------------------------------------------------------------------
478 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
480 return &blueColorsOfColorTransferenceFVector;
482 //--------------------------------------------------------------------
483 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
485 return &greyValueColorsOfColorTransferenceFVector;
487 //--------------------------------------------------------------------
488 //--------------------------------------
489 //Getters transference function
490 //and color of the transference function
491 //---------------------------------------
492 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
496 //--------------------------------------------------------------------
497 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
502 //-------------------------------------------------------------------
504 void vtkClipping3DDataViewer::ReadVolumeFunctions()
507 int i=0,xi,yi,r,g,b,gValue;
508 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
510 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
514 int tfSize=this->greyValuesTransferenceFVector.size();
518 hDlg->erasePointsTransferenceFunction();
521 double g=greyValuesTransferenceFVector[i];
522 double in=intensityValuesTransferenceFVector[i];
523 hDlg->addPointToTransferenceFunction(g,in*100);
529 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
535 double gr=greyValueColorsOfColorTransferenceFVector[i];
536 double r=redColorsOfColorTransferenceFVector[i];
537 double g=greenColorsOfColorTransferenceFVector[i];
538 double b=blueColorsOfColorTransferenceFVector[i];
539 hDlg->addColorPoint(gr,r*255,g*255,b*255);
543 //If it is smooth activate next line
544 //hDlg->updatePlotter();
545 //setting variables if the user wants to do refresh
546 hDlg->setCTF(_ctfun);
550 // when the user had changed the transference Function
552 if(hDlg->ShowModal()== wxID_OK )
554 // -- vtkPiecewiseFunction --
555 this->_tfun->RemoveAllPoints();
556 greyValuesTransferenceFVector.clear();
557 intensityValuesTransferenceFVector.clear();
559 int nTFPoints=hDlg->getSizeTransferenceFunction();
563 hDlg->getTransferenceFunctionPoint(i,xi,yi);
564 this->_tfun->AddPoint( xi , yi/100.0 );
565 greyValuesTransferenceFVector.push_back(xi);
566 intensityValuesTransferenceFVector.push_back(yi/100.0);
569 // -- vtkColorTransferFunction --
570 this->_ctfun->RemoveAllPoints ();
572 redColorsOfColorTransferenceFVector.clear();
573 greenColorsOfColorTransferenceFVector.clear();
574 blueColorsOfColorTransferenceFVector.clear();
575 greyValueColorsOfColorTransferenceFVector.clear();
577 int nCTFpoints=hDlg->getSizeBarColor();
581 hDlg->getDataBarColorPoint(i,xi,r,g,b);
582 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
583 redColorsOfColorTransferenceFVector.push_back(r/255.0);
584 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
585 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
586 greyValueColorsOfColorTransferenceFVector.push_back(xi);
590 this->_volumeMapper->Update();
591 this->_newvol->Update();
597 if(hDlg->getRefreshed())
600 //--Transference Function----
601 this->_tfun->RemoveAllPoints();
603 size=greyValuesTransferenceFVector.size();
606 double grey1=greyValuesTransferenceFVector[i];
607 double in2=intensityValuesTransferenceFVector[i];
608 this->_tfun->AddPoint( grey1 , in2 );
611 // -- vtkColorTransferFunction --
612 _ctfun->RemoveAllPoints ();
615 size=greyValueColorsOfColorTransferenceFVector.size();
618 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
619 double red =(redColorsOfColorTransferenceFVector)[i];
620 double green =(greenColorsOfColorTransferenceFVector)[i];
621 double blue = (blueColorsOfColorTransferenceFVector)[i];
622 _ctfun->AddRGBPoint(grey2,red,green,blue);
624 this->_volumeMapper->Update();
625 this->_newvol->Update();
633 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
640 FILE *ff = fopen ( namefile ,"r");
644 if (strcmp(tmp,"MAX")==0)
646 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
647 vtkimagedata->GetScalarRange(range);
648 max = (int) (range[1]);
653 fscanf(ff,"%s",tmp); // --
655 // -- vtkPiecewiseFunction --
656 this->_tfun->RemoveAllPoints();
658 while ( strcmp(tmp,"--")!=0 )
663 this->_tfun->AddPoint( x*max , val );
667 this->_ctfun->RemoveAllPoints ();
668 // -- vtkColorTransferFunction --
679 this->_ctfun->AddRGBPoint( x*max , r,g,b );
683 this->_volumeMapper->Update();
684 this->_newvol->Update();
691 //-------------------------------------------------------------------
693 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
695 vtkDataSetReader *reader = vtkDataSetReader::New();
696 reader->SetFileName(namefile);
698 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );
701 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
703 _volumeProperty->SetColor(colortable);
708 void vtkClipping3DDataViewer::SetRayCasting(bool active)
710 _isRayCasting = active;
714 void vtkClipping3DDataViewer::SetMIPActive(bool active)
719 void vtkClipping3DDataViewer::SetInterpolation(bool active)
721 _interpolation = active;
724 void vtkClipping3DDataViewer::SetShade(bool active)