#ifndef __INTERSECTABLE_H #define __INTERSECTABLE_H #include "AxisAlignedBox3.h" #include "Pvs.h" #include #include "VssRay.h" namespace GtpVisibilityPreprocessor { struct VssRayContainer; class KdLeaf; class BvhLeaf; class Intersectable; struct Face; struct FaceParentInfo { /// intersectable Intersectable *mObject; /// face index int mFaceIndex; FaceParentInfo(Intersectable *obj, const int fi): mObject(obj), mFaceIndex(fi) {} }; class Intersectable { public: // last mail id -> warning not thread safe! // both mailId and mailbox should be unique for each thread!!! static int sMailId; static int sReservedMailboxes; int mMailbox; /// unique object Id int mId; /// universal counter int mCounter; /// object based pvs KdPvs mKdPvs; /// view cell based pvs per object ViewCellPvs mViewCellPvs; /// pointer to the container bvh leaf BvhLeaf *mBvhLeaf; VssRayContainer mVssRays; /// # of references to this instance int mReferences; enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE, KD_INTERSECTABLE, BVH_INTERSECTABLE, TRIANGLE_INTERSECTABLE }; Intersectable(): mMailbox(0), mReferences(0), mBvhLeaf(0) {} void SetId(const int id) { mId = id; } int GetId() { return mId; } //////////////////////////////////////////////// // Mailing stuff static void NewMail(const int reserve = 1) { sMailId += sReservedMailboxes; sReservedMailboxes = reserve; } void Mail() { mMailbox = sMailId; } bool Mailed() const { return mMailbox == sMailId; } void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } int IncMail() { return ++ mMailbox - sMailId; } //////////////////////////////////////////////////// virtual AxisAlignedBox3 GetBox() const = 0; virtual int CastRay(GtpVisibilityPreprocessor::Ray &ray) = 0; virtual bool IsConvex() const = 0; virtual bool IsWatertight() const = 0; virtual float IntersectionComplexity() = 0; virtual int NumberOfFaces() const = 0; virtual int Type() const = 0; virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; virtual int GetRandomVisibleSurfacePoint(Vector3 &point, Vector3 &normal, const Vector3 &viewpoint, const int maxTries) = 0; virtual ostream &Describe(ostream &s) = 0; virtual int GenerateSilhouetteRays(const int nrays, const AxisAlignedBox3 &originBox, const AxisAlignedBox3 &directionBox, VssRayContainer &rays) { return 0; } static bool GreaterCounter(const Intersectable *a, const Intersectable *b) { return a->mCounter > b->mCounter; } static string GetTypeName(Intersectable *obj) { switch(obj->Type()) { case MESH_INSTANCE: return "mesh_instance\n"; case TRANSFORMED_MESH_INSTANCE: return "transformed_mesh_instance\n"; case SPHERE: return "sphere\n"; case VIEW_CELL: return "view cell\n"; case OGRE_MESH_INSTANCE: return "ogre_mesh_instance\n"; case KD_INTERSECTABLE: return "kd_intersectable\n"; default: return "unknown\n"; } } /** returns normal from the face with the specified index. PROBLEM: Does not fit to all intersectable types (e.g., spheres) */ virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); } }; } #endif