[1520] | 1 | #ifndef _RayCaster_H__
|
---|
| 2 | #define _RayCaster_H__
|
---|
| 3 |
|
---|
| 4 | #include "Containers.h"
|
---|
| 5 | #include <string>
|
---|
[1528] | 6 | #include "Vector3.h"
|
---|
[2014] | 7 | #include "VssRay.h"
|
---|
[1528] | 8 |
|
---|
[2176] | 9 | //
|
---|
[1520] | 10 |
|
---|
| 11 |
|
---|
| 12 | namespace GtpVisibilityPreprocessor {
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | class Intersectable;
|
---|
| 16 | class VssRay;
|
---|
| 17 | class SimpleRayContainer;
|
---|
| 18 | class AxisAlignedBox3;
|
---|
[1528] | 19 | //class Vector3;
|
---|
[1520] | 20 | struct VssRayContainer;
|
---|
| 21 | class Preprocessor;
|
---|
[1528] | 22 | struct SimpleRay;
|
---|
[1520] | 23 |
|
---|
[1528] | 24 |
|
---|
[1520] | 25 | /** This class provides an interface for ray casting.
|
---|
| 26 | */
|
---|
| 27 | class RayCaster
|
---|
| 28 | {
|
---|
[1528] | 29 |
|
---|
[1520] | 30 | public:
|
---|
| 31 |
|
---|
| 32 | enum {
|
---|
| 33 | INTERNAL_RAYCASTER = 0,
|
---|
| 34 | INTEL_RAYCASTER
|
---|
| 35 | };
|
---|
| 36 |
|
---|
| 37 | RayCaster(const Preprocessor &preprocessor);
|
---|
| 38 |
|
---|
[1521] | 39 | virtual ~RayCaster();
|
---|
[1520] | 40 |
|
---|
| 41 | virtual int Type() const = 0;
|
---|
| 42 |
|
---|
[1521] | 43 | /** Wrapper for casting single ray.
|
---|
[1545] | 44 | @returns ray or NULL if invalid
|
---|
[1521] | 45 | */
|
---|
[1932] | 46 | VssRay *CastRay(const SimpleRay &simpleRay,
|
---|
[1990] | 47 | const AxisAlignedBox3 &box,
|
---|
[1996] | 48 | const bool castDoubleRay);
|
---|
[1521] | 49 |
|
---|
[1932] | 50 | virtual int CastRay(const SimpleRay &simpleRay,
|
---|
| 51 | VssRayContainer &vssRays,
|
---|
| 52 | const AxisAlignedBox3 &box,
|
---|
| 53 | const bool castDoubleRay,
|
---|
[1996] | 54 | const bool pruneInvalidRays = true) = 0;
|
---|
[1520] | 55 |
|
---|
[2063] | 56 | virtual void CastRays16(SimpleRayContainer &rays,
|
---|
| 57 | VssRayContainer &vssRays,
|
---|
| 58 | const AxisAlignedBox3 &sbox,
|
---|
| 59 | const bool castDoubleRay,
|
---|
| 60 | const bool pruneInvalidRays = true) = 0;
|
---|
[1974] | 61 |
|
---|
[2076] | 62 | virtual void CastRays(
|
---|
| 63 | SimpleRayContainer &rays,
|
---|
| 64 | VssRayContainer &vssRays,
|
---|
| 65 | const AxisAlignedBox3 &sbox,
|
---|
| 66 | const bool castDoubleRay,
|
---|
| 67 | const bool pruneInvalidRays = true);
|
---|
[2077] | 68 |
|
---|
| 69 | /*virtual void CastRaysEye4(SimpleRayContainer &rays,
|
---|
[2063] | 70 | VssRayContainer &vssRays,
|
---|
| 71 | const AxisAlignedBox3 &sbox,
|
---|
| 72 | const bool castDoubleRay,
|
---|
| 73 | const bool pruneInvalidRays = true) = 0;
|
---|
| 74 | */
|
---|
| 75 | virtual void
|
---|
| 76 | SortRays(SimpleRayContainer &rays);
|
---|
[1974] | 77 |
|
---|
| 78 |
|
---|
[2543] | 79 | // pool of vss rays to be used in one pass of the sampling
|
---|
[2559] | 80 | struct VssRayPool
|
---|
| 81 | {
|
---|
[2543] | 82 | VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)
|
---|
| 83 | {}
|
---|
[2161] | 84 |
|
---|
[2543] | 85 | ~VssRayPool()
|
---|
| 86 | {
|
---|
| 87 | DEL_PTR(mRays);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[2559] | 90 | void Reserve(const int number)
|
---|
| 91 | {
|
---|
[2543] | 92 | DEL_PTR(mRays);
|
---|
| 93 | mRays = new VssRay[number];
|
---|
| 94 | mNumber = number;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[2559] | 97 | void Clear()
|
---|
| 98 | {
|
---|
[2048] | 99 | mIndex = 0;
|
---|
[2543] | 100 | }
|
---|
[2559] | 101 |
|
---|
| 102 | VssRay *Alloc()
|
---|
| 103 | {
|
---|
[2543] | 104 | // reset pool
|
---|
| 105 | if (mIndex == mNumber)
|
---|
| 106 | mIndex = 0;
|
---|
| 107 | return mRays + mIndex ++;
|
---|
| 108 | }
|
---|
| 109 | protected:
|
---|
| 110 | VssRay *mRays;
|
---|
| 111 | int mIndex;
|
---|
| 112 | int mNumber;
|
---|
| 113 | };
|
---|
| 114 |
|
---|
| 115 | VssRayPool mVssRayPool;
|
---|
| 116 |
|
---|
[2559] | 117 | void ReserveVssRayPool(const int n)
|
---|
| 118 | {
|
---|
[2543] | 119 | mVssRayPool.Reserve(n);
|
---|
[2012] | 120 | }
|
---|
| 121 |
|
---|
[2559] | 122 | void InitPass()
|
---|
| 123 | {
|
---|
[2543] | 124 | mVssRayPool.Clear();
|
---|
| 125 | }
|
---|
[2012] | 126 |
|
---|
| 127 |
|
---|
[1520] | 128 | protected:
|
---|
[2187] | 129 |
|
---|
| 130 | VssRay *RequestRay(const Vector3 &origin,
|
---|
[2543] | 131 | const Vector3 &termination,
|
---|
| 132 | Intersectable *originObject,
|
---|
| 133 | Intersectable *terminationObject,
|
---|
| 134 | const int pass,
|
---|
| 135 | const float pdf);
|
---|
[2187] | 136 |
|
---|
[2543] | 137 | void _SortRays(SimpleRayContainer &rays,
|
---|
| 138 | const int l,
|
---|
| 139 | const int r,
|
---|
| 140 | const int depth,
|
---|
| 141 | float box[12]);
|
---|
[1520] | 142 |
|
---|
[2543] | 143 | struct Intersection
|
---|
| 144 | {
|
---|
| 145 | Intersection(): mObject(NULL), mFaceId(0)
|
---|
| 146 | {}
|
---|
[1528] | 147 |
|
---|
[2543] | 148 | Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
|
---|
| 149 | mPoint(p), mNormal(n), mObject(o), mFaceId(f)
|
---|
| 150 | {}
|
---|
[1528] | 151 |
|
---|
[2543] | 152 | Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
|
---|
| 153 | {}
|
---|
[1824] | 154 |
|
---|
[1520] | 155 |
|
---|
[2543] | 156 | ////////////
|
---|
[1942] | 157 |
|
---|
[2543] | 158 | Vector3 mPoint;
|
---|
| 159 | Vector3 mNormal;
|
---|
| 160 | Intersectable *mObject;
|
---|
| 161 | int mFaceId;
|
---|
| 162 | };
|
---|
[2012] | 163 |
|
---|
| 164 |
|
---|
[2543] | 165 | int ProcessRay(const SimpleRay &ray,
|
---|
| 166 | Intersection &hitA,
|
---|
| 167 | Intersection &hitB,
|
---|
| 168 | VssRayContainer &vssRays,
|
---|
| 169 | const AxisAlignedBox3 &box,
|
---|
| 170 | const bool castDoubleRay,
|
---|
| 171 | const bool pruneInvalidRays = true);
|
---|
[2012] | 172 |
|
---|
[2543] | 173 | /** Checks if ray is valid.
|
---|
| 174 | I.e., the ray is in valid view space.
|
---|
| 175 | @note: clamps the ray to valid view space.
|
---|
| 176 | */
|
---|
| 177 | bool ValidateRay(const Vector3 &origin,
|
---|
| 178 | const Vector3 &direction,
|
---|
| 179 | const AxisAlignedBox3 &box,
|
---|
| 180 | Intersection &hit);
|
---|
[2012] | 181 |
|
---|
[2543] | 182 | bool ClipToViewSpaceBox(const Vector3 &origin,
|
---|
| 183 | const Vector3 &termination,
|
---|
| 184 | Vector3 &clippedOrigin,
|
---|
| 185 | Vector3 &clippedTermination);
|
---|
[2069] | 186 |
|
---|
| 187 |
|
---|
[2543] | 188 |
|
---|
| 189 |
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | const Preprocessor &mPreprocessor;
|
---|
[1520] | 193 | };
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | #endif
|
---|