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