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 _marImageData->GetImageData()->GetWholeExtent(ext);
81 //-------------------------------------------------------------------
82 double vtkBaseData::GetZ()
86 //-------------------------------------------------------------------
87 int vtkBaseData::GetT()
91 //-------------------------------------------------------------------
92 void vtkBaseData::SetT(double t)
94 int maxT = _marImageData->GetMaxT();
106 //-------------------------------------------------------------------
107 //-------------------------------------------------------------------
108 //-------------------------------------------------------------------
109 vtkMPRBaseData::vtkMPRBaseData()
114 _transformOrientation = NULL;
116 //-------------------------------------------------------------------
117 vtkMPRBaseData::~vtkMPRBaseData()
119 if (_marImageData) delete _marImageData;
120 if (_transformOrientation) _transformOrientation ->Delete();
122 //-------------------------------------------------------------------
123 void vtkMPRBaseData::Configure()
125 _marImageData->GetImageData()->GetExtent (_x1,_x2,_y1,_y2,_z1,_z2);
126 _transformOrientation=vtkTransform::New();
127 _transformOrientation->Identity();
129 //-------------------------------------------------------------------
130 void vtkMPRBaseData::GetDimensionExtention(int *x1,int *x2,int *y1,int *y2,int *z1,int *z2)
141 //------------------------------------------------------------------------
142 int vtkMPRBaseData::GetMaxPositionX( )
146 //------------------------------------------------------------------------
147 int vtkMPRBaseData::GetMaxPositionY( )
151 //------------------------------------------------------------------------
152 int vtkMPRBaseData::GetMaxPositionZ( )
156 //-------------------------------------------------------------------
157 double vtkMPRBaseData::GetX()
161 //-------------------------------------------------------------------
162 double vtkMPRBaseData::GetY()
166 //-------------------------------------------------------------------
167 void vtkMPRBaseData::SetX(double x)
170 _marImageData->GetImageData()->GetDimensions(dim);
181 //-------------------------------------------------------------------
182 void vtkMPRBaseData::SetY(double y)
185 _marImageData->GetImageData()->GetDimensions(dim);
196 //-------------------------------------------------------------------
197 vtkTransform *vtkMPRBaseData::GetTransformOrientation()
199 return _transformOrientation;
201 //-------------------------------------------------------------------
202 void vtkMPRBaseData::SetNormal(double nx, double ny, double nz)
204 double alfa = atan2(ny,nx) * 180.0 / 3.1416;
205 double beta = atan2( nz, sqrt( nx*nx + ny*ny ) ) * 180.0 / 3.1416;
206 _transformOrientation->Identity();
207 _transformOrientation->RotateWXYZ(alfa,0,0,1);
208 _transformOrientation->RotateWXYZ(-beta,0,1,0);
210 //-------------------------------------------------------------------
211 void vtkMPRBaseData::InitTransformOrientation(vtkTransform *trans)
213 _transformOrientation->SetMatrix( trans->GetMatrix() );
218 //-------------------------------------------------------------------
219 //-------------------------------------------------------------------
220 //-------------------------------------------------------------------
223 vtkMPR3DDataViewer::vtkMPR3DDataViewer()
225 _visiblePosition[0]=false;
226 _visiblePosition[1]=false;
227 _visiblePosition[2]=false;
230 //-------------------------------------------------------------------
231 vtkMPR3DDataViewer::~vtkMPR3DDataViewer()
233 _outlineData -> Delete();
234 _mapOutline -> Delete();
235 _outline -> Delete();
237 // if (_bwLut) _bwLut -> Delete();
238 // if (_hueLut) _hueLut -> Delete();
239 // if (_satLut) _satLut -> Delete();
240 if (_ctfun) _ctfun -> Delete();
241 if (_saggitalColors) _saggitalColors -> Delete();
242 if (_saggital) _saggital -> Delete();
243 if (_axialColors) _axialColors -> Delete();
244 if (_axial) _axial -> Delete();
245 if (_coronalColors) _coronalColors -> Delete();
246 if (_coronal) _coronal -> Delete();
249 //-------------------------------------------------------------------
250 vtkActor* vtkMPR3DDataViewer::GetOutlineActor()
254 //-------------------------------------------------------------------
255 vtkImageActor* vtkMPR3DDataViewer::GetImageActor(int id)
257 vtkImageActor *tmpVtkActor=NULL;
259 tmpVtkActor = GetvtkActor_saggital();
262 tmpVtkActor = GetvtkActor_coronal();
265 tmpVtkActor = GetvtkActor_axial();
269 //-------------------------------------------------------------------
270 void vtkMPR3DDataViewer::Refresh()
272 int x = (int)(_vtkmprbasedata->GetX());
273 int y = (int)(_vtkmprbasedata->GetY());
274 int z = (int)(_vtkmprbasedata->GetZ());
280 //-------------------------------------------------------------------
281 void vtkMPR3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
283 _vtkmprbasedata=vtkmprbasedata;
285 //-------------------------------------------------------------------
286 vtkMPRBaseData* vtkMPR3DDataViewer::GetVtkMPRBaseData()
288 return _vtkmprbasedata;
290 //-------------------------------------------------------------------
292 vtkColorTransferFunction *vtkMPR3DDataViewer::GetvtkColorTransferFunction()
296 //-------------------------------------------------------------------
298 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorPoint()
300 return &_ctFunVectorPoint;
302 //-------------------------------------------------------------------
303 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorRed()
305 return &_ctFunVectorRed;
308 //-------------------------------------------------------------------
309 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorGreen()
311 return &_ctFunVectorGreen;
314 //-------------------------------------------------------------------
315 std::vector<double>* vtkMPR3DDataViewer::GetctFunVectorBlue()
317 return &_ctFunVectorBlue;
320 //-------------------------------------------------------------------
321 void vtkMPR3DDataViewer::Configure()
324 // Start by creatin a black/white lookup table.
325 _bwLut = vtkLookupTable::New();
326 _bwLut->SetTableRange (0, 2000);
327 _bwLut->SetSaturationRange (0, 0);
328 _bwLut->SetHueRange (0, 0);
329 _bwLut->SetValueRange (0, 1);
331 // Now create a lookup table that consists of the full hue circle
333 _hueLut = vtkLookupTable::New();
334 _hueLut->SetTableRange (0, 2000);
335 _hueLut->SetHueRange (0, 1);
336 _hueLut->SetSaturationRange (1, 1);
337 _hueLut->SetValueRange (1, 1);
339 // Finally, create a lookup table with a single hue but having a range
340 // in the saturation of the hue.
341 _satLut = vtkLookupTable::New();
342 _satLut->SetTableRange (0, 2000);
343 _satLut->SetHueRange (.6, .6);
344 _satLut->SetSaturationRange (0, 1);
345 _satLut->SetValueRange (1, 1);
350 _vtkmprbasedata->GetImageData()->GetScalarRange(range);
351 double max = range[1];
354 _ctFunVectorPoint.push_back(max*0/4);
355 _ctFunVectorPoint.push_back(max*1/4);
356 _ctFunVectorPoint.push_back(max*2/4);
357 _ctFunVectorPoint.push_back(max*3/4);
358 _ctFunVectorPoint.push_back(max*4/4);
360 _ctFunVectorRed.push_back(0.0);
361 _ctFunVectorRed.push_back(1.0);
362 _ctFunVectorRed.push_back(0.0);
363 _ctFunVectorRed.push_back(0.0);
364 _ctFunVectorRed.push_back(0.0);
366 _ctFunVectorGreen.push_back(0.0);
367 _ctFunVectorGreen.push_back(0.0);
368 _ctFunVectorGreen.push_back(0.0);
369 _ctFunVectorGreen.push_back(1.0);
370 _ctFunVectorGreen.push_back(0.2);
372 _ctFunVectorBlue.push_back(0.0);
373 _ctFunVectorBlue.push_back(0.0);
374 _ctFunVectorBlue.push_back(1.0);
375 _ctFunVectorBlue.push_back(0.0);
376 _ctFunVectorBlue.push_back(0.0);
379 _ctfun = vtkColorTransferFunction::New();
381 int i,size=_ctFunVectorPoint.size();
384 _ctfun->AddRGBPoint( _ctFunVectorPoint[i] , _ctFunVectorRed[i],_ctFunVectorGreen[i],_ctFunVectorBlue[i]);
388 _ctfun->AddRGBPoint( 100 ,0 ,0,0);
389 _ctfun->AddRGBPoint( 200 ,1 ,0,0);
390 _ctfun->AddRGBPoint( 300 ,0 ,1,0);
391 _ctfun->AddRGBPoint( 400 ,0 ,0,1);
393 // void *p=this; // JPRx
395 // Create the first of the three planes. The filter vtkImageMapToColors
396 // maps the data through the corresponding lookup table created above. The
397 // vtkImageActor is a type of vtkProp and conveniently displays an image on
398 // a single quadrilateral plane. It does this using texture mapping and as
399 // a result is quite fast. (Note: the input image has to be unsigned char
400 // values, which the vtkImageMapToColors produces.) Note also that by
401 // specifying the DisplayExtent, the pipeline requests data of this extent
402 // and the vtkImageMapToColors only processes a slice of data.
403 _saggitalColors = vtkImageMapToColors::New();
404 _saggitalColors->SetInput( _vtkmprbasedata->GetImageData() );
405 // _saggitalColors->SetLookupTable(_bwLut);
406 _saggitalColors->SetLookupTable(_ctfun);
407 _saggital = vtkImageActor::New();
408 _saggital->SetInput(_saggitalColors->GetOutput());
411 // Create the second (axial) plane of the three planes. We use the
412 // same approach as before except that the extent differs.
413 _axialColors = vtkImageMapToColors::New();
414 _axialColors->SetInput( _vtkmprbasedata->GetImageData() );
415 // _axialColors->SetLookupTable(_hueLut);
416 _axialColors->SetLookupTable(_ctfun);
417 _axial = vtkImageActor::New();
418 _axial->SetInput(_axialColors->GetOutput());
420 // Create the third (coronal) plane of the three planes. We use
421 // the same approach as before except that the extent differs.
422 _coronalColors = vtkImageMapToColors::New();
423 _coronalColors->SetInput( _vtkmprbasedata->GetImageData() );
424 // _coronalColors->SetLookupTable(_satLut);
425 _coronalColors->SetLookupTable(_ctfun);
426 _coronal = vtkImageActor::New();
427 _coronal->SetInput(_coronalColors->GetOutput());
429 // An outline provides context around the data.
431 _outlineData = vtkOutlineFilter::New();
432 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
433 _mapOutline = vtkPolyDataMapper::New();
434 _mapOutline->SetInput(_outlineData->GetOutput());
435 _outline = vtkActor::New();
436 _outline->SetMapper(_mapOutline);
437 _outline->GetProperty()->SetColor(0,0,0);
440 _vtkmprbasedata->GetImageData()->GetExtent(ext);
446 //-------------------------------------------------------------------
447 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_saggital()
451 //-------------------------------------------------------------------
452 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_coronal()
456 //-------------------------------------------------------------------
457 vtkImageActor * vtkMPR3DDataViewer::GetvtkActor_axial()
462 //------------------------------------------------------------------------
463 void vtkMPR3DDataViewer::SetPositionX(int pos){
464 int x1,x2,y1,y2,z1,z2;
465 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
466 _saggital->SetDisplayExtent( pos , pos , y1 ,y2 , z1 , z2 );
468 //------------------------------------------------------------------------
469 void vtkMPR3DDataViewer::SetPositionY(int pos){
470 int x1,x2,y1,y2,z1,z2;
471 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
472 _coronal->SetDisplayExtent(x1,x2, pos,pos, z1,z2);
474 //------------------------------------------------------------------------
475 void vtkMPR3DDataViewer::SetPositionZ(int pos){
476 int x1,x2,y1,y2,z1,z2;
477 _vtkmprbasedata->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
478 _axial->SetDisplayExtent(x1,x2, y1,y2, pos,pos);
480 //-------------------------------------------------------------------
481 void vtkMPR3DDataViewer::SetVisiblePosition(int idPosition, bool visible)
483 _visiblePosition[idPosition]=visible;
485 //-------------------------------------------------------------------
486 bool vtkMPR3DDataViewer::GetVisiblePosition(int idPosition)
488 return _visiblePosition[idPosition];
490 //-------------------------------------------------------------------
491 //-------------------------------------------------------------------
492 //-------------------------------------------------------------------
495 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
498 for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
499 _visibleTissue[i] = false;
500 _representationType[i] = true;
502 _visibleVolume=false;
504 //-------------------------------------------------------------------
505 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
508 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
509 _mCubes[i] ->Delete();
510 _tissueStripper[i] ->Delete();
511 _tissueMapper[i] ->Delete();
512 _tissuePlanes[i] ->Delete();
513 _tissueClipper[i] ->Delete();
515 _outlineData ->Delete();
516 _mapOutline ->Delete();
521 _compositeFunction ->Delete();
522 _volumeMapper ->Delete();
523 _volumeProperty ->Delete();
525 _volumePlanes ->Delete();
527 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
528 _tissue[i] -> Delete();
529 _observerS[i] -> Delete();
531 _observerV -> Delete();
533 //-------------------------------------------------------------------
534 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
538 //-------------------------------------------------------------------
539 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
541 return this->_tissueClipper[id];
543 //-------------------------------------------------------------------
544 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
546 return _tissueMapper[id];
548 //-------------------------------------------------------------------
549 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
551 return _tissuePlanes[id];
553 //-------------------------------------------------------------------
554 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
556 return _tissueStripper[id];
558 //-------------------------------------------------------------------
559 void vtkClipping3DDataViewer::Refresh()
561 // _volumeMapper->SetClippingPlanes(_volumePlanes);
563 // this->_volumeMapper->Update();
564 // this->_newvol->Update();
566 // _newvol->VisibilityOn();
569 // _volumeMapper = vtkVolumeRayCastMapper::New();
570 // _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
571 // _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
572 // _volumeMapper->SetClippingPlanes( _volumePlanes );
573 // _newvol->SetMapper(_volumeMapper );
577 //-------------------------------------------------------------------
578 void vtkClipping3DDataViewer::RefreshSurface()
581 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
583 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
584 // this->GetMCubes(i)->Update();
587 //-------------------------------------------------------------------
588 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
590 _vtkmprbasedata=vtkmprbasedata;
592 //-------------------------------------------------------------------
593 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
595 return _vtkmprbasedata;
599 //-------------------------------------------------------------------
600 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
602 _visibleTissue[idTissue]=visible;
604 //-------------------------------------------------------------------
605 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
606 return _visibleTissue[idTissue];
608 //-------------------------------------------------------------------
609 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
611 _representationType[idTissue]=representationType;
613 //-------------------------------------------------------------------
614 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
616 return _representationType[idTissue];
619 //-------------------------------------------------------------------
620 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
624 //-------------------------------------------------------------------
625 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
627 return _observerS[idObserverS];
629 //-------------------------------------------------------------------
630 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
635 //-------------------------------------------------------------------
636 bool vtkClipping3DDataViewer::GetVisibleVolume()
638 return _visibleVolume;
640 //-------------------------------------------------------------------
641 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
643 _visibleVolume = visiblevolume;
647 //-------------------------------------------------------------------
648 void vtkClipping3DDataViewer::Configure_Tissue()
653 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
654 // Visualisation - original volume
655 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
656 imagedata->GetScalarRange( range );
657 _mCubes[i] = vtkMarchingCubes::New( );
658 _mCubes[i]->SetInput( imagedata );
660 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
661 // _mCubes[i]->SetValue( 0, 1500 );
663 _tissueStripper[i] = vtkStripper::New();
664 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
668 _tissuePlanes[i] = vtkPlanes::New();
670 int x1,x2,y1,y2,z1,z2;
671 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
672 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
674 _tissueClipper[i] = vtkClipPolyData::New();
675 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
676 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
677 _tissueClipper[i]->InsideOutOn( );
679 _tissueMapper[i] = vtkPolyDataMapper::New( );
680 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
681 _tissueMapper[i]->ScalarVisibilityOff( );
682 // _tissueMapper[i]->Update();
689 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
691 _tissue[i] = vtkActor::New();
692 _tissue[i]->SetMapper( GetTissueMapper(i) );
693 float cr=1,cg=0.5,cb=0.5;
694 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
695 _tissue[i]->GetProperty()->SetSpecular(.3);
696 _tissue[i]->GetProperty()->SetSpecularPower(20);
697 _tissue[i]->GetProperty()->SetOpacity(0.5);
698 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
699 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
700 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
701 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
704 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
706 _observerS[i] = boxSurfaceObserver::New();
707 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
708 _observerS[i]->SetActor( _tissue[i] );
713 //-----------------------------------------------------------------------------
715 void vtkClipping3DDataViewer::Configure_Volume()
719 _tfun = vtkPiecewiseFunction::New();
720 _ctfun = vtkColorTransferFunction::New();
723 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
724 double max = range[1];
727 adding the poinst of the transference function
730 greyValuesTransferenceFVector.push_back(max * 0/2);
731 greyValuesTransferenceFVector.push_back(max * 1/2);
732 greyValuesTransferenceFVector.push_back(max * 2/2);
734 intensityValuesTransferenceFVector.push_back(0.0);
735 intensityValuesTransferenceFVector.push_back(1.0);
736 intensityValuesTransferenceFVector.push_back(1.0);
738 _tfun->AddPoint(max * 0/2 , 0.0);
739 _tfun->AddPoint(max * 1/2 , 1.0);
740 _tfun->AddPoint(max * 2/2 , 1.0);
743 Adding the colors to the vectors
746 redColorsOfColorTransferenceFVector.push_back(0.0);
747 redColorsOfColorTransferenceFVector.push_back(1.0);
748 redColorsOfColorTransferenceFVector.push_back(0.0);
749 redColorsOfColorTransferenceFVector.push_back(0.0);
750 redColorsOfColorTransferenceFVector.push_back(0.0);
753 greenColorsOfColorTransferenceFVector.push_back(0.0);
754 greenColorsOfColorTransferenceFVector.push_back(0.0);
755 greenColorsOfColorTransferenceFVector.push_back(0.0);
756 greenColorsOfColorTransferenceFVector.push_back(1.0);
757 greenColorsOfColorTransferenceFVector.push_back(0.2);
760 blueColorsOfColorTransferenceFVector.push_back(0.0);
761 blueColorsOfColorTransferenceFVector.push_back(0.0);
762 blueColorsOfColorTransferenceFVector.push_back(1.0);
763 blueColorsOfColorTransferenceFVector.push_back(0.0);
764 blueColorsOfColorTransferenceFVector.push_back(0.0);
766 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
767 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
768 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
769 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
770 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
772 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
773 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
774 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
775 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
776 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
778 _volumePlanes = vtkPlanes::New();
779 // int x1,x2,y1,y2,z1,z2;
780 // vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
781 // imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
782 // _volumePlanes->SetBounds(x1,x2,y1,y2,z1,z2);
784 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
786 _volumeMapper = vtkVolumeRayCastMapper::New();
787 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
788 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
789 _volumeMapper->SetClippingPlanes( _volumePlanes );
790 _volumeMapper->AutoAdjustSampleDistancesOn();
792 _volumeProperty = vtkVolumeProperty::New();
793 _volumeProperty->SetColor(_ctfun);
794 _volumeProperty->SetScalarOpacity( _tfun );
796 _volumeProperty->SetInterpolationTypeToLinear();
797 _volumeProperty->ShadeOn();
798 _volumeProperty->DisableGradientOpacityOn();
800 // _volumeProperty->SetInterpolationTypeToNearest();
801 // _volumeProperty->ShadeOff();
802 // _volumeProperty->SetAmbient(0.3);
803 // _volumeProperty->SetDiffuse(0.1);
804 // _volumeProperty->SetSpecular(0.8);
805 // _volumeProperty->DisableGradientOpacityOn();
807 _newvol = vtkVolume::New();
808 _newvol->SetMapper(_volumeMapper );
809 _newvol->SetProperty(_volumeProperty );
811 _observerV = boxSurfaceObserver::New();
812 _observerV->SetPlanes( _volumePlanes );
813 _observerV->SetActor( _newvol );
814 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
818 //-------------------------------------------------------------------
819 void vtkClipping3DDataViewer::Configure()
824 // An outline provides context around the data.
826 _outlineData = vtkOutlineFilter::New();
827 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
828 _mapOutline = vtkPolyDataMapper::New();
829 _mapOutline->SetInput(_outlineData->GetOutput());
830 _outline = vtkActor::New();
831 _outline->SetMapper(_mapOutline);
832 _outline->GetProperty()->SetColor(0,0,0);
836 //-------------------------------------------------------------------
837 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
839 _mCubes[idTissue]->SetValue(0, isoValue);
841 //-------------------------------------------------------------------
842 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
844 return _mCubes[idTissue]->GetValue(0);
846 //-------------------------------------------------------------------
847 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
851 //-------------------------------------------------------------------
852 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
853 return _volumeMapper;
855 //-------------------------------------------------------------------
856 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
858 return _volumePlanes;
861 //-------------------------------------------------------------------
862 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
864 return _mCubes[idTissue];
866 //--------------------------------------------------------------------
867 //-------------------
869 //-------------------
871 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
873 return &greyValuesTransferenceFVector;
875 //--------------------------------------------------------------------
876 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
878 return &intensityValuesTransferenceFVector;
880 //--------------------------------------------------------------------
881 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
883 return &redColorsOfColorTransferenceFVector;
885 //--------------------------------------------------------------------
886 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
888 return &greenColorsOfColorTransferenceFVector;
890 //--------------------------------------------------------------------
891 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
893 return &blueColorsOfColorTransferenceFVector;
895 //--------------------------------------------------------------------
896 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
898 return &greyValueColorsOfColorTransferenceFVector;
900 //--------------------------------------------------------------------
901 //--------------------------------------
902 //Getters transference function
903 //and color of the transference function
904 //---------------------------------------
905 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
909 //--------------------------------------------------------------------
910 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
915 //-------------------------------------------------------------------
917 void vtkClipping3DDataViewer::ReadVolumeFunctions()
920 int i=0,xi,yi,r,g,b,gValue;
921 vtkImageData *imagedata = this->_vtkmprbasedata->GetImageData();
923 HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata);
927 int tfSize=this->greyValuesTransferenceFVector.size();
931 hDlg->erasePointsTransferenceFunction();
934 double g=greyValuesTransferenceFVector[i];
935 double in=intensityValuesTransferenceFVector[i];
936 hDlg->addPointToTransferenceFunction(g,in*100);
942 int ctfSize=this->redColorsOfColorTransferenceFVector.size();
948 double gr=greyValueColorsOfColorTransferenceFVector[i];
949 double r=redColorsOfColorTransferenceFVector[i];
950 double g=greenColorsOfColorTransferenceFVector[i];
951 double b=blueColorsOfColorTransferenceFVector[i];
952 hDlg->addColorPoint(gr,r*255,g*255,b*255);
956 //If it is smooth activate next line
957 //hDlg->updatePlotter();
958 //setting variables if the user wants to do refresh
959 hDlg->setCTF(_ctfun);
963 // when the user had changed the transference Function
965 if(hDlg->ShowModal()== wxID_OK )
967 // -- vtkPiecewiseFunction --
968 this->_tfun->RemoveAllPoints();
969 greyValuesTransferenceFVector.clear();
970 intensityValuesTransferenceFVector.clear();
972 int nTFPoints=hDlg->getSizeTransferenceFunction();
976 hDlg->getTransferenceFunctionPoint(i,xi,yi);
977 this->_tfun->AddPoint( xi , yi/100.0 );
978 greyValuesTransferenceFVector.push_back(xi);
979 intensityValuesTransferenceFVector.push_back(yi/100.0);
982 // -- vtkColorTransferFunction --
983 this->_ctfun->RemoveAllPoints ();
985 redColorsOfColorTransferenceFVector.clear();
986 greenColorsOfColorTransferenceFVector.clear();
987 blueColorsOfColorTransferenceFVector.clear();
988 greyValueColorsOfColorTransferenceFVector.clear();
990 int nCTFpoints=hDlg->getSizeBarColor();
994 hDlg->getDataBarColorPoint(i,xi,r,g,b);
995 this->_ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
996 redColorsOfColorTransferenceFVector.push_back(r/255.0);
997 greenColorsOfColorTransferenceFVector.push_back(g/255.0);
998 blueColorsOfColorTransferenceFVector.push_back(b/255.0);
999 greyValueColorsOfColorTransferenceFVector.push_back(xi);
1003 this->_volumeMapper->Update();
1004 this->_newvol->Update();
1010 if(hDlg->getRefreshed())
1013 //--Transference Function----
1014 this->_tfun->RemoveAllPoints();
1016 size=greyValuesTransferenceFVector.size();
1019 double grey1=greyValuesTransferenceFVector[i];
1020 double in2=intensityValuesTransferenceFVector[i];
1021 this->_tfun->AddPoint( grey1 , in2 );
1024 // -- vtkColorTransferFunction --
1025 _ctfun->RemoveAllPoints ();
1028 size=greyValueColorsOfColorTransferenceFVector.size();
1031 double grey2=(greyValueColorsOfColorTransferenceFVector)[i];
1032 double red =(redColorsOfColorTransferenceFVector)[i];
1033 double green =(greenColorsOfColorTransferenceFVector)[i];
1034 double blue = (blueColorsOfColorTransferenceFVector)[i];
1035 _ctfun->AddRGBPoint(grey2,red,green,blue);
1037 this->_volumeMapper->Update();
1038 this->_newvol->Update();
1046 void vtkClipping3DDataViewer::ReadVolumeFunctions(char *namefile)
1053 FILE *ff = fopen ( namefile ,"r");
1056 fscanf(ff,"%s",tmp);
1057 if (strcmp(tmp,"MAX")==0)
1059 vtkImageData *vtkimagedata = this->_vtkmprbasedata->GetImageData();
1060 vtkimagedata->GetScalarRange(range);
1061 max = (int) (range[1]);
1066 fscanf(ff,"%s",tmp); // --
1068 // -- vtkPiecewiseFunction --
1069 this->_tfun->RemoveAllPoints();
1070 fscanf(ff,"%s",tmp);
1071 while ( strcmp(tmp,"--")!=0 )
1074 fscanf(ff,"%s",tmp);
1076 this->_tfun->AddPoint( x*max , val );
1077 fscanf(ff,"%s",tmp);
1080 this->_ctfun->RemoveAllPoints ();
1081 // -- vtkColorTransferFunction --
1084 fscanf(ff,"%s",tmp);
1086 fscanf(ff,"%s",tmp);
1088 fscanf(ff,"%s",tmp);
1090 fscanf(ff,"%s",tmp);
1092 this->_ctfun->AddRGBPoint( x*max , r,g,b );
1096 this->_volumeMapper->Update();
1097 this->_newvol->Update();
1104 //-------------------------------------------------------------------
1106 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
1108 vtkDataSetReader *reader = vtkDataSetReader::New();
1109 reader->SetFileName(namefile);
1111 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );