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