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