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