[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;
|
---|
[1680] | 49 | //BvhNode *mBvhLeaf;
|
---|
[1696] | 50 |
|
---|
[1233] | 51 | /// # of references to this instance
|
---|
[1143] | 52 | int mReferences;
|
---|
[1135] | 53 |
|
---|
[1570] | 54 | //////////////////
|
---|
[1696] | 55 | // note matt: delete these, they are only taking memory
|
---|
[1570] | 56 |
|
---|
[1579] | 57 |
|
---|
[1570] | 58 | /// object based pvs
|
---|
| 59 | KdPvs mKdPvs;
|
---|
[1579] | 60 |
|
---|
[1570] | 61 | /// view cell based pvs per object
|
---|
| 62 | ViewCellPvs mViewCellPvs;
|
---|
| 63 |
|
---|
| 64 | ///////////////////////
|
---|
| 65 |
|
---|
[1135] | 66 | enum { MESH_INSTANCE,
|
---|
| 67 | TRANSFORMED_MESH_INSTANCE,
|
---|
| 68 | SPHERE,
|
---|
| 69 | VIEW_CELL,
|
---|
| 70 | OGRE_MESH_INSTANCE,
|
---|
[1233] | 71 | KD_INTERSECTABLE,
|
---|
[1314] | 72 | BVH_INTERSECTABLE,
|
---|
[1615] | 73 | TRIANGLE_INTERSECTABLE,
|
---|
| 74 | OBJECTS_INTERSECTABLE
|
---|
[1135] | 75 | };
|
---|
[162] | 76 |
|
---|
[1696] | 77 | Intersectable(): mMailbox(0), mReferences(0), mBvhLeaf(0), mVssRays(NULL) {}
|
---|
[245] | 78 |
|
---|
[1701] | 79 | virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);}
|
---|
[1615] | 80 |
|
---|
[1579] | 81 | void SetId(const int id) { mId = id; }
|
---|
| 82 | int GetId() { return mId; }
|
---|
| 83 |
|
---|
| 84 | ////////////////////////////////////////////////
|
---|
| 85 | // Mailing stuff
|
---|
| 86 |
|
---|
| 87 | static void NewMail(const int reserve = 1) {
|
---|
| 88 | sMailId += sReservedMailboxes;
|
---|
| 89 | sReservedMailboxes = reserve;
|
---|
| 90 | }
|
---|
[339] | 91 |
|
---|
[1579] | 92 | void Mail() { mMailbox = sMailId; }
|
---|
| 93 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
| 94 |
|
---|
| 95 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
| 96 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
| 97 |
|
---|
| 98 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
[382] | 99 |
|
---|
[1579] | 100 | ////////////////////////////////////////////////////
|
---|
| 101 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
| 102 | virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
|
---|
[176] | 103 |
|
---|
[1579] | 104 | virtual bool IsConvex() const = 0;
|
---|
| 105 | virtual bool IsWatertight() const = 0;
|
---|
| 106 | virtual float IntersectionComplexity() = 0;
|
---|
| 107 |
|
---|
| 108 | virtual int NumberOfFaces() const = 0;
|
---|
| 109 | virtual int Type() const = 0;
|
---|
[1686] | 110 | virtual float GetArea() const {return 0; }
|
---|
[1579] | 111 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
[556] | 112 |
|
---|
[1687] | 113 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
[1696] | 114 | Vector3 &normal,
|
---|
| 115 | const Vector3 &viewpoint,
|
---|
| 116 | const int maxTries) = 0;
|
---|
[1166] | 117 |
|
---|
[1687] | 118 | virtual ostream &Describe(ostream &s) = 0;
|
---|
[1166] | 119 |
|
---|
[1687] | 120 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
| 121 | const AxisAlignedBox3 &originBox,
|
---|
| 122 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
| 123 | {
|
---|
| 124 | return 0;
|
---|
| 125 | }
|
---|
[1166] | 126 |
|
---|
[1687] | 127 | static bool GreaterCounter(const Intersectable *a,
|
---|
| 128 | const Intersectable *b)
|
---|
| 129 | {
|
---|
| 130 | return a->mCounter > b->mCounter;
|
---|
| 131 | }
|
---|
[1166] | 132 |
|
---|
[1687] | 133 | static string GetTypeName(Intersectable *obj)
|
---|
| 134 | {
|
---|
| 135 | switch(obj->Type())
|
---|
| 136 | {
|
---|
| 137 | case MESH_INSTANCE:
|
---|
| 138 | return "mesh_instance\n";
|
---|
[1344] | 139 |
|
---|
[1687] | 140 | case TRANSFORMED_MESH_INSTANCE:
|
---|
| 141 | return "transformed_mesh_instance\n";
|
---|
| 142 |
|
---|
| 143 | case SPHERE:
|
---|
| 144 | return "sphere\n";
|
---|
| 145 |
|
---|
| 146 | case VIEW_CELL:
|
---|
| 147 | return "view cell\n";
|
---|
| 148 |
|
---|
| 149 | case OGRE_MESH_INSTANCE:
|
---|
| 150 | return "ogre_mesh_instance\n";
|
---|
| 151 |
|
---|
| 152 | case KD_INTERSECTABLE:
|
---|
| 153 | return "kd_intersectable\n";
|
---|
| 154 |
|
---|
| 155 | default:
|
---|
| 156 | return "unknown\n";
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[1696] | 160 | /** Returns normal from the face with the specified index.
|
---|
| 161 | PROBLEM: Does not fit to all intersectable types (e.g., spheres)
|
---|
[1687] | 162 | */
|
---|
| 163 | virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
|
---|
[1696] | 164 |
|
---|
| 165 | VssRayContainer *GetOrCreateRays()
|
---|
| 166 | {
|
---|
| 167 | if (!mVssRays)
|
---|
| 168 | mVssRays = new VssRayContainer();
|
---|
| 169 | return mVssRays;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | void DelRayRefs()
|
---|
| 173 | {
|
---|
| 174 | DEL_PTR(mVssRays);
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | protected:
|
---|
| 178 |
|
---|
| 179 | /// some rays piercing this intersectable
|
---|
| 180 | VssRayContainer *mVssRays;
|
---|
[162] | 181 | };
|
---|
| 182 |
|
---|
[1135] | 183 |
|
---|
[860] | 184 | }
|
---|
[162] | 185 |
|
---|
| 186 | #endif
|
---|