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

Last change on this file since 1474 was 1474, checked in by gah, 15 years ago
File size: 7.2 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    Vector3 _physical_min;
57    Vector3 _physical_max;
58
59    AxisRange xAxis, yAxis, zAxis, wAxis;
60    static bool update_pending;
61    static double valueMin, valueMax;
62
63    int n_components;
64
65    double nonzero_min;
66   
67    std::vector <CutPlane> plane; // cut planes
68
69    Texture3D* tex;             // OpenGL texture storing the volume
70
71    float* _data;
72   
73    int pointsetIndex;
74
75    Vector3 location;
76
77    bool enabled;
78
79    int n_slice;                // Number of slices when rendered. The greater
80                                // the better quality, lower speed.
81
82    float _specular;            // specular lighting parameter
83    float _diffuse;             // diffuse lighting parameter
84    float _opacity_scale;       // The scale multiplied to the opacity assigned
85                                // by the transfer function.  Rule of thumb:
86                                // higher opacity_scale the object is to appear
87                                // like plastic
88   
89    bool data_enabled;          // show/hide cloud of volume data
90   
91    bool outline_enabled;       // show/hide outline around volume
92
93    Color outline_color;        // color for outline around volume
94
95    int volume_type;            // cubic or zincblende
96   
97    float aspect_ratio_width;
98    float aspect_ratio_height;
99    float aspect_ratio_depth;
100
101    NVISid id;                  //OpenGL textue identifier (==tex->id)
102
103    int iso_surface;
104
105    Volume(float x, float y, float z, int width, int height, int depth,
106           float size, int n_component, float* data, double vmin, double vmax,
107           double nonzero_min);
108
109 
110    ~Volume();
111       
112    void visible(bool value) {
113        enabled = value;
114    }
115    bool visible(void) {
116        return enabled;
117    }
118    void move(Vector3 _loc) {
119        location = _loc;
120    }
121
122    Vector3* get_location();
123   
124    void set_isosurface(int iso);
125    int get_isosurface() const;
126
127    double range_nzero_min() { return nonzero_min; }
128   
129    void set_n_slice(int val);  // set number of slices
130    int get_n_slice();          // return number of slices
131   
132    void set_size(float s);     //set the drawing size of volume
133
134    //methods related to cutplanes
135    int add_cutplane(int _orientation, float _location); // add a plane and
136                                                         // returns its index
137    void enable_cutplane(int index);
138    void disable_cutplane(int index);
139    void move_cutplane(int index, float _location);
140    CutPlane* get_cutplane(int index);
141    int get_cutplane_count();  //returns the number of cutplanes in the volume
142    bool cutplane_is_enabled(int index); //check if a cutplane is enabled
143
144    //methods related to shading. These parameters are per volume
145    float specular(void) {
146        return _specular;
147    }
148    void specular(float value) {
149        _specular = value;
150    }
151    float diffuse(void) {
152        return _diffuse;
153    }
154    void diffuse(float value) {
155        _diffuse = value;
156    }
157    float opacity_scale(void) {
158        return _opacity_scale;
159    }
160    void opacity_scale(float value) {
161        _opacity_scale = value;
162    }
163    void data(bool value) {
164        data_enabled = value;
165    }
166    bool data(void) {
167        return data_enabled;
168    }
169    void outline(bool value) {
170        outline_enabled = value;
171    }
172    bool outline(void) {
173        return outline_enabled;
174    }
175    void set_outline_color(float* rgb);
176    void get_outline_color(float* rgb);
177   
178    void set_label(int axis, const char* txt); // change the label displayed
179                                               // on an axis
180    std::string label[3];       // the labels along each axis 0:x , 1:y, 2:z
181
182    void setPhysicalBBox(const Vector3& min, const Vector3& max);
183    Vector3& getPhysicalBBoxMin();
184    Vector3& getPhysicalBBoxMax();
185};
186
187inline Vector3* Volume::get_location() {
188    return &location;
189}
190inline
191int Volume::add_cutplane(int _orientation, float _location) {
192    plane.push_back(CutPlane(1, 0.5));
193    return plane.size() - 1;
194}
195
196inline void
197Volume::enable_cutplane(int index)
198{
199    //assert(index < plane.size());
200    plane[index].enabled = true;
201}
202inline void
203Volume::disable_cutplane(int index)
204{
205    //assert(index < plane.size());
206    plane[index].enabled = false;
207}
208
209inline void
210Volume::move_cutplane(int index, float location)
211{
212    //assert(index < plane.size());
213    plane[index].offset = location;
214}
215
216inline CutPlane*
217Volume::get_cutplane(int index)
218{
219    //assert(index < plane.size());
220    return &plane[index];
221}
222
223inline int
224Volume::get_cutplane_count()
225{
226    return plane.size();
227}
228
229inline bool
230Volume::cutplane_is_enabled(int index)
231{
232    //assert(index < plane.size());
233    return plane[index].enabled;
234}
235
236inline void
237Volume::set_n_slice(int n)
238{
239    n_slice = n;
240}
241
242inline int
243Volume::get_n_slice()
244{
245    return n_slice;
246}
247
248inline void
249Volume::set_size(float s)
250{
251    size = s;
252    aspect_ratio_width = s*tex->aspect_ratio_width;
253    aspect_ratio_height = s*tex->aspect_ratio_height;
254    aspect_ratio_depth = s*tex->aspect_ratio_depth;
255}
256
257inline void
258Volume::set_outline_color(float *rgb)
259{
260    outline_color = Color(rgb[0],rgb[1],rgb[2]);
261}
262
263inline void
264Volume::get_outline_color(float *rgb)
265{
266    outline_color.GetRGB(rgb);
267}
268
269inline void
270Volume::set_label(int axis, const char* txt)
271{
272    label[axis] = txt;
273}
274
275inline int
276Volume::get_isosurface() const
277{
278    return iso_surface;
279}
280
281inline void
282Volume::set_isosurface(int iso)
283{
284    iso_surface = iso;
285}
286
287inline void
288Volume::setPhysicalBBox(const Vector3& min, const Vector3& max)
289{
290        _physical_min = min;
291        _physical_max = max;
292
293/*
294        aspect_ratio_width = size * 1;
295        aspect_ratio_height = size * (max.y - min.y) / (max.x - min.x);
296        aspect_ratio_depth = size* (max.z - min.z) / (max.x - min.x);
297
298        location.x = -0.5;
299        location.y = -0.5* aspect_ratio_height;
300        location.z = -0.5* aspect_ratio_depth;
301*/
302}
303
304inline Vector3&
305Volume::getPhysicalBBoxMin()
306{
307    return _physical_min;
308}
309
310inline Vector3&
311Volume::getPhysicalBBoxMax()
312{
313    return _physical_max;
314}
315
316#endif
Note: See TracBrowser for help on using the repository browser.