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