]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasMultipleVolumeRendererManagerData.cxx
89d4dee29bad7d5d9b52c7740a9cb2bb62872372
[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         _volumeMapper->SetInput( _vol );
60         _volumeMapper->Update();
61         _newvol->Update();
62 }
63
64
65 wxMaracasMultipleVolumeRendererManagerData::~wxMaracasMultipleVolumeRendererManagerData(){
66         
67         _tfun->Delete();
68         _ctfun->Delete();
69         _volumePlanes->Delete();
70         _compositeFunction->Delete();
71         _volumeMapper->Delete();
72         _volumeProperty->Delete();
73         _newvol->Delete();
74         
75 }
76 /**
77 **      Set Volume Color
78 **/
79 void wxMaracasMultipleVolumeRendererManagerData::setVolumeColor(std::vector<double>& greylevelcolors,
80                                                                 std::vector<double>& red,
81                                                                 std::vector<double>& green,
82                                                                 std::vector<double>& blue)
83 {       
84         
85         _ctfun->RemoveAllPoints();
86         for(int i = 0; i < greylevelcolors.size();i++){
87                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
88                                 //std::cout<<"wxMaracasMultipleVolumeRendererManagerData::setVolumeColor "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
89         }               
90         _newvol->Update();      
91 }
92                                 
93 /**
94 **      Volume Opacity
95 **/
96 void wxMaracasMultipleVolumeRendererManagerData::setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value){
97                 
98         _tfun->RemoveAllPoints();
99         for(int i = 0; i < greylevel.size();i++){
100                 _tfun->AddPoint(greylevel[i], value[i]);
101                         //std::cout<<"wxMaracasMultipleVolumeRendererManagerData::setVolumeOpacity "<<greylevel[i]<<" "<< value[i]<<std::endl;
102         }
103     _newvol->Update();
104 }
105
106 /**
107 **      Check if the variables are setted correctly
108 **/
109 void wxMaracasMultipleVolumeRendererManagerData::checkInvariant()throw (char *){
110         if(!_compositeFunction){
111                 throw "No composite function initialized";
112         }
113         if(!_MIPFunction){
114                 throw "No MIP function initialized";
115         }
116         if(!_volumeMapper){
117                 throw "No volume mapper initialized";
118         }
119 }
120
121 /**
122 **      Check if the variables are setted correctly
123 **/
124 void wxMaracasMultipleVolumeRendererManagerData::Update(){
125          _newvol->Update();
126 }
127 /**
128 **      get the prop3D 
129 **/
130 vtkProp3D* wxMaracasMultipleVolumeRendererManagerData::getProp3D(){
131         return this->_newvol;
132 }
133 /**
134 **      return the id from the daat
135 **/
136 int wxMaracasMultipleVolumeRendererManagerData::getId(){
137         return _id;
138 }
139 /**
140 **      set data id
141 **/
142 void wxMaracasMultipleVolumeRendererManagerData::setId(int propid){
143         _id = propid;
144 }
145
146 /**
147 **      Get the filanme
148 **/
149 std::string wxMaracasMultipleVolumeRendererManagerData::getDataname(){
150         return _dataname;
151 }
152 /**
153 ** Set the filanme
154 **/
155 void wxMaracasMultipleVolumeRendererManagerData::setDataname(std::string dataname){
156         _dataname = dataname;
157 }
158
159 void wxMaracasMultipleVolumeRendererManagerData::changeCompositeMIPFunction(int function) throw (char *){
160         checkInvariant();
161         if(function == 0){
162                 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
163         }else{
164                 _volumeMapper->SetVolumeRayCastFunction(_MIPFunction);
165         }
166         
167 }