#ifndef __INTERSECTABLE_H #define __INTERSECTABLE_H #include "AxisAlignedBox3.h" #include "Mailable.h" #define STORE_VIEWCELLS_WITH_BVH 1 namespace GtpVisibilityPreprocessor { struct VssRayContainer; class KdLeaf; class BvhLeaf; class BvhNode; class Intersectable; class VssRay; 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; /////////////////////// enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL, OGRE_MESH_INSTANCE, KD_INTERSECTABLE, BVH_INTERSECTABLE, TRIANGLE_INTERSECTABLE, DUMMY_INTERSECTABLE, ENGINE_INTERSECTABLE, CONTAINER_INTERSECTABLE }; Intersectable(); virtual ~Intersectable(); inline void SetId(const int id) { mId = id; } inline 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 interface 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 int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0; virtual int GetRandomEdgePoint(Vector3 &point, Vector3 &normal) = 0; virtual int GetRandomVisibleSurfacePoint(Vector3 &point, Vector3 &normal, const Vector3 &viewpoint, const int maxTries) = 0; // virtual int GetRandomPoint(Vector3 &point, // vector3 &normal) = 0; virtual std::ostream &Describe(std::ostream &s) = 0; ////////////////////////////////////// virtual int GenerateSilhouetteRays(const int nrays, const AxisAlignedBox3 &originBox, const AxisAlignedBox3 &directionBox, VssRayContainer &rays); virtual int GetRandomSurfacePoint(const float u, const float v, Vector3 &point, Vector3 &normal); virtual float GetArea() const; static bool GreaterCounter(const Intersectable *a, const Intersectable *b); /** Returns the name of the type of this intersectable */ static std::string GetTypeName(Intersectable *obj); /** 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; /** Returns rays stored with this intersectable. */ VssRayContainer *GetOrCreateRays(); /** Deletes the rays associated with this intersectable. */ void DelRayRefs(); protected: /// some rays piercing this intersectable VssRayContainer *mVssRays; #if STORE_VIEWCELLS_WITH_BVH public: /** Returns rays stored with this intersectable. */ ViewCellContainer *GetOrCreateViewCells(); void DelViewCells(); protected: ViewCellContainer *mViewCells; #endif }; } #endif