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