]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.cxx
addition of files
[creaMaracasVisu.git] / lib / Kernel / VTKObjects / VolumeRenderer / volumerenderermanagerdata.cxx
1
2 #include "volumerenderermanagerdata.h"
3
4 /********************************************************************************************
5 ** Start of data viewmanagerData
6 *********************************************************************************************/
7
8 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, std::string dataname){
9
10     Initialize(vol, dataname);
11
12
13 }
14
15 VolumeRendererManagerData::VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname){
16
17     Initialize(vol, dataname);
18     render->AddActor(this->getProp3D());
19 }
20
21 void VolumeRendererManagerData::Initialize(vtkImageData* vol, std::string dataname){
22     _vol = vol;
23     _dataname = dataname;
24
25     _tfun = vtkPiecewiseFunction::New();
26     _ctfun = vtkColorTransferFunction::New();
27
28     _volumePlanes  = vtkPlanes::New();
29     _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
30     _MIPFunction = vtkVolumeRayCastMIPFunction::New();
31
32     _volumeMapper = vtkVolumeRayCastMapper::New();
33     _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
34     _volumeMapper->SetClippingPlanes( _volumePlanes );
35     _volumeMapper->AutoAdjustSampleDistancesOn();
36     _volumeProperty = vtkVolumeProperty::New();
37     _volumeProperty->SetInterpolationTypeToLinear();
38     //_volumeProperty->ShadeOn();
39     _volumeProperty->DisableGradientOpacityOn();
40     _volumeProperty->SetColor(_ctfun);
41     _volumeProperty->SetScalarOpacity(_tfun );
42
43     _newvol = vtkVolume::New();
44     _newvol->SetMapper(_volumeMapper );
45     _newvol->SetProperty(_volumeProperty );
46     _volumeMapper->SetInput( _vol );
47     _volumeMapper->Update();
48     _newvol->Update();
49 }
50
51
52 VolumeRendererManagerData::~VolumeRendererManagerData(){
53
54         _tfun->Delete();
55         _ctfun->Delete();
56         _volumePlanes->Delete();
57         _compositeFunction->Delete();
58         _volumeMapper->Delete();
59         _volumeProperty->Delete();
60         _newvol->Delete();
61
62 }
63 /**
64 **      Set Volume Color
65 **/
66 void VolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
67                                                                 std::vector<double>& red,
68                                                                 std::vector<double>& green,
69                                                                 std::vector<double>& blue)
70 {
71
72         _ctfun->RemoveAllPoints();
73         for(int i = 0; i < greylevelcolors.size();i++){
74                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
75                                 //std::cout<<"VolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
76         }
77         _newvol->Update();
78 }
79
80 /**
81 **      Volume Opacity
82 **/
83 void VolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
84
85         _tfun->RemoveAllPoints();
86         for(int i = 0; i < greylevel.size();i++){
87                 _tfun->AddPoint(greylevel[i], value[i]);
88                         //std::cout<<"VolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
89         }
90     _newvol->Update();
91 }
92
93 /**
94 **      Check if the variables are setted correctly
95 **/
96 void VolumeRendererManagerData::checkInvariant()throw (char *){
97         if(!_compositeFunction){
98                 throw "No composite function initialized";
99         }
100         if(!_MIPFunction){
101                 throw "No MIP function initialized";
102         }
103         if(!_volumeMapper){
104                 throw "No volume mapper initialized";
105         }
106 }
107
108 /**
109 **      Check if the variables are setted correctly
110 **/
111 void VolumeRendererManagerData::Update(){
112          _newvol->Update();
113 }
114 /**
115 **      get the prop3D
116 **/
117 vtkProp3D* VolumeRendererManagerData::getProp3D(){
118         return this->_newvol;
119 }
120 /**
121 **      return the id from the daat
122 **/
123 int VolumeRendererManagerData::getId(){
124         return _id;
125 }
126 /**
127 **      set data id
128 **/
129 void VolumeRendererManagerData::setId(int propid){
130         _id = propid;
131 }
132
133 /**
134 **      Get the filanme
135 **/
136 std::string VolumeRendererManagerData::getDataname(){
137         return _dataname;
138 }
139 /**
140 ** Set the filanme
141 **/
142 void VolumeRendererManagerData::setDataname(std::string dataname){
143         _dataname = dataname;
144 }
145
146 void VolumeRendererManagerData::changeCompositeMIPFunction(int function) throw (char *){
147         checkInvariant();
148         if(function == 0){
149                 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
150         }else{
151                 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
152         }
153
154 }
155
156 void VolumeRendererManagerData::SetLookupTable(vtkLookupTable* lookuptable){
157      _ctfun->RemoveAllPoints();
158      _ctfun->DeepCopy((vtkColorTransferFunction*)lookuptable);
159 }