source: GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h @ 2702

Revision 2702, 5.7 KB checked in by mattausch, 16 years ago (diff)

implemented dynamic object placement / removal

Line 
1#ifndef __INTERSECTABLEWRAPPER_H
2#define __INTERSECTABLEWRAPPER_H
3
4#include "AxisAlignedBox3.h"
5#include "Intersectable.h"
6#include "Triangle3.h"
7
8
9namespace GtpVisibilityPreprocessor {
10
11
12class KdNode;
13class BvhLeaf;
14class Ray;
15class KdTree;
16struct VssRayContainer;
17struct Triangle3;
18struct Face;
19
20/** Wrapper used for creating a PVS compliant intersectable.
21*/
22template<typename T>
23class IntersectableWrapper: public Intersectable
24{
25public:
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
65protected:
66       
67        T mItem;
68};
69
70
71template<typename T>
72IntersectableWrapper<T>::IntersectableWrapper(T item):
73Intersectable(), mItem(item)
74{
75}
76
77template<typename T>
78void IntersectableWrapper<T>::SetItem(T item)
79{
80        mItem = item;
81}
82
83template<typename T>
84T IntersectableWrapper<T>::GetItem() const
85{
86        return mItem;
87}
88       
89template<typename T>
90AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
91{       // TODO matt
92        return AxisAlignedBox3();
93}
94
95template<typename T>
96int IntersectableWrapper<T>::CastRay(Ray &ray)
97{       // TODO matt
98        return 0;
99}
100       
101template<typename T>
102bool IntersectableWrapper<T>::IsConvex() const
103{
104        return true;
105}
106
107template<typename T>
108bool IntersectableWrapper<T>::IsWatertight() const
109{
110        return true;
111}
112
113
114template<typename T>
115float IntersectableWrapper<T>::IntersectionComplexity()
116{
117        return 1.0f;
118}
119
120
121template<typename T>
122int IntersectableWrapper<T>::NumberOfFaces() const
123{
124        return 0;
125}
126
127
128template<typename T>
129int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
130                                                                                                   Vector3 &normal)
131{
132        return 0;
133}
134
135
136
137template<typename T>
138int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
139                                                                                                Vector3 &normal)
140{
141        return 0;
142}
143
144
145template<typename T>
146int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
147                                                                                                                  Vector3 &normal,
148                                                                                                                  const Vector3 &viewpoint,
149                                                                                                                  const int maxTries)
150{
151        return 0;
152}
153 
154
155
156template<typename T>
157std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
158{
159 s << mItem;
160   return s;
161         }
162
163
164class KdIntersectable: public IntersectableWrapper<KdNode *>
165{
166public:
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
186protected:
187
188        int mNumTriangles;
189};
190
191
192typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
193
194
195class TriangleIntersectable: public IntersectableWrapper<Triangle3>
196{
197public:
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*/
236class DummyIntersectable: public IntersectableWrapper<int>
237{
238public:
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*/
251class IntersectableGroup: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
252{
253public:
254        IntersectableGroup(ObjectContainer *item):
255          IntersectableWrapper<ObjectContainer *>(item) {}
256
257        // hack
258        ~IntersectableGroup()
259        {
260                delete mItem;
261        }
262
263        int Type() const
264        {
265                return Intersectable::CONTAINER_INTERSECTABLE;
266        }
267};
268
269
270class SceneGraphLeafIntersectable: public IntersectableWrapper<SceneGraphLeaf *>
271{
272public:
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
290protected:
291
292//      int mNumTriangles;
293};
294
295
296}
297
298#endif
Note: See TracBrowser for help on using the repository browser.