source: nanovis/branches/1.2/Volume.h @ 5489

Last change on this file since 5489 was 5406, checked in by ldelgass, 9 years ago

backport from trunk: remove unused ctor params

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