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