[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);
|
---|
[2575] | 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 | }
|
---|
[1877] | 134 | |
---|
[1233] | 135 |
|
---|
[1763] | 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 |
|
---|
| 154 | template<typename T>
|
---|
[2176] | 155 | std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
|
---|
[1233] | 156 | {
|
---|
| 157 | s << mItem;
|
---|
| 158 | return s;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 |
|
---|
[1344] | 162 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
[1233] | 163 | {
|
---|
| 164 | public:
|
---|
[2066] | 165 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
| 166 |
|
---|
[2569] | 167 | int ComputeNumTriangles();
|
---|
| 168 |
|
---|
[2066] | 169 | int Type() const
|
---|
[1233] | 170 | {
|
---|
[2066] | 171 | return Intersectable::KD_INTERSECTABLE;
|
---|
[1233] | 172 | }
|
---|
[2066] | 173 |
|
---|
| 174 | AxisAlignedBox3 GetBox() const
|
---|
| 175 | {
|
---|
| 176 | return mBox; |
---|
| 177 | } |
---|
[2538] | 178 | |
---|
| 179 | /// the bounding box of this intersectable |
---|
| 180 | AxisAlignedBox3 mBox; |
---|
[2569] | 181 | |
---|
| 182 | protected: |
---|
| 183 | |
---|
| 184 | int mNumTriangles; |
---|
[1694] | 185 | }; |
---|
[1615] | 186 |
|
---|
[1233] | 187 |
|
---|
[2176] | 188 | typedef std::map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
[1594] | 189 |
|
---|
[1233] | 190 |
|
---|
[1328] | 191 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
[1314] | 192 | {
|
---|
| 193 | public:
|
---|
[2048] | 194 | TriangleIntersectable(const Triangle3 &item):
|
---|
[1328] | 195 | IntersectableWrapper<Triangle3>(item) {}
|
---|
[1314] | 196 |
|
---|
[1328] | 197 | int CastRay(Ray &ray);
|
---|
[2575] | 198 | |
---|
| 199 | int CastSimpleRay(const SimpleRay &ray); |
---|
| 200 | int CastSimpleRay(const SimpleRay &ray, int rayIndex); |
---|
| 201 | |
---|
[1328] | 202 | AxisAlignedBox3 GetBox() const;
|
---|
| 203 | int NumberOfFaces() const;
|
---|
[1344] | 204 | Vector3 GetNormal(const int idx) const;
|
---|
[2575] | 205 | Vector3 GetNormal() const { return mItem.GetNormal();} |
---|
[1328] | 206 |
|
---|
[1686] | 207 | float GetArea() const {return mItem.GetArea();}
|
---|
[1999] | 208 |
|
---|
[1314] | 209 | int Type() const
|
---|
| 210 | {
|
---|
[1328] | 211 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
[1314] | 212 | }
|
---|
[1586] | 213 |
|
---|
| 214 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
[1877] | 215 | |
---|
| 216 | int GetRandomSurfacePoint(const float u, |
---|
[2575] | 217 | const float v, |
---|
| 218 | Vector3 &point, Vector3 &normal);
|
---|
[1877] | 219 | |
---|
| 220 |
|
---|
[1686] | 221 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[2575] | 222 | Vector3 &normal,
|
---|
| 223 | const Vector3 &viewpoint,
|
---|
| 224 | const int maxTries);
|
---|
[1763] | 225 |
|
---|
| 226 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
[1314] | 227 | };
|
---|
| 228 |
|
---|
| 229 |
|
---|
[2113] | 230 | /** Intersectable acting as a proxy.
|
---|
| 231 | */
|
---|
[2048] | 232 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
| 233 | {
|
---|
| 234 | public:
|
---|
[2113] | 235 | DummyIntersectable(const int item):
|
---|
[2176] | 236 | IntersectableWrapper<int>(item) { SetId(item); }
|
---|
[2048] | 237 |
|
---|
| 238 | int Type() const
|
---|
| 239 | {
|
---|
| 240 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
| 241 | }
|
---|
| 242 | };
|
---|
| 243 |
|
---|
[2113] | 244 |
|
---|
| 245 | /** Intersectable wrapping is a group of objects.
|
---|
| 246 | */
|
---|
| 247 | class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<ObjectContainer *>
|
---|
| 248 | {
|
---|
| 249 | public:
|
---|
| 250 | ContainerIntersectable(ObjectContainer *item):
|
---|
| 251 | IntersectableWrapper<ObjectContainer *>(item) {}
|
---|
| 252 |
|
---|
| 253 | // hack
|
---|
[2575] | 254 | ~ContainerIntersectable()
|
---|
[2113] | 255 | {
|
---|
| 256 | delete mItem;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | int Type() const
|
---|
| 260 | {
|
---|
| 261 | return Intersectable::CONTAINER_INTERSECTABLE;
|
---|
| 262 | }
|
---|
| 263 | };
|
---|
| 264 |
|
---|
[1233] | 265 | }
|
---|
| 266 |
|
---|
[1138] | 267 | #endif
|
---|