source: trunk/packages/vizservers/nanovis/Volume.h @ 1489

Last change on this file since 1489 was 1478, checked in by gah, 15 years ago

Fix volume management routines to handle deletion

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