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 | struct Face;
|
---|
16 | class Ray;
|
---|
17 | struct Triangle3;
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 | /**
|
---|
22 | Wrapper used for creating a PVS compliant intersectable.
|
---|
23 | */
|
---|
24 | template<typename T>
|
---|
25 | class IntersectableWrapper: public Intersectable
|
---|
26 | {
|
---|
27 | public:
|
---|
28 | IntersectableWrapper(T item);
|
---|
29 |
|
---|
30 | /** Returns node associated with this instance.
|
---|
31 | */
|
---|
32 | T GetItem() const;
|
---|
33 | /** See get.
|
---|
34 | */
|
---|
35 | void SetItem(T item);
|
---|
36 |
|
---|
37 |
|
---|
38 | /////////////////////////////////////////////
|
---|
39 | //-- inherited functions from Intersectable
|
---|
40 |
|
---|
41 | AxisAlignedBox3 GetBox() const;
|
---|
42 |
|
---|
43 | int CastRay(Ray &ray);
|
---|
44 |
|
---|
45 | bool IsConvex() const;
|
---|
46 | bool IsWatertight() const;
|
---|
47 | float IntersectionComplexity();
|
---|
48 |
|
---|
49 | int NumberOfFaces() const;
|
---|
50 |
|
---|
51 | int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
52 | GtpVisibilityPreprocessor::Vector3 &normal);
|
---|
53 |
|
---|
54 | int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
55 | GtpVisibilityPreprocessor::Vector3 &normal,
|
---|
56 | const GtpVisibilityPreprocessor::Vector3 &viewpoint,
|
---|
57 | const int maxTries);
|
---|
58 |
|
---|
59 | ostream &Describe(ostream &s);
|
---|
60 |
|
---|
61 |
|
---|
62 | protected:
|
---|
63 |
|
---|
64 | T mItem;
|
---|
65 | };
|
---|
66 |
|
---|
67 |
|
---|
68 | template<typename T>
|
---|
69 | IntersectableWrapper<T>::IntersectableWrapper(T item):
|
---|
70 | Intersectable(), mItem(item)
|
---|
71 | {
|
---|
72 | }
|
---|
73 |
|
---|
74 | template<typename T>
|
---|
75 | void IntersectableWrapper<T>::SetItem(T item)
|
---|
76 | {
|
---|
77 | mItem = item;
|
---|
78 | }
|
---|
79 |
|
---|
80 | template<typename T>
|
---|
81 | T IntersectableWrapper<T>::GetItem() const
|
---|
82 | {
|
---|
83 | return mItem;
|
---|
84 | }
|
---|
85 |
|
---|
86 | template<typename T>
|
---|
87 | AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
|
---|
88 | { // TODO matt
|
---|
89 | return AxisAlignedBox3();
|
---|
90 | }
|
---|
91 |
|
---|
92 | template<typename T>
|
---|
93 | int IntersectableWrapper<T>::CastRay(Ray &ray)
|
---|
94 | { // TODO matt
|
---|
95 | return 0;
|
---|
96 | }
|
---|
97 |
|
---|
98 | template<typename T>
|
---|
99 | bool IntersectableWrapper<T>::IsConvex() const
|
---|
100 | {
|
---|
101 | return true;
|
---|
102 | }
|
---|
103 |
|
---|
104 | template<typename T>
|
---|
105 | bool IntersectableWrapper<T>::IsWatertight() const
|
---|
106 | {
|
---|
107 | return true;
|
---|
108 | }
|
---|
109 |
|
---|
110 | template<typename T>
|
---|
111 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
112 | {
|
---|
113 | return 1.0f;
|
---|
114 | }
|
---|
115 |
|
---|
116 | template<typename T>
|
---|
117 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
118 | {
|
---|
119 | return 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | template<typename T>
|
---|
123 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
124 | Vector3 &normal)
|
---|
125 | {
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 |
|
---|
129 | template<typename T>
|
---|
130 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
131 | Vector3 &normal,
|
---|
132 | const Vector3 &viewpoint,
|
---|
133 | const int maxTries)
|
---|
134 | {
|
---|
135 | return 0;
|
---|
136 | }
|
---|
137 |
|
---|
138 | template<typename T>
|
---|
139 | ostream &IntersectableWrapper<T>::Describe(ostream &s)
|
---|
140 | {
|
---|
141 | s << mItem;
|
---|
142 | return s;
|
---|
143 | }
|
---|
144 |
|
---|
145 |
|
---|
146 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
147 | {
|
---|
148 | public:
|
---|
149 | KdIntersectable(KdNode *item):
|
---|
150 | IntersectableWrapper<KdNode *>(item) {}
|
---|
151 |
|
---|
152 | int Type() const
|
---|
153 | {
|
---|
154 | return Intersectable::KD_INTERSECTABLE;
|
---|
155 | }
|
---|
156 |
|
---|
157 | AxisAlignedBox3 GetBox() const { return mBbox; }
|
---|
158 | AxisAlignedBox3 mBbox;
|
---|
159 | };
|
---|
160 |
|
---|
161 |
|
---|
162 | typedef map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
163 |
|
---|
164 | class BvhIntersectable: public IntersectableWrapper<BvhNode *>
|
---|
165 | {
|
---|
166 | public:
|
---|
167 | BvhIntersectable(BvhNode *item):
|
---|
168 | IntersectableWrapper<BvhNode *>(item) {}
|
---|
169 |
|
---|
170 | int Type() const
|
---|
171 | {
|
---|
172 | return Intersectable::BVH_INTERSECTABLE;
|
---|
173 | }
|
---|
174 | };
|
---|
175 |
|
---|
176 |
|
---|
177 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
178 | {
|
---|
179 | public:
|
---|
180 | TriangleIntersectable(Triangle3 item):
|
---|
181 | IntersectableWrapper<Triangle3>(item) {}
|
---|
182 |
|
---|
183 | int CastRay(Ray &ray);
|
---|
184 | AxisAlignedBox3 GetBox() const;
|
---|
185 | int NumberOfFaces() const;
|
---|
186 | Vector3 GetNormal(const int idx) const;
|
---|
187 |
|
---|
188 | int Type() const
|
---|
189 | {
|
---|
190 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
191 | }
|
---|
192 |
|
---|
193 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
194 |
|
---|
195 | int GetRandomVisibleSurfacePoint(
|
---|
196 | Vector3 &point,
|
---|
197 | Vector3 &normal,
|
---|
198 | const Vector3 &viewpoint,
|
---|
199 | const int maxTries);
|
---|
200 | };
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 | }
|
---|
206 |
|
---|
207 | #endif
|
---|