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

Revision 2113, 4.8 KB checked in by mattausch, 17 years ago (diff)

warning: debug version

RevLine 
[2069]1#ifndef __INTERSECTABLEWRAPPER_H
2#define __INTERSECTABLEWRAPPER_H
[1138]3
4#include "AxisAlignedBox3.h"
5#include "Intersectable.h"
[1344]6#include "Triangle3.h"
[1138]7
8
9namespace GtpVisibilityPreprocessor {
10
[1344]11
[1138]12class KdNode;
[1707]13class BvhLeaf;
14class Ray;
[2113]15class KdTree;
16struct VssRayContainer;
17struct Triangle3;
[1314]18struct Face;
[1138]19
[2113]20/** Wrapper used for creating a PVS compliant intersectable.
[1138]21*/
[1233]22template<typename T>
23class IntersectableWrapper: public Intersectable
[1138]24{
25public:
[1344]26        IntersectableWrapper(T item);
[1138]27
[1233]28        /** Returns node associated with this instance.
[1138]29        */
[1344]30        T GetItem() const;
[1138]31        /** See get.
32        */
[1344]33        void SetItem(T item);
[1138]34
[1344]35
36        /////////////////////////////////////////////
[1138]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;
[1344]48       
[1138]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        ostream &Describe(ostream &s);
58       
[1763]59        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
[1768]60
61
[1138]62protected:
63       
[1344]64        T mItem;
[1138]65};
66
[1314]67
[1233]68template<typename T>
[1344]69IntersectableWrapper<T>::IntersectableWrapper(T item):
[1233]70Intersectable(), mItem(item)
71{
72}
[1138]73
[1233]74template<typename T>
[1344]75void IntersectableWrapper<T>::SetItem(T item)
[1233]76{
77        mItem = item;
[1138]78}
79
[1233]80template<typename T>
[1344]81T IntersectableWrapper<T>::GetItem() const
[1233]82{
83        return mItem;
84}
85       
86template<typename T>
87AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
88{       // TODO matt
89        return AxisAlignedBox3();
90}
91
92template<typename T>
93int IntersectableWrapper<T>::CastRay(Ray &ray)
94{       // TODO matt
95        return 0;
96}
97       
98template<typename T>
99bool IntersectableWrapper<T>::IsConvex() const
100{
101        return true;
102}
103
104template<typename T>
105bool IntersectableWrapper<T>::IsWatertight() const
106{
107        return true;
108}
109
[1763]110
[1233]111template<typename T>
112float IntersectableWrapper<T>::IntersectionComplexity()
113{
114        return 1.0f;
115}
116
[1763]117
[1233]118template<typename T>
119int IntersectableWrapper<T>::NumberOfFaces() const
120{
121        return 0;
122}
123
[1763]124
[1233]125template<typename T>
126int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
[1344]127                                                                                                   Vector3 &normal)
[1233]128{
129        return 0;
130}
[1877]131
[1233]132
[1763]133
[1233]134template<typename T>
[1763]135int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
136                                                                                                Vector3 &normal)
137{
138        return 0;
139}
140
141
142template<typename T>
[1233]143int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
[1344]144                                                                                                                  Vector3 &normal,
145                                                                                                                  const Vector3 &viewpoint,
146                                                                                                                  const int maxTries)
[1233]147{
148        return 0;
149}
150 
151template<typename T>
152ostream &IntersectableWrapper<T>::Describe(ostream &s)
153{
154        s << mItem;
155        return s;
156}
157
158
[1344]159class KdIntersectable: public IntersectableWrapper<KdNode *>
[1233]160{
161public:
[2066]162        AxisAlignedBox3 mBox;
163       
164        KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
165   
166        int Type() const
[1233]167        {
[2066]168                return Intersectable::KD_INTERSECTABLE;
[1233]169        }
[2066]170
171    AxisAlignedBox3 GetBox() const
172        {
173                return mBox;
174        }
[1694]175};
[1615]176
[1233]177
[1594]178typedef map<KdNode *, KdIntersectable *> KdIntersectableMap;
179
[1233]180
[1328]181class TriangleIntersectable: public IntersectableWrapper<Triangle3>
[1314]182{
183public:
[2048]184        TriangleIntersectable(const Triangle3 &item):
[1328]185        IntersectableWrapper<Triangle3>(item) {}
[1314]186
[1328]187        int CastRay(Ray &ray);
188        AxisAlignedBox3 GetBox() const;
189        int NumberOfFaces() const;
[1344]190        Vector3 GetNormal(const int idx) const;
[1328]191
[1686]192        float GetArea() const {return mItem.GetArea();}
[1999]193
[1314]194        int Type() const
195        {
[1328]196                return Intersectable::TRIANGLE_INTERSECTABLE;
[1314]197        }
[1586]198
199        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
[1877]200
201        int GetRandomSurfacePoint(const float u,
202                                                          const float v,
203                                                          Vector3 &point, Vector3 &normal);
204
205       
[1686]206        int GetRandomVisibleSurfacePoint(Vector3 &point,
207                                                                         Vector3 &normal,
208                                                                         const Vector3 &viewpoint,
209                                                                         const int maxTries);
[1763]210
211        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
212
[1314]213};
214
215
[2113]216/** Intersectable acting as a proxy.
217*/
[2048]218class DummyIntersectable: public IntersectableWrapper<int>
219{
220public:
[2113]221        DummyIntersectable(const int item):
222          IntersectableWrapper<int>(item) {}
[2048]223
224        int Type() const
225        {
226                return Intersectable::DUMMY_INTERSECTABLE;
227        }
228};
229
[2113]230
231/** Intersectable wrapping is a group of objects.
232*/
233class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
234{
235public:
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
[1233]251}
252
[1138]253#endif
Note: See TracBrowser for help on using the repository browser.