[162] | 1 | #ifndef __INTERSECTABLE_H
|
---|
| 2 | #define __INTERSECTABLE_H
|
---|
| 3 |
|
---|
[2198] | 4 |
|
---|
[176] | 5 | #include "AxisAlignedBox3.h"
|
---|
[1867] | 6 | #include "Mailable.h"
|
---|
[162] | 7 |
|
---|
[2199] | 8 | #define STORE_VIEWCELLS_WITH_BVH 1
|
---|
[2198] | 9 |
|
---|
[860] | 10 | namespace GtpVisibilityPreprocessor {
|
---|
| 11 |
|
---|
[497] | 12 | struct VssRayContainer;
|
---|
[1072] | 13 | class KdLeaf;
|
---|
[1233] | 14 | class BvhLeaf;
|
---|
[1680] | 15 | class BvhNode;
|
---|
[1281] | 16 | class Intersectable;
|
---|
[2116] | 17 | class VssRay;
|
---|
[1281] | 18 | struct Face;
|
---|
[1233] | 19 |
|
---|
[1344] | 20 |
|
---|
[2066] | 21 | struct FaceParentInfo
|
---|
| 22 | {
|
---|
[2575] | 23 | /// intersectable
|
---|
| 24 | Intersectable *mObject;
|
---|
| 25 | /// face index
|
---|
| 26 | int mFaceIndex;
|
---|
| 27 |
|
---|
| 28 | FaceParentInfo(Intersectable *obj, const int fi):
|
---|
| 29 | mObject(obj), mFaceIndex(fi)
|
---|
| 30 | {}
|
---|
[1281] | 31 | };
|
---|
| 32 |
|
---|
[1344] | 33 |
|
---|
[2066] | 34 | class Intersectable
|
---|
| 35 | {
|
---|
[176] | 36 | public:
|
---|
[1579] | 37 |
|
---|
[2543] | 38 | ///////////////////////
|
---|
[1077] | 39 |
|
---|
[2543] | 40 | enum {MESH_INSTANCE,
|
---|
[2615] | 41 | TRANSFORMED_MESH_INSTANCE,
|
---|
| 42 | SPHERE,
|
---|
| 43 | VIEW_CELL,
|
---|
| 44 | OGRE_MESH_INSTANCE,
|
---|
| 45 | KD_INTERSECTABLE,
|
---|
| 46 | BVH_INTERSECTABLE,
|
---|
| 47 | TRIANGLE_INTERSECTABLE,
|
---|
| 48 | DUMMY_INTERSECTABLE,
|
---|
| 49 | ENGINE_INTERSECTABLE,
|
---|
| 50 | CONTAINER_INTERSECTABLE,
|
---|
| 51 | SCENEGRAPHLEAF_INTERSECTABLE
|
---|
[2543] | 52 | };
|
---|
[1570] | 53 |
|
---|
[2543] | 54 | Intersectable();
|
---|
[245] | 55 |
|
---|
[2543] | 56 | virtual ~Intersectable();
|
---|
[1615] | 57 |
|
---|
[2543] | 58 | inline void SetId(const int id) { mId = id; }
|
---|
| 59 | inline int GetId() { return mId; }
|
---|
[382] | 60 |
|
---|
[2543] | 61 | /////////////
|
---|
| 62 | // Mailing stuff
|
---|
[1999] | 63 |
|
---|
[2543] | 64 | static void NewMail(const int reserve = 1)
|
---|
| 65 | {
|
---|
| 66 | sMailId += sReservedMailboxes;
|
---|
| 67 | sReservedMailboxes = reserve;
|
---|
| 68 | }
|
---|
[1999] | 69 |
|
---|
[2543] | 70 | void Mail() { mMailbox = sMailId; }
|
---|
| 71 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
[2066] | 72 |
|
---|
[2543] | 73 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
| 74 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
[1763] | 75 |
|
---|
[2543] | 76 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
[1166] | 77 |
|
---|
[2543] | 78 | // last mail id -> warning not thread safe!
|
---|
| 79 | // both mailId and mailbox should be unique for each thread!!!
|
---|
| 80 | static int sMailId;
|
---|
| 81 | static int sReservedMailboxes;
|
---|
[1990] | 82 |
|
---|
[2543] | 83 | /// Mailbox used for traversals
|
---|
| 84 | int mMailbox;
|
---|
[1166] | 85 |
|
---|
[2643] | 86 | static void NewMail2(const int reserve = 1)
|
---|
| 87 | {
|
---|
| 88 | sMailId2 += sReservedMailboxes2;
|
---|
| 89 | sReservedMailboxes2 = reserve;
|
---|
| 90 | }
|
---|
[1166] | 91 |
|
---|
[2643] | 92 | ////////////
|
---|
| 93 | void Mail2() { mMailbox2 = sMailId2; }
|
---|
| 94 | bool Mailed2() const { return mMailbox2 == sMailId2; }
|
---|
| 95 |
|
---|
| 96 | void Mail2(const int mailbox) { mMailbox2 = sMailId2 + mailbox; }
|
---|
| 97 | bool Mailed2(const int mailbox) const { return mMailbox2 == sMailId2 + mailbox; }
|
---|
| 98 |
|
---|
| 99 | int IncMail2() { return ++ mMailbox2 - sMailId2; }
|
---|
| 100 |
|
---|
| 101 | // last mail id -> warning not thread safe!
|
---|
| 102 | // both mailId and mailbox should be unique for each thread!!!
|
---|
| 103 | static int sMailId2;
|
---|
| 104 | static int sReservedMailboxes2;
|
---|
| 105 |
|
---|
| 106 | /// Mailbox used for traversals
|
---|
| 107 | int mMailbox2;
|
---|
| 108 |
|
---|
| 109 | ////////////
|
---|
| 110 |
|
---|
[2543] | 111 | ////////////////
|
---|
| 112 | // virtual interface
|
---|
[1166] | 113 |
|
---|
[2543] | 114 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
| 115 | virtual int CastRay(Ray &ray) = 0;
|
---|
[2575] | 116 | virtual int CastSimpleRay(const SimpleRay &ray) = 0;
|
---|
| 117 | virtual int CastSimpleRay(const SimpleRay &ray, int indexRay) = 0;
|
---|
[1344] | 118 |
|
---|
[2543] | 119 | virtual bool IsConvex() const = 0;
|
---|
| 120 | virtual bool IsWatertight() const = 0;
|
---|
| 121 | virtual float IntersectionComplexity() = 0;
|
---|
[1687] | 122 |
|
---|
[2543] | 123 | virtual int NumberOfFaces() const = 0;
|
---|
| 124 | virtual int Type() const = 0;
|
---|
[1687] | 125 |
|
---|
[2543] | 126 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
[1696] | 127 |
|
---|
[2543] | 128 | virtual int GetRandomEdgePoint(Vector3 &point,
|
---|
| 129 | Vector3 &normal) = 0;
|
---|
[1696] | 130 |
|
---|
[2543] | 131 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
| 132 | Vector3 &normal,
|
---|
| 133 | const Vector3 &viewpoint,
|
---|
| 134 | const int maxTries) = 0;
|
---|
[2066] | 135 |
|
---|
[2543] | 136 | // virtual int GetRandomPoint(Vector3 &point,
|
---|
| 137 | // vector3 &normal) = 0;
|
---|
[2198] | 138 |
|
---|
[2543] | 139 | virtual std::ostream &Describe(std::ostream &s) = 0;
|
---|
| 140 |
|
---|
| 141 | //////////////////////////////////////
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
| 145 | const AxisAlignedBox3 &originBox,
|
---|
| 146 | const AxisAlignedBox3 &directionBox,
|
---|
| 147 | VssRayContainer &rays);
|
---|
| 148 |
|
---|
| 149 | virtual int GetRandomSurfacePoint(const float u,
|
---|
| 150 | const float v,
|
---|
| 151 | Vector3 &point,
|
---|
| 152 | Vector3 &normal);
|
---|
| 153 |
|
---|
| 154 | virtual float GetArea() const;
|
---|
| 155 |
|
---|
| 156 | static bool GreaterCounter(const Intersectable *a,
|
---|
| 157 | const Intersectable *b);
|
---|
| 158 |
|
---|
| 159 | /** Returns the name of the type of this intersectable
|
---|
| 160 | */
|
---|
| 161 | static std::string GetTypeName(Intersectable *obj);
|
---|
| 162 | /** Returns normal from the face with the specified index.
|
---|
| 163 | PROBLEM: Does not fit to all intersectable types (e.g., spheres)
|
---|
| 164 | */
|
---|
| 165 | virtual Vector3 GetNormal(const int idx) const;
|
---|
| 166 | /** Returns rays stored with this intersectable.
|
---|
| 167 | */
|
---|
| 168 | VssRayContainer *GetOrCreateRays();
|
---|
| 169 |
|
---|
| 170 | /** Deletes the rays associated with this intersectable.
|
---|
| 171 | */
|
---|
| 172 | void DelRayRefs();
|
---|
| 173 |
|
---|
| 174 | /// hack
|
---|
| 175 | int mRenderedFrame;
|
---|
| 176 |
|
---|
| 177 | ///////////
|
---|
| 178 |
|
---|
| 179 | /// unique object Id
|
---|
| 180 | int mId;
|
---|
| 181 | /// universal counter
|
---|
| 182 | int mCounter;
|
---|
| 183 | /// pointer to the containing bvh leaf
|
---|
| 184 | BvhLeaf *mBvhLeaf;
|
---|
| 185 |
|
---|
[1696] | 186 | protected:
|
---|
[2543] | 187 |
|
---|
[2066] | 188 | /// some rays piercing this intersectable
|
---|
| 189 | VssRayContainer *mVssRays;
|
---|
[2198] | 190 |
|
---|
[2543] | 191 |
|
---|
[2198] | 192 | #if STORE_VIEWCELLS_WITH_BVH
|
---|
| 193 | public:
|
---|
[2543] | 194 | /** Returns rays stored with this intersectable.
|
---|
| 195 | */
|
---|
| 196 | ViewCellContainer *GetOrCreateViewCells();
|
---|
[2198] | 197 |
|
---|
[2543] | 198 | void DelViewCells();
|
---|
[2198] | 199 |
|
---|
| 200 | protected:
|
---|
[2543] | 201 | ViewCellContainer *mViewCells;
|
---|
[2198] | 202 | #endif
|
---|
[162] | 203 | };
|
---|
| 204 |
|
---|
[1135] | 205 |
|
---|
[860] | 206 | }
|
---|
[162] | 207 |
|
---|
| 208 | #endif
|
---|