[2069] | 1 | #ifndef __INTERSECTABLEWRAPPER_H
|
---|
| 2 | #define __INTERSECTABLEWRAPPER_H
|
---|
[1138] | 3 |
|
---|
| 4 | #include "AxisAlignedBox3.h"
|
---|
| 5 | #include "Intersectable.h"
|
---|
[1344] | 6 | #include "Triangle3.h"
|
---|
[1138] | 7 |
|
---|
| 8 |
|
---|
| 9 | namespace GtpVisibilityPreprocessor {
|
---|
| 10 |
|
---|
[1344] | 11 |
|
---|
[1138] | 12 | class KdNode;
|
---|
[1707] | 13 | class BvhLeaf;
|
---|
| 14 | class Ray;
|
---|
[2113] | 15 | class KdTree;
|
---|
| 16 | struct VssRayContainer;
|
---|
| 17 | struct Triangle3;
|
---|
[1314] | 18 | struct Face;
|
---|
[1138] | 19 |
|
---|
[2113] | 20 | /** Wrapper used for creating a PVS compliant intersectable.
|
---|
[1138] | 21 | */
|
---|
[1233] | 22 | template<typename T>
|
---|
| 23 | class IntersectableWrapper: public Intersectable
|
---|
[1138] | 24 | {
|
---|
| 25 | public:
|
---|
[1344] | 26 | IntersectableWrapper(T item);
|
---|
[1138] | 27 |
|
---|
[1233] | 28 | /** Returns node associated with this instance.
|
---|
[1138] | 29 | */
|
---|
[1344] | 30 | T GetItem() const;
|
---|
[1138] | 31 | /** See get.
|
---|
| 32 | */
|
---|
[1344] | 33 | void SetItem(T item);
|
---|
[1138] | 34 |
|
---|
[1344] | 35 |
|
---|
| 36 | /////////////////////////////////////////////
|
---|
[1138] | 37 | //-- inherited functions from Intersectable
|
---|
| 38 |
|
---|
| 39 | AxisAlignedBox3 GetBox() const;
|
---|
| 40 |
|
---|
| 41 | int CastRay(Ray &ray);
|
---|
[2694] | 42 | int CastSimpleRay(const SimpleRay &ray) { return 0;}
|
---|
| 43 | int CastSimpleRay(const SimpleRay &ray, int RayIndex) { return 0;}
|
---|
| 44 |
|
---|
[1138] | 45 |
|
---|
| 46 | bool IsConvex() const;
|
---|
| 47 | bool IsWatertight() const;
|
---|
| 48 | float IntersectionComplexity();
|
---|
| 49 |
|
---|
| 50 | int NumberOfFaces() const;
|
---|
[1344] | 51 |
|
---|
[1138] | 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 |
|
---|
[2176] | 60 | std::ostream &Describe(std::ostream &s);
|
---|
[1138] | 61 |
|
---|
[1763] | 62 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
[1768] | 63 |
|
---|
| 64 |
|
---|
[1138] | 65 | protected:
|
---|
| 66 |
|
---|
[1344] | 67 | T mItem;
|
---|
[1138] | 68 | };
|
---|
| 69 |
|
---|
[1314] | 70 |
|
---|
[1233] | 71 | template<typename T>
|
---|
[1344] | 72 | IntersectableWrapper<T>::IntersectableWrapper(T item):
|
---|
[1233] | 73 | Intersectable(), mItem(item)
|
---|
| 74 | {
|
---|
| 75 | }
|
---|
[1138] | 76 |
|
---|
[1233] | 77 | template<typename T>
|
---|
[1344] | 78 | void IntersectableWrapper<T>::SetItem(T item)
|
---|
[1233] | 79 | {
|
---|
| 80 | mItem = item;
|
---|
[1138] | 81 | }
|
---|
| 82 |
|
---|
[1233] | 83 | template<typename T>
|
---|
[1344] | 84 | T IntersectableWrapper<T>::GetItem() const
|
---|
[1233] | 85 | {
|
---|
| 86 | return mItem;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | template<typename T>
|
---|
| 90 | AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
|
---|
| 91 | { // TODO matt
|
---|
| 92 | return AxisAlignedBox3();
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | template<typename T>
|
---|
| 96 | int IntersectableWrapper<T>::CastRay(Ray &ray)
|
---|
| 97 | { // TODO matt
|
---|
| 98 | return 0;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | template<typename T>
|
---|
| 102 | bool IntersectableWrapper<T>::IsConvex() const
|
---|
| 103 | {
|
---|
| 104 | return true;
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | template<typename T>
|
---|
| 108 | bool IntersectableWrapper<T>::IsWatertight() const
|
---|
| 109 | {
|
---|
| 110 | return true;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
[1763] | 113 |
|
---|
[1233] | 114 | template<typename T>
|
---|
| 115 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
| 116 | {
|
---|
| 117 | return 1.0f;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[1763] | 120 |
|
---|
[1233] | 121 | template<typename T>
|
---|
| 122 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
| 123 | {
|
---|
| 124 | return 0;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
[1763] | 127 |
|
---|
[1233] | 128 | template<typename T>
|
---|
| 129 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
[1344] | 130 | Vector3 &normal)
|
---|
[1233] | 131 | {
|
---|
| 132 | return 0;
|
---|
| 133 | }
|
---|
| 134 |
|
---|
[1763] | 135 |
|
---|
[2694] | 136 |
|
---|
[1233] | 137 | template<typename T>
|
---|
[1763] | 138 | int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
|
---|
| 139 | Vector3 &normal)
|
---|
| 140 | {
|
---|
| 141 | return 0;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | template<typename T>
|
---|
[1233] | 146 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[1344] | 147 | Vector3 &normal,
|
---|
| 148 | const Vector3 &viewpoint,
|
---|
| 149 | const int maxTries)
|
---|
[1233] | 150 | {
|
---|
| 151 | return 0;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[2694] | 154 |
|
---|
| 155 |
|
---|
[1233] | 156 | template<typename T>
|
---|
[2176] | 157 | std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
|
---|
[1233] | 158 | {
|
---|
[2599] | 159 | s << mItem;
|
---|
| 160 | return s;
|
---|
| 161 | }
|
---|
[1233] | 162 |
|
---|
| 163 |
|
---|
[1344] | 164 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
[1233] | 165 | {
|
---|
| 166 | public:
|
---|
[2066] | 167 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
| 168 |
|
---|
[2569] | 169 | int ComputeNumTriangles();
|
---|
| 170 |
|
---|
[2066] | 171 | int Type() const
|
---|
[1233] | 172 | {
|
---|
[2066] | 173 | return Intersectable::KD_INTERSECTABLE;
|
---|
[1233] | 174 | }
|
---|
[2066] | 175 |
|
---|
| 176 | AxisAlignedBox3 GetBox() const
|
---|
| 177 | {
|
---|
[2694] | 178 | return mBox;
|
---|
| 179 | }
|
---|
[1615] | 180 |
|
---|
[2694] | 181 | /// the bounding box of this intersectable
|
---|
| 182 | AxisAlignedBox3 mBox;
|
---|
[1233] | 183 |
|
---|
[2694] | 184 | int mGenericIdx;
|
---|
| 185 |
|
---|
| 186 | protected:
|
---|
| 187 |
|
---|
| 188 | int mNumTriangles;
|
---|
| 189 | };
|
---|
| 190 |
|
---|
| 191 |
|
---|
[2176] | 192 | typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
[1594] | 193 |
|
---|
[1233] | 194 |
|
---|
[1328] | 195 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
[1314] | 196 | {
|
---|
| 197 | public:
|
---|
[2048] | 198 | TriangleIntersectable(const Triangle3 &item):
|
---|
[1328] | 199 | IntersectableWrapper<Triangle3>(item) {}
|
---|
[1314] | 200 |
|
---|
[1328] | 201 | int CastRay(Ray &ray);
|
---|
[2694] | 202 |
|
---|
| 203 | int CastSimpleRay(const SimpleRay &ray);
|
---|
| 204 | int CastSimpleRay(const SimpleRay &ray, int rayIndex);
|
---|
| 205 |
|
---|
[1328] | 206 | AxisAlignedBox3 GetBox() const;
|
---|
| 207 | int NumberOfFaces() const;
|
---|
[1344] | 208 | Vector3 GetNormal(const int idx) const;
|
---|
[2694] | 209 | Vector3 GetNormal() const { return mItem.GetNormal();}
|
---|
[1328] | 210 |
|
---|
[1686] | 211 | float GetArea() const {return mItem.GetArea();}
|
---|
[1999] | 212 |
|
---|
[1314] | 213 | int Type() const
|
---|
| 214 | {
|
---|
[1328] | 215 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
[1314] | 216 | }
|
---|
[1586] | 217 |
|
---|
| 218 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
[2694] | 219 |
|
---|
| 220 | int GetRandomSurfacePoint(const float u,
|
---|
| 221 | const float v,
|
---|
[2575] | 222 | Vector3 &point, Vector3 &normal);
|
---|
[2694] | 223 |
|
---|
[1877] | 224 |
|
---|
[1686] | 225 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[2575] | 226 | Vector3 &normal,
|
---|
| 227 | const Vector3 &viewpoint,
|
---|
| 228 | const int maxTries);
|
---|
[1763] | 229 |
|
---|
| 230 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
[1314] | 231 | };
|
---|
| 232 |
|
---|
| 233 |
|
---|
[2113] | 234 | /** Intersectable acting as a proxy.
|
---|
| 235 | */
|
---|
[2048] | 236 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
| 237 | {
|
---|
| 238 | public:
|
---|
[2113] | 239 | DummyIntersectable(const int item):
|
---|
[2176] | 240 | IntersectableWrapper<int>(item) { SetId(item); }
|
---|
[2048] | 241 |
|
---|
| 242 | int Type() const
|
---|
| 243 | {
|
---|
| 244 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
| 245 | }
|
---|
| 246 | };
|
---|
| 247 |
|
---|
[2113] | 248 |
|
---|
| 249 | /** Intersectable wrapping is a group of objects.
|
---|
| 250 | */
|
---|
[2702] | 251 | class IntersectableGroup: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
|
---|
[2113] | 252 | {
|
---|
| 253 | public:
|
---|
[2702] | 254 | IntersectableGroup(ObjectContainer *item):
|
---|
[2113] | 255 | IntersectableWrapper<ObjectContainer *>(item) {}
|
---|
| 256 |
|
---|
| 257 | // hack
|
---|
[2702] | 258 | ~IntersectableGroup()
|
---|
[2113] | 259 | {
|
---|
| 260 | delete mItem;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | int Type() const
|
---|
| 264 | {
|
---|
| 265 | return Intersectable::CONTAINER_INTERSECTABLE;
|
---|
| 266 | }
|
---|
| 267 | };
|
---|
| 268 |
|
---|
[2615] | 269 |
|
---|
| 270 | class SceneGraphLeafIntersectable: public IntersectableWrapper<SceneGraphLeaf *>
|
---|
| 271 | {
|
---|
| 272 | public:
|
---|
| 273 | SceneGraphLeafIntersectable(SceneGraphLeaf *item, const AxisAlignedBox3 &box);
|
---|
| 274 |
|
---|
| 275 | int ComputeNumTriangles() { return 0;}
|
---|
| 276 |
|
---|
| 277 | int Type() const
|
---|
| 278 | {
|
---|
| 279 | return Intersectable::SCENEGRAPHLEAF_INTERSECTABLE;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | AxisAlignedBox3 GetBox() const
|
---|
| 283 | {
|
---|
[2694] | 284 | return mBox;
|
---|
| 285 | }
|
---|
[2615] | 286 |
|
---|
[2694] | 287 | /// the bounding box of this intersectable
|
---|
| 288 | AxisAlignedBox3 mBox;
|
---|
[2615] | 289 |
|
---|
[2694] | 290 | protected:
|
---|
| 291 |
|
---|
| 292 | // int mNumTriangles;
|
---|
| 293 | };
|
---|
| 294 |
|
---|
| 295 |
|
---|
[1233] | 296 | }
|
---|
| 297 |
|
---|
[1138] | 298 | #endif
|
---|