]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.cxx
#3207 creaMaracasVisu Feature New Normal branch vtk7itk4wx3-mingw
[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         _tfun                                   = vtkPiecewiseFunction::New();
38         _ctfun                                  = vtkColorTransferFunction::New();   
39         _volumePlanes                   = vtkPlanes::New();
40
41
42 #if (VTK_MAJOR_VERSION <= 7) 
43         _compositeFunction              = vtkVolumeRayCastCompositeFunction::New();
44         _MIPFunction                    = vtkVolumeRayCastMIPFunction::New();
45         _volumeMapper                   = vtkVolumeRayCastMapper::New();                
46         _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
47 #else 
48         _volumeMapper                   = vtkFixedPointVolumeRayCastMapper::New();      
49 #endif
50
51         _volumeMapper->SetClippingPlanes( _volumePlanes );
52         _volumeMapper->AutoAdjustSampleDistancesOn();
53         _volumeProperty = vtkVolumeProperty::New();     
54         _volumeProperty->SetInterpolationTypeToLinear();
55         _volumeProperty->ShadeOn();
56         _volumeProperty->DisableGradientOpacityOn();    
57         _volumeProperty->SetColor(_ctfun);
58         _volumeProperty->SetScalarOpacity(_tfun );
59
60         _newvol = vtkVolume::New();
61         _newvol->SetMapper(_volumeMapper );
62         _newvol->SetProperty(_volumeProperty );
63
64 //EED 2017-01-01 Migration VTK7
65 #if VTK_MAJOR_VERSION <= 5
66         _volumeMapper->SetInput( _vol );
67 #else
68         _volumeMapper->SetInputData( _vol );
69 #endif
70
71         _volumeMapper->Update();
72         _newvol->Update();
73 }
74
75
76 wxMaracasMultipleVolumeRendererManagerData::~wxMaracasMultipleVolumeRendererManagerData(){
77         
78         _tfun->Delete();
79         _ctfun->Delete();
80         _volumePlanes->Delete();
81
82
83 #if (VTK_MAJOR_VERSION <= 7) 
84         _compositeFunction->Delete();
85 #else 
86         // ..
87 #endif
88
89         _volumeMapper->Delete();
90
91         _volumeProperty->Delete();
92         _newvol->Delete();
93         
94 }
95 /**
96 **      Set Volume Color
97 **/
98 void wxMaracasMultipleVolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
99                                                                 std::vector<double>& red,
100                                                                 std::vector<double>& green,
101                                                                 std::vector<double>& blue)
102 {       
103         
104         _ctfun->RemoveAllPoints();
105         for(int i = 0; i < greylevelcolors.size();i++){
106                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
107                                 //std::cout<<"wxMaracasMultipleVolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
108         }               
109         _newvol->Update();      
110 }
111                                 
112 /**
113 **      Volume Opacity
114 **/
115 void wxMaracasMultipleVolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
116                 
117         _tfun->RemoveAllPoints();
118         for(int i = 0; i < greylevel.size();i++){
119                 _tfun->AddPoint(greylevel[i], value[i]);
120                         //std::cout<<"wxMaracasMultipleVolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
121         }
122     _newvol->Update();
123 }
124
125 /**
126 **      Check if the variables are setted correctly
127 **/
128 void wxMaracasMultipleVolumeRendererManagerData::checkInvariant()throw (char *)
129 {
130
131         
132 #if (VTK_MAJOR_VERSION <= 7) 
133         if(!_compositeFunction)
134         {
135                 throw "No composite function initialized";
136         }
137         if(!_MIPFunction)
138         {
139                 throw "No MIP function initialized";
140         }
141 #else 
142         // ..
143 #endif
144         if(!_volumeMapper)
145         {
146                 throw "No volume mapper initialized";
147         }
148 }
149
150 /**
151 **      Check if the variables are setted correctly
152 **/
153 void wxMaracasMultipleVolumeRendererManagerData::Update(){
154          _newvol->Update();
155 }
156 /**
157 **      get the prop3D 
158 **/
159 vtkProp3D* wxMaracasMultipleVolumeRendererManagerData::getProp3D(){
160         return this->_newvol;
161 }
162 /**
163 **      return the id from the daat
164 **/
165 int wxMaracasMultipleVolumeRendererManagerData::getId(){
166         return _id;
167 }
168 /**
169 **      set data id
170 **/
171 void wxMaracasMultipleVolumeRendererManagerData::setId(int propid){
172         _id = propid;
173 }
174
175 /**
176 **      Get the filanme
177 **/
178 std::string wxMaracasMultipleVolumeRendererManagerData::getDataname(){
179         return _dataname;
180 }
181 /**
182 ** Set the filanme
183 **/
184 void wxMaracasMultipleVolumeRendererManagerData::setDataname(std::string dataname){
185         _dataname = dataname;
186 }
187
188 void wxMaracasMultipleVolumeRendererManagerData::changeCompositeMIPFunction(int function) throw (char *)
189 {
190         checkInvariant();       
191 #if (VTK_MAJOR_VERSION <= 7) 
192         if(function == 0)
193         {
194                 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
195         }else{
196                 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
197         }
198 #else 
199         printf("EED   wxMaracasMultipleVolumeRendererManagerData::changeCompositeMIPFunction   Composite MIP  ..... ??");
200 #endif
201 }