[162] | 1 | #ifndef __INTERSECTABLE_H
|
---|
| 2 | #define __INTERSECTABLE_H
|
---|
| 3 |
|
---|
[176] | 4 | #include "AxisAlignedBox3.h"
|
---|
| 5 | #include "Pvs.h"
|
---|
[1074] | 6 | #include <set>
|
---|
[1184] | 7 | #include "VssRay.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;
|
---|
| 16 | struct Face;
|
---|
[1233] | 17 |
|
---|
[1344] | 18 |
|
---|
[1281] | 19 | struct FaceParentInfo {
|
---|
[1344] | 20 | /// intersectable
|
---|
| 21 | Intersectable *mObject;
|
---|
| 22 | /// face index
|
---|
| 23 | int mFaceIndex;
|
---|
| 24 |
|
---|
| 25 | FaceParentInfo(Intersectable *obj, const int fi):
|
---|
| 26 | mObject(obj), mFaceIndex(fi)
|
---|
| 27 | {}
|
---|
[1281] | 28 | };
|
---|
| 29 |
|
---|
[1344] | 30 |
|
---|
[162] | 31 | class Intersectable {
|
---|
[176] | 32 | public:
|
---|
[811] | 33 | // last mail id -> warning not thread safe!
|
---|
| 34 | // both mailId and mailbox should be unique for each thread!!!
|
---|
| 35 | static int sMailId;
|
---|
| 36 | static int sReservedMailboxes;
|
---|
[1579] | 37 |
|
---|
| 38 | /// Mailbox used for traversals
|
---|
[811] | 39 | int mMailbox;
|
---|
| 40 |
|
---|
[1072] | 41 | /// unique object Id
|
---|
[811] | 42 | int mId;
|
---|
[1579] | 43 |
|
---|
[1072] | 44 | /// universal counter
|
---|
[811] | 45 | int mCounter;
|
---|
[1077] | 46 |
|
---|
[1680] | 47 | /// pointer to the containing bvh leaf
|
---|
[1233] | 48 | BvhLeaf *mBvhLeaf;
|
---|
[1696] | 49 |
|
---|
[1233] | 50 | /// # of references to this instance
|
---|
[1736] | 51 | //int mReferences;
|
---|
[1135] | 52 |
|
---|
[1570] | 53 | //////////////////
|
---|
[1696] | 54 | // note matt: delete these, they are only taking memory
|
---|
[1570] | 55 |
|
---|
| 56 | /// object based pvs
|
---|
[1736] | 57 | //KdPvs mKdPvs;
|
---|
[1579] | 58 |
|
---|
[1570] | 59 | /// view cell based pvs per object
|
---|
[1736] | 60 | //ViewCellPvs mViewCellPvs;
|
---|
[1570] | 61 |
|
---|
| 62 | ///////////////////////
|
---|
| 63 |
|
---|
[1135] | 64 | enum { MESH_INSTANCE,
|
---|
| 65 | TRANSFORMED_MESH_INSTANCE,
|
---|
| 66 | SPHERE,
|
---|
| 67 | VIEW_CELL,
|
---|
| 68 | OGRE_MESH_INSTANCE,
|
---|
[1233] | 69 | KD_INTERSECTABLE,
|
---|
[1314] | 70 | BVH_INTERSECTABLE,
|
---|
[1615] | 71 | TRIANGLE_INTERSECTABLE,
|
---|
| 72 | OBJECTS_INTERSECTABLE
|
---|
[1135] | 73 | };
|
---|
[162] | 74 |
|
---|
[1736] | 75 | Intersectable():
|
---|
| 76 | mMailbox(0),
|
---|
| 77 | //mReferences(0),
|
---|
| 78 | mBvhLeaf(0),
|
---|
| 79 | mVssRays(NULL) {}
|
---|
[245] | 80 |
|
---|
[1701] | 81 | virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
|
---|
[1615] | 82 |
|
---|
[1579] | 83 | void SetId(const int id) { mId = id; }
|
---|
| 84 | int GetId() { return mId; }
|
---|
| 85 |
|
---|
| 86 | ////////////////////////////////////////////////
|
---|
| 87 | // Mailing stuff
|
---|
| 88 |
|
---|
| 89 | static void NewMail(const int reserve = 1) {
|
---|
| 90 | sMailId += sReservedMailboxes;
|
---|
| 91 | sReservedMailboxes = reserve;
|
---|
| 92 | }
|
---|
[339] | 93 |
|
---|
[1579] | 94 | void Mail() { mMailbox = sMailId; }
|
---|
| 95 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
| 96 |
|
---|
| 97 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
| 98 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
| 99 |
|
---|
| 100 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
[382] | 101 |
|
---|
[1579] | 102 | ////////////////////////////////////////////////////
|
---|
| 103 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
| 104 | virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
|
---|
[176] | 105 |
|
---|
[1579] | 106 | virtual bool IsConvex() const = 0;
|
---|
| 107 | virtual bool IsWatertight() const = 0;
|
---|
| 108 | virtual float IntersectionComplexity() = 0;
|
---|
| 109 |
|
---|
| 110 | virtual int NumberOfFaces() const = 0;
|
---|
| 111 | virtual int Type() const = 0;
|
---|
[1686] | 112 | virtual float GetArea() const {return 0; }
|
---|
[1579] | 113 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
[556] | 114 |
|
---|
[1687] | 115 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[1696] | 116 | Vector3 &normal,
|
---|
| 117 | const Vector3 &viewpoint,
|
---|
| 118 | const int maxTries) = 0;
|
---|
[1166] | 119 |
|
---|
[1687] | 120 | virtual ostream &Describe(ostream &s) = 0;
|
---|
[1166] | 121 |
|
---|
[1687] | 122 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
| 123 | const AxisAlignedBox3 &originBox,
|
---|
| 124 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
| 125 | {
|
---|
| 126 | return 0;
|
---|
| 127 | }
|
---|
[1166] | 128 |
|
---|
[1687] | 129 | static bool GreaterCounter(const Intersectable *a,
|
---|
| 130 | const Intersectable *b)
|
---|
| 131 | {
|
---|
| 132 | return a->mCounter > b->mCounter;
|
---|
| 133 | }
|
---|
[1166] | 134 |
|
---|
[1687] | 135 | static string GetTypeName(Intersectable *obj)
|
---|
| 136 | {
|
---|
| 137 | switch(obj->Type())
|
---|
| 138 | {
|
---|
| 139 | case MESH_INSTANCE:
|
---|
| 140 | return "mesh_instance\n";
|
---|
[1344] | 141 |
|
---|
[1687] | 142 | case TRANSFORMED_MESH_INSTANCE:
|
---|
| 143 | return "transformed_mesh_instance\n";
|
---|
| 144 |
|
---|
| 145 | case SPHERE:
|
---|
| 146 | return "sphere\n";
|
---|
| 147 |
|
---|
| 148 | case VIEW_CELL:
|
---|
| 149 | return "view cell\n";
|
---|
| 150 |
|
---|
| 151 | case OGRE_MESH_INSTANCE:
|
---|
| 152 | return "ogre_mesh_instance\n";
|
---|
| 153 |
|
---|
| 154 | case KD_INTERSECTABLE:
|
---|
| 155 | return "kd_intersectable\n";
|
---|
| 156 |
|
---|
| 157 | default:
|
---|
| 158 | return "unknown\n";
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
[1696] | 162 | /** Returns normal from the face with the specified index.
|
---|
| 163 | PROBLEM: Does not fit to all intersectable types (e.g., spheres)
|
---|
[1687] | 164 | */
|
---|
| 165 | virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
|
---|
[1696] | 166 |
|
---|
| 167 | VssRayContainer *GetOrCreateRays()
|
---|
| 168 | {
|
---|
| 169 | if (!mVssRays)
|
---|
| 170 | mVssRays = new VssRayContainer();
|
---|
| 171 | return mVssRays;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | void DelRayRefs()
|
---|
| 175 | {
|
---|
| 176 | DEL_PTR(mVssRays);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | protected:
|
---|
| 180 |
|
---|
| 181 | /// some rays piercing this intersectable
|
---|
| 182 | VssRayContainer *mVssRays;
|
---|
[162] | 183 | };
|
---|
| 184 |
|
---|
[1135] | 185 |
|
---|
[860] | 186 | }
|
---|
[162] | 187 |
|
---|
| 188 | #endif
|
---|