[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;
|
---|
[176] | 14 |
|
---|
[1233] | 15 |
|
---|
[162] | 16 | class Intersectable {
|
---|
[176] | 17 | public:
|
---|
[811] | 18 | // last mail id -> warning not thread safe!
|
---|
| 19 | // both mailId and mailbox should be unique for each thread!!!
|
---|
| 20 | static int sMailId;
|
---|
| 21 | static int sReservedMailboxes;
|
---|
| 22 | int mMailbox;
|
---|
| 23 |
|
---|
[1072] | 24 | /// unique object Id
|
---|
[811] | 25 | int mId;
|
---|
| 26 |
|
---|
[1072] | 27 | /// universal counter
|
---|
[811] | 28 | int mCounter;
|
---|
[339] | 29 |
|
---|
[1072] | 30 | /// object based pvs
|
---|
[811] | 31 | KdPvs mKdPvs;
|
---|
[162] | 32 |
|
---|
[1174] | 33 | /// view cell based pvs per object
|
---|
[1077] | 34 | ViewCellPvs mViewCellPvs;
|
---|
| 35 |
|
---|
[1233] | 36 | /// pointer to the container bvh leaf
|
---|
| 37 | BvhLeaf *mBvhLeaf;
|
---|
| 38 |
|
---|
[1193] | 39 | VssRayContainer mVssRays;
|
---|
| 40 |
|
---|
[1233] | 41 | /// # of references to this instance
|
---|
[1143] | 42 | int mReferences;
|
---|
[1135] | 43 |
|
---|
| 44 | enum { MESH_INSTANCE,
|
---|
| 45 | TRANSFORMED_MESH_INSTANCE,
|
---|
| 46 | SPHERE,
|
---|
| 47 | VIEW_CELL,
|
---|
| 48 | OGRE_MESH_INSTANCE,
|
---|
[1233] | 49 | KD_INTERSECTABLE,
|
---|
| 50 | BVH_INTERSECTABLE
|
---|
[1135] | 51 | };
|
---|
[162] | 52 |
|
---|
[1176] | 53 | Intersectable(): mMailbox(0), mReferences(0) {}
|
---|
[245] | 54 |
|
---|
[339] | 55 | void SetId(const int id) { mId = id; }
|
---|
| 56 | int GetId() { return mId; }
|
---|
| 57 |
|
---|
[1184] | 58 | ////////////////////////////////////////////////
|
---|
| 59 | // Mailing stuff
|
---|
[382] | 60 |
|
---|
| 61 | static void NewMail(const int reserve = 1) {
|
---|
| 62 | sMailId += sReservedMailboxes;
|
---|
| 63 | sReservedMailboxes = reserve;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[339] | 66 | void Mail() { mMailbox = sMailId; }
|
---|
[837] | 67 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
[339] | 68 |
|
---|
[382] | 69 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
| 70 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
| 71 |
|
---|
[1176] | 72 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
[382] | 73 |
|
---|
[1184] | 74 | ////////////////////////////////////////////////////
|
---|
[1020] | 75 | virtual AxisAlignedBox3 GetBox() const = 0;
|
---|
[870] | 76 | virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0;
|
---|
[382] | 77 |
|
---|
[1020] | 78 | virtual bool IsConvex() const = 0;
|
---|
| 79 | virtual bool IsWatertight() const = 0;
|
---|
[850] | 80 | virtual float IntersectionComplexity() = 0;
|
---|
[176] | 81 |
|
---|
[850] | 82 | virtual int NumberOfFaces() const = 0;
|
---|
| 83 | virtual int Type() const = 0;
|
---|
[176] | 84 |
|
---|
[850] | 85 | virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
|
---|
| 86 |
|
---|
| 87 | virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
|
---|
| 88 | Vector3 &normal,
|
---|
| 89 | const Vector3 &viewpoint,
|
---|
| 90 | const int maxTries) = 0;
|
---|
[492] | 91 |
|
---|
[850] | 92 | virtual ostream &Describe(ostream &s) = 0;
|
---|
| 93 |
|
---|
| 94 | virtual int GenerateSilhouetteRays(const int nrays,
|
---|
| 95 | const AxisAlignedBox3 &originBox,
|
---|
| 96 | const AxisAlignedBox3 &directionBox, VssRayContainer &rays)
|
---|
| 97 | {
|
---|
| 98 | return 0;
|
---|
| 99 | }
|
---|
[556] | 100 |
|
---|
[850] | 101 | static bool GreaterCounter(const Intersectable *a,
|
---|
| 102 | const Intersectable *b)
|
---|
| 103 | {
|
---|
| 104 | return a->mCounter > b->mCounter;
|
---|
| 105 | }
|
---|
[1166] | 106 |
|
---|
| 107 | static string GetTypeName(Intersectable *obj)
|
---|
| 108 | {
|
---|
| 109 | switch(obj->Type())
|
---|
| 110 | {
|
---|
| 111 | case MESH_INSTANCE:
|
---|
| 112 | return "mesh_instance\n";
|
---|
| 113 |
|
---|
| 114 | case TRANSFORMED_MESH_INSTANCE:
|
---|
| 115 | return "transformed_mesh_instance\n";
|
---|
| 116 |
|
---|
| 117 | case SPHERE:
|
---|
| 118 | return "sphere\n";
|
---|
| 119 |
|
---|
| 120 | case VIEW_CELL:
|
---|
| 121 | return "view cell\n";
|
---|
| 122 |
|
---|
| 123 | case OGRE_MESH_INSTANCE:
|
---|
| 124 | return "ogre_mesh_instance\n";
|
---|
| 125 |
|
---|
| 126 | case KD_INTERSECTABLE:
|
---|
| 127 | return "kd_intersectable\n";
|
---|
| 128 |
|
---|
| 129 | default:
|
---|
| 130 | return "unknown\n";
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
[162] | 133 | };
|
---|
| 134 |
|
---|
[1135] | 135 |
|
---|
[860] | 136 | }
|
---|
[162] | 137 |
|
---|
| 138 | #endif
|
---|