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

Revision 2575, 5.2 KB checked in by bittner, 17 years ago (diff)

big merge: preparation for havran ray caster, check if everything works

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 
154template<typename T>
155std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
156{
157        s << mItem;
158        return s;
159}
160
161
162class KdIntersectable: public IntersectableWrapper<KdNode *>
163{
164public:
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
182protected:
183
184        int mNumTriangles;
185};
186
187
188typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
189
190
191class TriangleIntersectable: public IntersectableWrapper<Triangle3>
192{
193public:
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*/
232class DummyIntersectable: public IntersectableWrapper<int>
233{
234public:
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*/
247class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
248{
249public:
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
Note: See TracBrowser for help on using the repository browser.