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

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