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);
95 //-------------------------------------------------------------------
96 double vtkBaseData::GetZ()
100 //-------------------------------------------------------------------
101 int vtkBaseData::GetT()
105 //-------------------------------------------------------------------
106 void vtkBaseData::SetT(double t)
108 int maxT = _marImageData->GetMaxT();
120 //-------------------------------------------------------------------
121 //-------------------------------------------------------------------
122 //-------------------------------------------------------------------
123 vtkMPRBaseData::vtkMPRBaseData()
128 _transformOrientation = NULL;
129 _marImageData = NULL;
131 //-------------------------------------------------------------------
132 vtkMPRBaseData::~vtkMPRBaseData()
134 if (_marImageData) delete _marImageData;
135 if (_transformOrientation) _transformOrientation ->Delete();
137 //-------------------------------------------------------------------
138 void vtkMPRBaseData::Configure()
140 vtkImageData* img = _marImageData->GetImageData();
142 img->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2);
143 //std::cout<<"vtkMPRBaseData::Configure() _x1= "<<_x1<<" _x2= "<<_x2<<" _y1= "<<_y1<<" _y2= "<<_y2<<" _z1= "<<_z1<<" _z2= "<<_z2<<std::endl;
144 if(_transformOrientation==NULL){
145 _transformOrientation=vtkTransform::New();
147 _transformOrientation->Identity();
150 //-------------------------------------------------------------------
151 void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2)
162 //------------------------------------------------------------------------
163 int vtkMPRBaseData::GetMaxPositionX( )
167 //------------------------------------------------------------------------
168 int vtkMPRBaseData::GetMaxPositionY( )
172 //------------------------------------------------------------------------
173 int vtkMPRBaseData::GetMaxPositionZ( )
177 //-------------------------------------------------------------------
178 double vtkMPRBaseData::GetX()
183 //-------------------------------------------------------------------
184 double vtkMPRBaseData::GetY()
188 //-------------------------------------------------------------------
190 ** Calculates the value of the slider and the layer in the image that is spouse to show
192 void vtkMPRBaseData::SetX(double x)
197 vtkImageData* img = _marImageData->GetImageData();
199 /*img->GetDimensions(dim);
221 //-------------------------------------------------------------------
223 ** Calculates the value of the slider and the layer in the image that is spouse to show
225 void vtkMPRBaseData::SetY(double y)
229 vtkImageData* img = _marImageData->GetImageData();
231 /*img->GetDimensions(dim);
253 //-------------------------------------------------------------------
254 vtkTransform *vtkMPRBaseData::GetTransformOrientation()
256 return _transformOrientation;
258 //-------------------------------------------------------------------
259 void vtkMPRBaseData::SetNormal(double nx, double ny, double nz)
261 double alfa = atan2(ny,nx) * 180.0 / 3.1416;
262 double beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416;
263 _transformOrientation->Identity();
264 _transformOrientation->RotateWXYZ(alfa,0,0,1);
265 _transformOrientation->RotateWXYZ(-beta,0,1,0);
267 //-------------------------------------------------------------------
268 void vtkMPRBaseData::InitTransformOrientation(vtkTransform *trans)
270 _transformOrientation->SetMatrix( trans->GetMatrix() );
275 //-------------------------------------------------------------------
276 //-------------------------------------------------------------------
277 //-------------------------------------------------------------------
280 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
282 _visiblePosition[0]=false;
283 _visiblePosition[1]=false;
284 _visiblePosition[2]=false;
286 _vtkmprbasedata=NULL;
289 _saggitalColors=NULL;
299 //-------------------------------------------------------------------
300 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
302 _outlineData -> Delete();
303 _mapOutline -> Delete();
304 _outline -> Delete();
306 // if (_bwLut) _bwLut -> Delete();
307 // if (_hueLut) _hueLut -> Delete();
308 // if (_satLut) _satLut -> Delete();
309 if (_ctfun) _ctfun -> Delete();
310 if (_saggitalColors) _saggitalColors -> Delete();
311 if (_saggital) _saggital -> Delete();
312 if (_axialColors) _axialColors -> Delete();
313 if (_axial) _axial -> Delete();
314 if (_coronalColors) _coronalColors -> Delete();
315 if (_coronal) _coronal -> Delete();
318 //-------------------------------------------------------------------
319 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
323 //-------------------------------------------------------------------
324 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
326 vtkImageActor *tmpVtkActor=NULL;
328 tmpVtkActor = GetvtkActor_saggital();
331 tmpVtkActor = GetvtkActor_coronal();
334 tmpVtkActor = GetvtkActor_axial();
338 //-------------------------------------------------------------------
339 void vtkMPR3DDataViewer::Refresh()
341 int x = (int)(_vtkmprbasedata->GetX());
342 int y = (int)(_vtkmprbasedata->GetY());
343 int z = (int)(_vtkmprbasedata->GetZ());
344 std::cout<<" vtkMPR3DDataViewer::Refresh() x="<<x<<" y= "<<y<<" z= "<<z;
349 //-------------------------------------------------------------------
350 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
352 _vtkmprbasedata=vtkmprbasedata;
354 //-------------------------------------------------------------------
355 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
357 return _vtkmprbasedata;
359 //-------------------------------------------------------------------
361 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
365 //-------------------------------------------------------------------
367 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
369 return &_ctFunVectorPoint;
371 //-------------------------------------------------------------------
372 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
374 return &_ctFunVectorRed;
377 //-------------------------------------------------------------------
378 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
380 return &_ctFunVectorGreen;
383 //-------------------------------------------------------------------
384 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
386 return &_ctFunVectorBlue;
389 //-------------------------------------------------------------------
390 void vtkMPR3DDataViewer::Configure()
393 // Start by creatin a black/white lookup table.
394 _bwLut = vtkLookupTable::New();
395 _bwLut->SetTableRange (0, 2000);
396 _bwLut->SetSaturationRange (0, 0);
397 _bwLut->SetHueRange (0, 0);
398 _bwLut->SetValueRange (0, 1);
400 // Now create a lookup table that consists of the full hue circle
402 _hueLut = vtkLookupTable::New();
403 _hueLut->SetTableRange (0, 2000);
404 _hueLut->SetHueRange (0, 1);
405 _hueLut->SetSaturationRange (1, 1);
406 _hueLut->SetValueRange (1, 1);
408 // Finally, create a lookup table with a single hue but having a range
409 // in the saturation of the hue.
410 _satLut = vtkLookupTable::New();
411 _satLut->SetTableRange (0, 2000);
412 _satLut->SetHueRange (.6, .6);
413 _satLut->SetSaturationRange (0, 1);
414 _satLut->SetValueRange (1, 1);
419 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
420 double max = range[1];
422 _ctFunVectorPoint.clear();
423 _ctFunVectorPoint.push_back(max*0/4);
424 _ctFunVectorPoint.push_back(max*1/4);
425 _ctFunVectorPoint.push_back(max*2/4);
426 _ctFunVectorPoint.push_back(max*3/4);
427 _ctFunVectorPoint.push_back(max*4/4);
429 _ctFunVectorRed.clear();
430 _ctFunVectorRed.push_back(0.0);
431 _ctFunVectorRed.push_back(1.0);
432 _ctFunVectorRed.push_back(0.0);
433 _ctFunVectorRed.push_back(0.0);
434 _ctFunVectorRed.push_back(0.0);
436 _ctFunVectorGreen.clear();
437 _ctFunVectorGreen.push_back(0.0);
438 _ctFunVectorGreen.push_back(0.0);
439 _ctFunVectorGreen.push_back(0.0);
440 _ctFunVectorGreen.push_back(1.0);
441 _ctFunVectorGreen.push_back(0.2);
443 _ctFunVectorBlue.clear();
444 _ctFunVectorBlue.push_back(0.0);
445 _ctFunVectorBlue.push_back(0.0);
446 _ctFunVectorBlue.push_back(1.0);
447 _ctFunVectorBlue.push_back(0.0);
448 _ctFunVectorBlue.push_back(0.0);
452 _ctfun = vtkColorTransferFunction::New();
454 _ctfun->RemoveAllPoints();
456 int i,size=_ctFunVectorPoint.size();
459 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
463 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
464 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
465 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
466 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
468 // void *p=this; // JPRx
470 // Create the first of the three planes. The filter vtkImageMapToColors
471 // maps the data through the corresponding lookup table created above. The
472 // vtkImageActor is a type of vtkProp and conveniently displays an image on
473 // a single quadrilateral plane. It does this using texture mapping and as
474 // a result is quite fast. (Note: the input image has to be unsigned char
475 // values, which the vtkImageMapToColors produces.) Note also that by
476 // specifying the DisplayExtent, the pipeline requests data of this extent
477 // and the vtkImageMapToColors only processes a slice of data.
479 if(_saggitalColors==NULL){
480 _saggitalColors = vtkImageMapToColors::New();
482 _saggitalColors->RemoveAllInputs();
484 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
485 // _saggitalColors->SetLookupTable(_bwLut);
487 _saggitalColors->SetLookupTable(_ctfun);
492 _saggital = vtkImageActor::New();
493 _saggital->SetInput(_saggitalColors->GetOutput());
495 //_saggitalColors->Update();
499 // Create the second (axial) plane of the three planes. We use the
500 // same approach as before except that the extent differs.
503 if(_axialColors==NULL){
504 _axialColors = vtkImageMapToColors::New();
507 _axialColors->RemoveAllInputs();
508 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
509 // _axialColors->SetLookupTable(_hueLut);
510 _axialColors->SetLookupTable(_ctfun);
513 _axial = vtkImageActor::New();
514 _axial->SetInput(_axialColors->GetOutput());
517 //_axialColors->Update();
520 // Create the third (coronal) plane of the three planes. We use
521 // the same approach as before except that the extent differs.
522 if(_coronalColors==NULL){
523 _coronalColors = vtkImageMapToColors::New();
525 _coronalColors->RemoveAllInputs();
526 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
527 // _coronalColors->SetLookupTable(_satLut);
528 _coronalColors->SetLookupTable(_ctfun);
531 _coronal = vtkImageActor::New();
532 _coronal->SetInput(_coronalColors->GetOutput());
537 // An outline provides context around the data.
539 if(_outlineData==NULL){
540 _outlineData = vtkOutlineFilter::New();
542 _outlineData->RemoveAllInputs();
543 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
545 if(_mapOutline==NULL){
546 _mapOutline = vtkPolyDataMapper::New();
547 _mapOutline->SetInput(_outlineData->GetOutput());
549 _mapOutline->Update();
550 //_mapOutline->RemoveAllInputs();
553 _outline = vtkActor::New();
554 _outline->SetMapper(_mapOutline);
555 _outline->GetProperty()->SetColor(0,0,0);
561 _vtkmprbasedata->GetImageData()->GetExtent(ext);
568 //-------------------------------------------------------------------
569 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
573 //-------------------------------------------------------------------
574 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
578 //-------------------------------------------------------------------
579 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
584 //------------------------------------------------------------------------
585 void vtkMPR3DDataViewer::SetPositionX(int pos){
586 int x1,x2,y1,y2,z1,z2;
587 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
588 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
590 //------------------------------------------------------------------------
591 void vtkMPR3DDataViewer::SetPositionY(int pos){
592 int x1,x2,y1,y2,z1,z2;
593 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
594 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
596 //------------------------------------------------------------------------
597 void vtkMPR3DDataViewer::SetPositionZ(int pos){
598 int x1,x2,y1,y2,z1,z2;
599 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
600 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
602 //-------------------------------------------------------------------
603 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
605 _visiblePosition[idPosition]=visible;
607 //-------------------------------------------------------------------
608 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
610 return _visiblePosition[idPosition];
612 //-------------------------------------------------------------------
613 //-------------------------------------------------------------------
614 //-------------------------------------------------------------------
617 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
620 for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
621 _visibleTissue[i] = false;
622 _representationType[i] = true;
624 _visibleVolume=false;
626 //-------------------------------------------------------------------
627 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
630 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
631 _mCubes[i] ->Delete();
632 _tissueStripper[i] ->Delete();
633 _tissueMapper[i] ->Delete();
634 _tissuePlanes[i] ->Delete();
635 _tissueClipper[i] ->Delete();
637 _outlineData ->Delete();
638 _mapOutline ->Delete();
643 _compositeFunction ->Delete();
644 _volumeMapper ->Delete();
645 _volumeProperty ->Delete();
647 _volumePlanes ->Delete();
649 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
650 _tissue[i] -> Delete();
651 _observerS[i] -> Delete();
653 _observerV -> Delete();
655 //-------------------------------------------------------------------
656 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
660 //-------------------------------------------------------------------
661 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
663 return this->_tissueClipper[id];
665 //-------------------------------------------------------------------
666 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
668 return _tissueMapper[id];
670 //-------------------------------------------------------------------
671 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
673 return _tissuePlanes[id];
675 //-------------------------------------------------------------------
676 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
678 return _tissueStripper[id];
680 //-------------------------------------------------------------------
681 void vtkClipping3DDataViewer::Refresh()
683 // _volumeMapper->SetClippingPlanes(_volumePlanes);
685 // this->_volumeMapper->Update();
686 // this->_newvol->Update();
688 // _newvol->VisibilityOn();
691 // _volumeMapper = vtkVolumeRayCastMapper::New();
692 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
693 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
694 // _volumeMapper->SetClippingPlanes( _volumePlanes );
695 // _newvol->SetMapper(_volumeMapper );
699 //-------------------------------------------------------------------
700 void vtkClipping3DDataViewer::RefreshSurface()
703 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
705 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
706 // this->GetMCubes(i)->Update();
709 //-------------------------------------------------------------------
710 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
712 _vtkmprbasedata=vtkmprbasedata;
714 //-------------------------------------------------------------------
715 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
717 return _vtkmprbasedata;
721 //-------------------------------------------------------------------
722 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
724 _visibleTissue[idTissue]=visible;
726 //-------------------------------------------------------------------
727 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
728 return _visibleTissue[idTissue];
730 //-------------------------------------------------------------------
731 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
733 _representationType[idTissue]=representationType;
735 //-------------------------------------------------------------------
736 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
738 return _representationType[idTissue];
741 //-------------------------------------------------------------------
742 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
746 //-------------------------------------------------------------------
747 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
749 return _observerS[idObserverS];
751 //-------------------------------------------------------------------
752 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
757 //-------------------------------------------------------------------
758 bool vtkClipping3DDataViewer::GetVisibleVolume()
760 return _visibleVolume;
762 //-------------------------------------------------------------------
763 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
765 _visibleVolume = visiblevolume;
769 //-------------------------------------------------------------------
770 void vtkClipping3DDataViewer::Configure_Tissue()
775 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
776 // Visualisation - original volume
777 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
778 imagedata->GetScalarRange( range );
779 _mCubes[i] = vtkMarchingCubes::New( );
780 _mCubes[i]->SetInput( imagedata );
782 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
783 // _mCubes[i]->SetValue( 0, 1500 );
785 _tissueStripper[i] = vtkStripper::New();
786 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
790 _tissuePlanes[i] = vtkPlanes::New();
792 int x1,x2,y1,y2,z1,z2;
793 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
794 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
796 _tissueClipper[i] = vtkClipPolyData::New();
797 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
798 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
799 _tissueClipper[i]->InsideOutOn( );
801 _tissueMapper[i] = vtkPolyDataMapper::New( );
802 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
803 _tissueMapper[i]->ScalarVisibilityOff( );
804 // _tissueMapper[i]->Update();
811 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
813 _tissue[i] = vtkActor::New();
814 _tissue[i]->SetMapper( GetTissueMapper(i) );
815 float cr=1,cg=0.5,cb=0.5;
816 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
817 _tissue[i]->GetProperty()->SetSpecular(.3);
818 _tissue[i]->GetProperty()->SetSpecularPower(20);
819 _tissue[i]->GetProperty()->SetOpacity(0.5);
820 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
821 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
822 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
823 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
826 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
828 _observerS[i] = boxSurfaceObserver::New();
829 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
830 _observerS[i]->SetActor( _tissue[i] );
835 //-----------------------------------------------------------------------------
837 void vtkClipping3DDataViewer::Configure_Volume()
841 _tfun = vtkPiecewiseFunction::New();
842 _ctfun = vtkColorTransferFunction::New();
845 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
846 double max = range[1];
849 adding the poinst of the transference function
852 greyValuesTransferenceFVector.push_back(max * 0/2);
853 greyValuesTransferenceFVector.push_back(max * 1/2);
854 greyValuesTransferenceFVector.push_back(max * 2/2);
856 intensityValuesTransferenceFVector.push_back(0.0);
857 intensityValuesTransferenceFVector.push_back(1.0);
858 intensityValuesTransferenceFVector.push_back(1.0);
860 _tfun->AddPoint(max * 0/2 , 0.0);
861 _tfun->AddPoint(max * 1/2 , 1.0);
862 _tfun->AddPoint(max * 2/2 , 1.0);
865 Adding the colors to the vectors
868 redColorsOfColorTransferenceFVector.push_back(0.0);
869 redColorsOfColorTransferenceFVector.push_back(1.0);
870 redColorsOfColorTransferenceFVector.push_back(0.0);
871 redColorsOfColorTransferenceFVector.push_back(0.0);
872 redColorsOfColorTransferenceFVector.push_back(0.0);
875 greenColorsOfColorTransferenceFVector.push_back(0.0);
876 greenColorsOfColorTransferenceFVector.push_back(0.0);
877 greenColorsOfColorTransferenceFVector.push_back(0.0);
878 greenColorsOfColorTransferenceFVector.push_back(1.0);
879 greenColorsOfColorTransferenceFVector.push_back(0.2);
882 blueColorsOfColorTransferenceFVector.push_back(0.0);
883 blueColorsOfColorTransferenceFVector.push_back(0.0);
884 blueColorsOfColorTransferenceFVector.push_back(1.0);
885 blueColorsOfColorTransferenceFVector.push_back(0.0);
886 blueColorsOfColorTransferenceFVector.push_back(0.0);
888 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
889 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
890 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
891 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
892 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
894 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
895 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
896 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
897 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
898 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
900 _volumePlanes = vtkPlanes::New();
901 // int x1,x2,y1,y2,z1,z2;
902 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
903 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
904 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
906 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
908 _volumeMapper = vtkVolumeRayCastMapper::New();
909 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
910 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
911 _volumeMapper->SetClippingPlanes( _volumePlanes );
912 _volumeMapper->AutoAdjustSampleDistancesOn();
914 _volumeProperty = vtkVolumeProperty::New();
915 _volumeProperty->SetColor(_ctfun);
916 _volumeProperty->SetScalarOpacity( _tfun );
918 _volumeProperty->SetInterpolationTypeToLinear();
919 _volumeProperty->ShadeOn();
920 _volumeProperty->DisableGradientOpacityOn();
922 // _volumeProperty->SetInterpolationTypeToNearest();
923 // _volumeProperty->ShadeOff();
924 // _volumeProperty->SetAmbient(0.3);
925 // _volumeProperty->SetDiffuse(0.1);
926 // _volumeProperty->SetSpecular(0.8);
927 // _volumeProperty->DisableGradientOpacityOn();
929 _newvol = vtkVolume::New();
930 _newvol->SetMapper(_volumeMapper );
931 _newvol->SetProperty(_volumeProperty );
933 _observerV = boxSurfaceObserver::New();
934 _observerV->SetPlanes( _volumePlanes );
935 _observerV->SetActor( _newvol );
936 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
940 //-------------------------------------------------------------------
941 void vtkClipping3DDataViewer::Configure()
946 // An outline provides context around the data.
948 _outlineData = vtkOutlineFilter::New();
949 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
950 _mapOutline = vtkPolyDataMapper::New();
951 _mapOutline->SetInput(_outlineData->GetOutput());
952 _outline = vtkActor::New();
953 _outline->SetMapper(_mapOutline);
954 _outline->GetProperty()->SetColor(0,0,0);
958 //-------------------------------------------------------------------
959 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
961 _mCubes[idTissue]->SetValue(0, isoValue);
963 //-------------------------------------------------------------------
964 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
966 return _mCubes[idTissue]->GetValue(0);
968 //-------------------------------------------------------------------
969 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
973 //-------------------------------------------------------------------
974 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
975 return _volumeMapper;
977 //-------------------------------------------------------------------
978 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
980 return _volumePlanes;
983 //-------------------------------------------------------------------
984 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
986 return _mCubes[idTissue];
988 //--------------------------------------------------------------------
989 //-------------------
991 //-------------------
993 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
995 return &greyValuesTransferenceFVector;
997 //--------------------------------------------------------------------
998 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
1000 return &intensityValuesTransferenceFVector;
1002 //--------------------------------------------------------------------
1003 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
1005 return &redColorsOfColorTransferenceFVector;
1007 //--------------------------------------------------------------------
1008 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
1010 return &greenColorsOfColorTransferenceFVector;
1012 //--------------------------------------------------------------------
1013 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
1015 return &blueColorsOfColorTransferenceFVector;
1017 //--------------------------------------------------------------------
1018 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
1020 return &greyValueColorsOfColorTransferenceFVector;
1022 //--------------------------------------------------------------------
1023 //--------------------------------------
1024 //Getters transference function
1025 //and color of the transference function
1026 //---------------------------------------
1027 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
1031 //--------------------------------------------------------------------
1032 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
1034 return this->_ctfun;
1037 //-------------------------------------------------------------------
1039 void vtkClipping3DDataViewer::ReadVolumeFunctions()
1042 int i=0,xi,yi,r,g,b,gValue;
1043 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
1045 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
1049 int tfSize=this->greyValuesTransferenceFVector.size();
1053 hDlg->erasePointsTransferenceFunction();
1056 double g=greyValuesTransferenceFVector[i];
1057 double in=intensityValuesTransferenceFVector[i];
1058 hDlg->addPointToTransferenceFunction(g,in*100);
1064 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
1070 double gr=greyValueColorsOfColorTransferenceFVector[i];
1071 double r=redColorsOfColorTransferenceFVector[i];
1072 double g=greenColorsOfColorTransferenceFVector[i];
1073 double b=blueColorsOfColorTransferenceFVector[i];
1074 hDlg->addColorPoint(gr,r*255,g*255,b*255);
1078 //If it is smooth activate next line
1079 //hDlg->updatePlotter();
1080 //setting variables if the user wants to do refresh
1081 hDlg->setCTF(_ctfun);
1085 // when the user had changed the transference Function
1087 if(hDlg->ShowModal()== wxID_OK )
1089 // -- vtkPiecewiseFunction --
1090 this->_tfun->RemoveAllPoints();
1091 greyValuesTransferenceFVector.clear();
1092 intensityValuesTransferenceFVector.clear();
1094 int nTFPoints=hDlg->getSizeTransferenceFunction();
1098 hDlg->getTransferenceFunctionPoint(i,xi,yi);
1099 this->_tfun->AddPoint( xi , yi/100.0 );
1100 greyValuesTransferenceFVector.push_back(xi);
1101 intensityValuesTransferenceFVector.push_back(yi/100.0);
1104 // -- vtkColorTransferFunction --
1105 this->_ctfun->RemoveAllPoints ();
1107 redColorsOfColorTransferenceFVector.clear();
1108 greenColorsOfColorTransferenceFVector.clear();
1109 blueColorsOfColorTransferenceFVector.clear();
1110 greyValueColorsOfColorTransferenceFVector.clear();
1112 int nCTFpoints=hDlg->getSizeBarColor();
1116 hDlg->getDataBarColorPoint(i,xi,r,g,b);
1117 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
1118 redColorsOfColorTransferenceFVector.push_back(r/255.0);
1119 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
1120 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
1121 greyValueColorsOfColorTransferenceFVector.push_back(xi);
1125 this->_volumeMapper->Update();
1126 this->_newvol->Update();
1132 if(hDlg->getRefreshed())
1135 //--Transference Function----
1136 this->_tfun->RemoveAllPoints();
1138 size=greyValuesTransferenceFVector.size();
1141 double grey1=greyValuesTransferenceFVector[i];
1142 double in2=intensityValuesTransferenceFVector[i];
1143 this->_tfun->AddPoint( grey1 , in2 );
1146 // -- vtkColorTransferFunction --
1147 _ctfun->RemoveAllPoints ();
1150 size=greyValueColorsOfColorTransferenceFVector.size();
1153 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
1154 double red =(redColorsOfColorTransferenceFVector)[i];
1155 double green =(greenColorsOfColorTransferenceFVector)[i];
1156 double blue = (blueColorsOfColorTransferenceFVector)[i];
1157 _ctfun->AddRGBPoint(grey2,red,green,blue);
1159 this->_volumeMapper->Update();
1160 this->_newvol->Update();
1168 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
1175 FILE *ff = fopen ( namefile ,"r");
1178 fscanf(ff,"%s",tmp);
1179 if (strcmp(tmp,"MAX")==0)
1181 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
1182 vtkimagedata->GetScalarRange(range);
1183 max = (int) (range[1]);
1188 fscanf(ff,"%s",tmp); // --
1190 // -- vtkPiecewiseFunction --
1191 this->_tfun->RemoveAllPoints();
1192 fscanf(ff,"%s",tmp);
1193 while ( strcmp(tmp,"--")!=0 )
1196 fscanf(ff,"%s",tmp);
1198 this->_tfun->AddPoint( x*max , val );
1199 fscanf(ff,"%s",tmp);
1202 this->_ctfun->RemoveAllPoints ();
1203 // -- vtkColorTransferFunction --
1206 fscanf(ff,"%s",tmp);
1208 fscanf(ff,"%s",tmp);
1210 fscanf(ff,"%s",tmp);
1212 fscanf(ff,"%s",tmp);
1214 this->_ctfun->AddRGBPoint( x*max , r,g,b );
1218 this->_volumeMapper->Update();
1219 this->_newvol->Update();
1226 //-------------------------------------------------------------------
1228 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
1230 vtkDataSetReader *reader = vtkDataSetReader::New();
1231 reader->SetFileName(namefile);
1233 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );