4 #include <vtkProperty.h>
5 #include <vtkPolyData.h>
6 #include <vtkDataSet.h>
7 #include <vtkCellArray.h>
8 #include <vtkTransform.h>
9 #include <vtkTransformFilter.h>
10 #include <vtkDataSetReader.h>
12 #include "wxMPRBaseData.h"
13 #include "pPlotter/HistogramDialog.h"
17 //-------------------------------------------------------------------
18 //-------------------------------------------------------------------
19 //-------------------------------------------------------------------
21 vtkBaseData::vtkBaseData()
29 //-------------------------------------------------------------------
30 vtkBaseData::~vtkBaseData()
34 //-------------------------------------------------------------------
35 void vtkBaseData::SetMarImageData(marImageData *marimagedata)
37 _marImageData = marimagedata;
41 //-------------------------------------------------------------------
42 vtkImageData* vtkBaseData::GetImageData()
44 return _marImageData->GetImageDataT(_t);
46 //-------------------------------------------------------------------
47 marImageData* vtkBaseData::GetMarImageData()
52 //-------------------------------------------------------------------
54 void vtkBaseData::Configure() // virtual
58 //-------------------------------------------------------------------
59 void vtkBaseData::SetZ(double z){
63 // _marImageData->GetDimensions(dim);
67 vtkImageData* img = _marImageData->GetImageData();
69 img->GetWholeExtent(ext);
84 //-------------------------------------------------------------------
85 double vtkBaseData::GetZ()
89 //-------------------------------------------------------------------
90 int vtkBaseData::GetT()
94 //-------------------------------------------------------------------
95 void vtkBaseData::SetT(double t)
97 int maxT = _marImageData->GetMaxT();
109 //-------------------------------------------------------------------
110 //-------------------------------------------------------------------
111 //-------------------------------------------------------------------
112 vtkMPRBaseData::vtkMPRBaseData()
117 _transformOrientation = NULL;
119 //-------------------------------------------------------------------
120 vtkMPRBaseData::~vtkMPRBaseData()
122 if (_marImageData) delete _marImageData;
123 if (_transformOrientation) _transformOrientation ->Delete();
125 //-------------------------------------------------------------------
126 void vtkMPRBaseData::Configure()
128 vtkImageData* img = _marImageData->GetImageData();
130 img->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2);
131 _transformOrientation=vtkTransform::New();
132 _transformOrientation->Identity();
135 //-------------------------------------------------------------------
136 void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2)
147 //------------------------------------------------------------------------
148 int vtkMPRBaseData::GetMaxPositionX( )
152 //------------------------------------------------------------------------
153 int vtkMPRBaseData::GetMaxPositionY( )
157 //------------------------------------------------------------------------
158 int vtkMPRBaseData::GetMaxPositionZ( )
162 //-------------------------------------------------------------------
163 double vtkMPRBaseData::GetX()
167 //-------------------------------------------------------------------
168 double vtkMPRBaseData::GetY()
172 //-------------------------------------------------------------------
173 void vtkMPRBaseData::SetX(double x)
176 vtkImageData* img = _marImageData->GetImageData();
178 img->GetDimensions(dim);
190 //-------------------------------------------------------------------
191 void vtkMPRBaseData::SetY(double y)
194 vtkImageData* img = _marImageData->GetImageData();
196 img->GetDimensions(dim);
208 //-------------------------------------------------------------------
209 vtkTransform *vtkMPRBaseData::GetTransformOrientation()
211 return _transformOrientation;
213 //-------------------------------------------------------------------
214 void vtkMPRBaseData::SetNormal(double nx, double ny, double nz)
216 double alfa = atan2(ny,nx) * 180.0 / 3.1416;
217 double beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416;
218 _transformOrientation->Identity();
219 _transformOrientation->RotateWXYZ(alfa,0,0,1);
220 _transformOrientation->RotateWXYZ(-beta,0,1,0);
222 //-------------------------------------------------------------------
223 void vtkMPRBaseData::InitTransformOrientation(vtkTransform *trans)
225 _transformOrientation->SetMatrix( trans->GetMatrix() );
230 //-------------------------------------------------------------------
231 //-------------------------------------------------------------------
232 //-------------------------------------------------------------------
235 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
237 _visiblePosition[0]=false;
238 _visiblePosition[1]=false;
239 _visiblePosition[2]=false;
242 //-------------------------------------------------------------------
243 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
245 _outlineData -> Delete();
246 _mapOutline -> Delete();
247 _outline -> Delete();
249 // if (_bwLut) _bwLut -> Delete();
250 // if (_hueLut) _hueLut -> Delete();
251 // if (_satLut) _satLut -> Delete();
252 if (_ctfun) _ctfun -> Delete();
253 if (_saggitalColors) _saggitalColors -> Delete();
254 if (_saggital) _saggital -> Delete();
255 if (_axialColors) _axialColors -> Delete();
256 if (_axial) _axial -> Delete();
257 if (_coronalColors) _coronalColors -> Delete();
258 if (_coronal) _coronal -> Delete();
261 //-------------------------------------------------------------------
262 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
266 //-------------------------------------------------------------------
267 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
269 vtkImageActor *tmpVtkActor=NULL;
271 tmpVtkActor = GetvtkActor_saggital();
274 tmpVtkActor = GetvtkActor_coronal();
277 tmpVtkActor = GetvtkActor_axial();
281 //-------------------------------------------------------------------
282 void vtkMPR3DDataViewer::Refresh()
284 int x = (int)(_vtkmprbasedata->GetX());
285 int y = (int)(_vtkmprbasedata->GetY());
286 int z = (int)(_vtkmprbasedata->GetZ());
292 //-------------------------------------------------------------------
293 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
295 _vtkmprbasedata=vtkmprbasedata;
297 //-------------------------------------------------------------------
298 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
300 return _vtkmprbasedata;
302 //-------------------------------------------------------------------
304 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
308 //-------------------------------------------------------------------
310 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
312 return &_ctFunVectorPoint;
314 //-------------------------------------------------------------------
315 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
317 return &_ctFunVectorRed;
320 //-------------------------------------------------------------------
321 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
323 return &_ctFunVectorGreen;
326 //-------------------------------------------------------------------
327 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
329 return &_ctFunVectorBlue;
332 //-------------------------------------------------------------------
333 void vtkMPR3DDataViewer::Configure()
336 // Start by creatin a black/white lookup table.
337 _bwLut = vtkLookupTable::New();
338 _bwLut->SetTableRange (0, 2000);
339 _bwLut->SetSaturationRange (0, 0);
340 _bwLut->SetHueRange (0, 0);
341 _bwLut->SetValueRange (0, 1);
343 // Now create a lookup table that consists of the full hue circle
345 _hueLut = vtkLookupTable::New();
346 _hueLut->SetTableRange (0, 2000);
347 _hueLut->SetHueRange (0, 1);
348 _hueLut->SetSaturationRange (1, 1);
349 _hueLut->SetValueRange (1, 1);
351 // Finally, create a lookup table with a single hue but having a range
352 // in the saturation of the hue.
353 _satLut = vtkLookupTable::New();
354 _satLut->SetTableRange (0, 2000);
355 _satLut->SetHueRange (.6, .6);
356 _satLut->SetSaturationRange (0, 1);
357 _satLut->SetValueRange (1, 1);
362 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
363 double max = range[1];
366 _ctFunVectorPoint.push_back(max*0/4);
367 _ctFunVectorPoint.push_back(max*1/4);
368 _ctFunVectorPoint.push_back(max*2/4);
369 _ctFunVectorPoint.push_back(max*3/4);
370 _ctFunVectorPoint.push_back(max*4/4);
372 _ctFunVectorRed.push_back(0.0);
373 _ctFunVectorRed.push_back(1.0);
374 _ctFunVectorRed.push_back(0.0);
375 _ctFunVectorRed.push_back(0.0);
376 _ctFunVectorRed.push_back(0.0);
378 _ctFunVectorGreen.push_back(0.0);
379 _ctFunVectorGreen.push_back(0.0);
380 _ctFunVectorGreen.push_back(0.0);
381 _ctFunVectorGreen.push_back(1.0);
382 _ctFunVectorGreen.push_back(0.2);
384 _ctFunVectorBlue.push_back(0.0);
385 _ctFunVectorBlue.push_back(0.0);
386 _ctFunVectorBlue.push_back(1.0);
387 _ctFunVectorBlue.push_back(0.0);
388 _ctFunVectorBlue.push_back(0.0);
391 _ctfun = vtkColorTransferFunction::New();
393 int i,size=_ctFunVectorPoint.size();
396 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
400 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
401 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
402 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
403 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
405 // void *p=this; // JPRx
407 // Create the first of the three planes. The filter vtkImageMapToColors
408 // maps the data through the corresponding lookup table created above. The
409 // vtkImageActor is a type of vtkProp and conveniently displays an image on
410 // a single quadrilateral plane. It does this using texture mapping and as
411 // a result is quite fast. (Note: the input image has to be unsigned char
412 // values, which the vtkImageMapToColors produces.) Note also that by
413 // specifying the DisplayExtent, the pipeline requests data of this extent
414 // and the vtkImageMapToColors only processes a slice of data.
415 _saggitalColors = vtkImageMapToColors::New();
416 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
417 // _saggitalColors->SetLookupTable(_bwLut);
418 _saggitalColors->SetLookupTable(_ctfun);
419 _saggital = vtkImageActor::New();
420 _saggital->SetInput(_saggitalColors->GetOutput());
423 // Create the second (axial) plane of the three planes. We use the
424 // same approach as before except that the extent differs.
425 _axialColors = vtkImageMapToColors::New();
426 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
427 // _axialColors->SetLookupTable(_hueLut);
428 _axialColors->SetLookupTable(_ctfun);
429 _axial = vtkImageActor::New();
430 _axial->SetInput(_axialColors->GetOutput());
432 // Create the third (coronal) plane of the three planes. We use
433 // the same approach as before except that the extent differs.
434 _coronalColors = vtkImageMapToColors::New();
435 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
436 // _coronalColors->SetLookupTable(_satLut);
437 _coronalColors->SetLookupTable(_ctfun);
438 _coronal = vtkImageActor::New();
439 _coronal->SetInput(_coronalColors->GetOutput());
441 // An outline provides context around the data.
443 _outlineData = vtkOutlineFilter::New();
444 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
445 _mapOutline = vtkPolyDataMapper::New();
446 _mapOutline->SetInput(_outlineData->GetOutput());
447 _outline = vtkActor::New();
448 _outline->SetMapper(_mapOutline);
449 _outline->GetProperty()->SetColor(0,0,0);
452 _vtkmprbasedata->GetImageData()->GetExtent(ext);
458 //-------------------------------------------------------------------
459 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
463 //-------------------------------------------------------------------
464 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
468 //-------------------------------------------------------------------
469 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
474 //------------------------------------------------------------------------
475 void vtkMPR3DDataViewer::SetPositionX(int pos){
476 int x1,x2,y1,y2,z1,z2;
477 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
478 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
480 //------------------------------------------------------------------------
481 void vtkMPR3DDataViewer::SetPositionY(int pos){
482 int x1,x2,y1,y2,z1,z2;
483 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
484 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
486 //------------------------------------------------------------------------
487 void vtkMPR3DDataViewer::SetPositionZ(int pos){
488 int x1,x2,y1,y2,z1,z2;
489 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
490 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
492 //-------------------------------------------------------------------
493 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
495 _visiblePosition[idPosition]=visible;
497 //-------------------------------------------------------------------
498 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
500 return _visiblePosition[idPosition];
502 //-------------------------------------------------------------------
503 //-------------------------------------------------------------------
504 //-------------------------------------------------------------------
507 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
510 for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
511 _visibleTissue[i] = false;
512 _representationType[i] = true;
514 _visibleVolume=false;
516 //-------------------------------------------------------------------
517 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
520 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
521 _mCubes[i] ->Delete();
522 _tissueStripper[i] ->Delete();
523 _tissueMapper[i] ->Delete();
524 _tissuePlanes[i] ->Delete();
525 _tissueClipper[i] ->Delete();
527 _outlineData ->Delete();
528 _mapOutline ->Delete();
533 _compositeFunction ->Delete();
534 _volumeMapper ->Delete();
535 _volumeProperty ->Delete();
537 _volumePlanes ->Delete();
539 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
540 _tissue[i] -> Delete();
541 _observerS[i] -> Delete();
543 _observerV -> Delete();
545 //-------------------------------------------------------------------
546 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
550 //-------------------------------------------------------------------
551 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
553 return this->_tissueClipper[id];
555 //-------------------------------------------------------------------
556 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
558 return _tissueMapper[id];
560 //-------------------------------------------------------------------
561 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
563 return _tissuePlanes[id];
565 //-------------------------------------------------------------------
566 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
568 return _tissueStripper[id];
570 //-------------------------------------------------------------------
571 void vtkClipping3DDataViewer::Refresh()
573 // _volumeMapper->SetClippingPlanes(_volumePlanes);
575 // this->_volumeMapper->Update();
576 // this->_newvol->Update();
578 // _newvol->VisibilityOn();
581 // _volumeMapper = vtkVolumeRayCastMapper::New();
582 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
583 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
584 // _volumeMapper->SetClippingPlanes( _volumePlanes );
585 // _newvol->SetMapper(_volumeMapper );
589 //-------------------------------------------------------------------
590 void vtkClipping3DDataViewer::RefreshSurface()
593 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
595 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
596 // this->GetMCubes(i)->Update();
599 //-------------------------------------------------------------------
600 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
602 _vtkmprbasedata=vtkmprbasedata;
604 //-------------------------------------------------------------------
605 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
607 return _vtkmprbasedata;
611 //-------------------------------------------------------------------
612 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
614 _visibleTissue[idTissue]=visible;
616 //-------------------------------------------------------------------
617 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
618 return _visibleTissue[idTissue];
620 //-------------------------------------------------------------------
621 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
623 _representationType[idTissue]=representationType;
625 //-------------------------------------------------------------------
626 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
628 return _representationType[idTissue];
631 //-------------------------------------------------------------------
632 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
636 //-------------------------------------------------------------------
637 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
639 return _observerS[idObserverS];
641 //-------------------------------------------------------------------
642 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
647 //-------------------------------------------------------------------
648 bool vtkClipping3DDataViewer::GetVisibleVolume()
650 return _visibleVolume;
652 //-------------------------------------------------------------------
653 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
655 _visibleVolume = visiblevolume;
659 //-------------------------------------------------------------------
660 void vtkClipping3DDataViewer::Configure_Tissue()
665 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
666 // Visualisation - original volume
667 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
668 imagedata->GetScalarRange( range );
669 _mCubes[i] = vtkMarchingCubes::New( );
670 _mCubes[i]->SetInput( imagedata );
672 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
673 // _mCubes[i]->SetValue( 0, 1500 );
675 _tissueStripper[i] = vtkStripper::New();
676 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
680 _tissuePlanes[i] = vtkPlanes::New();
682 int x1,x2,y1,y2,z1,z2;
683 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
684 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
686 _tissueClipper[i] = vtkClipPolyData::New();
687 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
688 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
689 _tissueClipper[i]->InsideOutOn( );
691 _tissueMapper[i] = vtkPolyDataMapper::New( );
692 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
693 _tissueMapper[i]->ScalarVisibilityOff( );
694 // _tissueMapper[i]->Update();
701 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
703 _tissue[i] = vtkActor::New();
704 _tissue[i]->SetMapper( GetTissueMapper(i) );
705 float cr=1,cg=0.5,cb=0.5;
706 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
707 _tissue[i]->GetProperty()->SetSpecular(.3);
708 _tissue[i]->GetProperty()->SetSpecularPower(20);
709 _tissue[i]->GetProperty()->SetOpacity(0.5);
710 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
711 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
712 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
713 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
716 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
718 _observerS[i] = boxSurfaceObserver::New();
719 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
720 _observerS[i]->SetActor( _tissue[i] );
725 //-----------------------------------------------------------------------------
727 void vtkClipping3DDataViewer::Configure_Volume()
731 _tfun = vtkPiecewiseFunction::New();
732 _ctfun = vtkColorTransferFunction::New();
735 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
736 double max = range[1];
739 adding the poinst of the transference function
742 greyValuesTransferenceFVector.push_back(max * 0/2);
743 greyValuesTransferenceFVector.push_back(max * 1/2);
744 greyValuesTransferenceFVector.push_back(max * 2/2);
746 intensityValuesTransferenceFVector.push_back(0.0);
747 intensityValuesTransferenceFVector.push_back(1.0);
748 intensityValuesTransferenceFVector.push_back(1.0);
750 _tfun->AddPoint(max * 0/2 , 0.0);
751 _tfun->AddPoint(max * 1/2 , 1.0);
752 _tfun->AddPoint(max * 2/2 , 1.0);
755 Adding the colors to the vectors
758 redColorsOfColorTransferenceFVector.push_back(0.0);
759 redColorsOfColorTransferenceFVector.push_back(1.0);
760 redColorsOfColorTransferenceFVector.push_back(0.0);
761 redColorsOfColorTransferenceFVector.push_back(0.0);
762 redColorsOfColorTransferenceFVector.push_back(0.0);
765 greenColorsOfColorTransferenceFVector.push_back(0.0);
766 greenColorsOfColorTransferenceFVector.push_back(0.0);
767 greenColorsOfColorTransferenceFVector.push_back(0.0);
768 greenColorsOfColorTransferenceFVector.push_back(1.0);
769 greenColorsOfColorTransferenceFVector.push_back(0.2);
772 blueColorsOfColorTransferenceFVector.push_back(0.0);
773 blueColorsOfColorTransferenceFVector.push_back(0.0);
774 blueColorsOfColorTransferenceFVector.push_back(1.0);
775 blueColorsOfColorTransferenceFVector.push_back(0.0);
776 blueColorsOfColorTransferenceFVector.push_back(0.0);
778 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
779 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
780 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
781 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
782 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
784 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
785 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
786 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
787 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
788 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
790 _volumePlanes = vtkPlanes::New();
791 // int x1,x2,y1,y2,z1,z2;
792 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
793 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
794 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
796 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
798 _volumeMapper = vtkVolumeRayCastMapper::New();
799 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
800 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
801 _volumeMapper->SetClippingPlanes( _volumePlanes );
802 _volumeMapper->AutoAdjustSampleDistancesOn();
804 _volumeProperty = vtkVolumeProperty::New();
805 _volumeProperty->SetColor(_ctfun);
806 _volumeProperty->SetScalarOpacity( _tfun );
808 _volumeProperty->SetInterpolationTypeToLinear();
809 _volumeProperty->ShadeOn();
810 _volumeProperty->DisableGradientOpacityOn();
812 // _volumeProperty->SetInterpolationTypeToNearest();
813 // _volumeProperty->ShadeOff();
814 // _volumeProperty->SetAmbient(0.3);
815 // _volumeProperty->SetDiffuse(0.1);
816 // _volumeProperty->SetSpecular(0.8);
817 // _volumeProperty->DisableGradientOpacityOn();
819 _newvol = vtkVolume::New();
820 _newvol->SetMapper(_volumeMapper );
821 _newvol->SetProperty(_volumeProperty );
823 _observerV = boxSurfaceObserver::New();
824 _observerV->SetPlanes( _volumePlanes );
825 _observerV->SetActor( _newvol );
826 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
830 //-------------------------------------------------------------------
831 void vtkClipping3DDataViewer::Configure()
836 // An outline provides context around the data.
838 _outlineData = vtkOutlineFilter::New();
839 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
840 _mapOutline = vtkPolyDataMapper::New();
841 _mapOutline->SetInput(_outlineData->GetOutput());
842 _outline = vtkActor::New();
843 _outline->SetMapper(_mapOutline);
844 _outline->GetProperty()->SetColor(0,0,0);
848 //-------------------------------------------------------------------
849 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
851 _mCubes[idTissue]->SetValue(0, isoValue);
853 //-------------------------------------------------------------------
854 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
856 return _mCubes[idTissue]->GetValue(0);
858 //-------------------------------------------------------------------
859 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
863 //-------------------------------------------------------------------
864 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
865 return _volumeMapper;
867 //-------------------------------------------------------------------
868 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
870 return _volumePlanes;
873 //-------------------------------------------------------------------
874 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
876 return _mCubes[idTissue];
878 //--------------------------------------------------------------------
879 //-------------------
881 //-------------------
883 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
885 return &greyValuesTransferenceFVector;
887 //--------------------------------------------------------------------
888 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
890 return &intensityValuesTransferenceFVector;
892 //--------------------------------------------------------------------
893 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
895 return &redColorsOfColorTransferenceFVector;
897 //--------------------------------------------------------------------
898 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
900 return &greenColorsOfColorTransferenceFVector;
902 //--------------------------------------------------------------------
903 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
905 return &blueColorsOfColorTransferenceFVector;
907 //--------------------------------------------------------------------
908 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
910 return &greyValueColorsOfColorTransferenceFVector;
912 //--------------------------------------------------------------------
913 //--------------------------------------
914 //Getters transference function
915 //and color of the transference function
916 //---------------------------------------
917 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
921 //--------------------------------------------------------------------
922 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
927 //-------------------------------------------------------------------
929 void vtkClipping3DDataViewer::ReadVolumeFunctions()
932 int i=0,xi,yi,r,g,b,gValue;
933 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
935 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
939 int tfSize=this->greyValuesTransferenceFVector.size();
943 hDlg->erasePointsTransferenceFunction();
946 double g=greyValuesTransferenceFVector[i];
947 double in=intensityValuesTransferenceFVector[i];
948 hDlg->addPointToTransferenceFunction(g,in*100);
954 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
960 double gr=greyValueColorsOfColorTransferenceFVector[i];
961 double r=redColorsOfColorTransferenceFVector[i];
962 double g=greenColorsOfColorTransferenceFVector[i];
963 double b=blueColorsOfColorTransferenceFVector[i];
964 hDlg->addColorPoint(gr,r*255,g*255,b*255);
968 //If it is smooth activate next line
969 //hDlg->updatePlotter();
970 //setting variables if the user wants to do refresh
971 hDlg->setCTF(_ctfun);
975 // when the user had changed the transference Function
977 if(hDlg->ShowModal()== wxID_OK )
979 // -- vtkPiecewiseFunction --
980 this->_tfun->RemoveAllPoints();
981 greyValuesTransferenceFVector.clear();
982 intensityValuesTransferenceFVector.clear();
984 int nTFPoints=hDlg->getSizeTransferenceFunction();
988 hDlg->getTransferenceFunctionPoint(i,xi,yi);
989 this->_tfun->AddPoint( xi , yi/100.0 );
990 greyValuesTransferenceFVector.push_back(xi);
991 intensityValuesTransferenceFVector.push_back(yi/100.0);
994 // -- vtkColorTransferFunction --
995 this->_ctfun->RemoveAllPoints ();
997 redColorsOfColorTransferenceFVector.clear();
998 greenColorsOfColorTransferenceFVector.clear();
999 blueColorsOfColorTransferenceFVector.clear();
1000 greyValueColorsOfColorTransferenceFVector.clear();
1002 int nCTFpoints=hDlg->getSizeBarColor();
1006 hDlg->getDataBarColorPoint(i,xi,r,g,b);
1007 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
1008 redColorsOfColorTransferenceFVector.push_back(r/255.0);
1009 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
1010 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
1011 greyValueColorsOfColorTransferenceFVector.push_back(xi);
1015 this->_volumeMapper->Update();
1016 this->_newvol->Update();
1022 if(hDlg->getRefreshed())
1025 //--Transference Function----
1026 this->_tfun->RemoveAllPoints();
1028 size=greyValuesTransferenceFVector.size();
1031 double grey1=greyValuesTransferenceFVector[i];
1032 double in2=intensityValuesTransferenceFVector[i];
1033 this->_tfun->AddPoint( grey1 , in2 );
1036 // -- vtkColorTransferFunction --
1037 _ctfun->RemoveAllPoints ();
1040 size=greyValueColorsOfColorTransferenceFVector.size();
1043 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
1044 double red =(redColorsOfColorTransferenceFVector)[i];
1045 double green =(greenColorsOfColorTransferenceFVector)[i];
1046 double blue = (blueColorsOfColorTransferenceFVector)[i];
1047 _ctfun->AddRGBPoint(grey2,red,green,blue);
1049 this->_volumeMapper->Update();
1050 this->_newvol->Update();
1058 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
1065 FILE *ff = fopen ( namefile ,"r");
1068 fscanf(ff,"%s",tmp);
1069 if (strcmp(tmp,"MAX")==0)
1071 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
1072 vtkimagedata->GetScalarRange(range);
1073 max = (int) (range[1]);
1078 fscanf(ff,"%s",tmp); // --
1080 // -- vtkPiecewiseFunction --
1081 this->_tfun->RemoveAllPoints();
1082 fscanf(ff,"%s",tmp);
1083 while ( strcmp(tmp,"--")!=0 )
1086 fscanf(ff,"%s",tmp);
1088 this->_tfun->AddPoint( x*max , val );
1089 fscanf(ff,"%s",tmp);
1092 this->_ctfun->RemoveAllPoints ();
1093 // -- vtkColorTransferFunction --
1096 fscanf(ff,"%s",tmp);
1098 fscanf(ff,"%s",tmp);
1100 fscanf(ff,"%s",tmp);
1102 fscanf(ff,"%s",tmp);
1104 this->_ctfun->AddRGBPoint( x*max , r,g,b );
1108 this->_volumeMapper->Update();
1109 this->_newvol->Update();
1116 //-------------------------------------------------------------------
1118 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
1120 vtkDataSetReader *reader = vtkDataSetReader::New();
1121 reader->SetFileName(namefile);
1123 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );