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

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

removed using namespace std from .h

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       
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
62protected:
63       
64        T mItem;
65};
66
67
68template<typename T>
69IntersectableWrapper<T>::IntersectableWrapper(T item):
70Intersectable(), mItem(item)
71{
72}
73
74template<typename T>
75void IntersectableWrapper<T>::SetItem(T item)
76{
77        mItem = item;
78}
79
80template<typename T>
81T IntersectableWrapper<T>::GetItem() const
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
110
111template<typename T>
112float IntersectableWrapper<T>::IntersectionComplexity()
113{
114        return 1.0f;
115}
116
117
118template<typename T>
119int IntersectableWrapper<T>::NumberOfFaces() const
120{
121        return 0;
122}
123
124
125template<typename T>
126int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
127                                                                                                   Vector3 &normal)
128{
129        return 0;
130}
131
132
133
134template<typename T>
135int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
136                                                                                                Vector3 &normal)
137{
138        return 0;
139}
140
141
142template<typename T>
143int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
144                                                                                                                  Vector3 &normal,
145                                                                                                                  const Vector3 &viewpoint,
146                                                                                                                  const int maxTries)
147{
148        return 0;
149}
150 
151template<typename T>
152std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
153{
154        s << mItem;
155        return s;
156}
157
158
159class KdIntersectable: public IntersectableWrapper<KdNode *>
160{
161public:
162        AxisAlignedBox3 mBox;
163       
164        KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
165   
166        int Type() const
167        {
168                return Intersectable::KD_INTERSECTABLE;
169        }
170
171    AxisAlignedBox3 GetBox() const
172        {
173                return mBox;
174        }
175};
176
177
178typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
179
180
181class TriangleIntersectable: public IntersectableWrapper<Triangle3>
182{
183public:
184        TriangleIntersectable(const Triangle3 &item):
185        IntersectableWrapper<Triangle3>(item) {}
186
187        int CastRay(Ray &ray);
188        AxisAlignedBox3 GetBox() const;
189        int NumberOfFaces() const;
190        Vector3 GetNormal(const int idx) const;
191
192        float GetArea() const {return mItem.GetArea();}
193
194        int Type() const
195        {
196                return Intersectable::TRIANGLE_INTERSECTABLE;
197        }
198
199        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
200
201        int GetRandomSurfacePoint(const float u,
202                                                          const float v,
203                                                          Vector3 &point, Vector3 &normal);
204
205       
206        int GetRandomVisibleSurfacePoint(Vector3 &point,
207                                                                         Vector3 &normal,
208                                                                         const Vector3 &viewpoint,
209                                                                         const int maxTries);
210
211        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
212
213};
214
215
216/** Intersectable acting as a proxy.
217*/
218class DummyIntersectable: public IntersectableWrapper<int>
219{
220public:
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*/
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
251}
252
253#endif
Note: See TracBrowser for help on using the repository browser.