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