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

Revision 1763, 4.0 KB checked in by mattausch, 18 years ago (diff)
Line 
1#ifndef __KDINTERSECTABLE_H
2#define __KDINTERSECTABLE_H
3
4#include "AxisAlignedBox3.h"
5#include "Intersectable.h"
6#include "Triangle3.h"
7
8
9namespace GtpVisibilityPreprocessor {
10
11
12struct VssRayContainer;
13class KdNode;
14//class BvhNode;
15class BvhLeaf;
16class Ray;
17
18struct Face;
19struct Triangle3;
20
21class KdTree;
22
23
24/**
25        Wrapper used for creating a PVS compliant intersectable.
26*/
27template<typename T>
28class IntersectableWrapper: public Intersectable
29{
30public:
31        IntersectableWrapper(T item);
32
33        /** Returns node associated with this instance.
34        */
35        T GetItem() const;
36        /** See get.
37        */
38        void SetItem(T item);
39
40
41        /////////////////////////////////////////////
42        //-- inherited functions from Intersectable
43
44        AxisAlignedBox3 GetBox() const;
45       
46        int CastRay(Ray &ray);
47       
48        bool IsConvex() const;
49        bool IsWatertight() const;
50        float IntersectionComplexity();
51 
52        int NumberOfFaces() const;
53       
54        int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
55                                                          GtpVisibilityPreprocessor::Vector3 &normal);
56
57        int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
58                                                                         GtpVisibilityPreprocessor::Vector3 &normal,
59                                                                         const GtpVisibilityPreprocessor::Vector3 &viewpoint,
60                                                                         const int maxTries);
61 
62        ostream &Describe(ostream &s);
63       
64        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
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
136template<typename T>
137int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
138                                                                                                Vector3 &normal)
139{
140        return 0;
141}
142
143
144template<typename T>
145int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
146                                                                                                                  Vector3 &normal,
147                                                                                                                  const Vector3 &viewpoint,
148                                                                                                                  const int maxTries)
149{
150        return 0;
151}
152 
153template<typename T>
154ostream &IntersectableWrapper<T>::Describe(ostream &s)
155{
156        s << mItem;
157        return s;
158}
159
160
161class KdIntersectable: public IntersectableWrapper<KdNode *>
162{
163public:
164  AxisAlignedBox3 mBox;
165
166  KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
167
168 
169  int Type() const
170        {
171          return Intersectable::KD_INTERSECTABLE;
172        }
173
174 
175  AxisAlignedBox3 GetBox() const {
176        return mBox;
177  }
178};
179
180
181typedef map<KdNode *, KdIntersectable *> KdIntersectableMap;
182
183
184class TriangleIntersectable: public IntersectableWrapper<Triangle3>
185{
186public:
187        TriangleIntersectable(Triangle3 item):
188        IntersectableWrapper<Triangle3>(item) {}
189
190        int CastRay(Ray &ray);
191        AxisAlignedBox3 GetBox() const;
192        int NumberOfFaces() const;
193        Vector3 GetNormal(const int idx) const;
194
195        float GetArea() const {return mItem.GetArea();}
196        int Type() const
197        {
198                return Intersectable::TRIANGLE_INTERSECTABLE;
199        }
200
201        int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
202
203        int GetRandomVisibleSurfacePoint(Vector3 &point,
204                                                                         Vector3 &normal,
205                                                                         const Vector3 &viewpoint,
206                                                                         const int maxTries);
207
208        int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
209
210};
211
212
213
214
215}
216
217#endif
Note: See TracBrowser for help on using the repository browser.