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());
348 //-------------------------------------------------------------------
349 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
351 _vtkmprbasedata=vtkmprbasedata;
353 //-------------------------------------------------------------------
354 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
356 return _vtkmprbasedata;
358 //-------------------------------------------------------------------
360 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
364 //-------------------------------------------------------------------
366 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
368 return &_ctFunVectorPoint;
370 //-------------------------------------------------------------------
371 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
373 return &_ctFunVectorRed;
376 //-------------------------------------------------------------------
377 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
379 return &_ctFunVectorGreen;
382 //-------------------------------------------------------------------
383 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
385 return &_ctFunVectorBlue;
388 //-------------------------------------------------------------------
389 void vtkMPR3DDataViewer::Configure()
392 // Start by creatin a black/white lookup table.
393 _bwLut = vtkLookupTable::New();
394 _bwLut->SetTableRange (0, 2000);
395 _bwLut->SetSaturationRange (0, 0);
396 _bwLut->SetHueRange (0, 0);
397 _bwLut->SetValueRange (0, 1);
399 // Now create a lookup table that consists of the full hue circle
401 _hueLut = vtkLookupTable::New();
402 _hueLut->SetTableRange (0, 2000);
403 _hueLut->SetHueRange (0, 1);
404 _hueLut->SetSaturationRange (1, 1);
405 _hueLut->SetValueRange (1, 1);
407 // Finally, create a lookup table with a single hue but having a range
408 // in the saturation of the hue.
409 _satLut = vtkLookupTable::New();
410 _satLut->SetTableRange (0, 2000);
411 _satLut->SetHueRange (.6, .6);
412 _satLut->SetSaturationRange (0, 1);
413 _satLut->SetValueRange (1, 1);
418 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
419 double max = range[1];
421 _ctFunVectorPoint.clear();
422 _ctFunVectorPoint.push_back(max*0/4);
423 _ctFunVectorPoint.push_back(max*1/4);
424 _ctFunVectorPoint.push_back(max*2/4);
425 _ctFunVectorPoint.push_back(max*3/4);
426 _ctFunVectorPoint.push_back(max*4/4);
428 _ctFunVectorRed.clear();
429 _ctFunVectorRed.push_back(0.0);
430 _ctFunVectorRed.push_back(1.0);
431 _ctFunVectorRed.push_back(0.0);
432 _ctFunVectorRed.push_back(0.0);
433 _ctFunVectorRed.push_back(0.0);
435 _ctFunVectorGreen.clear();
436 _ctFunVectorGreen.push_back(0.0);
437 _ctFunVectorGreen.push_back(0.0);
438 _ctFunVectorGreen.push_back(0.0);
439 _ctFunVectorGreen.push_back(1.0);
440 _ctFunVectorGreen.push_back(0.2);
442 _ctFunVectorBlue.clear();
443 _ctFunVectorBlue.push_back(0.0);
444 _ctFunVectorBlue.push_back(0.0);
445 _ctFunVectorBlue.push_back(1.0);
446 _ctFunVectorBlue.push_back(0.0);
447 _ctFunVectorBlue.push_back(0.0);
451 _ctfun = vtkColorTransferFunction::New();
453 _ctfun->RemoveAllPoints();
455 int i,size=_ctFunVectorPoint.size();
458 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
462 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
463 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
464 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
465 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
467 // void *p=this; // JPRx
469 // Create the first of the three planes. The filter vtkImageMapToColors
470 // maps the data through the corresponding lookup table created above. The
471 // vtkImageActor is a type of vtkProp and conveniently displays an image on
472 // a single quadrilateral plane. It does this using texture mapping and as
473 // a result is quite fast. (Note: the input image has to be unsigned char
474 // values, which the vtkImageMapToColors produces.) Note also that by
475 // specifying the DisplayExtent, the pipeline requests data of this extent
476 // and the vtkImageMapToColors only processes a slice of data.
478 if(_saggitalColors==NULL){
479 _saggitalColors = vtkImageMapToColors::New();
481 _saggitalColors->RemoveAllInputs();
483 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
484 // _saggitalColors->SetLookupTable(_bwLut);
486 _saggitalColors->SetLookupTable(_ctfun);
491 _saggital = vtkImageActor::New();
492 _saggital->SetInput(_saggitalColors->GetOutput());
494 //_saggitalColors->Update();
498 // Create the second (axial) plane of the three planes. We use the
499 // same approach as before except that the extent differs.
502 if(_axialColors==NULL){
503 _axialColors = vtkImageMapToColors::New();
506 _axialColors->RemoveAllInputs();
507 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
508 // _axialColors->SetLookupTable(_hueLut);
509 _axialColors->SetLookupTable(_ctfun);
512 _axial = vtkImageActor::New();
513 _axial->SetInput(_axialColors->GetOutput());
516 //_axialColors->Update();
519 // Create the third (coronal) plane of the three planes. We use
520 // the same approach as before except that the extent differs.
521 if(_coronalColors==NULL){
522 _coronalColors = vtkImageMapToColors::New();
524 _coronalColors->RemoveAllInputs();
525 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
526 // _coronalColors->SetLookupTable(_satLut);
527 _coronalColors->SetLookupTable(_ctfun);
530 _coronal = vtkImageActor::New();
531 _coronal->SetInput(_coronalColors->GetOutput());
536 // An outline provides context around the data.
538 if(_outlineData==NULL){
539 _outlineData = vtkOutlineFilter::New();
541 _outlineData->RemoveAllInputs();
542 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
544 if(_mapOutline==NULL){
545 _mapOutline = vtkPolyDataMapper::New();
546 _mapOutline->SetInput(_outlineData->GetOutput());
548 _mapOutline->Update();
549 //_mapOutline->RemoveAllInputs();
552 _outline = vtkActor::New();
553 _outline->SetMapper(_mapOutline);
554 _outline->GetProperty()->SetColor(0,0,0);
560 _vtkmprbasedata->GetImageData()->GetExtent(ext);
567 //-------------------------------------------------------------------
568 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
572 //-------------------------------------------------------------------
573 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
577 //-------------------------------------------------------------------
578 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
583 //------------------------------------------------------------------------
584 void vtkMPR3DDataViewer::SetPositionX(int pos){
585 int x1,x2,y1,y2,z1,z2;
586 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
587 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
589 //------------------------------------------------------------------------
590 void vtkMPR3DDataViewer::SetPositionY(int pos){
591 int x1,x2,y1,y2,z1,z2;
592 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
593 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
595 //------------------------------------------------------------------------
596 void vtkMPR3DDataViewer::SetPositionZ(int pos){
597 int x1,x2,y1,y2,z1,z2;
598 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
599 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
601 //-------------------------------------------------------------------
602 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
604 _visiblePosition[idPosition]=visible;
606 //-------------------------------------------------------------------
607 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
609 return _visiblePosition[idPosition];
611 //-------------------------------------------------------------------
612 //-------------------------------------------------------------------
613 //-------------------------------------------------------------------
616 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
619 for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
620 _visibleTissue[i] = false;
621 _representationType[i] = true;
623 _visibleVolume=false;
625 //-------------------------------------------------------------------
626 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
629 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
630 _mCubes[i] ->Delete();
631 _tissueStripper[i] ->Delete();
632 _tissueMapper[i] ->Delete();
633 _tissuePlanes[i] ->Delete();
634 _tissueClipper[i] ->Delete();
636 _outlineData ->Delete();
637 _mapOutline ->Delete();
642 _compositeFunction ->Delete();
643 _volumeMapper ->Delete();
644 _volumeProperty ->Delete();
646 _volumePlanes ->Delete();
648 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
649 _tissue[i] -> Delete();
650 _observerS[i] -> Delete();
652 _observerV -> Delete();
654 //-------------------------------------------------------------------
655 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
659 //-------------------------------------------------------------------
660 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
662 return this->_tissueClipper[id];
664 //-------------------------------------------------------------------
665 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
667 return _tissueMapper[id];
669 //-------------------------------------------------------------------
670 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
672 return _tissuePlanes[id];
674 //-------------------------------------------------------------------
675 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
677 return _tissueStripper[id];
679 //-------------------------------------------------------------------
680 void vtkClipping3DDataViewer::Refresh()
682 // _volumeMapper->SetClippingPlanes(_volumePlanes);
684 // this->_volumeMapper->Update();
685 // this->_newvol->Update();
687 // _newvol->VisibilityOn();
690 // _volumeMapper = vtkVolumeRayCastMapper::New();
691 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
692 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
693 // _volumeMapper->SetClippingPlanes( _volumePlanes );
694 // _newvol->SetMapper(_volumeMapper );
698 //-------------------------------------------------------------------
699 void vtkClipping3DDataViewer::RefreshSurface()
702 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
704 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
705 // this->GetMCubes(i)->Update();
708 //-------------------------------------------------------------------
709 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
711 _vtkmprbasedata=vtkmprbasedata;
713 //-------------------------------------------------------------------
714 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
716 return _vtkmprbasedata;
720 //-------------------------------------------------------------------
721 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
723 _visibleTissue[idTissue]=visible;
725 //-------------------------------------------------------------------
726 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
727 return _visibleTissue[idTissue];
729 //-------------------------------------------------------------------
730 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
732 _representationType[idTissue]=representationType;
734 //-------------------------------------------------------------------
735 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
737 return _representationType[idTissue];
740 //-------------------------------------------------------------------
741 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
745 //-------------------------------------------------------------------
746 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
748 return _observerS[idObserverS];
750 //-------------------------------------------------------------------
751 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
756 //-------------------------------------------------------------------
757 bool vtkClipping3DDataViewer::GetVisibleVolume()
759 return _visibleVolume;
761 //-------------------------------------------------------------------
762 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
764 _visibleVolume = visiblevolume;
768 //-------------------------------------------------------------------
769 void vtkClipping3DDataViewer::Configure_Tissue()
774 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
775 // Visualisation - original volume
776 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
777 imagedata->GetScalarRange( range );
778 _mCubes[i] = vtkMarchingCubes::New( );
779 _mCubes[i]->SetInput( imagedata );
781 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
782 // _mCubes[i]->SetValue( 0, 1500 );
784 _tissueStripper[i] = vtkStripper::New();
785 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
789 _tissuePlanes[i] = vtkPlanes::New();
791 int x1,x2,y1,y2,z1,z2;
792 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
793 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
795 _tissueClipper[i] = vtkClipPolyData::New();
796 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
797 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
798 _tissueClipper[i]->InsideOutOn( );
800 _tissueMapper[i] = vtkPolyDataMapper::New( );
801 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
802 _tissueMapper[i]->ScalarVisibilityOff( );
803 // _tissueMapper[i]->Update();
810 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
812 _tissue[i] = vtkActor::New();
813 _tissue[i]->SetMapper( GetTissueMapper(i) );
814 float cr=1,cg=0.5,cb=0.5;
815 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
816 _tissue[i]->GetProperty()->SetSpecular(.3);
817 _tissue[i]->GetProperty()->SetSpecularPower(20);
818 _tissue[i]->GetProperty()->SetOpacity(0.5);
819 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
820 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
821 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
822 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
825 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
827 _observerS[i] = boxSurfaceObserver::New();
828 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
829 _observerS[i]->SetActor( _tissue[i] );
834 //-----------------------------------------------------------------------------
836 void vtkClipping3DDataViewer::Configure_Volume()
840 _tfun = vtkPiecewiseFunction::New();
841 _ctfun = vtkColorTransferFunction::New();
844 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
845 double max = range[1];
848 adding the poinst of the transference function
851 greyValuesTransferenceFVector.push_back(max * 0/2);
852 greyValuesTransferenceFVector.push_back(max * 1/2);
853 greyValuesTransferenceFVector.push_back(max * 2/2);
855 intensityValuesTransferenceFVector.push_back(0.0);
856 intensityValuesTransferenceFVector.push_back(1.0);
857 intensityValuesTransferenceFVector.push_back(1.0);
859 _tfun->AddPoint(max * 0/2 , 0.0);
860 _tfun->AddPoint(max * 1/2 , 1.0);
861 _tfun->AddPoint(max * 2/2 , 1.0);
864 Adding the colors to the vectors
867 redColorsOfColorTransferenceFVector.push_back(0.0);
868 redColorsOfColorTransferenceFVector.push_back(1.0);
869 redColorsOfColorTransferenceFVector.push_back(0.0);
870 redColorsOfColorTransferenceFVector.push_back(0.0);
871 redColorsOfColorTransferenceFVector.push_back(0.0);
874 greenColorsOfColorTransferenceFVector.push_back(0.0);
875 greenColorsOfColorTransferenceFVector.push_back(0.0);
876 greenColorsOfColorTransferenceFVector.push_back(0.0);
877 greenColorsOfColorTransferenceFVector.push_back(1.0);
878 greenColorsOfColorTransferenceFVector.push_back(0.2);
881 blueColorsOfColorTransferenceFVector.push_back(0.0);
882 blueColorsOfColorTransferenceFVector.push_back(0.0);
883 blueColorsOfColorTransferenceFVector.push_back(1.0);
884 blueColorsOfColorTransferenceFVector.push_back(0.0);
885 blueColorsOfColorTransferenceFVector.push_back(0.0);
887 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
888 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
889 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
890 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
891 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
893 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
894 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
895 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
896 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
897 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
899 _volumePlanes = vtkPlanes::New();
900 // int x1,x2,y1,y2,z1,z2;
901 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
902 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
903 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
905 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
907 _volumeMapper = vtkVolumeRayCastMapper::New();
908 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
909 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
910 _volumeMapper->SetClippingPlanes( _volumePlanes );
911 _volumeMapper->AutoAdjustSampleDistancesOn();
913 _volumeProperty = vtkVolumeProperty::New();
914 _volumeProperty->SetColor(_ctfun);
915 _volumeProperty->SetScalarOpacity( _tfun );
917 _volumeProperty->SetInterpolationTypeToLinear();
918 _volumeProperty->ShadeOn();
919 _volumeProperty->DisableGradientOpacityOn();
921 // _volumeProperty->SetInterpolationTypeToNearest();
922 // _volumeProperty->ShadeOff();
923 // _volumeProperty->SetAmbient(0.3);
924 // _volumeProperty->SetDiffuse(0.1);
925 // _volumeProperty->SetSpecular(0.8);
926 // _volumeProperty->DisableGradientOpacityOn();
928 _newvol = vtkVolume::New();
929 _newvol->SetMapper(_volumeMapper );
930 _newvol->SetProperty(_volumeProperty );
932 _observerV = boxSurfaceObserver::New();
933 _observerV->SetPlanes( _volumePlanes );
934 _observerV->SetActor( _newvol );
935 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
939 //-------------------------------------------------------------------
940 void vtkClipping3DDataViewer::Configure()
945 // An outline provides context around the data.
947 _outlineData = vtkOutlineFilter::New();
948 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
949 _mapOutline = vtkPolyDataMapper::New();
950 _mapOutline->SetInput(_outlineData->GetOutput());
951 _outline = vtkActor::New();
952 _outline->SetMapper(_mapOutline);
953 _outline->GetProperty()->SetColor(0,0,0);
957 //-------------------------------------------------------------------
958 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
960 _mCubes[idTissue]->SetValue(0, isoValue);
962 //-------------------------------------------------------------------
963 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
965 return _mCubes[idTissue]->GetValue(0);
967 //-------------------------------------------------------------------
968 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
972 //-------------------------------------------------------------------
973 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
974 return _volumeMapper;
976 //-------------------------------------------------------------------
977 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
979 return _volumePlanes;
982 //-------------------------------------------------------------------
983 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
985 return _mCubes[idTissue];
987 //--------------------------------------------------------------------
988 //-------------------
990 //-------------------
992 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
994 return &greyValuesTransferenceFVector;
996 //--------------------------------------------------------------------
997 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
999 return &intensityValuesTransferenceFVector;
1001 //--------------------------------------------------------------------
1002 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
1004 return &redColorsOfColorTransferenceFVector;
1006 //--------------------------------------------------------------------
1007 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
1009 return &greenColorsOfColorTransferenceFVector;
1011 //--------------------------------------------------------------------
1012 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
1014 return &blueColorsOfColorTransferenceFVector;
1016 //--------------------------------------------------------------------
1017 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
1019 return &greyValueColorsOfColorTransferenceFVector;
1021 //--------------------------------------------------------------------
1022 //--------------------------------------
1023 //Getters transference function
1024 //and color of the transference function
1025 //---------------------------------------
1026 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
1030 //--------------------------------------------------------------------
1031 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
1033 return this->_ctfun;
1036 //-------------------------------------------------------------------
1038 void vtkClipping3DDataViewer::ReadVolumeFunctions()
1041 int i=0,xi,yi,r,g,b,gValue;
1042 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
1044 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
1048 int tfSize=this->greyValuesTransferenceFVector.size();
1052 hDlg->erasePointsTransferenceFunction();
1055 double g=greyValuesTransferenceFVector[i];
1056 double in=intensityValuesTransferenceFVector[i];
1057 hDlg->addPointToTransferenceFunction(g,in*100);
1063 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
1069 double gr=greyValueColorsOfColorTransferenceFVector[i];
1070 double r=redColorsOfColorTransferenceFVector[i];
1071 double g=greenColorsOfColorTransferenceFVector[i];
1072 double b=blueColorsOfColorTransferenceFVector[i];
1073 hDlg->addColorPoint(gr,r*255,g*255,b*255);
1077 //If it is smooth activate next line
1078 //hDlg->updatePlotter();
1079 //setting variables if the user wants to do refresh
1080 hDlg->setCTF(_ctfun);
1084 // when the user had changed the transference Function
1086 if(hDlg->ShowModal()== wxID_OK )
1088 // -- vtkPiecewiseFunction --
1089 this->_tfun->RemoveAllPoints();
1090 greyValuesTransferenceFVector.clear();
1091 intensityValuesTransferenceFVector.clear();
1093 int nTFPoints=hDlg->getSizeTransferenceFunction();
1097 hDlg->getTransferenceFunctionPoint(i,xi,yi);
1098 this->_tfun->AddPoint( xi , yi/100.0 );
1099 greyValuesTransferenceFVector.push_back(xi);
1100 intensityValuesTransferenceFVector.push_back(yi/100.0);
1103 // -- vtkColorTransferFunction --
1104 this->_ctfun->RemoveAllPoints ();
1106 redColorsOfColorTransferenceFVector.clear();
1107 greenColorsOfColorTransferenceFVector.clear();
1108 blueColorsOfColorTransferenceFVector.clear();
1109 greyValueColorsOfColorTransferenceFVector.clear();
1111 int nCTFpoints=hDlg->getSizeBarColor();
1115 hDlg->getDataBarColorPoint(i,xi,r,g,b);
1116 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
1117 redColorsOfColorTransferenceFVector.push_back(r/255.0);
1118 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
1119 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
1120 greyValueColorsOfColorTransferenceFVector.push_back(xi);
1124 this->_volumeMapper->Update();
1125 this->_newvol->Update();
1131 if(hDlg->getRefreshed())
1134 //--Transference Function----
1135 this->_tfun->RemoveAllPoints();
1137 size=greyValuesTransferenceFVector.size();
1140 double grey1=greyValuesTransferenceFVector[i];
1141 double in2=intensityValuesTransferenceFVector[i];
1142 this->_tfun->AddPoint( grey1 , in2 );
1145 // -- vtkColorTransferFunction --
1146 _ctfun->RemoveAllPoints ();
1149 size=greyValueColorsOfColorTransferenceFVector.size();
1152 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
1153 double red =(redColorsOfColorTransferenceFVector)[i];
1154 double green =(greenColorsOfColorTransferenceFVector)[i];
1155 double blue = (blueColorsOfColorTransferenceFVector)[i];
1156 _ctfun->AddRGBPoint(grey2,red,green,blue);
1158 this->_volumeMapper->Update();
1159 this->_newvol->Update();
1167 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
1174 FILE *ff = fopen ( namefile ,"r");
1177 fscanf(ff,"%s",tmp);
1178 if (strcmp(tmp,"MAX")==0)
1180 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
1181 vtkimagedata->GetScalarRange(range);
1182 max = (int) (range[1]);
1187 fscanf(ff,"%s",tmp); // --
1189 // -- vtkPiecewiseFunction --
1190 this->_tfun->RemoveAllPoints();
1191 fscanf(ff,"%s",tmp);
1192 while ( strcmp(tmp,"--")!=0 )
1195 fscanf(ff,"%s",tmp);
1197 this->_tfun->AddPoint( x*max , val );
1198 fscanf(ff,"%s",tmp);
1201 this->_ctfun->RemoveAllPoints ();
1202 // -- vtkColorTransferFunction --
1205 fscanf(ff,"%s",tmp);
1207 fscanf(ff,"%s",tmp);
1209 fscanf(ff,"%s",tmp);
1211 fscanf(ff,"%s",tmp);
1213 this->_ctfun->AddRGBPoint( x*max , r,g,b );
1217 this->_volumeMapper->Update();
1218 this->_newvol->Update();
1225 //-------------------------------------------------------------------
1227 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
1229 vtkDataSetReader *reader = vtkDataSetReader::New();
1230 reader->SetFileName(namefile);
1232 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );