source: trunk/packages/vizservers/nanovis/VelocityArrowsSlice.h @ 2825

Last change on this file since 2825 was 2822, checked in by ldelgass, 12 years ago

Const correctness fixes, pass vector/matrix objects by reference, various
formatting and style cleanups, don't spam syslog and uncomment openlog() call.
Still needs to be compiled with -DWANT_TRACE to get tracing, but now trace
output will be output to file in /tmp.

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2#ifndef VELOCITY_ARROW_SLICE_H
3#define VELOCITY_ARROW_SLICE_H
4
5#include <Cg/cg.h>
6#include <Cg/cgGL.h>
7#include <vector>
8
9#define USE_NANOVIS_LIB
10
11#ifdef USE_NANOVIS_LIB
12#include "Texture2D.h"
13#include "Vector3.h"
14#else
15#include <vr3d/vrTexture2D.h>
16
17typedef vrTexture2D Texture2D;
18
19class Vector3
20{
21public:
22    float x, y, z;
23
24    Vector3() :
25        x(0.0f), y(0.0f), z(0.0f)
26    {}
27
28    Vector3(float x1, float y1, float z1) :
29        x(x1), y(y1), z(z1)
30    {}
31
32    Vector3 operator*(float scale)
33    {
34        Vector3 vec;
35        vec.x = x * scale;
36        vec.y = y * scale;
37        vec.z = z * scale;
38        return vec;
39    }
40
41    Vector3 scale(const Vector3& scale)
42    {
43        Vector3 vec;
44        vec.x = x * scale.x;
45        vec.y = y * scale.y;
46        vec.z = z * scale.z;
47        return vec;
48    }
49
50    Vector3 operator*(const Vector3& scale)
51    {
52        Vector3 vec;
53        vec.x = x * scale.x;
54        vec.y = y * scale.y;
55        vec.z = z * scale.z;
56        return vec;
57    }
58
59    friend Vector3 operator+(const Vector3& value1, const Vector3& value2);
60
61    void set(float x1, float y1, float z1)
62    {
63        x = x1; y = y1; z = z1;
64    }
65};
66
67inline Vector3 operator+(const Vector3& value1, const Vector3& value2)
68{
69    return Vector3(value1.x + value2.x, value1.y + value2.y, value1.z + value2.z);
70}
71
72#endif
73
74
75class VelocityArrowsSlice
76{
77public:
78    enum RenderMode {
79        LINES,
80        GLYPHS,
81    };
82
83private:
84    unsigned int _vectorFieldGraphicsID;
85    float _vfXscale;
86    float _vfYscale;
87    float _vfZscale;
88    float _slicePos;
89    int _axis;
90       
91    unsigned int _fbo; 
92    unsigned int _tex;
93       
94    CGcontext _context;
95    CGprogram _queryVelocityFP;
96    CGparameter _qvVectorFieldParam;
97
98    int _renderTargetWidth;
99    int _renderTargetHeight;
100    Vector3 *_velocities;
101    std::vector<Vector3> _samplingPositions;
102    Vector3 _projectionVector;
103
104    int _tickCountForMinSizeAxis;
105    int _tickCountX;
106    int _tickCountY;
107    int _tickCountZ;
108       
109    int _pointCount;
110
111    Vector3 _maxVelocityScale;
112    Vector3 _arrowColor;
113
114    bool _enabled;     
115    bool _dirty;
116    bool _dirtySamplingPosition;
117    bool _dirtyRenderTarget;
118
119    unsigned int _vertexBufferGraphicsID;
120
121    CGprogram _particleVP;
122    CGparameter _mvpParticleParam;
123    CGparameter _mvParticleParam;
124    CGparameter _mvTanHalfFOVParam;
125    CGparameter _mvCurrentTimeParam;
126       
127    CGprogram _particleFP;
128    CGparameter _vectorParticleParam;
129
130    Texture2D *_arrowsTex;
131
132    RenderMode _renderMode;
133
134    void createRenderTarget();
135    void computeSamplingTicks();
136
137public:
138    VelocityArrowsSlice();
139    ~VelocityArrowsSlice();
140
141    void vectorField(unsigned int vfGraphicsID, float xScale, float yScale, float zScale);
142    void axis(int axis);
143    int axis() const;
144    void slicePos(float pos);
145    float slicePos() const;
146    void queryVelocity();
147    void render();
148    void enabled(bool enabled)
149    {
150        _enabled = enabled;
151    }
152    bool enabled() const
153    {
154        return _enabled;
155    }
156    void tickCountForMinSizeAxis(int tickCount);
157    int tickCountForMinSizeAxis() const;
158    void arrowColor(const Vector3& color);
159    void renderMode(RenderMode mode);
160    RenderMode renderMode() const;
161};
162
163inline int VelocityArrowsSlice::axis() const
164{
165    return _axis;
166}
167
168inline float VelocityArrowsSlice::slicePos() const
169{
170    return _slicePos;
171}
172
173
174inline int VelocityArrowsSlice::tickCountForMinSizeAxis() const
175{
176    return _tickCountForMinSizeAxis;
177}
178
179inline void VelocityArrowsSlice::arrowColor(const Vector3& color)
180{
181    _arrowColor = color;
182}
183
184inline void VelocityArrowsSlice::renderMode(VelocityArrowsSlice::RenderMode mode)
185{
186    _renderMode = mode;
187    _dirty = true;
188}
189
190inline VelocityArrowsSlice::RenderMode VelocityArrowsSlice::renderMode() const
191{
192    return _renderMode;
193}
194 
195#endif
Note: See TracBrowser for help on using the repository browser.