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

Last change on this file since 1156 was 932, checked in by gah, 17 years ago

Initial implementation of axis autoscaling

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