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