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

Last change on this file since 1380 was 1370, checked in by vrinside, 15 years ago

improving the flow vis engine

  • particle advection for multiple vector field
  • specifying multiple advection planes
  • specifying the position of a particle injection plane
  • specifying the axis of a particle injection plane
  • specifying the visibility of particle injection planes
  • specifying the particle color for each particle injection plane
  • rendering device shapes

[NOTE] Currently, I commented out with the MACRO NEW_FLOW_ENGINE in config
To use this, please comment NEW_FLOW_ENGINE in

File size: 8.0 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 enable();              // VolumeRenderer will render an enabled
113                                // volume and its cutplanes
114    void disable();
115    void move(Vector3 _loc);
116    bool is_enabled();
117    Vector3* get_location();
118   
119    void set_isosurface(int iso);
120    int get_isosurface() const;
121
122    double range_nzero_min() { return nonzero_min; }
123   
124    void set_n_slice(int val);  // set number of slices
125    int get_n_slice();          // return number of slices
126   
127    void set_size(float s);     //set the drawing size of volume
128
129    //methods related to cutplanes
130    int add_cutplane(int _orientation, float _location); // add a plane and
131                                                         // returns its index
132    void enable_cutplane(int index);
133    void disable_cutplane(int index);
134    void move_cutplane(int index, float _location);
135    CutPlane* get_cutplane(int index);
136    int get_cutplane_count();  //returns the number of cutplanes in the volume
137    bool cutplane_is_enabled(int index); //check if a cutplane is enabled
138
139    //methods related to shading. These parameters are per volume
140    float get_specular();
141    float get_diffuse();
142    float get_opacity_scale();
143    void set_specular(float s);
144    void set_diffuse(float d);
145    void set_opacity_scale(float s);
146   
147    void enable_data();
148    void disable_data();
149    bool data_is_enabled();
150   
151    void enable_outline();
152    void disable_outline();
153    bool outline_is_enabled();
154    void set_outline_color(float* rgb);
155    void get_outline_color(float* rgb);
156   
157    void set_label(int axis, const char* txt); // change the label displayed
158                                               // on an axis
159    std::string label[3];       // the labels along each axis 0:x , 1:y, 2:z
160
161    void setPhysicalBBox(const Vector3& min, const Vector3& max);
162    Vector3& getPhysicalBBoxMin();
163    Vector3& getPhysicalBBoxMax();
164};
165
166inline void Volume::enable() {
167    enabled = true;
168}
169inline void Volume::disable() {
170    enabled = false;
171}
172inline void Volume::move(Vector3 _loc) {
173    location = _loc;
174}
175inline bool Volume::is_enabled() {
176    return enabled;
177}
178inline Vector3* Volume::get_location() {
179    return &location;
180}
181inline
182int Volume::add_cutplane(int _orientation, float _location) {
183    plane.push_back(CutPlane(1, 0.5));
184    return plane.size() - 1;
185}
186
187inline void
188Volume::enable_cutplane(int index)
189{
190    //assert(index < plane.size());
191    plane[index].enabled = true;
192}
193inline void
194Volume::disable_cutplane(int index)
195{
196    //assert(index < plane.size());
197    plane[index].enabled = false;
198}
199
200inline void
201Volume::move_cutplane(int index, float location)
202{
203    //assert(index < plane.size());
204    plane[index].offset = location;
205}
206
207inline CutPlane*
208Volume::get_cutplane(int index)
209{
210    //assert(index < plane.size());
211    return &plane[index];
212}
213
214inline int
215Volume::get_cutplane_count()
216{
217    return plane.size();
218}
219
220inline bool
221Volume::cutplane_is_enabled(int index)
222{
223    //assert(index < plane.size());
224    return plane[index].enabled;
225}
226
227inline void
228Volume::set_n_slice(int n)
229{
230    n_slice = n;
231}
232
233inline int
234Volume::get_n_slice()
235{
236    return n_slice;
237}
238
239inline void
240Volume::set_size(float s)
241{
242    size = s;
243    aspect_ratio_width = s*tex->aspect_ratio_width;
244    aspect_ratio_height = s*tex->aspect_ratio_height;
245    aspect_ratio_depth = s*tex->aspect_ratio_depth;
246}
247
248inline float
249Volume::get_specular()
250{
251    return specular;
252}
253
254inline float
255Volume::get_diffuse()
256{
257    return diffuse;
258}
259
260inline float
261Volume::get_opacity_scale()
262{
263    return opacity_scale;
264}
265
266inline void
267Volume::set_specular(float s)
268{
269    specular = s;
270}
271
272inline void
273Volume::set_diffuse(float d)
274{
275    diffuse = d;
276}
277
278inline void
279Volume::set_opacity_scale(float s)
280{
281    opacity_scale = s;
282}
283
284inline void
285Volume::enable_data()
286{
287    data_enabled = true;
288}
289
290inline void
291Volume::disable_data()
292{
293    data_enabled = false;
294}
295
296inline bool
297Volume::data_is_enabled()
298{
299    return data_enabled;
300}
301
302inline void
303Volume::enable_outline()
304{
305    outline_enabled = true;
306}
307
308inline void
309Volume::disable_outline()
310{
311    outline_enabled = false;
312}
313
314inline bool
315Volume::outline_is_enabled()
316{
317    return outline_enabled;
318}
319
320inline void
321Volume::set_outline_color(float *rgb)
322{
323    outline_color = Color(rgb[0],rgb[1],rgb[2]);
324}
325
326inline void
327Volume::get_outline_color(float *rgb)
328{
329    outline_color.GetRGB(rgb);
330}
331
332inline void
333Volume::set_label(int axis, const char* txt)
334{
335    label[axis] = txt;
336}
337
338inline int
339Volume::get_isosurface() const
340{
341    return iso_surface;
342}
343
344inline void
345Volume::set_isosurface(int iso)
346{
347    iso_surface = iso;
348}
349
350inline void
351Volume::setPhysicalBBox(const Vector3& min, const Vector3& max)
352{
353        _physical_min = min;
354        _physical_max = max;
355
356/*
357        aspect_ratio_width = size * 1;
358        aspect_ratio_height = size * (max.y - min.y) / (max.x - min.x);
359        aspect_ratio_depth = size* (max.z - min.z) / (max.x - min.x);
360
361        location.x = -0.5;
362        location.y = -0.5* aspect_ratio_height;
363        location.z = -0.5* aspect_ratio_depth;
364*/
365}
366
367inline Vector3&
368Volume::getPhysicalBBoxMin()
369{
370    return _physical_min;
371}
372
373inline Vector3&
374Volume::getPhysicalBBoxMax()
375{
376    return _physical_max;
377}
378
379#endif
Note: See TracBrowser for help on using the repository browser.