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();
23 //-------------------------------------------------------------------
24 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
27 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
29 _tissueStripper[i]->Delete();
30 _tissueMapper[i]->Delete();
31 _tissuePlanes[i]->Delete();
32 _tissueClipper[i]->Delete();
34 _outlineData->Delete();
35 _mapOutline->Delete();
40 _compositeFunction->Delete();
41 _volumeMapper->Delete();
42 _volumeProperty->Delete();
44 _volumePlanes->Delete();
46 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
47 _tissue[i]-> Delete();
48 _observerS[i]-> Delete();
50 _observerV-> Delete();
52 //-------------------------------------------------------------------
53 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
57 //-------------------------------------------------------------------
58 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
60 return this->_tissueClipper[id];
62 //-------------------------------------------------------------------
63 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
65 return _tissueMapper[id];
67 //-------------------------------------------------------------------
68 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
70 return _tissuePlanes[id];
72 //-------------------------------------------------------------------
73 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
75 return _tissueStripper[id];
77 //-------------------------------------------------------------------
78 void vtkClipping3DDataViewer::Refresh()
80 // _volumeMapper->SetClippingPlanes(_volumePlanes);
82 // this->_volumeMapper->Update();
83 // this->_newvol->Update();
85 // _newvol->VisibilityOn();
88 // _volumeMapper = vtkVolumeRayCastMapper::New();
89 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
90 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
91 // _volumeMapper->SetClippingPlanes( _volumePlanes );
92 // _newvol->SetMapper(_volumeMapper );
96 //-------------------------------------------------------------------
97 void vtkClipping3DDataViewer::RefreshSurface()
100 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
102 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
103 // this->GetMCubes(i)->Update();
106 //-------------------------------------------------------------------
107 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
109 _vtkmprbasedata=vtkmprbasedata;
111 //-------------------------------------------------------------------
112 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
114 return _vtkmprbasedata;
118 //-------------------------------------------------------------------
119 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
121 _visibleTissue[idTissue]=visible;
123 //-------------------------------------------------------------------
124 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
125 return _visibleTissue[idTissue];
127 //-------------------------------------------------------------------
128 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
130 _representationType[idTissue]=representationType;
132 //-------------------------------------------------------------------
133 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
135 return _representationType[idTissue];
138 //-------------------------------------------------------------------
139 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
143 //-------------------------------------------------------------------
144 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
146 return _observerS[idObserverS];
148 //-------------------------------------------------------------------
149 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
154 //-------------------------------------------------------------------
155 bool vtkClipping3DDataViewer::GetVisibleVolume()
157 return _visibleVolume;
159 //-------------------------------------------------------------------
160 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
162 _visibleVolume = visiblevolume;
166 //-------------------------------------------------------------------
167 void vtkClipping3DDataViewer::Configure_Tissue()
172 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
173 // Visualisation - original volume
174 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
175 imagedata->GetScalarRange( range );
176 _mCubes[i] = vtkMarchingCubes::New( );
177 _mCubes[i]->SetInput( imagedata );
179 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
180 // _mCubes[i]->SetValue( 0, 1500 );
182 _tissueStripper[i] = vtkStripper::New();
183 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
187 _tissuePlanes[i] = vtkPlanes::New();
189 int x1,x2,y1,y2,z1,z2;
190 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
191 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
193 _tissueClipper[i] = vtkClipPolyData::New();
194 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
195 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
196 _tissueClipper[i]->InsideOutOn( );
198 _tissueMapper[i] = vtkPolyDataMapper::New( );
199 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
200 _tissueMapper[i]->ScalarVisibilityOff( );
201 // _tissueMapper[i]->Update();
208 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
210 _tissue[i] = vtkActor::New();
211 _tissue[i]->SetMapper( GetTissueMapper(i) );
212 float cr=1,cg=0.5,cb=0.5;
213 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
214 _tissue[i]->GetProperty()->SetSpecular(.3);
215 _tissue[i]->GetProperty()->SetSpecularPower(20);
216 _tissue[i]->GetProperty()->SetOpacity(0.5);
217 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
218 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
219 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
220 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
223 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
225 _observerS[i] = boxSurfaceObserver::New();
226 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
227 _observerS[i]->SetActor( _tissue[i] );
232 //-----------------------------------------------------------------------------
234 void vtkClipping3DDataViewer::Configure_Volume()
240 /** if(_newvol != NULL)
243 _volumeMapper->Delete();
244 _volumeProperty->Delete();
249 _tfun = vtkPiecewiseFunction::New();
250 _ctfun = vtkColorTransferFunction::New();
253 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
254 double max = range[1];
257 adding the poinst of the transference function
260 greyValuesTransferenceFVector.push_back(max * 0/2); // JPR ?? 0/2
261 greyValuesTransferenceFVector.push_back(max * 1/2); // JPR ?? division entiere?
262 greyValuesTransferenceFVector.push_back(max * 2/2);
264 intensityValuesTransferenceFVector.push_back(0.0);
265 intensityValuesTransferenceFVector.push_back(1.0);
266 intensityValuesTransferenceFVector.push_back(1.0);
268 _tfun->AddPoint(max * 0/2 , 0.0);
269 _tfun->AddPoint(max * 1/2 , 1.0);
270 _tfun->AddPoint(max * 2/2 , 1.0);
273 Adding the colors to the vectors
276 redColorsOfColorTransferenceFVector.push_back(0.0);
277 redColorsOfColorTransferenceFVector.push_back(1.0);
278 redColorsOfColorTransferenceFVector.push_back(0.0);
279 redColorsOfColorTransferenceFVector.push_back(0.0);
280 redColorsOfColorTransferenceFVector.push_back(0.0);
283 greenColorsOfColorTransferenceFVector.push_back(0.0);
284 greenColorsOfColorTransferenceFVector.push_back(0.0);
285 greenColorsOfColorTransferenceFVector.push_back(0.0);
286 greenColorsOfColorTransferenceFVector.push_back(1.0);
287 greenColorsOfColorTransferenceFVector.push_back(0.2);
290 blueColorsOfColorTransferenceFVector.push_back(0.0);
291 blueColorsOfColorTransferenceFVector.push_back(0.0);
292 blueColorsOfColorTransferenceFVector.push_back(1.0);
293 blueColorsOfColorTransferenceFVector.push_back(0.0);
294 blueColorsOfColorTransferenceFVector.push_back(0.0);
296 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
297 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
298 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
299 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
300 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
302 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
303 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
304 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
305 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
306 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
308 _volumePlanes = vtkPlanes::New();
309 // int x1,x2,y1,y2,z1,z2;
310 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
311 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
312 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
316 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
317 vtkVolumeRayCastMIPFunction* _compositeFunctionMIP = vtkVolumeRayCastMIPFunction::New();
320 // _volumeMapper = vtkVolumeRayCastMapper::New();
321 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
325 cout<<"JPRG::vtkClipping3DDataViewer::Configure_Volume::isRayCasting"<<endl;
326 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
331 cout<<"JPRG::vtkClipping3DDataViewer::Configure_Volume::isMIP"<<endl;
332 _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
337 _volumeMapper->SetClippingPlanes( _volumePlanes );
338 _volumeMapper->AutoAdjustSampleDistancesOn();
340 //_volumeProperty = vtkVolumeProperty::New();
341 _volumeProperty->SetColor(_ctfun);
342 _volumeProperty->SetScalarOpacity( _tfun );
346 _volumeProperty->DisableGradientOpacityOn();
350 _volumeProperty->SetInterpolationTypeToLinear();
354 _volumeProperty->SetInterpolationTypeToNearest();
359 _volumeProperty->ShadeOn();
363 _volumeProperty->ShadeOff();
372 // _volumeProperty->SetInterpolationTypeToNearest();
373 // _volumeProperty->ShadeOff();
374 // _volumeProperty->SetAmbient(0.3);
375 // _volumeProperty->SetDiffuse(0.1);
376 // _volumeProperty->SetSpecular(0.8);
377 // _volumeProperty->DisableGradientOpacityOn();
379 // _newvol = vtkVolume::New();
380 _newvol->SetMapper(_volumeMapper );
381 _newvol->SetProperty(_volumeProperty );
383 _observerV = boxSurfaceObserver::New();
384 _observerV->SetPlanes( _volumePlanes );
385 _observerV->SetActor( _newvol );
386 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
390 //-------------------------------------------------------------------
391 void vtkClipping3DDataViewer::Configure()
396 // An outline provides context around the data.
398 _outlineData = vtkOutlineFilter::New();
399 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
400 _mapOutline = vtkPolyDataMapper::New();
401 _mapOutline->SetInput(_outlineData->GetOutput());
402 _outline = vtkActor::New();
403 _outline->SetMapper(_mapOutline);
404 _outline->GetProperty()->SetColor(0,0,0);
408 //-------------------------------------------------------------------
409 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
411 _mCubes[idTissue]->SetValue(0, isoValue);
413 //-------------------------------------------------------------------
414 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
416 return _mCubes[idTissue]->GetValue(0);
418 //-------------------------------------------------------------------
419 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
423 //-------------------------------------------------------------------
424 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
425 return _volumeMapper;
427 //-------------------------------------------------------------------
428 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
430 return _volumePlanes;
433 //-------------------------------------------------------------------
434 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
436 return _mCubes[idTissue];
438 //--------------------------------------------------------------------
439 //-------------------
441 //-------------------
443 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
445 return &greyValuesTransferenceFVector;
447 //--------------------------------------------------------------------
448 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
450 return &intensityValuesTransferenceFVector;
452 //--------------------------------------------------------------------
453 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
455 return &redColorsOfColorTransferenceFVector;
457 //--------------------------------------------------------------------
458 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
460 return &greenColorsOfColorTransferenceFVector;
462 //--------------------------------------------------------------------
463 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
465 return &blueColorsOfColorTransferenceFVector;
467 //--------------------------------------------------------------------
468 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
470 return &greyValueColorsOfColorTransferenceFVector;
472 //--------------------------------------------------------------------
473 //--------------------------------------
474 //Getters transference function
475 //and color of the transference function
476 //---------------------------------------
477 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
481 //--------------------------------------------------------------------
482 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
487 //-------------------------------------------------------------------
489 void vtkClipping3DDataViewer::ReadVolumeFunctions()
492 int i=0,xi,yi,r,g,b,gValue;
493 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
495 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
499 int tfSize=this->greyValuesTransferenceFVector.size();
503 hDlg->erasePointsTransferenceFunction();
506 double g=greyValuesTransferenceFVector[i];
507 double in=intensityValuesTransferenceFVector[i];
508 hDlg->addPointToTransferenceFunction(g,in*100);
514 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
520 double gr=greyValueColorsOfColorTransferenceFVector[i];
521 double r=redColorsOfColorTransferenceFVector[i];
522 double g=greenColorsOfColorTransferenceFVector[i];
523 double b=blueColorsOfColorTransferenceFVector[i];
524 hDlg->addColorPoint(gr,r*255,g*255,b*255);
528 //If it is smooth activate next line
529 //hDlg->updatePlotter();
530 //setting variables if the user wants to do refresh
531 hDlg->setCTF(_ctfun);
535 // when the user had changed the transference Function
537 if(hDlg->ShowModal()== wxID_OK )
539 // -- vtkPiecewiseFunction --
540 this->_tfun->RemoveAllPoints();
541 greyValuesTransferenceFVector.clear();
542 intensityValuesTransferenceFVector.clear();
544 int nTFPoints=hDlg->getSizeTransferenceFunction();
548 hDlg->getTransferenceFunctionPoint(i,xi,yi);
549 this->_tfun->AddPoint( xi , yi/100.0 );
550 greyValuesTransferenceFVector.push_back(xi);
551 intensityValuesTransferenceFVector.push_back(yi/100.0);
554 // -- vtkColorTransferFunction --
555 this->_ctfun->RemoveAllPoints ();
557 redColorsOfColorTransferenceFVector.clear();
558 greenColorsOfColorTransferenceFVector.clear();
559 blueColorsOfColorTransferenceFVector.clear();
560 greyValueColorsOfColorTransferenceFVector.clear();
562 int nCTFpoints=hDlg->getSizeBarColor();
566 hDlg->getDataBarColorPoint(i,xi,r,g,b);
567 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
568 redColorsOfColorTransferenceFVector.push_back(r/255.0);
569 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
570 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
571 greyValueColorsOfColorTransferenceFVector.push_back(xi);
575 this->_volumeMapper->Update();
576 this->_newvol->Update();
582 if(hDlg->getRefreshed())
585 //--Transference Function----
586 this->_tfun->RemoveAllPoints();
588 size=greyValuesTransferenceFVector.size();
591 double grey1=greyValuesTransferenceFVector[i];
592 double in2=intensityValuesTransferenceFVector[i];
593 this->_tfun->AddPoint( grey1 , in2 );
596 // -- vtkColorTransferFunction --
597 _ctfun->RemoveAllPoints ();
600 size=greyValueColorsOfColorTransferenceFVector.size();
603 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
604 double red =(redColorsOfColorTransferenceFVector)[i];
605 double green =(greenColorsOfColorTransferenceFVector)[i];
606 double blue = (blueColorsOfColorTransferenceFVector)[i];
607 _ctfun->AddRGBPoint(grey2,red,green,blue);
609 this->_volumeMapper->Update();
610 this->_newvol->Update();
618 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
625 FILE *ff = fopen ( namefile ,"r");
629 if (strcmp(tmp,"MAX")==0)
631 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
632 vtkimagedata->GetScalarRange(range);
633 max = (int) (range[1]);
638 fscanf(ff,"%s",tmp); // --
640 // -- vtkPiecewiseFunction --
641 this->_tfun->RemoveAllPoints();
643 while ( strcmp(tmp,"--")!=0 )
648 this->_tfun->AddPoint( x*max , val );
652 this->_ctfun->RemoveAllPoints ();
653 // -- vtkColorTransferFunction --
664 this->_ctfun->AddRGBPoint( x*max , r,g,b );
668 this->_volumeMapper->Update();
669 this->_newvol->Update();
676 //-------------------------------------------------------------------
678 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
680 vtkDataSetReader *reader = vtkDataSetReader::New();
681 reader->SetFileName(namefile);
683 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );
686 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
688 _volumeProperty->SetColor(colortable);
693 void vtkClipping3DDataViewer::SetRayCasting(bool active)
695 _isRayCasting = active;
699 void vtkClipping3DDataViewer::SetMIPActive(bool active)
704 void vtkClipping3DDataViewer::SetInterpolation(bool active)
706 _interpolation = active;
709 void vtkClipping3DDataViewer::SetShade(bool active)