#ifndef __INTERSECTABLE_H #define __INTERSECTABLE_H #include "AxisAlignedBox3.h" #include "Pvs.h" #include #include "VssRay.h" #include "Mailable.h" namespace GtpVisibilityPreprocessor { struct VssRayContainer; class KdLeaf; class BvhLeaf; class BvhNode; 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: /// unique object Id int mId; /// universal counter int mCounter; /// pointer to the containing bvh leaf BvhLeaf *mBvhLeaf; /// # of references to this instance //int mReferences; ////////////////// // note matt: delete these, they are only taking memory /// object based pvs //KdPvs mKdPvs; /// view cell based pvs per object //ViewCellPvs mViewCellPvs; /////////////////////// enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE, KD_INTERSECTABLE, BVH_INTERSECTABLE, TRIANGLE_INTERSECTABLE, OBJECTS_INTERSECTABLE }; Intersectable(): mMailbox(0), //mReferences(0), mBvhLeaf(0), mVssRays(NULL) {} virtual Intersectable::~Intersectable() {DEL_PTR(mVssRays);} 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; } // last mail id -> warning not thread safe! // both mailId and mailbox should be unique for each thread!!! static int sMailId; static int sReservedMailboxes; /// Mailbox used for traversals int mMailbox; //////////////////////////////////////////////////// virtual AxisAlignedBox3 GetBox() const = 0; virtual int CastRay(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 float GetArea() const {return 0; } virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; virtual int GetRandomSurfacePoint(const float u, const float v, Vector3 &point, Vector3 &normal) { cerr<<"GetRandomSurfacePoint(u,v...) not yet implemented"<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); } VssRayContainer *GetOrCreateRays() { if (!mVssRays) mVssRays = new VssRayContainer(); return mVssRays; } void DelRayRefs() { DEL_PTR(mVssRays); } protected: /// some rays piercing this intersectable VssRayContainer *mVssRays; }; } #endif