1 | #ifndef _RayCaster_H__
|
---|
2 | #define _RayCaster_H__
|
---|
3 |
|
---|
4 | #include "Containers.h"
|
---|
5 | #include <string>
|
---|
6 | #include "Vector3.h"
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 |
|
---|
11 | namespace GtpVisibilityPreprocessor {
|
---|
12 |
|
---|
13 |
|
---|
14 | class Intersectable;
|
---|
15 | class VssRay;
|
---|
16 | class SimpleRayContainer;
|
---|
17 | class AxisAlignedBox3;
|
---|
18 | //class Vector3;
|
---|
19 | struct VssRayContainer;
|
---|
20 | class Preprocessor;
|
---|
21 | struct SimpleRay;
|
---|
22 |
|
---|
23 |
|
---|
24 | /** This class provides an interface for ray casting.
|
---|
25 | */
|
---|
26 | class RayCaster
|
---|
27 | {
|
---|
28 |
|
---|
29 | public:
|
---|
30 |
|
---|
31 | enum {
|
---|
32 | INTERNAL_RAYCASTER = 0,
|
---|
33 | INTEL_RAYCASTER
|
---|
34 | };
|
---|
35 |
|
---|
36 | RayCaster(const Preprocessor &preprocessor);
|
---|
37 |
|
---|
38 | virtual ~RayCaster();
|
---|
39 |
|
---|
40 | virtual int Type() const = 0;
|
---|
41 |
|
---|
42 | /** Wrapper for casting single ray.
|
---|
43 | @returns ray or NULL if invalid
|
---|
44 | */
|
---|
45 | VssRay *CastRay(const SimpleRay &simpleRay,
|
---|
46 | const AxisAlignedBox3 &box,
|
---|
47 | const bool castDoubleRay);
|
---|
48 |
|
---|
49 | virtual int CastRay(const SimpleRay &simpleRay,
|
---|
50 | VssRayContainer &vssRays,
|
---|
51 | const AxisAlignedBox3 &box,
|
---|
52 | const bool castDoubleRay,
|
---|
53 | const bool pruneInvalidRays = true) = 0;
|
---|
54 |
|
---|
55 | virtual void CastRays16(
|
---|
56 | SimpleRayContainer &rays,
|
---|
57 | VssRayContainer &vssRays,
|
---|
58 | const AxisAlignedBox3 &sbox,
|
---|
59 | const bool castDoubleRay,
|
---|
60 | const bool pruneInvalidRays = true) = 0;
|
---|
61 |
|
---|
62 |
|
---|
63 | virtual void
|
---|
64 | SortRays(SimpleRayContainer &rays);
|
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 | // pool of vss rays to be used in one pass of the sampling
|
---|
69 | struct VssRayPool {
|
---|
70 | VssRayPool():mRays(), mIndex(0) {}
|
---|
71 |
|
---|
72 | void Reserve(const int number) {
|
---|
73 | mRays.reserve(number);
|
---|
74 | }
|
---|
75 | void Clear() {
|
---|
76 | mIndex = 0;
|
---|
77 | }
|
---|
78 | VssRay *Alloc() {
|
---|
79 | VssRay *result = &mRays[mIndex];
|
---|
80 | mIndex++;
|
---|
81 | return result;
|
---|
82 | }
|
---|
83 | vector<VssRay> mRays;
|
---|
84 | int mIndex;
|
---|
85 | };
|
---|
86 |
|
---|
87 |
|
---|
88 | VssRayPool mVssRayPool;
|
---|
89 |
|
---|
90 | void ReserveVssRayPool(const int n) {
|
---|
91 | mVssRayPool.Reserve(n);
|
---|
92 | }
|
---|
93 |
|
---|
94 | void InitPass() {
|
---|
95 | mVssRayPool.Clear();
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | protected:
|
---|
100 | void _SortRays(SimpleRayContainer &rays,
|
---|
101 | const int l,
|
---|
102 | const int r,
|
---|
103 | const int depth,
|
---|
104 | float box[12]);
|
---|
105 |
|
---|
106 | struct Intersection
|
---|
107 | {
|
---|
108 | Intersection(): mObject(NULL), mFaceId(0)
|
---|
109 | {}
|
---|
110 |
|
---|
111 | Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
|
---|
112 | mPoint(p), mNormal(n), mObject(o), mFaceId(f)
|
---|
113 | {}
|
---|
114 |
|
---|
115 | Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
|
---|
116 | {}
|
---|
117 | Vector3 mPoint;
|
---|
118 | Vector3 mNormal;
|
---|
119 | Intersectable *mObject;
|
---|
120 | int mFaceId;
|
---|
121 | };
|
---|
122 |
|
---|
123 |
|
---|
124 | int ProcessRay(const SimpleRay &ray,
|
---|
125 | Intersection &hitA,
|
---|
126 | Intersection &hitB,
|
---|
127 | VssRayContainer &vssRays,
|
---|
128 | const AxisAlignedBox3 &box,
|
---|
129 | const bool castDoubleRay,
|
---|
130 | const bool pruneInvalidRays = true);
|
---|
131 |
|
---|
132 | /** Checks if ray is valid.
|
---|
133 | I.e., the ray is in valid view space.
|
---|
134 | @note: clamps the ray to valid view space.
|
---|
135 | */
|
---|
136 | bool ValidateRay(const Vector3 &origin,
|
---|
137 | const Vector3 &direction,
|
---|
138 | const AxisAlignedBox3 &box,
|
---|
139 | Intersection &hit);
|
---|
140 |
|
---|
141 | bool
|
---|
142 | ClipToViewSpaceBox(const Vector3 &origin,
|
---|
143 | const Vector3 &termination,
|
---|
144 | Vector3 &clippedOrigin,
|
---|
145 | Vector3 &clippedTermination);
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 | const Preprocessor &mPreprocessor;
|
---|
153 | };
|
---|
154 |
|
---|
155 |
|
---|
156 | }
|
---|
157 |
|
---|
158 | #endif
|
---|