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