1 | |
---|
2 | /* |
---|
3 | * ---------------------------------------------------------------------- |
---|
4 | * Volume.h: 3d volume class |
---|
5 | * |
---|
6 | * ====================================================================== |
---|
7 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
8 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
9 | * |
---|
10 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
11 | * |
---|
12 | * See the file "license.terms" for information on usage and |
---|
13 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | * ====================================================================== |
---|
15 | */ |
---|
16 | |
---|
17 | #ifndef _VOLUME_H_ |
---|
18 | #define _VOLUME_H_ |
---|
19 | |
---|
20 | #include <string> |
---|
21 | #include <vector> |
---|
22 | |
---|
23 | #include "define.h" |
---|
24 | #include "Color.h" |
---|
25 | #include "Texture3D.h" |
---|
26 | #include "Vector3.h" |
---|
27 | #include "AxisRange.h" |
---|
28 | #include "R2/R2Object.h" |
---|
29 | #include "TransferFunction.h" |
---|
30 | |
---|
31 | struct CutPlane{ |
---|
32 | int orient; // orientation - 1: xy slice, 2: yz slice, 3: |
---|
33 | // xz slice |
---|
34 | float offset; // normalized offset [0,1] in the volume |
---|
35 | bool enabled; |
---|
36 | |
---|
37 | CutPlane(int _orient, float _offset): orient(_orient), offset(_offset), |
---|
38 | enabled(true) { |
---|
39 | } |
---|
40 | }; |
---|
41 | |
---|
42 | class VolumeInterpolator; |
---|
43 | |
---|
44 | |
---|
45 | class Volume { |
---|
46 | protected: |
---|
47 | TransferFunction *_tfPtr; // This is the designated transfer |
---|
48 | // to use to render this volume. |
---|
49 | |
---|
50 | float _specular; // Specular lighting parameter |
---|
51 | float _diffuse; // Diffuse lighting parameter |
---|
52 | float _opacity_scale; // The scale multiplied to the opacity |
---|
53 | // assigned by the transfer function. |
---|
54 | // Rule of thumb: higher opacity_scale |
---|
55 | // the object is to appear like |
---|
56 | // plastic |
---|
57 | const char *_name; |
---|
58 | Vector3 _physical_min; |
---|
59 | Vector3 _physical_max; |
---|
60 | float* _data; |
---|
61 | |
---|
62 | int _n_components; |
---|
63 | |
---|
64 | double _nonzero_min; |
---|
65 | |
---|
66 | std::vector <CutPlane> _plane; // cut planes |
---|
67 | |
---|
68 | Texture3D* _tex; // OpenGL texture storing the volume |
---|
69 | |
---|
70 | |
---|
71 | int _pointsetIndex; |
---|
72 | |
---|
73 | Vector3 _location; |
---|
74 | |
---|
75 | int _n_slices; // Number of slices when rendered. The greater |
---|
76 | // the better quality, lower speed. |
---|
77 | |
---|
78 | bool _enabled; |
---|
79 | |
---|
80 | bool _data_enabled; // show/hide cloud of volume data |
---|
81 | |
---|
82 | bool _outline_enabled; // show/hide outline around volume |
---|
83 | |
---|
84 | Color _outline_color; // color for outline around volume |
---|
85 | |
---|
86 | int _volume_type; // cubic or zincblende |
---|
87 | |
---|
88 | int _iso_surface; |
---|
89 | |
---|
90 | public: |
---|
91 | enum { CUBIC, VOLQD, ZINCBLENDE }; |
---|
92 | float aspect_ratio_width; |
---|
93 | float aspect_ratio_height; |
---|
94 | float aspect_ratio_depth; |
---|
95 | |
---|
96 | NVISid id; //OpenGL textue identifier (==tex->id) |
---|
97 | |
---|
98 | int width; // The resolution of the data (how many points |
---|
99 | // in each direction. |
---|
100 | int height; // It is different from the size of the volume |
---|
101 | // object drawn on screen. |
---|
102 | int depth; // Width, height and depth together determing |
---|
103 | // the proprotion of the volume ONLY. |
---|
104 | float size; // This is the scaling factor that will size |
---|
105 | // the volume on screen. A render program |
---|
106 | // drawing different objects, always knows how |
---|
107 | // large an object is in relation to other |
---|
108 | // objects. This size is provided by the |
---|
109 | // render engine. |
---|
110 | |
---|
111 | AxisRange xAxis, yAxis, zAxis, wAxis; |
---|
112 | static bool update_pending; |
---|
113 | static double valueMin, valueMax; |
---|
114 | |
---|
115 | public : |
---|
116 | Volume(float x, float y, float z, int width, int height, int depth, |
---|
117 | float size, int n_component, float* data, double vmin, double vmax, |
---|
118 | double nonzero_min); |
---|
119 | ~Volume(); |
---|
120 | |
---|
121 | public : |
---|
122 | void visible(bool value) { |
---|
123 | _enabled = value; |
---|
124 | } |
---|
125 | bool visible(void) { |
---|
126 | return _enabled; |
---|
127 | } |
---|
128 | void location(Vector3 loc) { |
---|
129 | _location = loc; |
---|
130 | } |
---|
131 | Vector3 location(void) const { |
---|
132 | return _location; |
---|
133 | } |
---|
134 | int isosurface(void) const { |
---|
135 | return _iso_surface; |
---|
136 | } |
---|
137 | void isosurface(int iso) { |
---|
138 | _iso_surface = iso; |
---|
139 | } |
---|
140 | int n_components(void) { |
---|
141 | return _n_components; |
---|
142 | } |
---|
143 | double nonzero_min(void) { |
---|
144 | return _nonzero_min; |
---|
145 | } |
---|
146 | int volume_type(void) { |
---|
147 | return _volume_type; |
---|
148 | } |
---|
149 | float *data(void) { |
---|
150 | return _data; |
---|
151 | } |
---|
152 | Texture3D *tex(void) { |
---|
153 | return _tex; |
---|
154 | } |
---|
155 | |
---|
156 | double range_nzero_min() { return _nonzero_min; } |
---|
157 | |
---|
158 | int n_slices(void) const { |
---|
159 | return _n_slices; |
---|
160 | } |
---|
161 | void n_slices(int n) { |
---|
162 | _n_slices = n; |
---|
163 | } |
---|
164 | |
---|
165 | void set_size(float s); //set the drawing size of volume |
---|
166 | |
---|
167 | //methods related to cutplanes |
---|
168 | int add_cutplane(int _orientation, float _location); // add a plane and |
---|
169 | // returns its index |
---|
170 | void enable_cutplane(int index); |
---|
171 | void disable_cutplane(int index); |
---|
172 | void move_cutplane(int index, float _location); |
---|
173 | CutPlane* get_cutplane(int index); |
---|
174 | int get_cutplane_count(); //returns the number of cutplanes in the volume |
---|
175 | bool cutplane_is_enabled(int index); //check if a cutplane is enabled |
---|
176 | |
---|
177 | //methods related to shading. These parameters are per volume |
---|
178 | float specular(void) { |
---|
179 | return _specular; |
---|
180 | } |
---|
181 | void specular(float value) { |
---|
182 | _specular = value; |
---|
183 | } |
---|
184 | float diffuse(void) { |
---|
185 | return _diffuse; |
---|
186 | } |
---|
187 | void diffuse(float value) { |
---|
188 | _diffuse = value; |
---|
189 | } |
---|
190 | float opacity_scale(void) { |
---|
191 | return _opacity_scale; |
---|
192 | } |
---|
193 | void opacity_scale(float value) { |
---|
194 | _opacity_scale = value; |
---|
195 | } |
---|
196 | void data_enabled(bool value) { |
---|
197 | _data_enabled = value; |
---|
198 | } |
---|
199 | bool data_enabled(void) { |
---|
200 | return _data_enabled; |
---|
201 | } |
---|
202 | void outline(bool value) { |
---|
203 | _outline_enabled = value; |
---|
204 | } |
---|
205 | bool outline(void) { |
---|
206 | return _outline_enabled; |
---|
207 | } |
---|
208 | TransferFunction *transferFunction(void) { |
---|
209 | return _tfPtr; |
---|
210 | } |
---|
211 | void transferFunction(TransferFunction *tfPtr) { |
---|
212 | _tfPtr = tfPtr; |
---|
213 | } |
---|
214 | void set_outline_color(float* rgb); |
---|
215 | void get_outline_color(float* rgb); |
---|
216 | |
---|
217 | void set_label(int axis, const char* txt); // change the label displayed |
---|
218 | // on an axis |
---|
219 | std::string label[3]; // the labels along each axis 0:x , 1:y, 2:z |
---|
220 | |
---|
221 | void setPhysicalBBox(const Vector3& min, const Vector3& max); |
---|
222 | Vector3& getPhysicalBBoxMin(); |
---|
223 | Vector3& getPhysicalBBoxMax(); |
---|
224 | |
---|
225 | const char *name(void) { |
---|
226 | return _name; |
---|
227 | } |
---|
228 | void name(const char *name) { |
---|
229 | _name = name; |
---|
230 | } |
---|
231 | }; |
---|
232 | |
---|
233 | inline |
---|
234 | int Volume::add_cutplane(int orientation, float location) { |
---|
235 | _plane.push_back(CutPlane(1, 0.5)); |
---|
236 | return _plane.size() - 1; |
---|
237 | } |
---|
238 | |
---|
239 | inline void |
---|
240 | Volume::enable_cutplane(int index) |
---|
241 | { |
---|
242 | //assert(index < plane.size()); |
---|
243 | _plane[index].enabled = true; |
---|
244 | } |
---|
245 | inline void |
---|
246 | Volume::disable_cutplane(int index) |
---|
247 | { |
---|
248 | //assert(index < plane.size()); |
---|
249 | _plane[index].enabled = false; |
---|
250 | } |
---|
251 | |
---|
252 | inline void |
---|
253 | Volume::move_cutplane(int index, float location) |
---|
254 | { |
---|
255 | //assert(index < plane.size()); |
---|
256 | _plane[index].offset = location; |
---|
257 | } |
---|
258 | |
---|
259 | inline CutPlane* |
---|
260 | Volume::get_cutplane(int index) |
---|
261 | { |
---|
262 | //assert(index < plane.size()); |
---|
263 | return &_plane[index]; |
---|
264 | } |
---|
265 | |
---|
266 | inline int |
---|
267 | Volume::get_cutplane_count() |
---|
268 | { |
---|
269 | return _plane.size(); |
---|
270 | } |
---|
271 | |
---|
272 | inline bool |
---|
273 | Volume::cutplane_is_enabled(int index) |
---|
274 | { |
---|
275 | //assert(index < plane.size()); |
---|
276 | return _plane[index].enabled; |
---|
277 | } |
---|
278 | |
---|
279 | inline void |
---|
280 | Volume::set_size(float s) |
---|
281 | { |
---|
282 | size = s; |
---|
283 | aspect_ratio_width = s * _tex->aspect_ratio_width; |
---|
284 | aspect_ratio_height = s * _tex->aspect_ratio_height; |
---|
285 | aspect_ratio_depth = s * _tex->aspect_ratio_depth; |
---|
286 | } |
---|
287 | |
---|
288 | inline void |
---|
289 | Volume::set_outline_color(float *rgb) |
---|
290 | { |
---|
291 | _outline_color = Color(rgb[0],rgb[1],rgb[2]); |
---|
292 | } |
---|
293 | |
---|
294 | inline void |
---|
295 | Volume::get_outline_color(float *rgb) |
---|
296 | { |
---|
297 | _outline_color.GetRGB(rgb); |
---|
298 | } |
---|
299 | |
---|
300 | inline void |
---|
301 | Volume::set_label(int axis, const char* txt) |
---|
302 | { |
---|
303 | label[axis] = txt; |
---|
304 | } |
---|
305 | |
---|
306 | |
---|
307 | inline void |
---|
308 | Volume::setPhysicalBBox(const Vector3& min, const Vector3& max) |
---|
309 | { |
---|
310 | _physical_min = min; |
---|
311 | _physical_max = max; |
---|
312 | |
---|
313 | /* |
---|
314 | aspect_ratio_width = size * 1; |
---|
315 | aspect_ratio_height = size * (max.y - min.y) / (max.x - min.x); |
---|
316 | aspect_ratio_depth = size* (max.z - min.z) / (max.x - min.x); |
---|
317 | |
---|
318 | location.x = -0.5; |
---|
319 | location.y = -0.5* aspect_ratio_height; |
---|
320 | location.z = -0.5* aspect_ratio_depth; |
---|
321 | */ |
---|
322 | } |
---|
323 | |
---|
324 | inline Vector3& |
---|
325 | Volume::getPhysicalBBoxMin() |
---|
326 | { |
---|
327 | return _physical_min; |
---|
328 | } |
---|
329 | |
---|
330 | inline Vector3& |
---|
331 | Volume::getPhysicalBBoxMax() |
---|
332 | { |
---|
333 | return _physical_max; |
---|
334 | } |
---|
335 | |
---|
336 | |
---|
337 | #endif |
---|