[2582] | 1 | #ifndef _HavranRayCaster_H__
|
---|
| 2 | #define _HavranRayCaster_H__
|
---|
| 3 |
|
---|
[2643] | 4 | #ifdef USE_HAVRAN_RAYCASTER
|
---|
| 5 |
|
---|
[2582] | 6 | #include "RayCaster.h"
|
---|
| 7 | #include "Containers.h"
|
---|
| 8 | #include <string>
|
---|
[2592] | 9 | #include "ktbconf.h"
|
---|
| 10 | #include "raypack.h"
|
---|
[2582] | 11 |
|
---|
| 12 | namespace GtpVisibilityPreprocessor {
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | class Intersectable;
|
---|
| 16 | class VssRay;
|
---|
| 17 | class KdTree;
|
---|
| 18 | class Ray;
|
---|
| 19 | class SimpleRayContainer;
|
---|
| 20 | class AxisAlignedBox3;
|
---|
| 21 | class Vector3;
|
---|
| 22 | struct VssRayContainer;
|
---|
| 23 | class Preprocessor;
|
---|
| 24 | struct SimpleRay;
|
---|
| 25 | class CKTB;
|
---|
| 26 |
|
---|
[2629] | 27 | // This macro should be undefined when testing ray tracing
|
---|
| 28 | // by casting rays from file or using camera
|
---|
| 29 | #define _PROCESS_RAY
|
---|
| 30 |
|
---|
[2582] | 31 | /** This class provides an interface for ray casting.
|
---|
| 32 | */
|
---|
| 33 | class HavranRayCaster: public RayCaster
|
---|
| 34 | {
|
---|
| 35 | public:
|
---|
| 36 | /** Default constructor initialising e.g., KD tree
|
---|
| 37 | */
|
---|
| 38 | HavranRayCaster(const Preprocessor &preprocessor);
|
---|
| 39 | virtual ~HavranRayCaster();
|
---|
| 40 |
|
---|
| 41 | void Build(ObjectContainer &objlist);
|
---|
| 42 |
|
---|
| 43 | int Type() const { return HAVRAN_RAYCASTER; }
|
---|
[2629] | 44 |
|
---|
[2582] | 45 | virtual int CastRay(
|
---|
| 46 | const SimpleRay &simpleRay,
|
---|
| 47 | VssRayContainer &vssRays,
|
---|
| 48 | const AxisAlignedBox3 &box,
|
---|
| 49 | const bool castDoubleRay,
|
---|
| 50 | const bool pruneInvalidRays = true
|
---|
| 51 | );
|
---|
| 52 |
|
---|
| 53 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
| 54 | VssRayContainer &vssRays,
|
---|
| 55 | const AxisAlignedBox3 &sbox,
|
---|
| 56 | const bool castDoubleRay,
|
---|
| 57 | const bool pruneInvalidRays = true
|
---|
| 58 | );
|
---|
| 59 |
|
---|
| 60 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
| 61 | int offset,
|
---|
| 62 | VssRayContainer &vssRays,
|
---|
| 63 | const AxisAlignedBox3 &sbox,
|
---|
| 64 | const bool castDoubleRay,
|
---|
| 65 | const bool pruneInvalidRays = true
|
---|
| 66 | );
|
---|
| 67 | void
|
---|
| 68 | CastSimpleForwardRays(SimpleRayContainer &rays,
|
---|
| 69 | const AxisAlignedBox3 &sbox
|
---|
| 70 | );
|
---|
| 71 |
|
---|
| 72 | virtual void CastRays(
|
---|
| 73 | SimpleRayContainer &rays,
|
---|
| 74 | VssRayContainer &vssRays,
|
---|
| 75 | const AxisAlignedBox3 &sbox,
|
---|
| 76 | const bool castDoubleRay,
|
---|
| 77 | const bool pruneInvalidRays = true);
|
---|
[2592] | 78 |
|
---|
| 79 | // Using packet of 4 rays supposing that these are coherent
|
---|
| 80 | // We give a box to which each ray is clipped to before the
|
---|
| 81 | // ray shooting is computed !
|
---|
[2599] | 82 | virtual void CastRaysPacket4(const Vector3 &minBox,
|
---|
[2602] | 83 | const Vector3 &maxBox,
|
---|
| 84 | const Vector3 origin4[],
|
---|
| 85 | const Vector3 direction4[],
|
---|
| 86 | int result4[],
|
---|
| 87 | float dist4[]);
|
---|
[2592] | 88 |
|
---|
| 89 | #ifdef _USE_HAVRAN_SSE
|
---|
| 90 | // Just for testing concept
|
---|
| 91 | virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
| 92 | bool castDoubleRay,
|
---|
| 93 | const bool pruneInvalidRays = true);
|
---|
| 94 | #endif
|
---|
| 95 |
|
---|
| 96 | bool ExportBinTree(const string &filename);
|
---|
| 97 | bool ImportBinTree(const string &filename, ObjectContainer &objects);
|
---|
| 98 |
|
---|
[2582] | 99 | protected:
|
---|
| 100 | CKTB *mKtbtree;
|
---|
[2629] | 101 | #ifdef _USE_HAVRAN_SSE
|
---|
| 102 | static GALIGN16 RayPacket2x2 raypack;
|
---|
| 103 | #endif
|
---|
[2582] | 104 | };
|
---|
| 105 |
|
---|
| 106 |
|
---|
[2629] | 107 | // --------------------------------------------------------------------
|
---|
| 108 | // The implementation of ray caster with dynamic objects
|
---|
| 109 |
|
---|
| 110 | class HavranDynRayCaster: public HavranRayCaster
|
---|
| 111 | {
|
---|
| 112 | public:
|
---|
| 113 | /** Default constructor initialising e.g., KD tree
|
---|
| 114 | */
|
---|
| 115 | HavranDynRayCaster(const Preprocessor &preprocessor);
|
---|
| 116 | virtual ~HavranDynRayCaster();
|
---|
| 117 |
|
---|
| 118 | int Type() const { return HAVRAN_DYN_RAYCASTER; }
|
---|
| 119 |
|
---|
| 120 | virtual int CastRay(const SimpleRay &simpleRay,
|
---|
| 121 | VssRayContainer &vssRays,
|
---|
| 122 | const AxisAlignedBox3 &box,
|
---|
| 123 | const bool castDoubleRay,
|
---|
| 124 | const bool pruneInvalidRays = true
|
---|
| 125 | );
|
---|
| 126 |
|
---|
| 127 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
| 128 | VssRayContainer &vssRays,
|
---|
| 129 | const AxisAlignedBox3 &sbox,
|
---|
| 130 | const bool castDoubleRay,
|
---|
| 131 | const bool pruneInvalidRays = true
|
---|
| 132 | );
|
---|
| 133 |
|
---|
| 134 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
| 135 | int offset,
|
---|
| 136 | VssRayContainer &vssRays,
|
---|
| 137 | const AxisAlignedBox3 &sbox,
|
---|
| 138 | const bool castDoubleRay,
|
---|
| 139 | const bool pruneInvalidRays = true
|
---|
| 140 | );
|
---|
| 141 | virtual void
|
---|
| 142 | CastSimpleForwardRays(SimpleRayContainer &rays,
|
---|
| 143 | const AxisAlignedBox3 &sbox);
|
---|
| 144 |
|
---|
| 145 | virtual void CastRays(SimpleRayContainer &rays,
|
---|
| 146 | VssRayContainer &vssRays,
|
---|
| 147 | const AxisAlignedBox3 &sbox,
|
---|
| 148 | const bool castDoubleRay,
|
---|
| 149 | const bool pruneInvalidRays = true);
|
---|
| 150 |
|
---|
| 151 | // Using packet of 4 rays supposing that these are coherent
|
---|
| 152 | // We give a box to which each ray is clipped to before the
|
---|
| 153 | // ray shooting is computed !
|
---|
| 154 | virtual void CastRaysPacket4(const Vector3 &minBox,
|
---|
| 155 | const Vector3 &maxBox,
|
---|
| 156 | const Vector3 origin4[],
|
---|
| 157 | const Vector3 direction4[],
|
---|
| 158 | int result4[],
|
---|
| 159 | float dist4[]);
|
---|
| 160 |
|
---|
| 161 | #ifdef _USE_HAVRAN_SSE
|
---|
| 162 | // Just for testing concept
|
---|
| 163 | virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
| 164 | bool castDoubleRay,
|
---|
| 165 | const bool pruneInvalidRays = true);
|
---|
| 166 | #endif
|
---|
| 167 |
|
---|
| 168 | virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m);
|
---|
| 169 |
|
---|
| 170 | virtual void UpdateDynamicObjects(const Matrix4x4 &m);
|
---|
| 171 |
|
---|
| 172 | virtual void DeleteDynamicObjects();
|
---|
| 173 |
|
---|
| 174 | protected:
|
---|
| 175 |
|
---|
| 176 | // The kd-tree for dynamic objects
|
---|
| 177 | CKTB *mDynKtbtree;
|
---|
| 178 |
|
---|
| 179 | #ifdef _USE_HAVRAN_SSE
|
---|
| 180 | // This has to be aligned by 16 Bytes boundary - if HavranDynRayCaster
|
---|
| 181 | // is aligned, then also this data entity below !!!
|
---|
| 182 | static GALIGN16 RayPacket2x2 raypack_t;
|
---|
| 183 | #endif
|
---|
| 184 |
|
---|
| 185 | ObjectContainer *dynobjects;
|
---|
| 186 | bool dynamicFlag;
|
---|
| 187 |
|
---|
| 188 | Matrix4x4 matTr, matTr_inv;
|
---|
| 189 |
|
---|
| 190 | int result4_t[4];
|
---|
| 191 | float dist4_t[4];
|
---|
| 192 | SimpleRay sray_t;
|
---|
| 193 |
|
---|
| 194 | Vector3 orig[16];
|
---|
| 195 | Vector3 dirs[16];
|
---|
| 196 | float tdist[32];
|
---|
| 197 | Intersectable* objI[32];
|
---|
| 198 | Vector3 normal[32];
|
---|
| 199 |
|
---|
| 200 | // This transforms the ray
|
---|
| 201 | void ApplyTransform(SimpleRay &sray) {
|
---|
| 202 | sray.mOrigin = matTr_inv * sray.mOrigin;
|
---|
| 203 | sray.mDirection = RotateOnly(matTr_inv, sray.mDirection);
|
---|
| 204 | // note that normalization to the unit size of the direction
|
---|
| 205 | // is NOT computed -- this is what we want.
|
---|
| 206 | }
|
---|
| 207 | };
|
---|
| 208 |
|
---|
| 209 |
|
---|
[2582] | 210 | } // namespace
|
---|
| 211 |
|
---|
[2643] | 212 | #endif
|
---|
| 213 |
|
---|
[2629] | 214 | #endif // _HavranRayCaster_H__
|
---|