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 | template<typename T>
|
---|
155 | std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
|
---|
156 | {
|
---|
157 | s << mItem;
|
---|
158 | return s;
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
163 | {
|
---|
164 | public:
|
---|
165 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
166 |
|
---|
167 | int ComputeNumTriangles();
|
---|
168 |
|
---|
169 | int Type() const
|
---|
170 | {
|
---|
171 | return Intersectable::KD_INTERSECTABLE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | AxisAlignedBox3 GetBox() const
|
---|
175 | {
|
---|
176 | return mBox; |
---|
177 | } |
---|
178 | |
---|
179 | /// the bounding box of this intersectable |
---|
180 | AxisAlignedBox3 mBox; |
---|
181 | |
---|
182 | protected: |
---|
183 | |
---|
184 | int mNumTriangles; |
---|
185 | }; |
---|
186 |
|
---|
187 |
|
---|
188 | typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
189 |
|
---|
190 |
|
---|
191 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
192 | {
|
---|
193 | public:
|
---|
194 | TriangleIntersectable(const Triangle3 &item):
|
---|
195 | IntersectableWrapper<Triangle3>(item) {}
|
---|
196 |
|
---|
197 | int CastRay(Ray &ray);
|
---|
198 | |
---|
199 | int CastSimpleRay(const SimpleRay &ray); |
---|
200 | int CastSimpleRay(const SimpleRay &ray, int rayIndex); |
---|
201 | |
---|
202 | AxisAlignedBox3 GetBox() const;
|
---|
203 | int NumberOfFaces() const;
|
---|
204 | Vector3 GetNormal(const int idx) const;
|
---|
205 | Vector3 GetNormal() const { return mItem.GetNormal();} |
---|
206 |
|
---|
207 | float GetArea() const {return mItem.GetArea();}
|
---|
208 |
|
---|
209 | int Type() const
|
---|
210 | {
|
---|
211 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
212 | }
|
---|
213 |
|
---|
214 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
215 | |
---|
216 | int GetRandomSurfacePoint(const float u, |
---|
217 | const float v, |
---|
218 | Vector3 &point, Vector3 &normal);
|
---|
219 | |
---|
220 |
|
---|
221 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
222 | Vector3 &normal,
|
---|
223 | const Vector3 &viewpoint,
|
---|
224 | const int maxTries);
|
---|
225 |
|
---|
226 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
227 | };
|
---|
228 |
|
---|
229 |
|
---|
230 | /** Intersectable acting as a proxy.
|
---|
231 | */
|
---|
232 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
233 | {
|
---|
234 | public:
|
---|
235 | DummyIntersectable(const int item):
|
---|
236 | IntersectableWrapper<int>(item) { SetId(item); }
|
---|
237 |
|
---|
238 | int Type() const
|
---|
239 | {
|
---|
240 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
241 | }
|
---|
242 | };
|
---|
243 |
|
---|
244 |
|
---|
245 | /** Intersectable wrapping is a group of objects.
|
---|
246 | */
|
---|
247 | class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
|
---|
248 | {
|
---|
249 | public:
|
---|
250 | ContainerIntersectable(ObjectContainer *item):
|
---|
251 | IntersectableWrapper<ObjectContainer *>(item) {}
|
---|
252 |
|
---|
253 | // hack
|
---|
254 | ~ContainerIntersectable()
|
---|
255 | {
|
---|
256 | delete mItem;
|
---|
257 | }
|
---|
258 |
|
---|
259 | int Type() const
|
---|
260 | {
|
---|
261 | return Intersectable::CONTAINER_INTERSECTABLE;
|
---|
262 | }
|
---|
263 | };
|
---|
264 |
|
---|
265 | }
|
---|
266 |
|
---|
267 | #endif
|
---|