]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/VTKObjects/VolumeRenderer/volumerenderermanagerdata.h
#3230 vtk8itk4wx3-mingw64 MACOS
[creaMaracasVisu.git] / lib / Kernel / VTKObjects / VolumeRenderer / volumerenderermanagerdata.h
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 #ifndef VolumeRendererManagerData_H_
27 #define VolumeRendererManagerData_H_
28
29 #include "vtkCommand.h"
30
31 #if (VTK_MAJOR_VERSION <= 7) 
32         #include "vtkVolumeRayCastCompositeFunction.h"
33         #include "vtkVolumeRayCastMIPFunction.h"
34 #else 
35         // ..
36 #endif
37
38
39 #include <vtkPlanes.h>
40 #include <vtkVolumeMapper.h>
41
42 #include <vtkVolumeProperty.h>
43 #include <vtkVolume.h>
44 #include <vtkPiecewiseFunction.h>
45 #include <vtkColorTransferFunction.h>
46 #include <vtkImageData.h>
47 #include <vtkProp3D.h>
48 #include <vtkRenderer.h>
49 #include <vtkLookupTable.h>
50 #include <vtkBoxWidget.h>
51 #include <vtkAbstractMapper.h>
52
53
54 #include <vector>
55
56 using namespace std;
57
58 // Callback for moving the planes from the box widget to the mapper
59 class vtkBoxWidgetCallback : public vtkCommand
60 {
61 public:
62   static vtkBoxWidgetCallback *New()
63     { return new vtkBoxWidgetCallback; }
64   virtual void Execute(vtkObject *caller, unsigned long, void*)
65     {
66       vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
67       vtkPlanes *planes = vtkPlanes::New();
68       widget->GetPlanes(planes);
69       for(unsigned i = 0; i< VectorMapper.size(); i++){
70           VectorMapper[i]->SetClippingPlanes(planes);
71       }
72       planes->Delete();
73     }
74   void SetMapper(vtkAbstractMapper* m)
75     { if(VectorMapper.size() == 0){
76           VectorMapper.push_back(m);
77       }else{
78           VectorMapper[0] = m;
79       }
80     }
81
82   void AddMapper(vtkAbstractMapper* m){
83       VectorMapper.push_back(m);
84   }
85
86 protected:
87   vtkBoxWidgetCallback()
88     {  }
89
90   vector< vtkAbstractMapper* > VectorMapper;
91 };
92
93
94 class VolumeRendererManagerData  : public vtkObject{
95
96 public:
97         VolumeRendererManagerData(vtkImageData* vol, std::string dataname="");
98         VolumeRendererManagerData(vtkImageData* vol, vtkRenderer* render, std::string dataname="");
99         VolumeRendererManagerData(vtkImageData* vol, bool usegpu);
100
101
102         ~VolumeRendererManagerData();
103
104         /**
105         **      Check if the variables are setted correctly
106         **/
107         void checkInvariant()throw (char *);
108
109         /**
110         ** Updates volume
111         **/
112         void Update();
113
114         /**
115         **      get the prop3D
116         **/
117         vtkProp3D* getProp3D();
118
119         /**
120         **      return the id from the daat
121         **/
122         int getId();
123
124         /**
125         **      set data id
126         **/
127         void setId(int propid);
128
129         /**
130         **      Get the filanme
131         **/
132     std::string getDataname();
133
134         /**
135         ** Set the filanme
136         **/
137     void setDataname(std::string dataname);
138
139         /**
140         **      Set Volume Color
141         **/
142         void setVolumeColor(std::vector<double>& greylevel,
143                                                                         std::vector<double>& red,
144                                                                         std::vector<double>& green,
145                                                                         std::vector<double>& blue);
146
147         /**
148         **      Volume Opacity
149         **/
150         void setVolumeOpacity(std::vector<double> greylevel,std::vector<double> value);
151         /**
152         **      Volume Opacity
153         **/
154         void setVolumeOpacity(std::vector<double> greylevel,double value);
155
156         vtkPiecewiseFunction* GetTransferFunction(){
157                 return _tfun;
158         }
159
160         vtkColorTransferFunction* GetColorFunction(){
161                 return _ctfun;
162         }
163
164         void changeCompositeMIPFunction(int function);
165
166         void SetLookupTable(vtkLookupTable* lookuptable);
167
168         void EnableBoundingBox(vtkRenderWindowInteractor* interactor);
169         void DisableBoundingBox();
170
171         /**
172           changes the interoplation type of the volume
173           type = 0 linear
174           type = 1 nearest
175            */
176         void changeInterpolationType(int type);
177
178
179         vtkGetMacro(BoxWidget, vtkBoxWidget*);
180         vtkSetMacro(BoxWidget, vtkBoxWidget*);
181
182         vtkGetMacro(VolumeMapper, vtkVolumeMapper*);
183         vtkSetMacro(VolumeMapper, vtkVolumeMapper*);
184
185         void SetColorTransferFunction(int i, vtkColorTransferFunction* colorf);
186
187         void SetIndependentComponents(bool independent);
188 protected:
189         /**
190          * Prop 3D (data actor)
191          */
192         vtkImageData* _vol;
193         /**
194          *  Dataname given by the user (ex. filename)
195          **/
196         std::string _dataname;
197
198
199 private:
200
201         /*
202          * id of the data
203          */
204         int _id;
205
206 #if (VTK_MAJOR_VERSION <= 7) 
207         vtkVolumeRayCastCompositeFunction       *_compositeFunction;
208         vtkVolumeRayCastMIPFunction                     *_MIPFunction;
209 #else 
210                 //..
211 #endif
212
213         vtkPlanes                                                       *_volumePlanes; 
214         vtkVolumeProperty                                       *_volumeProperty;
215         vtkVolume                                                       *_newvol;
216         vtkPiecewiseFunction                            *_tfun;
217         vtkColorTransferFunction                        *_ctfun;
218         /**
219         ** boxwidget to control the volume
220         **/
221         vtkBoxWidget                                            *BoxWidget;
222         vtkVolumeMapper                                         *VolumeMapper;
223
224         void Initialize(vtkImageData* vol, std::string dataname, bool usegpu = false);
225
226
227 };
228
229 #endif /*VolumeRendererManagerData_H_*/