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"
36 #include <vtkVolumeRayCastMapper.h>
39 //EED 2017-01-01 Migration VTK7
40 #if VTK_MAJOR_VERSION <= 5
43 #include <vtkGPUVolumeRayCastMapper.h>
46 // EED This is code for Juan Carlos Prieto TESTES
47 //#if VTK_MAJOR_VERSION >= 5
48 // #if VTK_MINOR_VERSION >= 6
49 // #include "vtkGPUVolumeRayCastMapper.h"
53 #if VTK_MAJOR_VERSION >= 6
54 #include "vtkSmartVolumeMapper.h"
61 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, bool usegpu){
62 Initialize(vol, "", usegpu);
65 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){
67 Initialize(vol, dataname);
72 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname){
74 Initialize(vol, dataname);
75 render->AddActor(this->getProp3D());
79 void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname, bool usegpu){
85 _volumePlanes = vtkPlanes::New();
87 _volumeProperty = vtkVolumeProperty::New();
88 _volumeProperty->SetInterpolationTypeToLinear();
89 _volumeProperty->ShadeOff();
90 _volumeProperty->SetAmbient(3);
91 _volumeProperty->SetDiffuse(0.2);
92 _volumeProperty->SetSpecular(0.5);
93 _volumeProperty->DisableGradientOpacityOn();
94 _tfun = vtkPiecewiseFunction::New();
95 _volumeProperty->SetScalarOpacity(_tfun );
96 _ctfun = vtkColorTransferFunction::New();
98 if(vol->GetNumberOfScalarComponents() == 1 ){
100 _ctfun->AddRGBPoint(vol->GetScalarRange()[0], 0, 0 , 0);
101 _ctfun->AddRGBPoint(vol->GetScalarRange()[1], 1, 1 , 1);
103 _volumeProperty->SetColor(_ctfun);
106 _newvol = vtkVolume::New();
107 _newvol->SetProperty(_volumeProperty );
110 _compositeFunction = 0;
116 if(usegpu && _vol->GetDataDimension() > 2){
117 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
118 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
119 _volumeMappergpu->AutoAdjustSampleDistancesOn();
121 _newvol->SetMapper(_volumeMappergpu );
123 _volumeMappergpu->SetInput( _vol );
124 _volumeMappergpu->Update();
126 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
127 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
129 _volumeMapper = vtkVolumeRayCastMapper::New();
130 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
131 _volumeMapper->SetClippingPlanes( _volumePlanes );
132 _volumeMapper->AutoAdjustSampleDistancesOn();
134 _newvol->SetMapper(_volumeMapper );
136 _volumeMapper->SetInput( _vol );
137 _volumeMapper->Update();
143 // EED This is code for Juan Carlos Prieto TESTES
144 //#if VTK_MAJOR_VERSION >= 5
145 // #if VTK_MINOR_VERSION >= 6
146 // cout<<"using volume render GPU"<<endl;
147 // vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
148 // volumeMappergpu->AutoAdjustSampleDistancesOn();
149 // VolumeMapper = volumeMappergpu;
152 // _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
153 // _MIPFunction = vtkVolumeRayCastMIPFunction::New();
154 // vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
155 // volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
156 // volumeMapper->AutoAdjustSampleDistancesOn();
157 // VolumeMapper = volumeMapper;
160 #if VTK_MAJOR_VERSION >= 6
161 cout<<"using SmartVolumeRenderingMapper render GPU"<<endl;
162 vtkSmartVolumeMapper * smartvolumemapper = vtkSmartVolumeMapper::New();
163 VolumeMapper = smartvolumemapper;
164 smartvolumemapper->AutoAdjustSampleDistancesOn();
166 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
167 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
168 vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
169 VolumeMapper = volumeMapper;
170 volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
171 volumeMapper->AutoAdjustSampleDistancesOn();
173 VolumeMapper->SetClippingPlanes( _volumePlanes );
174 _newvol->SetMapper(VolumeMapper );
176 //EED 2017-01-01 Migration VTK7
177 #if VTK_MAJOR_VERSION <= 5
178 VolumeMapper->SetInput( _vol );
180 VolumeMapper->SetInputData( _vol );
184 VolumeMapper->Update();
189 VolumeRendererManagerData::~VolumeRendererManagerData()
193 _volumePlanes->Delete();
194 _volumeProperty->Delete();
197 if(_compositeFunction)
198 _compositeFunction->Delete();
200 _MIPFunction->Delete();
202 VolumeMapper->Delete();
205 DisableBoundingBox();
210 void VolumeRendererManagerData::SetIndependentComponents(bool independent)
214 _volumeProperty->IndependentComponentsOn();
216 _volumeProperty->IndependentComponentsOff();
221 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
223 //EED9Juin2011 if(_volumeMappergpu){
227 BoxWidget = vtkBoxWidget::New();
228 BoxWidget->SetInteractor( interactor );
229 BoxWidget->SetPlaceFactor(1.01);
231 //EED 2017-01-01 Migration VTK7
232 #if VTK_MAJOR_VERSION <= 5
233 BoxWidget->SetInput( _vol );
235 BoxWidget->SetInputData( _vol );
238 BoxWidget->InsideOutOn();
239 BoxWidget->PlaceWidget();
242 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
245 callback->SetMapper(VolumeMapper);
248 BoxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
251 BoxWidget->EnabledOn();
252 BoxWidget->GetSelectedFaceProperty()->SetOpacity(0.0);
254 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
258 BoxWidget->EnabledOn();
260 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
266 void VolumeRendererManagerData::DisableBoundingBox()
270 BoxWidget->EnabledOff();
271 //BoxWidget->Delete();
273 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
280 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
281 std::vector<double>& red,
282 std::vector<double>& green,
283 std::vector<double>& blue)
286 _ctfun->RemoveAllPoints();
287 for(unsigned int i = 0; i < greylevelcolors.size();i++){
288 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
289 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
299 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value)
301 _tfun->RemoveAllPoints();
302 for(unsigned int i = 0; i < greylevel.size();i++)
304 _tfun->AddPoint(greylevel[i], value[i]);
305 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
314 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value){
315 std::vector<double> valuevector;
316 for(unsigned i = 0; i < greylevel.size(); i++){
317 valuevector.push_back(value);
319 setVolumeOpacity(greylevel, valuevector);
324 ** Check if the variables are setted correctly
326 void VolumeRendererManagerData::checkInvariant()throw (char *){
327 if(!_compositeFunction){
328 throw "No composite function initialized";
331 throw "No MIP function initialized";
334 throw "No volume mapper initialized";
340 ** Check if the variables are setted correctly
342 void VolumeRendererManagerData::Update()
351 vtkProp3D* VolumeRendererManagerData::getProp3D()
353 return this->_newvol;
357 ** return the id from the daat
359 int VolumeRendererManagerData::getId()
368 void VolumeRendererManagerData::setId(int propid)
377 std::string VolumeRendererManagerData::getDataname()
386 void VolumeRendererManagerData::setDataname(std::string dataname)
388 _dataname = dataname;
392 void VolumeRendererManagerData::changeCompositeMIPFunction(int function)
395 if(VolumeMapper!=NULL){
396 #if VTK_MAJOR_VERSION >= 6
397 if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper))
399 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
401 volumemapper->SetVolumeRayCastFunction(_compositeFunction);
403 volumemapper->SetVolumeRayCastFunction(_MIPFunction);
405 }else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
406 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
408 volumemapper->SetBlendModeToComposite();
409 }else if(function == 1){
410 volumemapper->SetBlendModeToMaximumIntensity();
411 }else if(function == 2){
412 volumemapper->SetBlendModeToMinimumIntensity();
416 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
418 volumemapper->SetBlendModeToComposite();
419 }else if(function == 1){
420 volumemapper->SetBlendModeToMaximumIntensity();
421 }else if(function == 2){
422 volumemapper->SetBlendModeToMinimumIntensity();
429 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable)
432 _ctfun->RemoveAllPoints();
433 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
434 for(int i = 0; i < colort->GetSize(); i++){
436 colort->GetNodeValue(i, val);
437 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
438 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);
445 void VolumeRendererManagerData::changeInterpolationType(int type)
449 _volumeProperty->SetInterpolationTypeToLinear();
451 _volumeProperty->SetInterpolationTypeToNearest();
455 void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf){
457 _volumeProperty->SetColor(i, colorf);