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->SetAmbient(3);
52 _volumeProperty->SetDiffuse(0.2);
53 _volumeProperty->SetSpecular(0.5);
54 //_volumeProperty->DisableGradientOpacityOn();
55 _tfun = vtkPiecewiseFunction::New();
56 _volumeProperty->SetScalarOpacity(_tfun );
57 _ctfun = vtkColorTransferFunction::New();
59 if(vol->GetNumberOfScalarComponents() == 1 ){
61 _ctfun->AddRGBPoint(vol->GetScalarRange()[0], 0, 0 , 0);
62 _ctfun->AddRGBPoint(vol->GetScalarRange()[1], 1, 1 , 1);
64 _volumeProperty->SetColor(_ctfun);
67 _newvol = vtkVolume::New();
68 _newvol->SetProperty(_volumeProperty );
71 _compositeFunction = 0;
77 if(usegpu && _vol->GetDataDimension() > 2){
78 _volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
79 _volumeMappergpu->SetClippingPlanes( _volumePlanes );
80 _volumeMappergpu->AutoAdjustSampleDistancesOn();
82 _newvol->SetMapper(_volumeMappergpu );
84 _volumeMappergpu->SetInput( _vol );
85 _volumeMappergpu->Update();
87 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
88 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
90 _volumeMapper = vtkVolumeRayCastMapper::New();
91 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
92 _volumeMapper->SetClippingPlanes( _volumePlanes );
93 _volumeMapper->AutoAdjustSampleDistancesOn();
95 _newvol->SetMapper(_volumeMapper );
97 _volumeMapper->SetInput( _vol );
98 _volumeMapper->Update();
103 #if VTK_MAJOR_VERSION >= 5
104 #if VTK_MINOR_VERSION >= 6
105 cout<<"using volume render GPU"<<endl;
106 vtkGPUVolumeRayCastMapper * volumeMappergpu = vtkGPUVolumeRayCastMapper::New();
107 volumeMappergpu->AutoAdjustSampleDistancesOn();
108 VolumeMapper = volumeMappergpu;
113 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
114 _MIPFunction = vtkVolumeRayCastMIPFunction::New();
115 vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New();
116 volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
117 volumeMapper->AutoAdjustSampleDistancesOn();
118 VolumeMapper = volumeMapper;
122 VolumeMapper->SetClippingPlanes( _volumePlanes );
123 _newvol->SetMapper(VolumeMapper );
124 VolumeMapper->SetInput( _vol );
125 VolumeMapper->Update();
130 VolumeRendererManagerData::~VolumeRendererManagerData()
135 _volumePlanes->Delete();
136 _volumeProperty->Delete();
139 if(_compositeFunction)
140 _compositeFunction->Delete();
142 _MIPFunction->Delete();
144 VolumeMapper->Delete();
147 DisableBoundingBox();
151 void VolumeRendererManagerData::SetIndependentComponents(bool independent){
154 _volumeProperty->IndependentComponentsOn();
156 _volumeProperty->IndependentComponentsOff();
160 void VolumeRendererManagerData::EnableBoundingBox(vtkRenderWindowInteractor* interactor)
162 //EED9Juin2011 if(_volumeMappergpu){
165 BoxWidget = vtkBoxWidget::New();
166 BoxWidget->SetInteractor( interactor );
167 BoxWidget->SetPlaceFactor(1.01);
169 BoxWidget->SetInput( _vol );
170 BoxWidget->InsideOutOn();
171 BoxWidget->PlaceWidget();
174 vtkBoxWidgetCallback *callback = vtkBoxWidgetCallback::New();
177 callback->SetMapper(VolumeMapper);
180 BoxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
183 BoxWidget->EnabledOn();
184 BoxWidget->GetSelectedFaceProperty()->SetOpacity(0.0);
186 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox::CREATE"<<endl;
190 BoxWidget->EnabledOn();
192 cout<<"JPRG::VolumeRendererManagerData::EnableBoundingBox"<<endl;
198 void VolumeRendererManagerData::DisableBoundingBox(){
201 BoxWidget->EnabledOff();
202 //BoxWidget->Delete();
205 cout<<"JPRG::VolumeRendererManagerData::DisableBoundingBox"<<endl;
214 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
215 std::vector<double>& red,
216 std::vector<double>& green,
217 std::vector<double>& blue)
220 _ctfun->RemoveAllPoints();
221 for(unsigned int i = 0; i < greylevelcolors.size();i++){
222 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
223 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
231 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
233 _tfun->RemoveAllPoints();
234 for(unsigned int i = 0; i < greylevel.size();i++){
235 _tfun->AddPoint(greylevel[i], value[i]);
236 //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
244 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,double value){
245 std::vector<double> valuevector;
246 for(unsigned i = 0; i < greylevel.size(); i++){
247 valuevector.push_back(value);
249 setVolumeOpacity(greylevel, valuevector);
253 ** Check if the variables are setted correctly
255 void VolumeRendererManagerData::checkInvariant()throw (char *){
256 if(!_compositeFunction){
257 throw "No composite function initialized";
260 throw "No MIP function initialized";
263 throw "No volume mapper initialized";
268 ** Check if the variables are setted correctly
270 void VolumeRendererManagerData::Update(){
276 vtkProp3D* VolumeRendererManagerData::getProp3D(){
277 return this->_newvol;
280 ** return the id from the daat
282 int VolumeRendererManagerData::getId(){
288 void VolumeRendererManagerData::setId(int propid){
295 std::string VolumeRendererManagerData::getDataname(){
301 void VolumeRendererManagerData::setDataname(std::string dataname){
302 _dataname = dataname;
305 void VolumeRendererManagerData::changeCompositeMIPFunction(int function){
308 #if VTK_MAJOR_VERSION >= 5
309 #if VTK_MINOR_VERSION >= 6
310 if(dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper)){
311 vtkVolumeRayCastMapper* volumemapper = dynamic_cast<vtkVolumeRayCastMapper*>(VolumeMapper);
313 volumemapper->SetVolumeRayCastFunction(_compositeFunction);
315 volumemapper->SetVolumeRayCastFunction(_MIPFunction);
317 }else if(dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper)){
318 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
320 volumemapper->SetBlendModeToComposite();
321 }else if(function == 1){
322 volumemapper->SetBlendModeToMaximumIntensity();
323 }else if(function == 2){
324 volumemapper->SetBlendModeToMinimumIntensity();
329 vtkGPUVolumeRayCastMapper* volumemapper = dynamic_cast<vtkGPUVolumeRayCastMapper*>(VolumeMapper);
331 volumemapper->SetBlendModeToComposite();
332 }else if(function == 1){
333 volumemapper->SetBlendModeToMaximumIntensity();
334 }else if(function == 2){
335 volumemapper->SetBlendModeToMinimumIntensity();
342 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
344 _ctfun->RemoveAllPoints();
345 vtkColorTransferFunction* colort = (vtkColorTransferFunction*)lookuptable;
346 for(int i = 0; i < colort->GetSize(); i++){
348 colort->GetNodeValue(i, val);
349 cout<< "JPRG::VolumeRendererManagerData::SetLookupTable::"<<val[0]<<" "<< val[1]<<" "<<val[2]<<" "<< val[3]<<endl;
350 _ctfun->AddRGBPoint(val[0], val[1], val[2], val[3]);
357 void VolumeRendererManagerData::changeInterpolationType(int type){
360 _volumeProperty->SetInterpolationTypeToLinear();
362 _volumeProperty->SetInterpolationTypeToNearest();
366 void VolumeRendererManagerData::SetColorTransferFunction(int i, vtkColorTransferFunction* colorf){
368 _volumeProperty->SetColor(i, colorf);