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