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);
297 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
298 vtkVolumeRayCastMIPFunction* _compositeFunctionMIP = vtkVolumeRayCastMIPFunction::New();
301 _volumeMapper = vtkVolumeRayCastMapper::New();
302 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
304 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
305 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunctionMIP);
307 _volumeMapper->SetClippingPlanes( _volumePlanes );
308 _volumeMapper->AutoAdjustSampleDistancesOn();
310 _volumeProperty = vtkVolumeProperty::New();
311 _volumeProperty->SetColor(_ctfun);
312 _volumeProperty->SetScalarOpacity( _tfun );
316 _volumeProperty->DisableGradientOpacityOn();
318 _volumeProperty->SetInterpolationTypeToLinear();
319 // _volumeProperty->SetInterpolationTypeToNearest();
321 _volumeProperty->ShadeOn();
322 // _volumeProperty->ShadeOff();
325 // _volumeProperty->SetInterpolationTypeToNearest();
326 // _volumeProperty->ShadeOff();
327 // _volumeProperty->SetAmbient(0.3);
328 // _volumeProperty->SetDiffuse(0.1);
329 // _volumeProperty->SetSpecular(0.8);
330 // _volumeProperty->DisableGradientOpacityOn();
332 _newvol = vtkVolume::New();
333 _newvol->SetMapper(_volumeMapper );
334 _newvol->SetProperty(_volumeProperty );
336 _observerV = boxSurfaceObserver::New();
337 _observerV->SetPlanes( _volumePlanes );
338 _observerV->SetActor( _newvol );
339 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
343 //-------------------------------------------------------------------
344 void vtkClipping3DDataViewer::Configure()
349 // An outline provides context around the data.
351 _outlineData = vtkOutlineFilter::New();
352 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
353 _mapOutline = vtkPolyDataMapper::New();
354 _mapOutline->SetInput(_outlineData->GetOutput());
355 _outline = vtkActor::New();
356 _outline->SetMapper(_mapOutline);
357 _outline->GetProperty()->SetColor(0,0,0);
361 //-------------------------------------------------------------------
362 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
364 _mCubes[idTissue]->SetValue(0, isoValue);
366 //-------------------------------------------------------------------
367 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
369 return _mCubes[idTissue]->GetValue(0);
371 //-------------------------------------------------------------------
372 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
376 //-------------------------------------------------------------------
377 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
378 return _volumeMapper;
380 //-------------------------------------------------------------------
381 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
383 return _volumePlanes;
386 //-------------------------------------------------------------------
387 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
389 return _mCubes[idTissue];
391 //--------------------------------------------------------------------
392 //-------------------
394 //-------------------
396 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
398 return &greyValuesTransferenceFVector;
400 //--------------------------------------------------------------------
401 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
403 return &intensityValuesTransferenceFVector;
405 //--------------------------------------------------------------------
406 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
408 return &redColorsOfColorTransferenceFVector;
410 //--------------------------------------------------------------------
411 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
413 return &greenColorsOfColorTransferenceFVector;
415 //--------------------------------------------------------------------
416 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
418 return &blueColorsOfColorTransferenceFVector;
420 //--------------------------------------------------------------------
421 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
423 return &greyValueColorsOfColorTransferenceFVector;
425 //--------------------------------------------------------------------
426 //--------------------------------------
427 //Getters transference function
428 //and color of the transference function
429 //---------------------------------------
430 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
434 //--------------------------------------------------------------------
435 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
440 //-------------------------------------------------------------------
442 void vtkClipping3DDataViewer::ReadVolumeFunctions()
445 int i=0,xi,yi,r,g,b,gValue;
446 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
448 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
452 int tfSize=this->greyValuesTransferenceFVector.size();
456 hDlg->erasePointsTransferenceFunction();
459 double g=greyValuesTransferenceFVector[i];
460 double in=intensityValuesTransferenceFVector[i];
461 hDlg->addPointToTransferenceFunction(g,in*100);
467 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
473 double gr=greyValueColorsOfColorTransferenceFVector[i];
474 double r=redColorsOfColorTransferenceFVector[i];
475 double g=greenColorsOfColorTransferenceFVector[i];
476 double b=blueColorsOfColorTransferenceFVector[i];
477 hDlg->addColorPoint(gr,r*255,g*255,b*255);
481 //If it is smooth activate next line
482 //hDlg->updatePlotter();
483 //setting variables if the user wants to do refresh
484 hDlg->setCTF(_ctfun);
488 // when the user had changed the transference Function
490 if(hDlg->ShowModal()== wxID_OK )
492 // -- vtkPiecewiseFunction --
493 this->_tfun->RemoveAllPoints();
494 greyValuesTransferenceFVector.clear();
495 intensityValuesTransferenceFVector.clear();
497 int nTFPoints=hDlg->getSizeTransferenceFunction();
501 hDlg->getTransferenceFunctionPoint(i,xi,yi);
502 this->_tfun->AddPoint( xi , yi/100.0 );
503 greyValuesTransferenceFVector.push_back(xi);
504 intensityValuesTransferenceFVector.push_back(yi/100.0);
507 // -- vtkColorTransferFunction --
508 this->_ctfun->RemoveAllPoints ();
510 redColorsOfColorTransferenceFVector.clear();
511 greenColorsOfColorTransferenceFVector.clear();
512 blueColorsOfColorTransferenceFVector.clear();
513 greyValueColorsOfColorTransferenceFVector.clear();
515 int nCTFpoints=hDlg->getSizeBarColor();
519 hDlg->getDataBarColorPoint(i,xi,r,g,b);
520 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
521 redColorsOfColorTransferenceFVector.push_back(r/255.0);
522 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
523 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
524 greyValueColorsOfColorTransferenceFVector.push_back(xi);
528 this->_volumeMapper->Update();
529 this->_newvol->Update();
535 if(hDlg->getRefreshed())
538 //--Transference Function----
539 this->_tfun->RemoveAllPoints();
541 size=greyValuesTransferenceFVector.size();
544 double grey1=greyValuesTransferenceFVector[i];
545 double in2=intensityValuesTransferenceFVector[i];
546 this->_tfun->AddPoint( grey1 , in2 );
549 // -- vtkColorTransferFunction --
550 _ctfun->RemoveAllPoints ();
553 size=greyValueColorsOfColorTransferenceFVector.size();
556 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
557 double red =(redColorsOfColorTransferenceFVector)[i];
558 double green =(greenColorsOfColorTransferenceFVector)[i];
559 double blue = (blueColorsOfColorTransferenceFVector)[i];
560 _ctfun->AddRGBPoint(grey2,red,green,blue);
562 this->_volumeMapper->Update();
563 this->_newvol->Update();
571 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
578 FILE *ff = fopen ( namefile ,"r");
582 if (strcmp(tmp,"MAX")==0)
584 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
585 vtkimagedata->GetScalarRange(range);
586 max = (int) (range[1]);
591 fscanf(ff,"%s",tmp); // --
593 // -- vtkPiecewiseFunction --
594 this->_tfun->RemoveAllPoints();
596 while ( strcmp(tmp,"--")!=0 )
601 this->_tfun->AddPoint( x*max , val );
605 this->_ctfun->RemoveAllPoints ();
606 // -- vtkColorTransferFunction --
617 this->_ctfun->AddRGBPoint( x*max , r,g,b );
621 this->_volumeMapper->Update();
622 this->_newvol->Update();
629 //-------------------------------------------------------------------
631 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
633 vtkDataSetReader *reader = vtkDataSetReader::New();
634 reader->SetFileName(namefile);
636 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );
639 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
641 _volumeProperty->SetColor(colortable);