1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 #include "volumerenderermanagerdata.h"
28 /********************************************************************************************
29 ** Start of data viewmanagerData
30 *********************************************************************************************/
32 #include "vtkStripper.h"
33 #include "boxSurfaceObserver.h"
34 #include "vtkProperty.h"
37 #if (VTK_MAJOR_VERSION <= 7)
38 #include <vtkVolumeRayCastMapper.h>
40 #include <vtkFixedPointVolumeRayCastMapper.h>
44 //EED 2017-01-01 Migration VTK7
45 #if VTK_MAJOR_VERSION <= 5
48 #include <vtkGPUVolumeRayCastMapper.h>
51 // EED This is code for Juan Carlos Prieto TESTES
52 //#if VTK_MAJOR_VERSION >= 5
53 // #if VTK_MINOR_VERSION >= 6
54 // #include "vtkGPUVolumeRayCastMapper.h"
58 #if VTK_MAJOR_VERSION >= 6
59 #include "vtkSmartVolumeMapper.h"
66 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu)
68 Initialize(vol, "", usegpu);
71 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname)
74 Initialize(vol, dataname);
79 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname)
82 Initialize(vol, dataname);
83 render->AddActor(this->getProp3D());
87 void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu)
93 _volumePlanes = vtkPlanes::New();
95 _volumeProperty = vtkVolumeProperty::New();
96 _volumeProperty->SetInterpolationTypeToLinear();
97 _volumeProperty->ShadeOff();
98 _volumeProperty->SetAmbient(3);
99 _volumeProperty->SetDiffuse(0.2);
100 _volumeProperty->SetSpecular(0.5);
101 _volumeProperty->DisableGradientOpacityOn();
102 _tfun = vtkPiecewiseFunction::New();
103 _volumeProperty->SetScalarOpacity(_tfun );
104 _ctfun = vtkColorTransferFunction::New();
106 if(vol->GetNumberOfScalarComponents() == 1 ){
108 _ctfun->AddRGBPoint(vol->GetScalarRange()[0], 0, 0 , 0);
109 _ctfun->AddRGBPoint(vol->GetScalarRange()[1], 1, 1 , 1);
111 _volumeProperty->SetColor(_ctfun);
114 _newvol = vtkVolume::New();
115 _newvol->SetProperty(_volumeProperty );
118 #if (VTK_MAJOR_VERSION <= 7)
119 _compositeFunction = 0;
128 if(usegpu && _vol->GetDataDimension() > 2){
129 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
130 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
131 _volumeMappergpu->AutoAdjustSampleDistancesOn();
133 _newvol->SetMapper(_volumeMappergpu );
135 _volumeMappergpu->SetInput( _vol );
136 _volumeMappergpu->Update();
138 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
139 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
141 _volumeMapper = vtkVolumeRayCastMapper::New();
142 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
143 _volumeMapper->SetClippingPlanes( _volumePlanes );
144 _volumeMapper->AutoAdjustSampleDistancesOn();
146 _newvol->SetMapper(_volumeMapper );
148 _volumeMapper->SetInput( _vol );
149 _volumeMapper->Update();
155 // EED This is code for Juan Carlos Prieto TESTES
156 //#if VTK_MAJOR_VERSION >= 5
157 // #if VTK_MINOR_VERSION >= 6
158 // cout<<"using volume render GPU"<<endl;
159 // vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
160 // volumeMappergpu->AutoAdjustSampleDistancesOn();
161 // VolumeMapper = volumeMappergpu;
164 // _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
165 // _MIPFunction = vtkVolumeRayCastMIPFunction::New();
166 // vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
167 // volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
168 // volumeMapper->AutoAdjustSampleDistancesOn();
169 // VolumeMapper = volumeMapper;
172 #if VTK_MAJOR_VERSION >= 6
173 cout<<"using SmartVolumeRenderingMapper render GPU"<<endl;
174 vtkSmartVolumeMapper * smartvolumemapper = vtkSmartVolumeMapper::New();
175 VolumeMapper = smartvolumemapper;
176 // smartvolumemapper->AutoAdjustSampleDistancesOn();
178 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
179 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
180 vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
181 VolumeMapper = volumeMapper;
182 volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
183 volumeMapper->AutoAdjustSampleDistancesOn();
185 VolumeMapper->SetClippingPlanes( _volumePlanes );
186 _newvol->SetMapper(VolumeMapper );
188 //EED 2017-01-01 Migration VTK7
189 #if VTK_MAJOR_VERSION <= 5
190 VolumeMapper->SetInput( _vol );
192 VolumeMapper->SetInputData( _vol );
196 VolumeMapper->Update();
201 VolumeRendererManagerData::~VolumeRendererManagerData()
205 _volumePlanes->Delete();
206 _volumeProperty->Delete();
210 #if (VTK_MAJOR_VERSION <= 7)
211 if(_compositeFunction)
212 _compositeFunction->Delete();
214 _MIPFunction->Delete();
220 VolumeMapper->Delete();
223 DisableBoundingBox();
228 void VolumeRendererManagerData::SetIndependentComponents(bool independent)
232 _volumeProperty->IndependentComponentsOn();
234 _volumeProperty->IndependentComponentsOff();
239 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
241 //EED9Juin2011 if(_volumeMappergpu){
245 BoxWidget = vtkBoxWidget::New();
246 BoxWidget->SetInteractor( interactor );
247 BoxWidget->SetPlaceFactor(1.01);
249 //EED 2017-01-01 Migration VTK7
250 #if VTK_MAJOR_VERSION <= 5
251 BoxWidget->SetInput( _vol );
253 BoxWidget->SetInputData( _vol );
256 BoxWidget->InsideOutOn();
257 BoxWidget->PlaceWidget();
260 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
263 callback->SetMapper(VolumeMapper);
266 BoxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
269 BoxWidget->EnabledOn();
270 BoxWidget->GetSelectedFaceProperty()->SetOpacity(0.0);
272 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
276 BoxWidget->EnabledOn();
278 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
284 void VolumeRendererManagerData::DisableBoundingBox()
288 BoxWidget->EnabledOff();
289 //BoxWidget->Delete();
291 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
298 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
299 std::vector<double>& red,
300 std::vector<double>& green,
301 std::vector<double>& blue)
304 _ctfun->RemoveAllPoints();
305 for(unsigned int i = 0; i < greylevelcolors.size();i++){
306 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
307 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
317 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value)
319 _tfun->RemoveAllPoints();
320 for(unsigned int i = 0; i < greylevel.size();i++)
322 _tfun->AddPoint(greylevel[i], value[i]);
323 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
332 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value){
333 std::vector<double> valuevector;
334 for(unsigned i = 0; i < greylevel.size(); i++){
335 valuevector.push_back(value);
337 setVolumeOpacity(greylevel, valuevector);
342 ** Check if the variables are setted correctly
344 void VolumeRendererManagerData::checkInvariant()throw (char *)
346 #if (VTK_MAJOR_VERSION <= 7)
347 if(!_compositeFunction)
349 throw "No composite function initialized";
353 throw "No MIP function initialized";
360 throw "No volume mapper initialized";
366 ** Check if the variables are setted correctly
368 void VolumeRendererManagerData::Update()
377 vtkProp3D* VolumeRendererManagerData::getProp3D()
379 return this->_newvol;
383 ** return the id from the daat
385 int VolumeRendererManagerData::getId()
394 void VolumeRendererManagerData::setId(int propid)
403 std::string VolumeRendererManagerData::getDataname()
412 void VolumeRendererManagerData::setDataname(std::string dataname)
414 _dataname = dataname;
418 void VolumeRendererManagerData::changeCompositeMIPFunction(int function)
421 if(VolumeMapper!=NULL){
422 #if VTK_MAJOR_VERSION >= 6
424 #if (VTK_MAJOR_VERSION <= 7)
425 if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper))
427 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
429 volumemapper->SetVolumeRayCastFunction(_compositeFunction);
431 volumemapper->SetVolumeRayCastFunction(_MIPFunction);
433 } else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
434 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
436 volumemapper->SetBlendModeToComposite();
437 } else if(function == 1) {
438 volumemapper->SetBlendModeToMaximumIntensity();
439 } else if(function == 2) {
440 volumemapper->SetBlendModeToMinimumIntensity();
445 if(dynamic_cast<vtkFixedPointVolumeRayCastMapper*>(VolumeMapper))
447 vtkFixedPointVolumeRayCastMapper* volumemapper = dynamic_cast<vtkFixedPointVolumeRayCastMapper*>(VolumeMapper);
448 // ... for composote or MIP
449 } else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
450 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
452 volumemapper->SetBlendModeToComposite();
453 } else if(function == 1) {
454 volumemapper->SetBlendModeToMaximumIntensity();
455 } else if(function == 2) {
456 volumemapper->SetBlendModeToMinimumIntensity();
464 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
466 volumemapper->SetBlendModeToComposite();
467 }else if(function == 1){
468 volumemapper->SetBlendModeToMaximumIntensity();
469 }else if(function == 2){
470 volumemapper->SetBlendModeToMinimumIntensity();
477 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable)
480 _ctfun->RemoveAllPoints();
481 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
482 for(int i = 0; i < colort->GetSize(); i++){
484 colort->GetNodeValue(i, val);
485 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
486 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);
493 void VolumeRendererManagerData::changeInterpolationType(int type)
497 _volumeProperty->SetInterpolationTypeToLinear();
499 _volumeProperty->SetInterpolationTypeToNearest();
503 void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf){
505 _volumeProperty->SetColor(i, colorf);