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 _volumerendererdata = VolumeRendererData::New();
20 _volumeMapper = vtkVolumeRayCastMapper::New();
21 _newvol = vtkVolume::New();
22 _volumeProperty = vtkVolumeProperty::New();
23 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
24 _compositeFunctionMIP = vtkVolumeRayCastMIPFunction::New();
27 //-------------------------------------------------------------------
28 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
31 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
33 _tissueStripper[i]->Delete();
34 _tissueMapper[i]->Delete();
35 _tissuePlanes[i]->Delete();
36 _tissueClipper[i]->Delete();
38 _outlineData->Delete();
39 _mapOutline->Delete();
44 _compositeFunction->Delete();
45 _volumeMapper->Delete();
46 _volumeProperty->Delete();
48 _volumePlanes->Delete();
50 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
51 _tissue[i]-> Delete();
52 _observerS[i]-> Delete();
54 _observerV-> Delete();
56 //-------------------------------------------------------------------
57 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
61 //-------------------------------------------------------------------
62 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
64 return this->_tissueClipper[id];
66 //-------------------------------------------------------------------
67 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
69 return _tissueMapper[id];
71 //-------------------------------------------------------------------
72 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
74 return _tissuePlanes[id];
76 //-------------------------------------------------------------------
77 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
79 return _tissueStripper[id];
81 //-------------------------------------------------------------------
82 void vtkClipping3DDataViewer::Refresh()
84 // _volumeMapper->SetClippingPlanes(_volumePlanes);
86 // this->_volumeMapper->Update();
87 // this->_newvol->Update();
89 // _newvol->VisibilityOn();
92 // _volumeMapper = vtkVolumeRayCastMapper::New();
93 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
94 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
95 // _volumeMapper->SetClippingPlanes( _volumePlanes );
96 // _newvol->SetMapper(_volumeMapper );
100 //-------------------------------------------------------------------
101 void vtkClipping3DDataViewer::RefreshSurface()
104 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
106 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
107 // this->GetMCubes(i)->Update();
110 //-------------------------------------------------------------------
111 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
113 _vtkmprbasedata=vtkmprbasedata;
115 //-------------------------------------------------------------------
116 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
118 return _vtkmprbasedata;
122 //-------------------------------------------------------------------
123 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
125 _visibleTissue[idTissue]=visible;
127 //-------------------------------------------------------------------
128 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
129 return _visibleTissue[idTissue];
131 //-------------------------------------------------------------------
132 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
134 _representationType[idTissue]=representationType;
136 //-------------------------------------------------------------------
137 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
139 return _representationType[idTissue];
142 //-------------------------------------------------------------------
143 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
147 //-------------------------------------------------------------------
148 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
150 return _observerS[idObserverS];
152 //-------------------------------------------------------------------
153 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
158 //-------------------------------------------------------------------
159 bool vtkClipping3DDataViewer::GetVisibleVolume()
161 return _visibleVolume;
163 //-------------------------------------------------------------------
164 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
166 _visibleVolume = visiblevolume;
169 bool vtkClipping3DDataViewer::GetVisibleVolumeBox()
171 return _visibleVolumeBox;
173 //-------------------------------------------------------------------
174 void vtkClipping3DDataViewer::SetVisibleVolumeBox(bool visibleBox)
176 _visibleVolumeBox = visibleBox;
179 //-------------------------------------------------------------------
180 void vtkClipping3DDataViewer::Configure_Tissue()
185 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
186 // Visualisation - original volume
187 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
188 imagedata->GetScalarRange( range );
189 _mCubes[i] = vtkMarchingCubes::New( );
190 _mCubes[i]->SetInput( imagedata );
192 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
193 // _mCubes[i]->SetValue( 0, 1500 );
195 _tissueStripper[i] = vtkStripper::New();
196 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
200 _tissuePlanes[i] = vtkPlanes::New();
202 int x1,x2,y1,y2,z1,z2;
203 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
204 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
206 _tissueClipper[i] = vtkClipPolyData::New();
207 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
208 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
209 _tissueClipper[i]->InsideOutOn( );
211 _tissueMapper[i] = vtkPolyDataMapper::New( );
212 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
213 _tissueMapper[i]->ScalarVisibilityOff( );
214 // _tissueMapper[i]->Update();
221 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
223 _tissue[i] = vtkActor::New();
224 _tissue[i]->SetMapper( GetTissueMapper(i) );
225 float cr=1,cg=0.5,cb=0.5;
226 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
227 _tissue[i]->GetProperty()->SetSpecular(.3);
228 _tissue[i]->GetProperty()->SetSpecularPower(20);
229 _tissue[i]->GetProperty()->SetOpacity(0.5);
230 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
231 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
232 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
233 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
236 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
238 _observerS[i] = boxSurfaceObserver::New();
239 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
240 _observerS[i]->SetActor( _tissue[i] );
245 //-----------------------------------------------------------------------------
247 void vtkClipping3DDataViewer::Configure_Volume()
253 /** if(_newvol != NULL)
256 _volumeMapper->Delete();
257 _volumeProperty->Delete();
262 _tfun = vtkPiecewiseFunction::New();
263 _ctfun = vtkColorTransferFunction::New();
266 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
267 double max = range[1];
270 adding the poinst of the transference function
273 greyValuesTransferenceFVector.push_back(max * 0/2); // JPR ?? 0/2
274 greyValuesTransferenceFVector.push_back(max * 1/2); // JPR ?? division entiere?
275 greyValuesTransferenceFVector.push_back(max * 2/2);
277 intensityValuesTransferenceFVector.push_back(0.0);
278 intensityValuesTransferenceFVector.push_back(1.0);
279 intensityValuesTransferenceFVector.push_back(1.0);
281 _tfun->AddPoint(max * 0/2 , 0.0);
282 _tfun->AddPoint(max * 1/2 , 1.0);
283 _tfun->AddPoint(max * 2/2 , 1.0);
286 Adding the colors to the vectors
289 redColorsOfColorTransferenceFVector.push_back(0.0);
290 redColorsOfColorTransferenceFVector.push_back(1.0);
291 redColorsOfColorTransferenceFVector.push_back(0.0);
292 redColorsOfColorTransferenceFVector.push_back(0.0);
293 redColorsOfColorTransferenceFVector.push_back(0.0);
296 greenColorsOfColorTransferenceFVector.push_back(0.0);
297 greenColorsOfColorTransferenceFVector.push_back(0.0);
298 greenColorsOfColorTransferenceFVector.push_back(0.0);
299 greenColorsOfColorTransferenceFVector.push_back(1.0);
300 greenColorsOfColorTransferenceFVector.push_back(0.2);
303 blueColorsOfColorTransferenceFVector.push_back(0.0);
304 blueColorsOfColorTransferenceFVector.push_back(0.0);
305 blueColorsOfColorTransferenceFVector.push_back(1.0);
306 blueColorsOfColorTransferenceFVector.push_back(0.0);
307 blueColorsOfColorTransferenceFVector.push_back(0.0);
309 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
310 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
311 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
312 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
313 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
315 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
316 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
317 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
318 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
319 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
321 _volumePlanes = vtkPlanes::New();
322 // int x1,x2,y1,y2,z1,z2;
323 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
324 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
325 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
331 // _volumeMapper = vtkVolumeRayCastMapper::New();
332 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
336 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
339 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
343 _volumeMapper->SetClippingPlanes( _volumePlanes );
344 _volumeMapper->AutoAdjustSampleDistancesOn();
346 _volumeProperty->SetInterpolationTypeToNearest();
347 //_volumeProperty = vtkVolumeProperty::New();
348 _volumeProperty->SetColor(_ctfun);
349 _volumeProperty->SetScalarOpacity( _tfun );
353 _volumeProperty->DisableGradientOpacityOn();
363 // _volumeProperty->SetInterpolationTypeToNearest();
364 // _volumeProperty->ShadeOff();
365 // _volumeProperty->SetAmbient(0.3);
366 // _volumeProperty->SetDiffuse(0.1);
367 // _volumeProperty->SetSpecular(0.8);
368 // _volumeProperty->DisableGradientOpacityOn();
370 // _newvol = vtkVolume::New();
371 _newvol->SetMapper(_volumeMapper );
372 _newvol->SetProperty(_volumeProperty );
374 _observerV = boxSurfaceObserver::New();
375 _observerV->SetPlanes( _volumePlanes );
376 _observerV->SetActor( _newvol );
377 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
381 void vtkClipping3DDataViewer::Configure_VolumeBox()
383 cout<<"JPRG::vtkClipping3DDataViewer::Configure_VolumeBox()"<<endl;
385 _volumerendererdata->SetImageData(_vtkmprbasedata->GetImageData());
388 vector<double> *gv = this->GetGreyValuesTransferenceFVector();
389 vector<double> *op = this->GetIntensityValuesTransferenceFVector();
392 _volumerendererdata->SetLookUpTable((vtkLookupTable*)(_ctfun));
393 _volumerendererdata->OpacityChanged(*gv, *op);
395 //_wxvtkclipping3Dview->VisibleVolumeActor( false );
396 //_volumerendererdata->ShowVolume(event.IsChecked() );
397 //_volumerendererdata->BoundingBoxChanged(event.IsChecked() );
400 void vtkClipping3DDataViewer::SetRenderer(vtkRenderer* renderer)
402 _volumerendererdata->SetRenderer(renderer);
406 void vtkClipping3DDataViewer::SetInteractor(vtkRenderWindowInteractor* interactor)
409 _volumerendererdata->SetInteractor(interactor);
413 void vtkClipping3DDataViewer::BoxActorChanged(bool changed)
415 vector<double> *gv = this->GetGreyValuesTransferenceFVector();
416 vector<double> *op = this->GetIntensityValuesTransferenceFVector();
418 _volumerendererdata->ShowVolume(changed);
419 _volumerendererdata->OpacityChanged(*gv, *op);
420 _volumerendererdata->BoundingBoxChanged(changed);
424 void vtkClipping3DDataViewer::UpdateVolumeBox(vector<double> gf, vector<double> vf, vtkColorTransferFunction* ctfun)
426 _volumerendererdata->SetLookUpTable((vtkLookupTable*)(ctfun));
427 _volumerendererdata->OpacityChanged(gf, vf);
431 void vtkClipping3DDataViewer::updateVolume()
436 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
437 _volumerendererdata->changeCompositeMIPFunction(0);
441 _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
442 _volumerendererdata->changeCompositeMIPFunction(1);
447 _volumeProperty->SetInterpolationTypeToLinear();
451 _volumeProperty->SetInterpolationTypeToNearest();
456 _volumeProperty->ShadeOn();
460 _volumeProperty->ShadeOff();
465 //-------------------------------------------------------------------
466 void vtkClipping3DDataViewer::Configure()
470 Configure_VolumeBox();
471 // An outline provides context around the data.
473 _outlineData = vtkOutlineFilter::New();
474 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
475 _mapOutline = vtkPolyDataMapper::New();
476 _mapOutline->SetInput(_outlineData->GetOutput());
477 _outline = vtkActor::New();
478 _outline->SetMapper(_mapOutline);
479 _outline->GetProperty()->SetColor(0,0,0);
483 //-------------------------------------------------------------------
484 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
486 _mCubes[idTissue]->SetValue(0, isoValue);
488 //-------------------------------------------------------------------
489 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
491 return _mCubes[idTissue]->GetValue(0);
493 //-------------------------------------------------------------------
494 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
498 //-------------------------------------------------------------------
499 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
500 return _volumeMapper;
502 //-------------------------------------------------------------------
503 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
505 return _volumePlanes;
508 //-------------------------------------------------------------------
509 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
511 return _mCubes[idTissue];
513 //--------------------------------------------------------------------
514 //-------------------
516 //-------------------
518 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
520 return &greyValuesTransferenceFVector;
522 //--------------------------------------------------------------------
523 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
525 return &intensityValuesTransferenceFVector;
527 //--------------------------------------------------------------------
528 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
530 return &redColorsOfColorTransferenceFVector;
532 //--------------------------------------------------------------------
533 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
535 return &greenColorsOfColorTransferenceFVector;
537 //--------------------------------------------------------------------
538 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
540 return &blueColorsOfColorTransferenceFVector;
542 //--------------------------------------------------------------------
543 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
545 return &greyValueColorsOfColorTransferenceFVector;
547 //--------------------------------------------------------------------
548 //--------------------------------------
549 //Getters transference function
550 //and color of the transference function
551 //---------------------------------------
552 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
556 //--------------------------------------------------------------------
557 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
562 //-------------------------------------------------------------------
564 void vtkClipping3DDataViewer::ReadVolumeFunctions()
567 int i=0,xi,yi,r,g,b,gValue;
568 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
570 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
574 int tfSize=this->greyValuesTransferenceFVector.size();
578 hDlg->erasePointsTransferenceFunction();
581 double g=greyValuesTransferenceFVector[i];
582 double in=intensityValuesTransferenceFVector[i];
583 hDlg->addPointToTransferenceFunction(g,in*100);
589 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
595 double gr=greyValueColorsOfColorTransferenceFVector[i];
596 double r=redColorsOfColorTransferenceFVector[i];
597 double g=greenColorsOfColorTransferenceFVector[i];
598 double b=blueColorsOfColorTransferenceFVector[i];
599 hDlg->addColorPoint(gr,r*255,g*255,b*255);
603 //If it is smooth activate next line
604 //hDlg->updatePlotter();
605 //setting variables if the user wants to do refresh
606 hDlg->setCTF(_ctfun);
610 // when the user had changed the transference Function
612 if(hDlg->ShowModal()== wxID_OK )
614 // -- vtkPiecewiseFunction --
615 this->_tfun->RemoveAllPoints();
616 greyValuesTransferenceFVector.clear();
617 intensityValuesTransferenceFVector.clear();
619 int nTFPoints=hDlg->getSizeTransferenceFunction();
623 hDlg->getTransferenceFunctionPoint(i,xi,yi);
624 this->_tfun->AddPoint( xi , yi/100.0 );
625 greyValuesTransferenceFVector.push_back(xi);
626 intensityValuesTransferenceFVector.push_back(yi/100.0);
629 // -- vtkColorTransferFunction --
630 this->_ctfun->RemoveAllPoints ();
632 redColorsOfColorTransferenceFVector.clear();
633 greenColorsOfColorTransferenceFVector.clear();
634 blueColorsOfColorTransferenceFVector.clear();
635 greyValueColorsOfColorTransferenceFVector.clear();
637 int nCTFpoints=hDlg->getSizeBarColor();
641 hDlg->getDataBarColorPoint(i,xi,r,g,b);
642 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
643 redColorsOfColorTransferenceFVector.push_back(r/255.0);
644 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
645 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
646 greyValueColorsOfColorTransferenceFVector.push_back(xi);
650 this->_volumeMapper->Update();
651 this->_newvol->Update();
657 if(hDlg->getRefreshed())
660 //--Transference Function----
661 this->_tfun->RemoveAllPoints();
663 size=greyValuesTransferenceFVector.size();
666 double grey1=greyValuesTransferenceFVector[i];
667 double in2=intensityValuesTransferenceFVector[i];
668 this->_tfun->AddPoint( grey1 , in2 );
671 // -- vtkColorTransferFunction --
672 _ctfun->RemoveAllPoints ();
675 size=greyValueColorsOfColorTransferenceFVector.size();
678 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
679 double red =(redColorsOfColorTransferenceFVector)[i];
680 double green =(greenColorsOfColorTransferenceFVector)[i];
681 double blue = (blueColorsOfColorTransferenceFVector)[i];
682 _ctfun->AddRGBPoint(grey2,red,green,blue);
684 this->_volumeMapper->Update();
685 this->_newvol->Update();
693 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
700 FILE *ff = fopen ( namefile ,"r");
704 if (strcmp(tmp,"MAX")==0)
706 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
707 vtkimagedata->GetScalarRange(range);
708 max = (int) (range[1]);
713 fscanf(ff,"%s",tmp); // --
715 // -- vtkPiecewiseFunction --
716 this->_tfun->RemoveAllPoints();
718 while ( strcmp(tmp,"--")!=0 )
723 this->_tfun->AddPoint( x*max , val );
727 this->_ctfun->RemoveAllPoints ();
728 // -- vtkColorTransferFunction --
739 this->_ctfun->AddRGBPoint( x*max , r,g,b );
743 this->_volumeMapper->Update();
744 this->_newvol->Update();
751 //-------------------------------------------------------------------
753 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
755 vtkDataSetReader *reader = vtkDataSetReader::New();
756 reader->SetFileName(namefile);
758 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );
761 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
763 _volumeProperty->SetColor(colortable);
768 void vtkClipping3DDataViewer::SetRayCasting(bool active)
770 _isRayCasting = active;
774 void vtkClipping3DDataViewer::SetMIPActive(bool active)
779 void vtkClipping3DDataViewer::SetInterpolation(bool active)
781 _interpolation = active;
784 void vtkClipping3DDataViewer::SetShade(bool active)