[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 |
|
---|
[1520] | 9 | using namespace std;
|
---|
| 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 |
|
---|
[1990] | 56 | virtual void CastRays16(
|
---|
[1932] | 57 | SimpleRayContainer &rays,
|
---|
| 58 | VssRayContainer &vssRays,
|
---|
| 59 | const AxisAlignedBox3 &sbox,
|
---|
| 60 | const bool castDoubleRay,
|
---|
[1996] | 61 | const bool pruneInvalidRays = true) = 0;
|
---|
[1974] | 62 |
|
---|
| 63 |
|
---|
| 64 | virtual void
|
---|
| 65 | SortRays(SimpleRayContainer &rays);
|
---|
| 66 |
|
---|
[1520] | 67 |
|
---|
[2012] | 68 |
|
---|
| 69 | // pool of vss rays to be used in one pass of the sampling
|
---|
| 70 | struct VssRayPool {
|
---|
[2048] | 71 | VssRayPool():mRays(NULL), mIndex(0), mNumber(0) {}
|
---|
[2014] | 72 | ~VssRayPool() {
|
---|
| 73 | if (mRays)
|
---|
| 74 | delete mRays;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[2012] | 77 | void Reserve(const int number) {
|
---|
[2014] | 78 | if (mRays)
|
---|
| 79 | delete mRays;
|
---|
| 80 | mRays = new VssRay[number];
|
---|
[2048] | 81 | mNumber = number;
|
---|
[2012] | 82 | }
|
---|
[2014] | 83 |
|
---|
[2012] | 84 | void Clear() {
|
---|
| 85 | mIndex = 0;
|
---|
| 86 | }
|
---|
| 87 | VssRay *Alloc() {
|
---|
[2048] | 88 | // reset pool
|
---|
| 89 | if (mIndex == mNumber)
|
---|
| 90 | mIndex = 0;
|
---|
[2014] | 91 | return mRays + mIndex++;
|
---|
[2012] | 92 | }
|
---|
[2014] | 93 |
|
---|
| 94 | VssRay *mRays;
|
---|
[2012] | 95 | int mIndex;
|
---|
[2048] | 96 | int mNumber;
|
---|
[2012] | 97 | };
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | VssRayPool mVssRayPool;
|
---|
| 101 |
|
---|
| 102 | void ReserveVssRayPool(const int n) {
|
---|
| 103 | mVssRayPool.Reserve(n);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void InitPass() {
|
---|
| 107 | mVssRayPool.Clear();
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
[1520] | 111 | protected:
|
---|
[1984] | 112 | void _SortRays(SimpleRayContainer &rays,
|
---|
| 113 | const int l,
|
---|
| 114 | const int r,
|
---|
| 115 | const int depth,
|
---|
| 116 | float box[12]);
|
---|
| 117 |
|
---|
[1974] | 118 | struct Intersection
|
---|
[1528] | 119 | {
|
---|
| 120 | Intersection(): mObject(NULL), mFaceId(0)
|
---|
| 121 | {}
|
---|
[1520] | 122 |
|
---|
[1528] | 123 | Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
|
---|
[1824] | 124 | mPoint(p), mNormal(n), mObject(o), mFaceId(f)
|
---|
[1528] | 125 | {}
|
---|
| 126 |
|
---|
| 127 | Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
|
---|
| 128 | {}
|
---|
| 129 | Vector3 mPoint;
|
---|
| 130 | Vector3 mNormal;
|
---|
| 131 | Intersectable *mObject;
|
---|
| 132 | int mFaceId;
|
---|
| 133 | };
|
---|
| 134 |
|
---|
[1824] | 135 |
|
---|
[1932] | 136 | int ProcessRay(const SimpleRay &ray,
|
---|
| 137 | Intersection &hitA,
|
---|
| 138 | Intersection &hitB,
|
---|
| 139 | VssRayContainer &vssRays,
|
---|
| 140 | const AxisAlignedBox3 &box,
|
---|
| 141 | const bool castDoubleRay,
|
---|
[1996] | 142 | const bool pruneInvalidRays = true);
|
---|
[1520] | 143 |
|
---|
[1528] | 144 | /** Checks if ray is valid.
|
---|
| 145 | I.e., the ray is in valid view space.
|
---|
| 146 | @note: clamps the ray to valid view space.
|
---|
| 147 | */
|
---|
| 148 | bool ValidateRay(const Vector3 &origin,
|
---|
| 149 | const Vector3 &direction,
|
---|
| 150 | const AxisAlignedBox3 &box,
|
---|
| 151 | Intersection &hit);
|
---|
[1942] | 152 |
|
---|
[1990] | 153 | bool
|
---|
| 154 | ClipToViewSpaceBox(const Vector3 &origin,
|
---|
| 155 | const Vector3 &termination,
|
---|
| 156 | Vector3 &clippedOrigin,
|
---|
| 157 | Vector3 &clippedTermination);
|
---|
[1520] | 158 |
|
---|
[2012] | 159 |
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | const Preprocessor &mPreprocessor;
|
---|
[1520] | 165 | };
|
---|
| 166 |
|
---|
| 167 |
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | #endif
|
---|