1 | #ifndef __INTERSECTABLEWRAPPER_H
|
---|
2 | #define __INTERSECTABLEWRAPPER_H
|
---|
3 |
|
---|
4 | #include "AxisAlignedBox3.h"
|
---|
5 | #include "Intersectable.h"
|
---|
6 | #include "Triangle3.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 |
|
---|
12 | class KdNode;
|
---|
13 | class BvhLeaf;
|
---|
14 | class Ray;
|
---|
15 | class KdTree;
|
---|
16 | struct VssRayContainer;
|
---|
17 | struct Triangle3;
|
---|
18 | struct Face;
|
---|
19 |
|
---|
20 | /** Wrapper used for creating a PVS compliant intersectable.
|
---|
21 | */
|
---|
22 | template<typename T>
|
---|
23 | class IntersectableWrapper: public Intersectable
|
---|
24 | {
|
---|
25 | public:
|
---|
26 | IntersectableWrapper(T item);
|
---|
27 |
|
---|
28 | /** Returns node associated with this instance.
|
---|
29 | */
|
---|
30 | T GetItem() const;
|
---|
31 | /** See get.
|
---|
32 | */
|
---|
33 | void SetItem(T item);
|
---|
34 |
|
---|
35 |
|
---|
36 | /////////////////////////////////////////////
|
---|
37 | //-- inherited functions from Intersectable
|
---|
38 |
|
---|
39 | AxisAlignedBox3 GetBox() const;
|
---|
40 |
|
---|
41 | int CastRay(Ray &ray);
|
---|
42 | int CastSimpleRay(const SimpleRay &ray) { return 0;}
|
---|
43 | int CastSimpleRay(const SimpleRay &ray, int RayIndex) { return 0;}
|
---|
44 |
|
---|
45 |
|
---|
46 | bool IsConvex() const;
|
---|
47 | bool IsWatertight() const;
|
---|
48 | float IntersectionComplexity();
|
---|
49 |
|
---|
50 | int NumberOfFaces() const;
|
---|
51 |
|
---|
52 | int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
53 | GtpVisibilityPreprocessor::Vector3 &normal);
|
---|
54 |
|
---|
55 | int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
56 | GtpVisibilityPreprocessor::Vector3 &normal,
|
---|
57 | const GtpVisibilityPreprocessor::Vector3 &viewpoint,
|
---|
58 | const int maxTries);
|
---|
59 |
|
---|
60 | std::ostream &Describe(std::ostream &s);
|
---|
61 |
|
---|
62 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
63 |
|
---|
64 |
|
---|
65 | protected:
|
---|
66 |
|
---|
67 | T mItem;
|
---|
68 | };
|
---|
69 |
|
---|
70 |
|
---|
71 | template<typename T>
|
---|
72 | IntersectableWrapper<T>::IntersectableWrapper(T item):
|
---|
73 | Intersectable(), mItem(item)
|
---|
74 | {
|
---|
75 | }
|
---|
76 |
|
---|
77 | template<typename T>
|
---|
78 | void IntersectableWrapper<T>::SetItem(T item)
|
---|
79 | {
|
---|
80 | mItem = item;
|
---|
81 | }
|
---|
82 |
|
---|
83 | template<typename T>
|
---|
84 | T IntersectableWrapper<T>::GetItem() const
|
---|
85 | {
|
---|
86 | return mItem;
|
---|
87 | }
|
---|
88 |
|
---|
89 | template<typename T>
|
---|
90 | AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
|
---|
91 | { // TODO matt
|
---|
92 | return AxisAlignedBox3();
|
---|
93 | }
|
---|
94 |
|
---|
95 | template<typename T>
|
---|
96 | int IntersectableWrapper<T>::CastRay(Ray &ray)
|
---|
97 | { // TODO matt
|
---|
98 | return 0;
|
---|
99 | }
|
---|
100 |
|
---|
101 | template<typename T>
|
---|
102 | bool IntersectableWrapper<T>::IsConvex() const
|
---|
103 | {
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | template<typename T>
|
---|
108 | bool IntersectableWrapper<T>::IsWatertight() const
|
---|
109 | {
|
---|
110 | return true;
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | template<typename T>
|
---|
115 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
116 | {
|
---|
117 | return 1.0f;
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | template<typename T>
|
---|
122 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
123 | {
|
---|
124 | return 0;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 | template<typename T>
|
---|
129 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
130 | Vector3 &normal)
|
---|
131 | {
|
---|
132 | return 0;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 | template<typename T>
|
---|
138 | int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
|
---|
139 | Vector3 &normal)
|
---|
140 | {
|
---|
141 | return 0;
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | template<typename T>
|
---|
146 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
147 | Vector3 &normal,
|
---|
148 | const Vector3 &viewpoint,
|
---|
149 | const int maxTries)
|
---|
150 | {
|
---|
151 | return 0;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 | template<typename T>
|
---|
157 | std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
|
---|
158 | {
|
---|
159 | s << mItem;
|
---|
160 | return s;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
165 | {
|
---|
166 | public:
|
---|
167 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
168 |
|
---|
169 | int ComputeNumTriangles();
|
---|
170 |
|
---|
171 | int Type() const
|
---|
172 | {
|
---|
173 | return Intersectable::KD_INTERSECTABLE;
|
---|
174 | }
|
---|
175 |
|
---|
176 | AxisAlignedBox3 GetBox() const
|
---|
177 | {
|
---|
178 | return mBox;
|
---|
179 | }
|
---|
180 |
|
---|
181 | /// the bounding box of this intersectable
|
---|
182 | AxisAlignedBox3 mBox;
|
---|
183 |
|
---|
184 | int mGenericIdx;
|
---|
185 |
|
---|
186 | protected:
|
---|
187 |
|
---|
188 | int mNumTriangles;
|
---|
189 | };
|
---|
190 |
|
---|
191 |
|
---|
192 | typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
193 |
|
---|
194 |
|
---|
195 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
196 | {
|
---|
197 | public:
|
---|
198 | TriangleIntersectable(const Triangle3 &item):
|
---|
199 | IntersectableWrapper<Triangle3>(item) {}
|
---|
200 |
|
---|
201 | int CastRay(Ray &ray);
|
---|
202 |
|
---|
203 | int CastSimpleRay(const SimpleRay &ray);
|
---|
204 | int CastSimpleRay(const SimpleRay &ray, int rayIndex);
|
---|
205 |
|
---|
206 | AxisAlignedBox3 GetBox() const;
|
---|
207 | int NumberOfFaces() const;
|
---|
208 | Vector3 GetNormal(const int idx) const;
|
---|
209 | Vector3 GetNormal() const { return mItem.GetNormal();}
|
---|
210 |
|
---|
211 | float GetArea() const {return mItem.GetArea();}
|
---|
212 |
|
---|
213 | int Type() const
|
---|
214 | {
|
---|
215 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
216 | }
|
---|
217 |
|
---|
218 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
219 |
|
---|
220 | int GetRandomSurfacePoint(const float u,
|
---|
221 | const float v,
|
---|
222 | Vector3 &point, Vector3 &normal);
|
---|
223 |
|
---|
224 |
|
---|
225 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
226 | Vector3 &normal,
|
---|
227 | const Vector3 &viewpoint,
|
---|
228 | const int maxTries);
|
---|
229 |
|
---|
230 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
231 | };
|
---|
232 |
|
---|
233 |
|
---|
234 | /** Intersectable acting as a proxy.
|
---|
235 | */
|
---|
236 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
237 | {
|
---|
238 | public:
|
---|
239 | DummyIntersectable(const int item):
|
---|
240 | IntersectableWrapper<int>(item) { SetId(item); }
|
---|
241 |
|
---|
242 | int Type() const
|
---|
243 | {
|
---|
244 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
245 | }
|
---|
246 | };
|
---|
247 |
|
---|
248 |
|
---|
249 | /** Intersectable wrapping is a group of objects.
|
---|
250 | */
|
---|
251 | class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
|
---|
252 | {
|
---|
253 | public:
|
---|
254 | ContainerIntersectable(ObjectContainer *item):
|
---|
255 | IntersectableWrapper<ObjectContainer *>(item) {}
|
---|
256 |
|
---|
257 | // hack
|
---|
258 | ~ContainerIntersectable()
|
---|
259 | {
|
---|
260 | delete mItem;
|
---|
261 | }
|
---|
262 |
|
---|
263 | int Type() const
|
---|
264 | {
|
---|
265 | return Intersectable::CONTAINER_INTERSECTABLE;
|
---|
266 | }
|
---|
267 | };
|
---|
268 |
|
---|
269 |
|
---|
270 | class SceneGraphLeafIntersectable: public IntersectableWrapper<SceneGraphLeaf *>
|
---|
271 | {
|
---|
272 | public:
|
---|
273 | SceneGraphLeafIntersectable(SceneGraphLeaf *item, const AxisAlignedBox3 &box);
|
---|
274 |
|
---|
275 | int ComputeNumTriangles() { return 0;}
|
---|
276 |
|
---|
277 | int Type() const
|
---|
278 | {
|
---|
279 | return Intersectable::SCENEGRAPHLEAF_INTERSECTABLE;
|
---|
280 | }
|
---|
281 |
|
---|
282 | AxisAlignedBox3 GetBox() const
|
---|
283 | {
|
---|
284 | return mBox;
|
---|
285 | }
|
---|
286 |
|
---|
287 | /// the bounding box of this intersectable
|
---|
288 | AxisAlignedBox3 mBox;
|
---|
289 |
|
---|
290 | protected:
|
---|
291 |
|
---|
292 | // int mNumTriangles;
|
---|
293 | };
|
---|
294 |
|
---|
295 |
|
---|
296 | }
|
---|
297 |
|
---|
298 | #endif
|
---|