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