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"
22 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu){
23 Initialize(vol, "", usegpu);
26 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){
28 Initialize(vol, dataname);
33 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname){
35 Initialize(vol, dataname);
36 render->AddActor(this->getProp3D());
40 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();
92 #if VTK_MAJOR_VERSION >= 5
93 #if VTK_MINOR_VERSION >= 6
94 vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
95 volumeMappergpu->AutoAdjustSampleDistancesOn();
96 VolumeMapper = volumeMappergpu;
100 _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();
195 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
204 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
205 std::vector<double>& red,
206 std::vector<double>& green,
207 std::vector<double>& blue)
210 _ctfun->RemoveAllPoints();
211 for(unsigned int i = 0; i < greylevelcolors.size();i++){
212 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
213 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
221 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
223 _tfun->RemoveAllPoints();
224 for(unsigned int i = 0; i < greylevel.size();i++){
225 _tfun->AddPoint(greylevel[i], value[i]);
226 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
234 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(){
266 vtkProp3D* VolumeRendererManagerData::getProp3D(){
267 return this->_newvol;
270 ** return the id from the daat
272 int VolumeRendererManagerData::getId(){
278 void VolumeRendererManagerData::setId(int propid){
285 std::string VolumeRendererManagerData::getDataname(){
291 void VolumeRendererManagerData::setDataname(std::string dataname){
292 _dataname = dataname;
295 void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
298 #if VTK_MAJOR_VERSION >= 5
299 #if VTK_MINOR_VERSION >= 6
300 if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper)){
301 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
303 volumemapper->SetVolumeRayCastFunction(_compositeFunction);
305 volumemapper->SetVolumeRayCastFunction(_MIPFunction);
307 }else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
308 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
310 volumemapper->SetBlendModeToComposite();
311 }else if(function == 1){
312 volumemapper->SetBlendModeToMaximumIntensity();
313 }else if(function == 2){
314 volumemapper->SetBlendModeToMinimumIntensity();
319 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
321 volumemapper->SetBlendModeToComposite();
322 }else if(function == 1){
323 volumemapper->SetBlendModeToMaximumIntensity();
324 }else if(function == 2){
325 volumemapper->SetBlendModeToMinimumIntensity();
332 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
334 _ctfun->RemoveAllPoints();
335 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
336 for(int i = 0; i < colort->GetSize(); i++){
338 colort->GetNodeValue(i, val);
339 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
340 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);
347 void VolumeRendererManagerData::changeInterpolationType(int type){
350 _volumeProperty->SetInterpolationTypeToLinear();
352 _volumeProperty->SetInterpolationTypeToNearest();
356 void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf){
358 _volumeProperty->SetColor(i, colorf);