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

Last change on this file since 3628 was 3613, checked in by ldelgass, 11 years ago

Include namespace in header guard defines

  • Property svn:eol-style set to native
File size: 9.1 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright (c) 2004-2013  HUBzero Foundation, LLC
4 *
5 * Author:
6 *   Wei Qiao <qiaow@purdue.edu>
7 */
8#ifndef NV_VOLUME_H
9#define NV_VOLUME_H
10
11#include <cstring>
12#include <string>
13#include <vector>
14
15#include <vrmath/Vector3f.h>
16
17#include "Texture3D.h"
18#include "AxisRange.h"
19#include "TransferFunction.h"
20
21namespace nv {
22
23struct CutPlane {
24    /// orientation - 1: xy slice, 2: yz slice, 3: xz slice
25    int orient;
26    float offset;       ///< normalized offset [0,1] in the volume
27    bool enabled;
28
29    CutPlane(int _orient, float _offset) :
30        orient(_orient),
31        offset(_offset),
32        enabled(true)
33    {
34    }
35};
36
37class VolumeInterpolator;
38
39class Volume
40{
41public:
42    enum VolumeType {
43        CUBIC,
44        VOLQD,
45        ZINCBLENDE
46    };
47
48    /**
49     * \brief Volume data constructor
50     *
51     * Represents a 3D regular grid with uniform spacing along
52     * each axis.  Sample spacing may differ between X, Y and Z
53     *
54     * \param x X location
55     * \param y Y location
56     * \param z Z location
57     * \param width Number of samples in X
58     * \param height Number of samples in Y
59     * \param depth Number of samples in Z
60     * \param numComponents Number of components per sample
61     * \param data width * height * depth * numComponent sample array
62     * \param vmin Scalar value minimum
63     * \param vmax Scalar value maximum
64     * \param nonZeroMin Scalar minimum which is greater than zero
65     */
66    Volume(float x, float y, float z,
67           int width, int height, int depth,
68           int numComponents,
69           float *data,
70           double vmin, double vmax,
71           double nonZeroMin);
72
73    virtual ~Volume();
74
75    int width() const
76    {
77        return _width;
78    }
79
80    int height() const
81    {
82        return _height;
83    }
84
85    int depth() const
86    {
87        return _depth;
88    }
89
90    void visible(bool value)
91    {
92        _enabled = value;
93    }
94
95    bool visible() const
96    {
97        return _enabled;
98    }
99
100    void location(const vrmath::Vector3f& loc)
101    {
102        _location = loc;
103    }
104
105    vrmath::Vector3f location() const
106    {
107        return _location;
108    }
109
110    int isosurface() const
111    {
112        return _isosurface;
113    }
114
115    void isosurface(int iso)
116    {
117        _isosurface = iso;
118    }
119
120    int numComponents() const
121    {
122        return _numComponents;
123    }
124
125    double nonZeroMin() const
126    {
127        return _nonZeroMin;
128    }
129
130    int volumeType() const
131    {
132        return _volumeType;
133    }
134
135    const float *data() const
136    {
137        return _data;
138    }
139
140    const Texture3D *tex() const
141    {
142        return _tex;
143    }
144
145    int numSlices() const
146    {
147        return _numSlices;
148    }
149
150    void numSlices(int n)
151    {
152        _numSlices = n;
153    }
154
155    // methods related to cutplanes
156    /// add a plane and returns its index
157    int addCutplane(int orientation, float location);
158
159    void enableCutplane(int index);
160
161    void disableCutplane(int index);
162
163    void moveCutplane(int index, float location);
164
165    CutPlane *getCutplane(int index);
166
167    /// returns the number of cutplanes in the volume
168    int getCutplaneCount();
169
170    /// check if a cutplane is enabled
171    bool isCutplaneEnabled(int index) const;
172
173    // methods related to shading. These parameters are per volume
174
175    /// Get ambient coefficient
176    float ambient() const
177    {
178        return _ambient;
179    }
180
181    /// Set ambient coefficient [0,1]
182    void ambient(float value)
183    {
184        if (value < 0.0f) value = 0.0f;
185        if (value > 1.0f) value = 1.0f;
186        _ambient = value;
187    }
188
189    /// Get diffuse coefficient
190    float diffuse() const
191    {
192        return _diffuse;
193    }
194
195    /// Set diffuse coefficient [0,1]
196    void diffuse(float value)
197    {
198        if (value < 0.0f) value = 0.0f;
199        if (value > 1.0f) value = 1.0f;
200        _diffuse = value;
201    }
202
203    /// Get specular coefficient
204    float specularLevel() const
205    {
206        return _specular;
207    }
208
209    /// Set specular coefficient [0,1]
210    void specularLevel(float value)
211    {
212        if (value < 0.0f) value = 0.0f;
213        if (value > 1.0f) value = 1.0f;
214        _specular = value;
215    }
216
217    /// Get specular exponent
218    float specularExponent() const
219    {
220        return _specularExp;
221    }
222
223    /// Set specular exponent [0,128]
224    void specularExponent(float value)
225    {
226        if (value < 0.0f) value = 0.0f;
227        if (value > 128.0f) value = 128.0f;
228        _specularExp = value;
229    }
230
231    bool twoSidedLighting() const
232    {
233        return _lightTwoSide;
234    }
235
236    void twoSidedLighting(bool value)
237    {
238        _lightTwoSide = value;
239    }
240
241    float opacityScale() const
242    {
243        return _opacityScale;
244    }
245
246    void opacityScale(float value)
247    {
248        _opacityScale = value;
249    }
250
251    void dataEnabled(bool value)
252    {
253        _dataEnabled = value;
254    }
255
256    bool dataEnabled() const
257    {
258        return _dataEnabled;
259    }
260
261    void outline(bool value)
262    {
263        _outlineEnabled = value;
264    }
265
266    bool outline()
267    {
268        return _outlineEnabled;
269    }
270
271    TransferFunction *transferFunction()
272    {
273        return _transferFunc;
274    }
275
276    void transferFunction(TransferFunction *transferFunc)
277    {
278        _transferFunc = transferFunc;
279    }
280
281    void setOutlineColor(float *rgb);
282
283    void getOutlineColor(float *rgb);
284
285    vrmath::Vector3f getPhysicalScaling() const
286    {
287        vrmath::Vector3f scale;
288        scale.x = 1;
289        scale.y = yAxis.length() / xAxis.length();
290        scale.z = zAxis.length() / xAxis.length();
291        return scale;
292    }
293
294    void getWorldSpaceBounds(vrmath::Vector3f& bboxMin,
295                             vrmath::Vector3f& bboxMax) const;
296 
297    double sampleDistanceX() const
298    {
299        return (xAxis.length() / ((double)_width-1.0));
300    }
301
302    double sampleDistanceY() const
303    {
304        return (yAxis.length() / ((double)_height-1.0));
305    }
306
307    double sampleDistanceZ() const
308    {
309        if (_depth == 1)
310            return sampleDistanceX();
311        return (zAxis.length() / ((double)_depth-1.0));
312    }
313
314    const char *name() const
315    {
316        return _name.c_str();
317    }
318
319    void name(const char *name)
320    {
321        _name = name;
322    }
323
324    GLuint textureID() const
325    {
326        return _id;
327    }
328
329    AxisRange xAxis, yAxis, zAxis, wAxis;
330
331    static bool updatePending;
332    static double valueMin, valueMax;
333
334    friend class VolumeInterpolator;
335
336protected:
337    float *data()
338    {
339        return _data;
340    }
341
342    Texture3D *tex()
343    {
344        return _tex;
345    }
346
347    GLuint _id;         ///< OpenGL textue identifier (==_tex->id)
348
349    // Width, height and depth are point resolution, NOT physical
350    // units
351    /// The resolution of the data (how many points in X direction)
352    int _width;
353    /// The resolution of the data (how many points in Y direction)
354    int _height;
355    /// The resolution of the data (how many points in Z direction)
356    int _depth;
357
358    /**
359     * This is the designated transfer function to use to
360     * render this volume.
361     */
362    TransferFunction *_transferFunc;
363
364    float _ambient;      ///< Ambient material coefficient
365    float _diffuse;      ///< Diffuse material coefficient
366    float _specular;     ///< Specular level material coefficient
367    float _specularExp;  ///< Specular exponent
368    bool _lightTwoSide;  ///< Two-sided lighting flag
369
370    /**
371     * The scale multiplied to the opacity assigned by the
372     * transfer function. Rule of thumb: higher opacity_scale
373     * the object is to appear like plastic
374     */
375    float _opacityScale;
376
377    std::string _name;
378
379    float *_data;
380
381    int _numComponents;
382
383    double _nonZeroMin;
384
385    std::vector<CutPlane> _plane; ///< cut planes
386
387    Texture3D *_tex;            ///< OpenGL texture storing the volume
388
389    vrmath::Vector3f _location;
390
391    /**
392     * Number of slices when rendered. The greater
393     * the better quality, lower speed.
394     */
395    int _numSlices;
396    bool _enabled;
397    bool _dataEnabled;          ///< show/hide cloud of volume data
398    bool _outlineEnabled;       ///< show/hide outline around volume
399    float _outlineColor[3];     ///< color for outline around volume
400    int _volumeType;            ///< cubic or zincblende
401    int _isosurface;
402};
403
404inline int
405Volume::addCutplane(int orientation, float location)
406{
407    _plane.push_back(CutPlane(orientation, location));
408    return _plane.size() - 1;
409}
410
411inline void
412Volume::enableCutplane(int index)
413{
414    //assert(index < plane.size());
415    _plane[index].enabled = true;
416}
417
418inline void
419Volume::disableCutplane(int index)
420{
421    //assert(index < plane.size());
422    _plane[index].enabled = false;
423}
424
425inline void
426Volume::moveCutplane(int index, float location)
427{
428    //assert(index < plane.size());
429    _plane[index].offset = location;
430}
431
432inline CutPlane *
433Volume::getCutplane(int index)
434{
435    //assert(index < plane.size());
436    return &_plane[index];
437}
438
439inline int
440Volume::getCutplaneCount()
441{
442    return _plane.size();
443}
444
445inline bool
446Volume::isCutplaneEnabled(int index) const
447{
448    //assert(index < plane.size());
449    return _plane[index].enabled;
450}
451
452inline void
453Volume::setOutlineColor(float *rgb)
454{
455    memcpy(_outlineColor, rgb, sizeof(float)*3);
456}
457
458inline void
459Volume::getOutlineColor(float *rgb)
460{
461    memcpy(rgb, _outlineColor, sizeof(float)*3);
462}
463
464}
465
466#endif
Note: See TracBrowser for help on using the repository browser.