2 #include "volumerenderermanagerdata.h"
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
8 #include "vtkStripper.h"
9 #include "boxSurfaceObserver.h"
10 #include "vtkProperty.h"
12 #include <vtkVolumeRayCastMapper.h>
14 #if VTK_MAJOR_VERSION >= 5
15 #if VTK_MINOR_VERSION >= 6
16 #include "vtkGPUVolumeRayCastMapper.h"
23 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu)
25 Initialize(vol, "", usegpu);
28 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname)
30 Initialize(vol, dataname);
33 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname)
35 Initialize(vol, dataname);
36 render->AddActor(this->getProp3D());
39 void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu)
46 _volumePlanes = vtkPlanes::New();
48 _volumeProperty = vtkVolumeProperty::New();
49 _volumeProperty->SetInterpolationTypeToLinear();
50 //_volumeProperty->ShadeOn();
51 _volumeProperty->DisableGradientOpacityOn();
52 _tfun = vtkPiecewiseFunction::New();
53 _volumeProperty->SetScalarOpacity(_tfun );
54 _ctfun = vtkColorTransferFunction::New();
56 _newvol = vtkVolume::New();
57 _newvol->SetProperty(_volumeProperty );
60 _compositeFunction = 0;
66 if(usegpu && _vol->GetDataDimension() > 2){
67 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
68 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
69 _volumeMappergpu->AutoAdjustSampleDistancesOn();
71 _newvol->SetMapper(_volumeMappergpu );
73 _volumeMappergpu->SetInput( _vol );
74 _volumeMappergpu->Update();
76 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
77 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
79 _volumeMapper = vtkVolumeRayCastMapper::New();
80 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
81 _volumeMapper->SetClippingPlanes( _volumePlanes );
82 _volumeMapper->AutoAdjustSampleDistancesOn();
84 _newvol->SetMapper(_volumeMapper );
86 _volumeMapper->SetInput( _vol );
87 _volumeMapper->Update();
94 #if ( VTK_MAJOR_VERSION >= 5 && VTK_MINOR_VERSION >= 8 )
96 //EED 10/Nov/2011 vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
97 vtkSmartVolumeMapper * volumeMappergpu = vtkSmartVolumeMapper::New();
99 volumeMappergpu->AutoAdjustSampleDistancesOn();
100 VolumeMapper = volumeMappergpu;
102 _volumeProperty->SetColor(_ctfun);
103 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
104 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
105 vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
106 volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
107 volumeMapper->AutoAdjustSampleDistancesOn();
108 VolumeMapper = volumeMapper;
112 VolumeMapper->SetClippingPlanes( _volumePlanes );
113 _newvol->SetMapper(VolumeMapper );
114 VolumeMapper->SetInput( _vol );
115 VolumeMapper->Update();
120 VolumeRendererManagerData::~VolumeRendererManagerData()
125 _volumePlanes->Delete();
126 _volumeProperty->Delete();
129 if(_compositeFunction)
130 _compositeFunction->Delete();
132 _MIPFunction->Delete();
134 VolumeMapper->Delete();
137 DisableBoundingBox();
141 void VolumeRendererManagerData::SetIndependentComponents(bool independent)
144 _volumeProperty->IndependentComponentsOff();
146 _volumeProperty->IndependentComponentsOn();
150 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
152 //EED9Juin2011 if(_volumeMappergpu){
155 BoxWidget = vtkBoxWidget::New();
156 BoxWidget->SetInteractor( interactor );
157 BoxWidget->SetPlaceFactor(1.01);
159 BoxWidget->SetInput( _vol );
160 BoxWidget->InsideOutOn();
161 BoxWidget->PlaceWidget();
164 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
167 callback->SetMapper(VolumeMapper);
170 BoxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
173 BoxWidget->EnabledOn();
174 BoxWidget->GetSelectedFaceProperty()->SetOpacity(0.0);
176 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
180 BoxWidget->EnabledOn();
182 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
188 void VolumeRendererManagerData::DisableBoundingBox()
191 BoxWidget->EnabledOff();
192 //BoxWidget->Delete();
194 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
201 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
202 std::vector<double>& red,
203 std::vector<double>& green,
204 std::vector<double>& blue)
207 _ctfun->RemoveAllPoints();
208 for(unsigned int i = 0; i < greylevelcolors.size();i++){
209 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
210 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
218 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value)
221 _tfun->RemoveAllPoints();
222 for(unsigned int i = 0; i < greylevel.size();i++){
223 _tfun->AddPoint(greylevel[i], value[i]);
224 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
233 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value)
235 std::vector<double> valuevector;
236 for(unsigned i = 0; i < greylevel.size(); i++){
237 valuevector.push_back(value);
239 setVolumeOpacity(greylevel, valuevector);
243 ** Check if the variables are setted correctly
245 void VolumeRendererManagerData::checkInvariant()throw (char *){
246 if(!_compositeFunction){
247 throw "No composite function initialized";
250 throw "No MIP function initialized";
253 throw "No volume mapper initialized";
258 ** Check if the variables are setted correctly
260 void VolumeRendererManagerData::Update()
268 vtkProp3D* VolumeRendererManagerData::getProp3D()
270 return this->_newvol;
274 ** return the id from the daat
276 int VolumeRendererManagerData::getId()
284 void VolumeRendererManagerData::setId(int propid)
292 std::string VolumeRendererManagerData::getDataname()
299 void VolumeRendererManagerData::setDataname(std::string dataname)
301 _dataname = dataname;
305 void VolumeRendererManagerData::changeCompositeMIPFunction(int function)
310 #if VTK_MAJOR_VERSION >= 5
311 #if VTK_MINOR_VERSION >= 6
312 if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper)){
313 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
315 volumemapper->SetVolumeRayCastFunction(_compositeFunction);
317 volumemapper->SetVolumeRayCastFunction(_MIPFunction);
319 }else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
320 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
322 volumemapper->SetBlendModeToComposite();
323 }else if(function == 1){
324 volumemapper->SetBlendModeToMaximumIntensity();
325 }else if(function == 2){
326 volumemapper->SetBlendModeToMinimumIntensity();
332 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
334 volumemapper->SetBlendModeToComposite();
335 }else if(function == 1){
336 volumemapper->SetBlendModeToMaximumIntensity();
337 }else if(function == 2){
338 volumemapper->SetBlendModeToMinimumIntensity();
345 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable)
348 _ctfun->RemoveAllPoints();
349 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
350 for(int i = 0; i < colort->GetSize(); i++){
352 colort->GetNodeValue(i, val);
353 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
354 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);
361 void VolumeRendererManagerData::changeInterpolationType(int type)
365 _volumeProperty->SetInterpolationTypeToLinear();
367 _volumeProperty->SetInterpolationTypeToNearest();
371 void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf)
373 _volumeProperty->SetColor(i, colorf);