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

Last change on this file since 2844 was 2844, checked in by ldelgass, 13 years ago

Cleanups, no functional changes

  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
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#ifndef VOLUME_H
17#define VOLUME_H
18
19#include <string>
20#include <vector>
21
22#include <R2/R2Object.h>
23
24#include "define.h"
25#include "Color.h"
26#include "Texture3D.h"
27#include "Vector3.h"
28#include "AxisRange.h"
29#include "TransferFunction.h"
30
31struct CutPlane {
32    /// orientation - 1: xy slice, 2: yz slice, 3: xz slice
33    int orient;
34    float offset;       ///< normalized offset [0,1] in the volume
35    bool enabled;
36
37    CutPlane(int _orient, float _offset) :
38        orient(_orient),
39        offset(_offset),
40        enabled(true)
41    {
42    }
43};
44
45class VolumeInterpolator;
46
47class Volume
48{
49public:
50    enum VolumeType {
51        CUBIC,
52        VOLQD,
53        ZINCBLENDE
54    };
55
56    Volume(float x, float y, float z,
57           int width, int height, int depth,
58           float size, int n_component,
59           float *data,
60           double vmin, double vmax,
61           double nonzero_min);
62
63    virtual ~Volume();
64
65    void visible(bool value)
66    {
67        _enabled = value;
68    }
69
70    bool visible() const
71    {
72        return _enabled;
73    }
74
75    void location(const Vector3& loc)
76    {
77        _location = loc;
78    }
79
80    Vector3 location() const
81    {
82        return _location;
83    }
84
85    int isosurface() const
86    {
87        return _iso_surface;
88    }
89
90    void isosurface(int iso)
91    {
92        _iso_surface = iso;
93    }
94
95    int n_components() const
96    {
97        return _n_components;
98    }
99
100    double nonzero_min() const
101    {
102        return _nonzero_min;
103    }
104
105    double range_nzero_min() const
106    {
107        return _nonzero_min;
108    }
109
110    int volume_type() const
111    {
112        return _volume_type;
113    }
114
115    float *data()
116    {
117        return _data;
118    }
119
120    Texture3D *tex()
121    {
122        return _tex;
123    }
124   
125    int n_slices() const
126    {
127        return _n_slices;
128    }
129
130    void n_slices(int n)
131    {
132        _n_slices = n;
133    }
134
135    /// set the drawing size of volume
136    void set_size(float s);
137
138    // methods related to cutplanes
139    /// add a plane and returns its index
140    int add_cutplane(int orientation, float location);
141
142    void enable_cutplane(int index);
143
144    void disable_cutplane(int index);
145
146    void move_cutplane(int index, float location);
147
148    CutPlane *get_cutplane(int index);
149
150    /// returns the number of cutplanes in the volume
151    int get_cutplane_count();
152
153    /// check if a cutplane is enabled
154    bool cutplane_is_enabled(int index) const;
155
156    // methods related to shading. These parameters are per volume
157    float specular() const
158    {
159        return _specular;
160    }
161
162    void specular(float value)
163    {
164        _specular = value;
165    }
166
167    float diffuse() const
168    {
169        return _diffuse;
170    }
171
172    void diffuse(float value)
173    {
174        _diffuse = value;
175    }
176
177    float opacity_scale() const
178    {
179        return _opacity_scale;
180    }
181
182    void opacity_scale(float value)
183    {
184        _opacity_scale = value;
185    }
186
187    void data_enabled(bool value)
188    {
189        _data_enabled = value;
190    }
191
192    bool data_enabled() const
193    {
194        return _data_enabled;
195    }
196
197    void outline(bool value)
198    {
199        _outline_enabled = value;
200    }
201
202    bool outline()
203    {
204        return _outline_enabled;
205    }
206
207    TransferFunction *transferFunction()
208    {
209        return _tfPtr;
210    }
211
212    void transferFunction(TransferFunction *tfPtr)
213    {
214        _tfPtr = tfPtr;
215    }
216
217    void set_outline_color(float *rgb);
218
219    void get_outline_color(float *rgb);
220   
221    /// change the label displayed on an axis
222    void set_label(int axis, const char *txt);
223
224    void setPhysicalBBox(const Vector3& min, const Vector3& max);
225
226    const Vector3& getPhysicalBBoxMin() const;
227
228    const Vector3& getPhysicalBBoxMax() const;
229
230    const char *name() const
231    {
232        return _name;
233    }
234
235    void name(const char *name)
236    {
237        _name = name;
238    }
239
240    float aspect_ratio_width;
241    float aspect_ratio_height;
242    float aspect_ratio_depth;
243
244    GLuint id;          ///< OpenGL textue identifier (==_tex->id)
245
246    // Width, height and depth are point resolution, NOT physical
247    // units
248    /// The resolution of the data (how many points in X direction)
249    int width;
250    /// The resolution of the data (how many points in Y direction)
251    int height;
252    /// The resolution of the data (how many points in Z direction)
253    int depth;
254    /**
255     * This is the scaling factor that will size the volume on screen.
256     * A render program drawing different objects, always knows how
257     * large an object is in relation to other objects. This size is
258     * provided by the render engine.
259     */
260    float size;
261
262    int pointsetIndex;
263
264    AxisRange xAxis, yAxis, zAxis, wAxis;
265    std::string label[3]; ///< the labels along each axis 0:x, 1:y, 2:z
266
267    static bool update_pending;
268    static double valueMin, valueMax;
269
270protected:
271    /**
272     * This is the designated transfer function to use to
273     * render this volume.
274     */
275    TransferFunction *_tfPtr;
276
277    float _specular;            ///< Specular lighting parameter
278    float _diffuse;             ///< Diffuse lighting parameter
279    /**
280     * The scale multiplied to the opacity assigned by the
281     * transfer function. Rule of thumb: higher opacity_scale
282     * the object is to appear like plastic
283     */
284    float _opacity_scale;
285
286    const char *_name;
287    Vector3 _physical_min;
288    Vector3 _physical_max;
289    float *_data;
290
291    int _n_components;
292
293    double _nonzero_min;
294
295    std::vector<CutPlane> _plane; ///< cut planes
296
297    Texture3D *_tex;            ///< OpenGL texture storing the volume
298
299    Vector3 _location;
300
301    /**
302     * Number of slices when rendered. The greater
303     * the better quality, lower speed.
304     */
305    int _n_slices;
306    bool _enabled;
307    bool _data_enabled;         ///< show/hide cloud of volume data
308    bool _outline_enabled;      ///< show/hide outline around volume
309    Color _outline_color;       ///< color for outline around volume
310    int _volume_type;           ///< cubic or zincblende
311    int _iso_surface;
312};
313
314inline int
315Volume::add_cutplane(int orientation, float location)
316{
317    _plane.push_back(CutPlane(orientation, location));
318    return _plane.size() - 1;
319}
320
321inline void
322Volume::enable_cutplane(int index)
323{
324    //assert(index < plane.size());
325    _plane[index].enabled = true;
326}
327inline void
328Volume::disable_cutplane(int index)
329{
330    //assert(index < plane.size());
331    _plane[index].enabled = false;
332}
333
334inline void
335Volume::move_cutplane(int index, float location)
336{
337    //assert(index < plane.size());
338    _plane[index].offset = location;
339}
340
341inline CutPlane *
342Volume::get_cutplane(int index)
343{
344    //assert(index < plane.size());
345    return &_plane[index];
346}
347
348inline int
349Volume::get_cutplane_count()
350{
351    return _plane.size();
352}
353
354inline bool
355Volume::cutplane_is_enabled(int index) const
356{
357    //assert(index < plane.size());
358    return _plane[index].enabled;
359}
360
361inline void
362Volume::set_size(float s)
363{
364    size = s;
365    aspect_ratio_width  = s * _tex->aspect_ratio_width;
366    aspect_ratio_height = s * _tex->aspect_ratio_height;
367    aspect_ratio_depth  = s * _tex->aspect_ratio_depth;
368}
369
370inline void
371Volume::set_outline_color(float *rgb)
372{
373    _outline_color = Color(rgb[0], rgb[1], rgb[2]);
374}
375
376inline void
377Volume::get_outline_color(float *rgb)
378{
379    _outline_color.getRGB(rgb);
380}
381
382inline void
383Volume::set_label(int axis, const char* txt)
384{
385    label[axis] = txt;
386}
387
388inline void
389Volume::setPhysicalBBox(const Vector3& min, const Vector3& max)
390{
391    _physical_min = min;
392    _physical_max = max;
393
394    /*
395    aspect_ratio_width = size * 1;
396    aspect_ratio_height = size * (max.y - min.y) / (max.x - min.x);
397    aspect_ratio_depth = size* (max.z - min.z) / (max.x - min.x);
398
399    location.x = -0.5;
400    location.y = -0.5* aspect_ratio_height;
401    location.z = -0.5* aspect_ratio_depth;
402    */
403}
404
405inline const Vector3&
406Volume::getPhysicalBBoxMin() const
407{
408    return _physical_min;
409}
410
411inline const Vector3&
412Volume::getPhysicalBBoxMax() const
413{
414    return _physical_max;
415}
416
417#endif
Note: See TracBrowser for help on using the repository browser.