[1520] | 1 | #ifndef _RayCaster_H__
|
---|
| 2 | #define _RayCaster_H__
|
---|
| 3 |
|
---|
[2583] | 4 |
|
---|
[1520] | 5 | #include "Containers.h"
|
---|
| 6 | #include <string>
|
---|
[2583] | 7 | #include <iostream>
|
---|
[1528] | 8 | #include "Vector3.h"
|
---|
[2014] | 9 | #include "VssRay.h"
|
---|
[1528] | 10 |
|
---|
[2583] | 11 | using namespace std;
|
---|
| 12 |
|
---|
[2176] | 13 | //
|
---|
[1520] | 14 |
|
---|
| 15 |
|
---|
| 16 | namespace GtpVisibilityPreprocessor {
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | class Intersectable;
|
---|
| 20 | class VssRay;
|
---|
| 21 | class SimpleRayContainer;
|
---|
| 22 | class AxisAlignedBox3;
|
---|
| 23 | struct VssRayContainer;
|
---|
| 24 | class Preprocessor;
|
---|
[1528] | 25 | struct SimpleRay;
|
---|
[2575] | 26 | class RayPacket2x2;
|
---|
[2621] | 27 | class Matrix4x4;
|
---|
[1520] | 28 |
|
---|
| 29 | /** This class provides an interface for ray casting.
|
---|
| 30 | */
|
---|
| 31 | class RayCaster
|
---|
| 32 | {
|
---|
[1528] | 33 |
|
---|
[1520] | 34 | public:
|
---|
| 35 |
|
---|
[2575] | 36 | enum {
|
---|
| 37 | INTERNAL_RAYCASTER = 0,
|
---|
| 38 | INTEL_RAYCASTER = 1,
|
---|
| 39 | HAVRAN_RAYCASTER = 2
|
---|
| 40 | };
|
---|
[1520] | 41 |
|
---|
[2575] | 42 | RayCaster(const Preprocessor &preprocessor);
|
---|
[1520] | 43 |
|
---|
[2575] | 44 | virtual ~RayCaster();
|
---|
| 45 |
|
---|
| 46 | virtual int Type() const = 0;
|
---|
[1520] | 47 |
|
---|
[2575] | 48 | /** Wrapper for casting single ray.
|
---|
| 49 | @returns ray or NULL if invalid
|
---|
| 50 | */
|
---|
| 51 | VssRay *CastRay(const SimpleRay &simpleRay,
|
---|
| 52 | const AxisAlignedBox3 &box,
|
---|
| 53 | const bool castDoubleRay);
|
---|
[1520] | 54 |
|
---|
[2575] | 55 | virtual int CastRay(const SimpleRay &simpleRay,
|
---|
| 56 | VssRayContainer &vssRays,
|
---|
| 57 | const AxisAlignedBox3 &box,
|
---|
| 58 | const bool castDoubleRay,
|
---|
| 59 | const bool pruneInvalidRays = true) = 0;
|
---|
[1521] | 60 |
|
---|
[2575] | 61 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
| 62 | VssRayContainer &vssRays,
|
---|
| 63 | const AxisAlignedBox3 &sbox,
|
---|
| 64 | const bool castDoubleRay,
|
---|
| 65 | const bool pruneInvalidRays = true) = 0;
|
---|
| 66 |
|
---|
[2076] | 67 | virtual void CastRays(
|
---|
[2575] | 68 | SimpleRayContainer &rays,
|
---|
| 69 | VssRayContainer &vssRays,
|
---|
| 70 | const AxisAlignedBox3 &sbox,
|
---|
| 71 | const bool castDoubleRay,
|
---|
| 72 | const bool pruneInvalidRays = true);
|
---|
[2077] | 73 |
|
---|
[2582] | 74 | // Using packet of 4 rays supposing that these are coherent
|
---|
| 75 | virtual void CastRaysPacket4(Vector3 origin4[],
|
---|
| 76 | Vector3 direction4[],
|
---|
| 77 | int result4[],
|
---|
| 78 | float dist4[]) { }
|
---|
| 79 |
|
---|
| 80 | // Using packet of 4 rays supposing that these are coherent
|
---|
| 81 | // We give a box to which each ray is clipped to before the
|
---|
| 82 | // ray shooting is computed !
|
---|
| 83 | virtual void CastRaysPacket4(const Vector3 &minBox,
|
---|
| 84 | const Vector3 &maxBox,
|
---|
| 85 | const Vector3 origin4[],
|
---|
| 86 | const Vector3 direction4[],
|
---|
| 87 | int result4[],
|
---|
| 88 | float dist4[]) { }
|
---|
| 89 |
|
---|
[2575] | 90 | // Just for testing concept
|
---|
| 91 | virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
| 92 | bool castDoubleRay,
|
---|
| 93 | const bool pruneInvalidRays = true)
|
---|
| 94 | { }
|
---|
| 95 |
|
---|
[2077] | 96 | /*virtual void CastRaysEye4(SimpleRayContainer &rays,
|
---|
[2575] | 97 | VssRayContainer &vssRays,
|
---|
| 98 | const AxisAlignedBox3 &sbox,
|
---|
| 99 | const bool castDoubleRay,
|
---|
| 100 | const bool pruneInvalidRays = true) = 0;
|
---|
| 101 | */
|
---|
[1974] | 102 |
|
---|
[2575] | 103 | virtual void
|
---|
| 104 | SortRays(SimpleRayContainer &rays);
|
---|
[1974] | 105 |
|
---|
[2161] | 106 |
|
---|
[2621] | 107 | virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) = 0;
|
---|
| 108 | virtual void UpdateDynamicObjects(const Matrix4x4 &m) = 0;
|
---|
| 109 | virtual void DeleteDynamicObjects() = 0;
|
---|
| 110 |
|
---|
[2575] | 111 | // pool of vss rays to be used in one pass of the sampling
|
---|
| 112 | struct VssRayPool
|
---|
| 113 | {
|
---|
| 114 | VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)
|
---|
| 115 | {}
|
---|
| 116 |
|
---|
| 117 | ~VssRayPool()
|
---|
| 118 | {
|
---|
| 119 | delete []mRays;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | void Reserve(const int number)
|
---|
| 123 | {
|
---|
| 124 | DEL_PTR(mRays);
|
---|
| 125 | mRays = new VssRay[number];
|
---|
| 126 | mNumber = number;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | void Clear()
|
---|
| 130 | {
|
---|
| 131 | mIndex = 0;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | VssRay *Alloc()
|
---|
| 135 | {
|
---|
| 136 | // reset pool
|
---|
| 137 | if (mIndex == mNumber)
|
---|
| 138 | mIndex = 0;
|
---|
| 139 | return mRays + mIndex ++;
|
---|
| 140 | }
|
---|
| 141 | protected:
|
---|
| 142 | VssRay *mRays;
|
---|
| 143 | int mIndex;
|
---|
| 144 | int mNumber;
|
---|
| 145 | };
|
---|
[2543] | 146 |
|
---|
| 147 |
|
---|
[2575] | 148 | VssRayPool mVssRayPool;
|
---|
| 149 |
|
---|
| 150 | void ReserveVssRayPool(const int n)
|
---|
| 151 | {
|
---|
| 152 | mVssRayPool.Reserve(n);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | void InitPass()
|
---|
| 156 | {
|
---|
| 157 | mVssRayPool.Clear();
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 |
|
---|
[1520] | 161 | protected:
|
---|
[2575] | 162 |
|
---|
| 163 | VssRay *RequestRay(const Vector3 &origin,
|
---|
| 164 | const Vector3 &termination,
|
---|
| 165 | Intersectable *originObject,
|
---|
| 166 | Intersectable *terminationObject,
|
---|
| 167 | const int pass,
|
---|
| 168 | const float pdf);
|
---|
| 169 |
|
---|
| 170 | void _SortRays(SimpleRayContainer &rays,
|
---|
| 171 | const int l,
|
---|
| 172 | const int r,
|
---|
| 173 | const int depth,
|
---|
| 174 | float box[12]);
|
---|
| 175 |
|
---|
| 176 | struct Intersection
|
---|
| 177 | {
|
---|
| 178 | Intersection(): mObject(NULL), mFaceId(0)
|
---|
| 179 | {}
|
---|
| 180 |
|
---|
| 181 | Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
|
---|
| 182 | mPoint(p), mNormal(n), mObject(o), mFaceId(f)
|
---|
| 183 | {}
|
---|
| 184 |
|
---|
| 185 | Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
|
---|
| 186 | {}
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | ////////////
|
---|
| 190 |
|
---|
| 191 | Vector3 mPoint;
|
---|
| 192 | Vector3 mNormal;
|
---|
| 193 | Intersectable *mObject;
|
---|
| 194 | int mFaceId;
|
---|
| 195 | };
|
---|
[2187] | 196 |
|
---|
| 197 |
|
---|
[2575] | 198 | int ProcessRay(const SimpleRay &ray,
|
---|
| 199 | Intersection &hitA,
|
---|
| 200 | Intersection &hitB,
|
---|
| 201 | VssRayContainer &vssRays,
|
---|
| 202 | const AxisAlignedBox3 &box,
|
---|
| 203 | const bool castDoubleRay,
|
---|
| 204 | const bool pruneInvalidRays = true);
|
---|
| 205 |
|
---|
| 206 | /** Checks if ray is valid.
|
---|
| 207 | I.e., the ray is in valid view space.
|
---|
| 208 | @note: clamps the ray to valid view space.
|
---|
| 209 | */
|
---|
| 210 | bool ValidateRay(const Vector3 &origin,
|
---|
| 211 | const Vector3 &direction,
|
---|
| 212 | const AxisAlignedBox3 &box,
|
---|
| 213 | Intersection &hit);
|
---|
| 214 |
|
---|
| 215 | bool ClipToViewSpaceBox(const Vector3 &origin,
|
---|
| 216 | const Vector3 &termination,
|
---|
| 217 | Vector3 &clippedOrigin,
|
---|
| 218 | Vector3 &clippedTermination);
|
---|
| 219 |
|
---|
| 220 | const Preprocessor &mPreprocessor;
|
---|
| 221 | #if 1
|
---|
| 222 | public:
|
---|
| 223 | // Added by VH for debugging
|
---|
| 224 | Intersection intersect;
|
---|
| 225 | #endif
|
---|
[1520] | 226 | };
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | #endif
|
---|