[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 | struct VssRayContainer;
|
---|
| 13 | class KdNode;
|
---|
[1707] | 14 | //class BvhNode;
|
---|
| 15 | class BvhLeaf;
|
---|
| 16 | class Ray;
|
---|
| 17 |
|
---|
[1314] | 18 | struct Face;
|
---|
[1328] | 19 | struct Triangle3;
|
---|
[1138] | 20 |
|
---|
[1707] | 21 | class KdTree;
|
---|
[1314] | 22 |
|
---|
[1707] | 23 |
|
---|
[1138] | 24 | /**
|
---|
[1233] | 25 | Wrapper used for creating a PVS compliant intersectable.
|
---|
[1138] | 26 | */
|
---|
[1233] | 27 | template<typename T>
|
---|
| 28 | class IntersectableWrapper: public Intersectable
|
---|
[1138] | 29 | {
|
---|
| 30 | public:
|
---|
[1344] | 31 | IntersectableWrapper(T item);
|
---|
[1138] | 32 |
|
---|
[1233] | 33 | /** Returns node associated with this instance.
|
---|
[1138] | 34 | */
|
---|
[1344] | 35 | T GetItem() const;
|
---|
[1138] | 36 | /** See get.
|
---|
| 37 | */
|
---|
[1344] | 38 | void SetItem(T item);
|
---|
[1138] | 39 |
|
---|
[1344] | 40 |
|
---|
| 41 | /////////////////////////////////////////////
|
---|
[1138] | 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;
|
---|
[1344] | 53 |
|
---|
[1138] | 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 |
|
---|
[1763] | 64 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
[1768] | 65 |
|
---|
| 66 |
|
---|
[1138] | 67 | protected:
|
---|
| 68 |
|
---|
[1344] | 69 | T mItem;
|
---|
[1138] | 70 | };
|
---|
| 71 |
|
---|
[1314] | 72 |
|
---|
[1233] | 73 | template<typename T>
|
---|
[1344] | 74 | IntersectableWrapper<T>::IntersectableWrapper(T item):
|
---|
[1233] | 75 | Intersectable(), mItem(item)
|
---|
| 76 | {
|
---|
| 77 | }
|
---|
[1138] | 78 |
|
---|
[1233] | 79 | template<typename T>
|
---|
[1344] | 80 | void IntersectableWrapper<T>::SetItem(T item)
|
---|
[1233] | 81 | {
|
---|
| 82 | mItem = item;
|
---|
[1138] | 83 | }
|
---|
| 84 |
|
---|
[1233] | 85 | template<typename T>
|
---|
[1344] | 86 | T IntersectableWrapper<T>::GetItem() const
|
---|
[1233] | 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 |
|
---|
[1763] | 115 |
|
---|
[1233] | 116 | template<typename T>
|
---|
| 117 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
| 118 | {
|
---|
| 119 | return 1.0f;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[1763] | 122 |
|
---|
[1233] | 123 | template<typename T>
|
---|
| 124 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
| 125 | {
|
---|
| 126 | return 0;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[1763] | 129 |
|
---|
[1233] | 130 | template<typename T>
|
---|
| 131 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
[1344] | 132 | Vector3 &normal)
|
---|
[1233] | 133 | {
|
---|
| 134 | return 0;
|
---|
| 135 | }
|
---|
[1877] | 136 | |
---|
[1233] | 137 |
|
---|
[1763] | 138 |
|
---|
[1233] | 139 | template<typename T>
|
---|
[1763] | 140 | int IntersectableWrapper<T>::GetRandomEdgePoint(Vector3 &point,
|
---|
| 141 | Vector3 &normal)
|
---|
| 142 | {
|
---|
| 143 | return 0;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 |
|
---|
| 147 | template<typename T>
|
---|
[1233] | 148 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[1344] | 149 | Vector3 &normal,
|
---|
| 150 | const Vector3 &viewpoint,
|
---|
| 151 | const int maxTries)
|
---|
[1233] | 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 |
|
---|
[1344] | 164 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
[1233] | 165 | {
|
---|
| 166 | public:
|
---|
[2066] | 167 | AxisAlignedBox3 mBox;
|
---|
| 168 |
|
---|
| 169 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
| 170 |
|
---|
| 171 | int Type() const
|
---|
[1233] | 172 | {
|
---|
[2066] | 173 | return Intersectable::KD_INTERSECTABLE;
|
---|
[1233] | 174 | }
|
---|
[2066] | 175 |
|
---|
| 176 | AxisAlignedBox3 GetBox() const
|
---|
| 177 | {
|
---|
| 178 | return mBox; |
---|
| 179 | } |
---|
[1694] | 180 | }; |
---|
[1615] | 181 |
|
---|
[1233] | 182 |
|
---|
[1594] | 183 | typedef map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
| 184 |
|
---|
[1233] | 185 |
|
---|
[1328] | 186 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
[1314] | 187 | {
|
---|
| 188 | public:
|
---|
[2048] | 189 | TriangleIntersectable(const Triangle3 &item):
|
---|
[1328] | 190 | IntersectableWrapper<Triangle3>(item) {}
|
---|
[1314] | 191 |
|
---|
[1328] | 192 | int CastRay(Ray &ray);
|
---|
| 193 | AxisAlignedBox3 GetBox() const;
|
---|
| 194 | int NumberOfFaces() const;
|
---|
[1344] | 195 | Vector3 GetNormal(const int idx) const;
|
---|
[1328] | 196 |
|
---|
[1686] | 197 | float GetArea() const {return mItem.GetArea();}
|
---|
[1999] | 198 |
|
---|
[1314] | 199 | int Type() const
|
---|
| 200 | {
|
---|
[1328] | 201 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
[1314] | 202 | }
|
---|
[1586] | 203 |
|
---|
| 204 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
[1877] | 205 | |
---|
| 206 | int GetRandomSurfacePoint(const float u, |
---|
| 207 | const float v, |
---|
| 208 | Vector3 &point, Vector3 &normal);
|
---|
| 209 | |
---|
| 210 |
|
---|
[1686] | 211 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
| 212 | Vector3 &normal,
|
---|
| 213 | const Vector3 &viewpoint,
|
---|
| 214 | const int maxTries);
|
---|
[1763] | 215 |
|
---|
| 216 | int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
|
---|
| 217 |
|
---|
[1314] | 218 | };
|
---|
| 219 |
|
---|
| 220 |
|
---|
[2048] | 221 | class DummyIntersectable: public IntersectableWrapper<int>
|
---|
| 222 | {
|
---|
| 223 | public:
|
---|
| 224 | DummyIntersectable(const int item):
|
---|
| 225 | IntersectableWrapper<int>(item) {}
|
---|
| 226 |
|
---|
| 227 | int Type() const
|
---|
| 228 | {
|
---|
| 229 | return Intersectable::DUMMY_INTERSECTABLE;
|
---|
| 230 | }
|
---|
| 231 | };
|
---|
| 232 |
|
---|
[1233] | 233 | }
|
---|
| 234 |
|
---|
[1138] | 235 | #endif
|
---|