#include "volumerenderermanagerdata.h" /******************************************************************************************** ** Start of data viewmanagerData *********************************************************************************************/ #include "vtkStripper.h" #include "boxSurfaceObserver.h" #include "vtkProperty.h" using namespace std; VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){ Initialize(vol, dataname); } VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname){ Initialize(vol, dataname); render->AddActor(this->getProp3D()); } VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu, std::string dataname){ Initialize(vol, dataname, usegpu); } void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu){ _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->SetScalarOpacity(_tfun ); _newvol = vtkVolume::New(); _newvol->SetProperty(_volumeProperty ); _volumeMapper = 0; _volumeMappergpu = 0; _compositeFunction = 0; _MIPFunction = 0; _boxWidgetS1 = 0; /* EED9Juin2011 if(usegpu && _vol->GetDataDimension() > 2){ _volumeMappergpu = vtkGPUVolumeRayCastMapper::New(); _volumeMappergpu->SetClippingPlanes( _volumePlanes ); _volumeMappergpu->AutoAdjustSampleDistancesOn(); _newvol->SetMapper(_volumeMappergpu ); _volumeMappergpu->SetInput( _vol ); _volumeMappergpu->Update(); }else{ _compositeFunction = vtkVolumeRayCastCompositeFunction::New(); _MIPFunction = vtkVolumeRayCastMIPFunction::New(); _volumeMapper = vtkVolumeRayCastMapper::New(); _volumeMapper->SetVolumeRayCastFunction(_compositeFunction); _volumeMapper->SetClippingPlanes( _volumePlanes ); _volumeMapper->AutoAdjustSampleDistancesOn(); _newvol->SetMapper(_volumeMapper ); _volumeMapper->SetInput( _vol ); _volumeMapper->Update(); } */ 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; } volMapperTmp->SetClippingPlanes( _volumePlanes ); _newvol->SetMapper(volMapperTmp ); volMapperTmp->SetInput( _vol ); volMapperTmp->Update(); _newvol->Update(); } VolumeRendererManagerData::~VolumeRendererManagerData() { _tfun->Delete(); _ctfun->Delete(); _volumePlanes->Delete(); _volumeProperty->Delete(); _newvol->Delete(); if(_compositeFunction) _compositeFunction->Delete(); if(_MIPFunction) _MIPFunction->Delete(); if(_volumeMapper) _volumeMapper->Delete(); if(_volumeMappergpu) _volumeMappergpu->Delete(); if(_boxWidgetS1){ DisableBoundingBox(); } } 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(); vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New(); if (_volumeMapper!=0){ callback->SetMapper(_volumeMapper); } else { callback->SetMapper(_volumeMappergpu); } _boxWidgetS1->AddObserver(vtkCommand::InteractionEvent, callback); callback->Delete(); _boxWidgetS1->EnabledOn(); _boxWidgetS1->GetSelectedFaceProperty()->SetOpacity(0.0); cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<EnabledOn(); } //EED9Juin2011 } } void VolumeRendererManagerData::DisableBoundingBox(){ if(_boxWidgetS1){ cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<EnabledOff(); //_boxWidgetS1->Delete(); //_boxWidgetS1 = 0; } } /** ** Set Volume Color **/ void VolumeRendererManagerData::setVolumeColor(std::vector& greylevelcolors, std::vector& red, std::vector& green, std::vector& blue) { _ctfun->RemoveAllPoints(); for(unsigned int i = 0; i < greylevelcolors.size();i++){ _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]); //std::cout<<"VolumeRendererManagerData::setVolumeColor "<Update(); } /** ** Volume Opacity **/ void VolumeRendererManagerData::setVolumeOpacity(std::vector greylevel,std::vector value){ _tfun->RemoveAllPoints(); for(unsigned int i = 0; i < greylevel.size();i++){ _tfun->AddPoint(greylevel[i], value[i]); //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<Update(); } /** ** Volume Opacity **/ void VolumeRendererManagerData::setVolumeOpacity(std::vector greylevel,double value){ std::vector valuevector; for(unsigned i = 0; i < greylevel.size(); i++){ valuevector.push_back(value); } setVolumeOpacity(greylevel, valuevector); } /** ** Check if the variables are setted correctly **/ void VolumeRendererManagerData::checkInvariant()throw (char *){ if(!_compositeFunction){ throw "No composite function initialized"; } if(!_MIPFunction){ throw "No MIP function initialized"; } if(!_volumeMapper && !_volumeMappergpu){ throw "No volume mapper initialized"; } } /** ** Check if the variables are setted correctly **/ void VolumeRendererManagerData::Update(){ _newvol->Update(); } /** ** get the prop3D **/ vtkProp3D* VolumeRendererManagerData::getProp3D(){ return this->_newvol; } /** ** return the id from the daat **/ int VolumeRendererManagerData::getId(){ return _id; } /** ** set data id **/ void VolumeRendererManagerData::setId(int propid){ _id = propid; } /** ** Get the filanme **/ std::string VolumeRendererManagerData::getDataname(){ return _dataname; } /** ** Set the filanme **/ void VolumeRendererManagerData::setDataname(std::string dataname){ _dataname = dataname; } void VolumeRendererManagerData::changeCompositeMIPFunction(int function){ checkInvariant(); if(_volumeMapper){ if(function == 0){ _volumeMapper->SetVolumeRayCastFunction(_compositeFunction); }else{ _volumeMapper->SetVolumeRayCastFunction(_MIPFunction); } } } 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(); }