]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.cxx
#3144 creaMaracasVisu Bug New Normal - changeWx28to30
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasMultipleVolumeRendererManagerData.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26
27 #include "wxMaracasMultipleVolumeRendererManagerData.h"
28
29 /********************************************************************************************
30 ** Start of data viewmanagerData
31 *********************************************************************************************/
32
33 wxMaracasMultipleVolumeRendererManagerData::wxMaracasMultipleVolumeRendererManagerData(vtkImageData* vol, std::string dataname){
34
35         _vol = vol;     
36         _dataname = dataname;
37         
38         _tfun = vtkPiecewiseFunction::New();
39         _ctfun = vtkColorTransferFunction::New();   
40
41         _volumePlanes  = vtkPlanes::New();
42         _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
43         _MIPFunction = vtkVolumeRayCastMIPFunction::New();
44
45         _volumeMapper = vtkVolumeRayCastMapper::New();  
46         _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
47         _volumeMapper->SetClippingPlanes( _volumePlanes );
48         _volumeMapper->AutoAdjustSampleDistancesOn();
49         _volumeProperty = vtkVolumeProperty::New();     
50         _volumeProperty->SetInterpolationTypeToLinear();
51         _volumeProperty->ShadeOn();
52         _volumeProperty->DisableGradientOpacityOn();    
53         _volumeProperty->SetColor(_ctfun);
54         _volumeProperty->SetScalarOpacity(_tfun );
55
56         _newvol = vtkVolume::New();
57         _newvol->SetMapper(_volumeMapper );
58         _newvol->SetProperty(_volumeProperty );
59
60 //EED 2017-01-01 Migration VTK7
61 #if VTK_MAJOR_VERSION <= 5
62         _volumeMapper->SetInput( _vol );
63 #else
64         _volumeMapper->SetInputData( _vol );
65 #endif
66
67         _volumeMapper->Update();
68         _newvol->Update();
69 }
70
71
72 wxMaracasMultipleVolumeRendererManagerData::~wxMaracasMultipleVolumeRendererManagerData(){
73         
74         _tfun->Delete();
75         _ctfun->Delete();
76         _volumePlanes->Delete();
77         _compositeFunction->Delete();
78         _volumeMapper->Delete();
79         _volumeProperty->Delete();
80         _newvol->Delete();
81         
82 }
83 /**
84 **      Set Volume Color
85 **/
86 void wxMaracasMultipleVolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
87                                                                 std::vector<double>& red,
88                                                                 std::vector<double>& green,
89                                                                 std::vector<double>& blue)
90 {       
91         
92         _ctfun->RemoveAllPoints();
93         for(int i = 0; i < greylevelcolors.size();i++){
94                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
95                                 //std::cout<<"wxMaracasMultipleVolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
96         }               
97         _newvol->Update();      
98 }
99                                 
100 /**
101 **      Volume Opacity
102 **/
103 void wxMaracasMultipleVolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
104                 
105         _tfun->RemoveAllPoints();
106         for(int i = 0; i < greylevel.size();i++){
107                 _tfun->AddPoint(greylevel[i], value[i]);
108                         //std::cout<<"wxMaracasMultipleVolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
109         }
110     _newvol->Update();
111 }
112
113 /**
114 **      Check if the variables are setted correctly
115 **/
116 void wxMaracasMultipleVolumeRendererManagerData::checkInvariant()throw (char *){
117         if(!_compositeFunction){
118                 throw "No composite function initialized";
119         }
120         if(!_MIPFunction){
121                 throw "No MIP function initialized";
122         }
123         if(!_volumeMapper){
124                 throw "No volume mapper initialized";
125         }
126 }
127
128 /**
129 **      Check if the variables are setted correctly
130 **/
131 void wxMaracasMultipleVolumeRendererManagerData::Update(){
132          _newvol->Update();
133 }
134 /**
135 **      get the prop3D 
136 **/
137 vtkProp3D* wxMaracasMultipleVolumeRendererManagerData::getProp3D(){
138         return this->_newvol;
139 }
140 /**
141 **      return the id from the daat
142 **/
143 int wxMaracasMultipleVolumeRendererManagerData::getId(){
144         return _id;
145 }
146 /**
147 **      set data id
148 **/
149 void wxMaracasMultipleVolumeRendererManagerData::setId(int propid){
150         _id = propid;
151 }
152
153 /**
154 **      Get the filanme
155 **/
156 std::string wxMaracasMultipleVolumeRendererManagerData::getDataname(){
157         return _dataname;
158 }
159 /**
160 ** Set the filanme
161 **/
162 void wxMaracasMultipleVolumeRendererManagerData::setDataname(std::string dataname){
163         _dataname = dataname;
164 }
165
166 void wxMaracasMultipleVolumeRendererManagerData::changeCompositeMIPFunction(int function) throw (char *){
167         checkInvariant();
168         if(function == 0){
169                 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
170         }else{
171                 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
172         }
173         
174 }