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 | //
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace GtpVisibilityPreprocessor {
|
---|
13 |
|
---|
14 |
|
---|
15 | class Intersectable;
|
---|
16 | class VssRay;
|
---|
17 | class SimpleRayContainer;
|
---|
18 | class AxisAlignedBox3;
|
---|
19 | struct VssRayContainer;
|
---|
20 | class Preprocessor;
|
---|
21 | struct SimpleRay;
|
---|
22 | class RayPacket2x2;
|
---|
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 = 1,
|
---|
34 | HAVRAN_RAYCASTER = 2
|
---|
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(SimpleRayContainer &rays,
|
---|
57 | VssRayContainer &vssRays,
|
---|
58 | const AxisAlignedBox3 &sbox,
|
---|
59 | const bool castDoubleRay,
|
---|
60 | const bool pruneInvalidRays = true) = 0;
|
---|
61 |
|
---|
62 | virtual void CastRays(
|
---|
63 | SimpleRayContainer &rays,
|
---|
64 | VssRayContainer &vssRays,
|
---|
65 | const AxisAlignedBox3 &sbox,
|
---|
66 | const bool castDoubleRay,
|
---|
67 | const bool pruneInvalidRays = true);
|
---|
68 |
|
---|
69 | // Using packet of 4 rays supposing that these are coherent
|
---|
70 | virtual void CastRaysPacket4(Vector3 origin4[],
|
---|
71 | Vector3 direction4[],
|
---|
72 | int result4[],
|
---|
73 | float dist4[]) { }
|
---|
74 |
|
---|
75 | // Using packet of 4 rays supposing that these are coherent
|
---|
76 | // We give a box to which each ray is clipped to before the
|
---|
77 | // ray shooting is computed !
|
---|
78 | virtual void CastRaysPacket4(const Vector3 &minBox,
|
---|
79 | const Vector3 &maxBox,
|
---|
80 | const Vector3 origin4[],
|
---|
81 | const Vector3 direction4[],
|
---|
82 | int result4[],
|
---|
83 | float dist4[]) { }
|
---|
84 |
|
---|
85 | // Just for testing concept
|
---|
86 | virtual void CastRaysPacket2x2(RayPacket2x2 &raysPack,
|
---|
87 | bool castDoubleRay,
|
---|
88 | const bool pruneInvalidRays = true)
|
---|
89 | { }
|
---|
90 |
|
---|
91 | /*virtual void CastRaysEye4(SimpleRayContainer &rays,
|
---|
92 | VssRayContainer &vssRays,
|
---|
93 | const AxisAlignedBox3 &sbox,
|
---|
94 | const bool castDoubleRay,
|
---|
95 | const bool pruneInvalidRays = true) = 0;
|
---|
96 | */
|
---|
97 |
|
---|
98 | virtual void
|
---|
99 | SortRays(SimpleRayContainer &rays);
|
---|
100 |
|
---|
101 |
|
---|
102 | // pool of vss rays to be used in one pass of the sampling
|
---|
103 | struct VssRayPool
|
---|
104 | {
|
---|
105 | VssRayPool(): mRays(NULL), mIndex(0), mNumber(0)
|
---|
106 | {}
|
---|
107 |
|
---|
108 | ~VssRayPool()
|
---|
109 | {
|
---|
110 | delete []mRays;
|
---|
111 | }
|
---|
112 |
|
---|
113 | void Reserve(const int number)
|
---|
114 | {
|
---|
115 | DEL_PTR(mRays);
|
---|
116 | mRays = new VssRay[number];
|
---|
117 | mNumber = number;
|
---|
118 | }
|
---|
119 |
|
---|
120 | void Clear()
|
---|
121 | {
|
---|
122 | mIndex = 0;
|
---|
123 | }
|
---|
124 |
|
---|
125 | VssRay *Alloc()
|
---|
126 | {
|
---|
127 | // reset pool
|
---|
128 | if (mIndex == mNumber)
|
---|
129 | mIndex = 0;
|
---|
130 | return mRays + mIndex ++;
|
---|
131 | }
|
---|
132 | protected:
|
---|
133 | VssRay *mRays;
|
---|
134 | int mIndex;
|
---|
135 | int mNumber;
|
---|
136 | };
|
---|
137 |
|
---|
138 |
|
---|
139 | VssRayPool mVssRayPool;
|
---|
140 |
|
---|
141 | void ReserveVssRayPool(const int n)
|
---|
142 | {
|
---|
143 | mVssRayPool.Reserve(n);
|
---|
144 | }
|
---|
145 |
|
---|
146 | void InitPass()
|
---|
147 | {
|
---|
148 | mVssRayPool.Clear();
|
---|
149 | }
|
---|
150 |
|
---|
151 |
|
---|
152 | protected:
|
---|
153 |
|
---|
154 | VssRay *RequestRay(const Vector3 &origin,
|
---|
155 | const Vector3 &termination,
|
---|
156 | Intersectable *originObject,
|
---|
157 | Intersectable *terminationObject,
|
---|
158 | const int pass,
|
---|
159 | const float pdf);
|
---|
160 |
|
---|
161 | void _SortRays(SimpleRayContainer &rays,
|
---|
162 | const int l,
|
---|
163 | const int r,
|
---|
164 | const int depth,
|
---|
165 | float box[12]);
|
---|
166 |
|
---|
167 | struct Intersection
|
---|
168 | {
|
---|
169 | Intersection(): mObject(NULL), mFaceId(0)
|
---|
170 | {}
|
---|
171 |
|
---|
172 | Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f):
|
---|
173 | mPoint(p), mNormal(n), mObject(o), mFaceId(f)
|
---|
174 | {}
|
---|
175 |
|
---|
176 | Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0)
|
---|
177 | {}
|
---|
178 |
|
---|
179 |
|
---|
180 | ////////////
|
---|
181 |
|
---|
182 | Vector3 mPoint;
|
---|
183 | Vector3 mNormal;
|
---|
184 | Intersectable *mObject;
|
---|
185 | int mFaceId;
|
---|
186 | };
|
---|
187 |
|
---|
188 |
|
---|
189 | int ProcessRay(const SimpleRay &ray,
|
---|
190 | Intersection &hitA,
|
---|
191 | Intersection &hitB,
|
---|
192 | VssRayContainer &vssRays,
|
---|
193 | const AxisAlignedBox3 &box,
|
---|
194 | const bool castDoubleRay,
|
---|
195 | const bool pruneInvalidRays = true);
|
---|
196 |
|
---|
197 | /** Checks if ray is valid.
|
---|
198 | I.e., the ray is in valid view space.
|
---|
199 | @note: clamps the ray to valid view space.
|
---|
200 | */
|
---|
201 | bool ValidateRay(const Vector3 &origin,
|
---|
202 | const Vector3 &direction,
|
---|
203 | const AxisAlignedBox3 &box,
|
---|
204 | Intersection &hit);
|
---|
205 |
|
---|
206 | bool ClipToViewSpaceBox(const Vector3 &origin,
|
---|
207 | const Vector3 &termination,
|
---|
208 | Vector3 &clippedOrigin,
|
---|
209 | Vector3 &clippedTermination);
|
---|
210 |
|
---|
211 | const Preprocessor &mPreprocessor;
|
---|
212 | #if 1
|
---|
213 | public:
|
---|
214 | // Added by VH for debugging
|
---|
215 | Intersection intersect;
|
---|
216 | #endif
|
---|
217 | };
|
---|
218 |
|
---|
219 |
|
---|
220 | }
|
---|
221 |
|
---|
222 | #endif
|
---|