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