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
95 #if VTK_MINOR_VERSION >= 6
96 vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
97 // vtkSmartVolumeMapper * volumeMappergpu = vtkSmartVolumeMapper::New();
99 volumeMappergpu->AutoAdjustSampleDistancesOn();
100 VolumeMapper = volumeMappergpu;
104 _volumeProperty->SetColor(_ctfun);
107 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
108 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
109 vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
110 volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
111 volumeMapper->AutoAdjustSampleDistancesOn();
112 VolumeMapper = volumeMapper;
116 VolumeMapper->SetClippingPlanes( _volumePlanes );
117 _newvol->SetMapper(VolumeMapper );
118 VolumeMapper->SetInput( _vol );
119 VolumeMapper->Update();
124 VolumeRendererManagerData::~VolumeRendererManagerData()
129 _volumePlanes->Delete();
130 _volumeProperty->Delete();
133 if(_compositeFunction)
134 _compositeFunction->Delete();
136 _MIPFunction->Delete();
138 VolumeMapper->Delete();
141 DisableBoundingBox();
145 void VolumeRendererManagerData::SetIndependentComponents(bool independent)
148 _volumeProperty->IndependentComponentsOff();
150 _volumeProperty->IndependentComponentsOn();
154 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
156 //EED9Juin2011 if(_volumeMappergpu){
159 BoxWidget = vtkBoxWidget::New();
160 BoxWidget->SetInteractor( interactor );
161 BoxWidget->SetPlaceFactor(1.01);
163 BoxWidget->SetInput( _vol );
164 BoxWidget->InsideOutOn();
165 BoxWidget->PlaceWidget();
168 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
171 callback->SetMapper(VolumeMapper);
174 BoxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
177 BoxWidget->EnabledOn();
178 BoxWidget->GetSelectedFaceProperty()->SetOpacity(0.0);
180 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
184 BoxWidget->EnabledOn();
186 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
192 void VolumeRendererManagerData::DisableBoundingBox()
195 BoxWidget->EnabledOff();
196 //BoxWidget->Delete();
198 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
205 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
206 std::vector<double>& red,
207 std::vector<double>& green,
208 std::vector<double>& blue)
211 _ctfun->RemoveAllPoints();
212 for(unsigned int i = 0; i < greylevelcolors.size();i++){
213 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
214 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
222 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value)
225 _tfun->RemoveAllPoints();
226 for(unsigned int i = 0; i < greylevel.size();i++){
227 _tfun->AddPoint(greylevel[i], value[i]);
228 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
237 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value)
239 std::vector<double> valuevector;
240 for(unsigned i = 0; i < greylevel.size(); i++){
241 valuevector.push_back(value);
243 setVolumeOpacity(greylevel, valuevector);
247 ** Check if the variables are setted correctly
249 void VolumeRendererManagerData::checkInvariant()throw (char *){
250 if(!_compositeFunction){
251 throw "No composite function initialized";
254 throw "No MIP function initialized";
257 throw "No volume mapper initialized";
262 ** Check if the variables are setted correctly
264 void VolumeRendererManagerData::Update()
272 vtkProp3D* VolumeRendererManagerData::getProp3D()
274 return this->_newvol;
278 ** return the id from the daat
280 int VolumeRendererManagerData::getId()
288 void VolumeRendererManagerData::setId(int propid)
296 std::string VolumeRendererManagerData::getDataname()
303 void VolumeRendererManagerData::setDataname(std::string dataname)
305 _dataname = dataname;
309 void VolumeRendererManagerData::changeCompositeMIPFunction(int function)
314 #if VTK_MAJOR_VERSION >= 5
315 #if VTK_MINOR_VERSION >= 6
316 if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper)){
317 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
319 volumemapper->SetVolumeRayCastFunction(_compositeFunction);
321 volumemapper->SetVolumeRayCastFunction(_MIPFunction);
323 }else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
324 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
326 volumemapper->SetBlendModeToComposite();
327 }else if(function == 1){
328 volumemapper->SetBlendModeToMaximumIntensity();
329 }else if(function == 2){
330 volumemapper->SetBlendModeToMinimumIntensity();
336 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
338 volumemapper->SetBlendModeToComposite();
339 }else if(function == 1){
340 volumemapper->SetBlendModeToMaximumIntensity();
341 }else if(function == 2){
342 volumemapper->SetBlendModeToMinimumIntensity();
349 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable)
352 _ctfun->RemoveAllPoints();
353 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
354 for(int i = 0; i < colort->GetSize(); i++){
356 colort->GetNodeValue(i, val);
357 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
358 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);
365 void VolumeRendererManagerData::changeInterpolationType(int type)
369 _volumeProperty->SetInterpolationTypeToLinear();
371 _volumeProperty->SetInterpolationTypeToNearest();
375 void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf)
377 _volumeProperty->SetColor(i, colorf);