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 |
|
---|
43 | bool IsConvex() const;
|
---|
44 | bool IsWatertight() const;
|
---|
45 | float IntersectionComplexity();
|
---|
46 |
|
---|
47 | int NumberOfFaces() const;
|
---|
48 |
|
---|
49 | int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
50 | GtpVisibilityPreprocessor::Vector3 &normal);
|
---|
51 |
|
---|
52 | int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
53 | GtpVisibilityPreprocessor::Vector3 &normal,
|
---|
54 | const GtpVisibilityPreprocessor::Vector3 &viewpoint,
|
---|
55 | const int maxTries);
|
---|
56 |
|
---|
57 | std::ostream &Describe(std::ostream &s);
|
---|
58 |
|
---|
59 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
60 |
|
---|
61 |
|
---|
62 | protected:
|
---|
63 |
|
---|
64 | T mItem;
|
---|
65 | };
|
---|
66 |
|
---|
67 |
|
---|
68 | template<typename T>
|
---|
69 | IntersectableWrapper<T>::IntersectableWrapper(T item):
|
---|
70 | Intersectable(), mItem(item)
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | template<typename T>
|
---|
75 | void IntersectableWrapper<T>::SetItem(T item)
|
---|
76 | {
|
---|
77 | mItem = item;
|
---|
78 | }
|
---|
79 |
|
---|
80 | template<typename T>
|
---|
81 | T IntersectableWrapper<T>::GetItem() const
|
---|
82 | {
|
---|
83 | return mItem;
|
---|
84 | }
|
---|
85 |
|
---|
86 | template<typename T>
|
---|
87 | AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
|
---|
88 | { // TODO matt
|
---|
89 | return AxisAlignedBox3();
|
---|
90 | }
|
---|
91 |
|
---|
92 | template<typename T>
|
---|
93 | int IntersectableWrapper<T>::CastRay(Ray &ray)
|
---|
94 | { // TODO matt
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | template<typename T>
|
---|
99 | bool IntersectableWrapper<T>::IsConvex() const
|
---|
100 | {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | template<typename T>
|
---|
105 | bool IntersectableWrapper<T>::IsWatertight() const
|
---|
106 | {
|
---|
107 | return true;
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | template<typename T>
|
---|
112 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
113 | {
|
---|
114 | return 1.0f;
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | template<typename T>
|
---|
119 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
120 | {
|
---|
121 | return 0;
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | template<typename T>
|
---|
126 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
127 | Vector3 &normal)
|
---|
128 | {
|
---|
129 | return 0;
|
---|
130 | }
|
---|
131 | |
---|
132 |
|
---|
133 |
|
---|
134 | template<typename T>
|
---|
135 | int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
|
---|
136 | Vector3 &normal)
|
---|
137 | {
|
---|
138 | return 0;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | template<typename T>
|
---|
143 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
144 | Vector3 &normal,
|
---|
145 | const Vector3 &viewpoint,
|
---|
146 | const int maxTries)
|
---|
147 | {
|
---|
148 | return 0;
|
---|
149 | }
|
---|
150 |
|
---|
151 | template<typename T>
|
---|
152 | std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
|
---|
153 | {
|
---|
154 | s << mItem;
|
---|
155 | return s;
|
---|
156 | }
|
---|
157 |
|
---|
158 |
|
---|
159 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
160 | {
|
---|
161 | public:
|
---|
162 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
163 |
|
---|
164 | int Type() const
|
---|
165 | {
|
---|
166 | return Intersectable::KD_INTERSECTABLE;
|
---|
167 | }
|
---|
168 |
|
---|
169 | AxisAlignedBox3 GetBox() const
|
---|
170 | {
|
---|
171 | return mBox; |
---|
172 | } |
---|
173 | |
---|
174 | /// the bounding box of this intersectable |
---|
175 | AxisAlignedBox3 mBox; |
---|
176 | }; |
---|
177 |
|
---|
178 |
|
---|
179 | typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
180 |
|
---|
181 |
|
---|
182 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
183 | {
|
---|
184 | public:
|
---|
185 | TriangleIntersectable(const Triangle3 &item):
|
---|
186 | IntersectableWrapper<Triangle3>(item) {}
|
---|
187 |
|
---|
188 | int CastRay(Ray &ray);
|
---|
189 | AxisAlignedBox3 GetBox() const;
|
---|
190 | int NumberOfFaces() const;
|
---|
191 | Vector3 GetNormal(const int idx) const;
|
---|
192 |
|
---|
193 | float GetArea() const {return mItem.GetArea();}
|
---|
194 |
|
---|
195 | int Type() const
|
---|
196 | {
|
---|
197 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
198 | }
|
---|
199 |
|
---|
200 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
201 | |
---|
202 | int GetRandomSurfacePoint(const float u, |
---|
203 | const float v, |
---|
204 | Vector3 &point, Vector3 &normal);
|
---|
205 | |
---|
206 |
|
---|
207 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
208 | Vector3 &normal,
|
---|
209 | const Vector3 &viewpoint,
|
---|
210 | const int maxTries);
|
---|
211 |
|
---|
212 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
213 | };
|
---|
214 |
|
---|
215 |
|
---|
216 | /** Intersectable acting as a proxy.
|
---|
217 | */
|
---|
218 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
219 | {
|
---|
220 | public:
|
---|
221 | DummyIntersectable(const int item):
|
---|
222 | IntersectableWrapper<int>(item) { SetId(item); }
|
---|
223 |
|
---|
224 | int Type() const
|
---|
225 | {
|
---|
226 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
227 | }
|
---|
228 | };
|
---|
229 |
|
---|
230 |
|
---|
231 | /** Intersectable wrapping is a group of objects.
|
---|
232 | */
|
---|
233 | class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
|
---|
234 | {
|
---|
235 | public:
|
---|
236 | ContainerIntersectable(ObjectContainer *item):
|
---|
237 | IntersectableWrapper<ObjectContainer *>(item) {}
|
---|
238 |
|
---|
239 | // hack
|
---|
240 | ContainerIntersectable::~ContainerIntersectable()
|
---|
241 | {
|
---|
242 | delete mItem;
|
---|
243 | }
|
---|
244 |
|
---|
245 | int Type() const
|
---|
246 | {
|
---|
247 | return Intersectable::CONTAINER_INTERSECTABLE;
|
---|
248 | }
|
---|
249 | };
|
---|
250 |
|
---|
251 | }
|
---|
252 |
|
---|
253 | #endif
|
---|