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