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