[1138] | 1 | #ifndef __KDINTERSECTABLE_H
|
---|
| 2 | #define __KDINTERSECTABLE_H
|
---|
| 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 |
|
---|
| 64 |
|
---|
| 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 |
|
---|
| 113 | template<typename T>
|
---|
| 114 | float IntersectableWrapper<T>::IntersectionComplexity()
|
---|
| 115 | {
|
---|
| 116 | return 1.0f;
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | template<typename T>
|
---|
| 120 | int IntersectableWrapper<T>::NumberOfFaces() const
|
---|
| 121 | {
|
---|
| 122 | return 0;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | template<typename T>
|
---|
| 126 | int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
|
---|
[1344] | 127 | Vector3 &normal)
|
---|
[1233] | 128 | {
|
---|
| 129 | return 0;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | template<typename T>
|
---|
| 133 | int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[1344] | 134 | Vector3 &normal,
|
---|
| 135 | const Vector3 &viewpoint,
|
---|
| 136 | const int maxTries)
|
---|
[1233] | 137 | {
|
---|
| 138 | return 0;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | template<typename T>
|
---|
| 142 | ostream &IntersectableWrapper<T>::Describe(ostream &s)
|
---|
| 143 | {
|
---|
| 144 | s << mItem;
|
---|
| 145 | return s;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
[1344] | 149 | class KdIntersectable: public IntersectableWrapper<KdNode *>
|
---|
[1233] | 150 | {
|
---|
| 151 | public:
|
---|
[1694] | 152 | AxisAlignedBox3 mBox;
|
---|
[1233] | 153 |
|
---|
[1694] | 154 | KdIntersectable(KdNode *item, const AxisAlignedBox3 &box);
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | int Type() const
|
---|
[1233] | 158 | {
|
---|
[1694] | 159 | return Intersectable::KD_INTERSECTABLE;
|
---|
[1233] | 160 | }
|
---|
[1694] | 161 | |
---|
| 162 |
|
---|
| 163 | AxisAlignedBox3 GetBox() const {
|
---|
| 164 | return mBox;
|
---|
| 165 | } |
---|
| 166 | }; |
---|
[1615] | 167 |
|
---|
[1233] | 168 |
|
---|
[1594] | 169 | typedef map<KdNode *, KdIntersectable *> KdIntersectableMap;
|
---|
| 170 |
|
---|
[1707] | 171 | class BvhIntersectable: public IntersectableWrapper<BvhLeaf *>
|
---|
[1233] | 172 | {
|
---|
| 173 | public:
|
---|
[1707] | 174 | BvhIntersectable(BvhLeaf *item):
|
---|
| 175 | IntersectableWrapper<BvhLeaf *>(item) {}
|
---|
[1233] | 176 |
|
---|
| 177 | int Type() const
|
---|
| 178 | {
|
---|
| 179 | return Intersectable::BVH_INTERSECTABLE;
|
---|
| 180 | }
|
---|
| 181 | };
|
---|
| 182 |
|
---|
[1344] | 183 |
|
---|
[1328] | 184 | class TriangleIntersectable: public IntersectableWrapper<Triangle3>
|
---|
[1314] | 185 | {
|
---|
| 186 | public:
|
---|
[1344] | 187 | TriangleIntersectable(Triangle3 item):
|
---|
[1328] | 188 | IntersectableWrapper<Triangle3>(item) {}
|
---|
[1314] | 189 |
|
---|
[1328] | 190 | int CastRay(Ray &ray);
|
---|
| 191 | AxisAlignedBox3 GetBox() const;
|
---|
| 192 | int NumberOfFaces() const;
|
---|
[1344] | 193 | Vector3 GetNormal(const int idx) const;
|
---|
[1328] | 194 |
|
---|
[1686] | 195 | float GetArea() const {return mItem.GetArea();}
|
---|
[1314] | 196 | int Type() const
|
---|
| 197 | {
|
---|
[1328] | 198 | return Intersectable::TRIANGLE_INTERSECTABLE;
|
---|
[1314] | 199 | }
|
---|
[1586] | 200 |
|
---|
| 201 | int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
|
---|
[1587] | 202 |
|
---|
[1686] | 203 | int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
| 204 | Vector3 &normal,
|
---|
| 205 | const Vector3 &viewpoint,
|
---|
| 206 | const int maxTries);
|
---|
[1314] | 207 | };
|
---|
| 208 |
|
---|
| 209 |
|
---|
[1615] | 210 |
|
---|
| 211 |
|
---|
[1233] | 212 | }
|
---|
| 213 |
|
---|
[1138] | 214 | #endif
|
---|