[1493] | 1 | |
---|
[835] | 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" |
---|
[929] | 27 | #include "AxisRange.h" |
---|
[1475] | 28 | #include "R2/R2Object.h" |
---|
[1478] | 29 | #include "TransferFunction.h" |
---|
[835] | 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 | |
---|
[1478] | 42 | class VolumeInterpolator; |
---|
[835] | 43 | |
---|
[1475] | 44 | |
---|
[1478] | 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 |
---|
[1493] | 57 | const char *_name; |
---|
[1370] | 58 | Vector3 _physical_min; |
---|
| 59 | Vector3 _physical_max; |
---|
[1478] | 60 | float* _data; |
---|
| 61 | |
---|
| 62 | int _n_components; |
---|
[835] | 63 | |
---|
[1478] | 64 | double _nonzero_min; |
---|
[835] | 65 | |
---|
[1478] | 66 | std::vector <CutPlane> _plane; // cut planes |
---|
[835] | 67 | |
---|
[1478] | 68 | Texture3D* _tex; // OpenGL texture storing the volume |
---|
[884] | 69 | |
---|
[835] | 70 | |
---|
[1478] | 71 | int _pointsetIndex; |
---|
[835] | 72 | |
---|
[1478] | 73 | Vector3 _location; |
---|
[835] | 74 | |
---|
[1478] | 75 | int _n_slices; // Number of slices when rendered. The greater |
---|
[835] | 76 | // the better quality, lower speed. |
---|
| 77 | |
---|
[1478] | 78 | bool _enabled; |
---|
| 79 | |
---|
| 80 | bool _data_enabled; // show/hide cloud of volume data |
---|
[835] | 81 | |
---|
[1478] | 82 | bool _outline_enabled; // show/hide outline around volume |
---|
[835] | 83 | |
---|
[1478] | 84 | Color _outline_color; // color for outline around volume |
---|
[835] | 85 | |
---|
[1478] | 86 | int _volume_type; // cubic or zincblende |
---|
[835] | 87 | |
---|
[1478] | 88 | int _iso_surface; |
---|
| 89 | |
---|
| 90 | public: |
---|
| 91 | enum { CUBIC, VOLQD, ZINCBLENDE }; |
---|
[835] | 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 | |
---|
[1478] | 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. |
---|
[870] | 110 | |
---|
[1478] | 111 | AxisRange xAxis, yAxis, zAxis, wAxis; |
---|
| 112 | static bool update_pending; |
---|
| 113 | static double valueMin, valueMax; |
---|
| 114 | |
---|
[1475] | 115 | public : |
---|
[835] | 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); |
---|
[1478] | 119 | ~Volume(); |
---|
[835] | 120 | |
---|
[1475] | 121 | public : |
---|
[1474] | 122 | void visible(bool value) { |
---|
[1478] | 123 | _enabled = value; |
---|
[1474] | 124 | } |
---|
| 125 | bool visible(void) { |
---|
[1478] | 126 | return _enabled; |
---|
[1474] | 127 | } |
---|
[1478] | 128 | void location(Vector3 loc) { |
---|
| 129 | _location = loc; |
---|
[1474] | 130 | } |
---|
[1478] | 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 | } |
---|
[1474] | 155 | |
---|
[1478] | 156 | double range_nzero_min() { return _nonzero_min; } |
---|
[835] | 157 | |
---|
[1478] | 158 | int n_slices(void) const { |
---|
| 159 | return _n_slices; |
---|
| 160 | } |
---|
| 161 | void n_slices(int n) { |
---|
| 162 | _n_slices = n; |
---|
| 163 | } |
---|
[870] | 164 | |
---|
[835] | 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 |
---|
[1474] | 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 | } |
---|
[1478] | 196 | void data_enabled(bool value) { |
---|
| 197 | _data_enabled = value; |
---|
[1474] | 198 | } |
---|
[1478] | 199 | bool data_enabled(void) { |
---|
| 200 | return _data_enabled; |
---|
[1474] | 201 | } |
---|
| 202 | void outline(bool value) { |
---|
[1478] | 203 | _outline_enabled = value; |
---|
[1474] | 204 | } |
---|
| 205 | bool outline(void) { |
---|
[1478] | 206 | return _outline_enabled; |
---|
[1474] | 207 | } |
---|
[1478] | 208 | TransferFunction *transferFunction(void) { |
---|
| 209 | return _tfPtr; |
---|
| 210 | } |
---|
| 211 | void transferFunction(TransferFunction *tfPtr) { |
---|
| 212 | _tfPtr = tfPtr; |
---|
| 213 | } |
---|
[835] | 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 |
---|
[1370] | 220 | |
---|
| 221 | void setPhysicalBBox(const Vector3& min, const Vector3& max); |
---|
| 222 | Vector3& getPhysicalBBoxMin(); |
---|
| 223 | Vector3& getPhysicalBBoxMax(); |
---|
[1475] | 224 | |
---|
[1493] | 225 | const char *name(void) { |
---|
| 226 | return _name; |
---|
[1478] | 227 | } |
---|
[1493] | 228 | void name(const char *name) { |
---|
| 229 | _name = name; |
---|
[1478] | 230 | } |
---|
[835] | 231 | }; |
---|
| 232 | |
---|
[849] | 233 | inline |
---|
[1478] | 234 | int Volume::add_cutplane(int orientation, float location) { |
---|
| 235 | _plane.push_back(CutPlane(1, 0.5)); |
---|
| 236 | return _plane.size() - 1; |
---|
[849] | 237 | } |
---|
| 238 | |
---|
[927] | 239 | inline void |
---|
| 240 | Volume::enable_cutplane(int index) |
---|
| 241 | { |
---|
[849] | 242 | //assert(index < plane.size()); |
---|
[1478] | 243 | _plane[index].enabled = true; |
---|
[849] | 244 | } |
---|
[927] | 245 | inline void |
---|
| 246 | Volume::disable_cutplane(int index) |
---|
| 247 | { |
---|
[849] | 248 | //assert(index < plane.size()); |
---|
[1478] | 249 | _plane[index].enabled = false; |
---|
[849] | 250 | } |
---|
| 251 | |
---|
[927] | 252 | inline void |
---|
| 253 | Volume::move_cutplane(int index, float location) |
---|
| 254 | { |
---|
[849] | 255 | //assert(index < plane.size()); |
---|
[1478] | 256 | _plane[index].offset = location; |
---|
[849] | 257 | } |
---|
| 258 | |
---|
[927] | 259 | inline CutPlane* |
---|
| 260 | Volume::get_cutplane(int index) |
---|
| 261 | { |
---|
[849] | 262 | //assert(index < plane.size()); |
---|
[1478] | 263 | return &_plane[index]; |
---|
[849] | 264 | } |
---|
| 265 | |
---|
[927] | 266 | inline int |
---|
| 267 | Volume::get_cutplane_count() |
---|
| 268 | { |
---|
[1478] | 269 | return _plane.size(); |
---|
[849] | 270 | } |
---|
| 271 | |
---|
[927] | 272 | inline bool |
---|
| 273 | Volume::cutplane_is_enabled(int index) |
---|
| 274 | { |
---|
[849] | 275 | //assert(index < plane.size()); |
---|
[1478] | 276 | return _plane[index].enabled; |
---|
[849] | 277 | } |
---|
| 278 | |
---|
[927] | 279 | inline void |
---|
| 280 | Volume::set_size(float s) |
---|
| 281 | { |
---|
[849] | 282 | size = s; |
---|
[1478] | 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; |
---|
[849] | 286 | } |
---|
| 287 | |
---|
[927] | 288 | inline void |
---|
| 289 | Volume::set_outline_color(float *rgb) |
---|
| 290 | { |
---|
[1478] | 291 | _outline_color = Color(rgb[0],rgb[1],rgb[2]); |
---|
[849] | 292 | } |
---|
| 293 | |
---|
[927] | 294 | inline void |
---|
| 295 | Volume::get_outline_color(float *rgb) |
---|
| 296 | { |
---|
[1478] | 297 | _outline_color.GetRGB(rgb); |
---|
[849] | 298 | } |
---|
| 299 | |
---|
[927] | 300 | inline void |
---|
| 301 | Volume::set_label(int axis, const char* txt) |
---|
| 302 | { |
---|
[849] | 303 | label[axis] = txt; |
---|
| 304 | } |
---|
[870] | 305 | |
---|
[927] | 306 | |
---|
| 307 | inline void |
---|
[1370] | 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 | |
---|
[1475] | 336 | |
---|
[835] | 337 | #endif |
---|