[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);
|
---|
| 42 |
|
---|
| 43 | bool IsConvex() const;
|
---|
| 44 | bool IsWatertight() const;
|
---|
| 45 | float IntersectionComplexity();
|
---|
| 46 |
|
---|
| 47 | int NumberOfFaces() const;
|
---|
[1344] | 48 |
|
---|
[1138] | 49 | int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
| 50 | GtpVisibilityPreprocessor::Vector3 &normal);
|
---|
| 51 |
|
---|
| 52 | int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
|
---|
| 53 | GtpVisibilityPreprocessor::Vector3 &normal,
|
---|
| 54 | const GtpVisibilityPreprocessor::Vector3 &viewpoint,
|
---|
| 55 | const int maxTries);
|
---|
| 56 |
|
---|
[2176] | 57 | std::ostream &Describe(std::ostream &s);
|
---|
[1138] | 58 |
|
---|
[1763] | 59 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
[1768] | 60 |
|
---|
| 61 |
|
---|
[1138] | 62 | protected:
|
---|
| 63 |
|
---|
[1344] | 64 | T mItem;
|
---|
[1138] | 65 | };
|
---|
| 66 |
|
---|
[1314] | 67 |
|
---|
[1233] | 68 | template<typename T>
|
---|
[1344] | 69 | IntersectableWrapper<T>::IntersectableWrapper(T item):
|
---|
[1233] | 70 | Intersectable(), mItem(item)
|
---|
| 71 | {
|
---|
| 72 | }
|
---|
[1138] | 73 |
|
---|
[1233] | 74 | template<typename T>
|
---|
[1344] | 75 | void IntersectableWrapper<T>::SetItem(T item)
|
---|
[1233] | 76 | {
|
---|
| 77 | mItem = item;
|
---|
[1138] | 78 | }
|
---|
| 79 |
|
---|
[1233] | 80 | template<typename T>
|
---|
[1344] | 81 | T IntersectableWrapper<T>::GetItem() const
|
---|
[1233] | 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 |
|
---|
[1763] | 110 |
|
---|
[1233] | 111 | template<typename T>
|
---|
| 112 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
| 113 | {
|
---|
| 114 | return 1.0f;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
[1763] | 117 |
|
---|
[1233] | 118 | template<typename T>
|
---|
| 119 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
| 120 | {
|
---|
| 121 | return 0;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
[1763] | 124 |
|
---|
[1233] | 125 | template<typename T>
|
---|
| 126 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
[1344] | 127 | Vector3 &normal)
|
---|
[1233] | 128 | {
|
---|
| 129 | return 0;
|
---|
| 130 | }
|
---|
[1877] | 131 | |
---|
[1233] | 132 |
|
---|
[1763] | 133 |
|
---|
[1233] | 134 | template<typename T>
|
---|
[1763] | 135 | int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
|
---|
| 136 | Vector3 &normal)
|
---|
| 137 | {
|
---|
| 138 | return 0;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | template<typename T>
|
---|
[1233] | 143 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[1344] | 144 | Vector3 &normal,
|
---|
| 145 | const Vector3 &viewpoint,
|
---|
| 146 | const int maxTries)
|
---|
[1233] | 147 | {
|
---|
| 148 | return 0;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | template<typename T>
|
---|
[2176] | 152 | std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
|
---|
[1233] | 153 | {
|
---|
| 154 | s << mItem;
|
---|
| 155 | return s;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 |
|
---|
[1344] | 159 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
[1233] | 160 | {
|
---|
| 161 | public:
|
---|
[2066] | 162 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
| 163 |
|
---|
| 164 | int Type() const
|
---|
[1233] | 165 | {
|
---|
[2066] | 166 | return Intersectable::KD_INTERSECTABLE;
|
---|
[1233] | 167 | }
|
---|
[2066] | 168 |
|
---|
| 169 | AxisAlignedBox3 GetBox() const
|
---|
| 170 | {
|
---|
| 171 | return mBox; |
---|
| 172 | } |
---|
[2538] | 173 | |
---|
| 174 | /// the bounding box of this intersectable |
---|
| 175 | AxisAlignedBox3 mBox; |
---|
[1694] | 176 | }; |
---|
[1615] | 177 |
|
---|
[1233] | 178 |
|
---|
[2176] | 179 | typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
[1594] | 180 |
|
---|
[1233] | 181 |
|
---|
[1328] | 182 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
[1314] | 183 | {
|
---|
| 184 | public:
|
---|
[2048] | 185 | TriangleIntersectable(const Triangle3 &item):
|
---|
[1328] | 186 | IntersectableWrapper<Triangle3>(item) {}
|
---|
[1314] | 187 |
|
---|
[1328] | 188 | int CastRay(Ray &ray);
|
---|
| 189 | AxisAlignedBox3 GetBox() const;
|
---|
| 190 | int NumberOfFaces() const;
|
---|
[1344] | 191 | Vector3 GetNormal(const int idx) const;
|
---|
[1328] | 192 |
|
---|
[1686] | 193 | float GetArea() const {return mItem.GetArea();}
|
---|
[1999] | 194 |
|
---|
[1314] | 195 | int Type() const
|
---|
| 196 | {
|
---|
[1328] | 197 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
[1314] | 198 | }
|
---|
[1586] | 199 |
|
---|
| 200 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
[1877] | 201 | |
---|
| 202 | int GetRandomSurfacePoint(const float u, |
---|
| 203 | const float v, |
---|
| 204 | Vector3 &point, Vector3 &normal);
|
---|
| 205 | |
---|
| 206 |
|
---|
[1686] | 207 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
| 208 | Vector3 &normal,
|
---|
| 209 | const Vector3 &viewpoint,
|
---|
| 210 | const int maxTries);
|
---|
[1763] | 211 |
|
---|
| 212 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
[1314] | 213 | };
|
---|
| 214 |
|
---|
| 215 |
|
---|
[2113] | 216 | /** Intersectable acting as a proxy.
|
---|
| 217 | */
|
---|
[2048] | 218 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
| 219 | {
|
---|
| 220 | public:
|
---|
[2113] | 221 | DummyIntersectable(const int item):
|
---|
[2176] | 222 | IntersectableWrapper<int>(item) { SetId(item); }
|
---|
[2048] | 223 |
|
---|
| 224 | int Type() const
|
---|
| 225 | {
|
---|
| 226 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
| 227 | }
|
---|
| 228 | };
|
---|
| 229 |
|
---|
[2113] | 230 |
|
---|
| 231 | /** Intersectable wrapping is a group of objects.
|
---|
| 232 | */
|
---|
| 233 | class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
|
---|
| 234 | {
|
---|
| 235 | public:
|
---|
| 236 | ContainerIntersectable(ObjectContainer *item):
|
---|
| 237 | IntersectableWrapper<ObjectContainer *>(item) {}
|
---|
| 238 |
|
---|
| 239 | // hack
|
---|
| 240 | ContainerIntersectable::~ContainerIntersectable()
|
---|
| 241 | {
|
---|
| 242 | delete mItem;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | int Type() const
|
---|
| 246 | {
|
---|
| 247 | return Intersectable::CONTAINER_INTERSECTABLE;
|
---|
| 248 | }
|
---|
| 249 | };
|
---|
| 250 |
|
---|
[1233] | 251 | }
|
---|
| 252 |
|
---|
[1138] | 253 | #endif
|
---|