source: branches/blt4/packages/vizservers/nanovis/Volume.h @ 2742

Last change on this file since 2742 was 2307, checked in by gah, 13 years ago

update from trunk

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