X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FKernel%2FVTKObjects%2FVolumeRenderer%2Fvolumerenderermanagerdata.cxx;h=3e6ad74dda2afae136efb66e602c061bfdbf8297;hb=8aa8568d0fa7b4e2c8f92372de3859a03c4072d0;hp=f267e3f983aee2bc401bbeced394ff32623cadcb;hpb=afeeee6e8ef4a7b29e33db89bf6fc03542201ed1;p=creaMaracasVisu.git diff --git a/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx b/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx index f267e3f..3e6ad74 100644 --- a/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx +++ b/lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx @@ -9,9 +9,20 @@ #include "boxSurfaceObserver.h" #include "vtkProperty.h" +#include + +#if VTK_MAJOR_VERSION >= 5 + #if VTK_MINOR_VERSION >= 6 + #include "vtkGPUVolumeRayCastMapper.h" + #endif +#endif using namespace std; +VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu){ + Initialize(vol, "", usegpu); +} + VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){ Initialize(vol, dataname); @@ -26,35 +37,30 @@ VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRende } -VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu, std::string dataname){ - Initialize(vol, dataname, usegpu); -} - void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu){ + _id = 0; _vol = vol; _dataname = dataname; - _tfun = vtkPiecewiseFunction::New(); - _ctfun = vtkColorTransferFunction::New(); _volumePlanes = vtkPlanes::New(); _volumeProperty = vtkVolumeProperty::New(); _volumeProperty->SetInterpolationTypeToLinear(); //_volumeProperty->ShadeOn(); - _volumeProperty->DisableGradientOpacityOn(); - _volumeProperty->SetColor(_ctfun); + _volumeProperty->DisableGradientOpacityOn(); + _tfun = vtkPiecewiseFunction::New(); _volumeProperty->SetScalarOpacity(_tfun ); - + _ctfun = vtkColorTransferFunction::New(); _newvol = vtkVolume::New(); - _newvol->SetProperty(_volumeProperty ); + _newvol->SetProperty(_volumeProperty ); + - _volumeMapper = 0; - _volumeMappergpu = 0; _compositeFunction = 0; _MIPFunction = 0; - _boxWidgetS1 = 0; + + BoxWidget = 0; /* EED9Juin2011 if(usegpu && _vol->GetDataDimension() > 2){ @@ -82,33 +88,31 @@ void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string datana } */ - vtkVolumeMapper *volMapperTmp; - if(usegpu && _vol->GetDataDimension() > 2){ - #if (VTK_MAYOR_VERSION>=5 && VTK_MINOR_VERSION>=6) - _volumeMappergpu = vtkGPUVolumeRayCastMapper::New(); - _volumeMappergpu->AutoAdjustSampleDistancesOn(); - volMapperTmp = _volumeMappergpu; - #else - _compositeFunction = vtkVolumeRayCastCompositeFunction::New(); - _MIPFunction = vtkVolumeRayCastMIPFunction::New(); - _volumeMapper = vtkVolumeRayCastMapper::New(); - _volumeMapper->SetVolumeRayCastFunction(_compositeFunction); - _volumeMapper->AutoAdjustSampleDistancesOn(); - volMapperTmp = _volumeMapper; - #endif - }else{ - _compositeFunction = vtkVolumeRayCastCompositeFunction::New(); - _MIPFunction = vtkVolumeRayCastMIPFunction::New(); - _volumeMapper = vtkVolumeRayCastMapper::New(); - _volumeMapper->SetVolumeRayCastFunction(_compositeFunction); - _volumeMapper->AutoAdjustSampleDistancesOn(); - volMapperTmp = _volumeMapper; - } + VolumeMapper = 0; +#if VTK_MAJOR_VERSION >= 5 + #if VTK_MINOR_VERSION >= 6 + vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New(); + volumeMappergpu->AutoAdjustSampleDistancesOn(); + VolumeMapper = volumeMappergpu; + #endif +#else + + _volumeProperty->SetColor(_ctfun); + + + _compositeFunction = vtkVolumeRayCastCompositeFunction::New(); + _MIPFunction = vtkVolumeRayCastMIPFunction::New(); + vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New(); + volumeMapper->SetVolumeRayCastFunction(_compositeFunction); + volumeMapper->AutoAdjustSampleDistancesOn(); + VolumeMapper = volumeMapper; +#endif - volMapperTmp->SetClippingPlanes( _volumePlanes ); - _newvol->SetMapper(volMapperTmp ); - volMapperTmp->SetInput( _vol ); - volMapperTmp->Update(); + + VolumeMapper->SetClippingPlanes( _volumePlanes ); + _newvol->SetMapper(VolumeMapper ); + VolumeMapper->SetInput( _vol ); + VolumeMapper->Update(); _newvol->Update(); } @@ -126,54 +130,71 @@ VolumeRendererManagerData::~VolumeRendererManagerData() _compositeFunction->Delete(); if(_MIPFunction) _MIPFunction->Delete(); - if(_volumeMapper) - _volumeMapper->Delete(); - if(_volumeMappergpu) - _volumeMappergpu->Delete(); - if(_boxWidgetS1){ + if(VolumeMapper) + VolumeMapper->Delete(); + + if(BoxWidget){ DisableBoundingBox(); } } +void VolumeRendererManagerData::SetIndependentComponents(bool independent){ + + if(!independent){ + _volumeProperty->IndependentComponentsOff(); + }else{ + _volumeProperty->IndependentComponentsOn(); + } +} void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor) { //EED9Juin2011 if(_volumeMappergpu){ - if(_boxWidgetS1==NULL){ - _boxWidgetS1 = vtkBoxWidget::New(); - _boxWidgetS1->SetInteractor( interactor ); - _boxWidgetS1->SetPlaceFactor(1.01); - _boxWidgetS1->SetInput( _vol ); - _boxWidgetS1->InsideOutOn(); - _boxWidgetS1->PlaceWidget(); + if(!BoxWidget){ + BoxWidget = vtkBoxWidget::New(); + BoxWidget->SetInteractor( interactor ); + BoxWidget->SetPlaceFactor(1.01); + + BoxWidget->SetInput( _vol ); + BoxWidget->InsideOutOn(); + BoxWidget->PlaceWidget(); + vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New(); - if (_volumeMapper!=0){ - callback->SetMapper(_volumeMapper); - } else { - callback->SetMapper(_volumeMappergpu); - } - _boxWidgetS1->AddObserver(vtkCommand::InteractionEvent, callback); + callback->SetMapper(VolumeMapper); + + + BoxWidget->AddObserver(vtkCommand::InteractionEvent, callback); callback->Delete(); - _boxWidgetS1->EnabledOn(); - _boxWidgetS1->GetSelectedFaceProperty()->SetOpacity(0.0); + + BoxWidget->EnabledOn(); + BoxWidget->GetSelectedFaceProperty()->SetOpacity(0.0); + cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<EnabledOn(); + cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<EnabledOn(); + } //EED9Juin2011 } } void VolumeRendererManagerData::DisableBoundingBox(){ - if(_boxWidgetS1){ + + if(BoxWidget){ + BoxWidget->EnabledOff(); + //BoxWidget->Delete(); + //BoxWidget = 0; + cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<EnabledOff(); - //_boxWidgetS1->Delete(); - //_boxWidgetS1 = 0; + + } } @@ -228,7 +249,7 @@ void VolumeRendererManagerData::checkInvariant()throw (char *){ if(!_MIPFunction){ throw "No MIP function initialized"; } - if(!_volumeMapper && !_volumeMappergpu){ + if(!VolumeMapper){ throw "No volume mapper initialized"; } } @@ -272,26 +293,68 @@ void VolumeRendererManagerData::setDataname(std::string dataname){ } void VolumeRendererManagerData::changeCompositeMIPFunction(int function){ - checkInvariant(); - if(_volumeMapper){ + //checkInvariant(); + if(VolumeMapper){ +#if VTK_MAJOR_VERSION >= 5 + #if VTK_MINOR_VERSION >= 6 + if(dynamic_cast(VolumeMapper)){ + vtkVolumeRayCastMapper* volumemapper = dynamic_cast(VolumeMapper); + if(function == 0){ + volumemapper->SetVolumeRayCastFunction(_compositeFunction); + }else{ + volumemapper->SetVolumeRayCastFunction(_MIPFunction); + } + }else if(dynamic_cast(VolumeMapper)){ + vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast(VolumeMapper); + if(function == 0){ + volumemapper->SetBlendModeToComposite(); + }else if(function == 1){ + volumemapper->SetBlendModeToMaximumIntensity(); + }else if(function == 2){ + volumemapper->SetBlendModeToMinimumIntensity(); + } + } + #endif +#else + vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast(VolumeMapper); if(function == 0){ - _volumeMapper->SetVolumeRayCastFunction(_compositeFunction); - }else{ - _volumeMapper->SetVolumeRayCastFunction(_MIPFunction); + volumemapper->SetBlendModeToComposite(); + }else if(function == 1){ + volumemapper->SetBlendModeToMaximumIntensity(); + }else if(function == 2){ + volumemapper->SetBlendModeToMinimumIntensity(); } +#endif } } void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){ - _ctfun->RemoveAllPoints(); - vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable; - for(int i = 0; i < colort->GetSize(); i++){ - double val[6]; - colort->GetNodeValue(i, val); - cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<AddRGBPoint(val[0], val[1], val[2], val[3]); - } - _newvol->Update(); + if(lookuptable){ + _ctfun->RemoveAllPoints(); + vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable; + for(int i = 0; i < colort->GetSize(); i++){ + double val[6]; + colort->GetNodeValue(i, val); + cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<AddRGBPoint(val[0], val[1], val[2], val[3]); + } + _newvol->Update(); + } + +} + +void VolumeRendererManagerData::changeInterpolationType(int type){ + //checkInvariant(); + if(type == 0){ + _volumeProperty->SetInterpolationTypeToLinear(); + }else if(type == 1){ + _volumeProperty->SetInterpolationTypeToNearest(); + } +} + +void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf){ + + _volumeProperty->SetColor(i, colorf); }