#ifndef __INTERSECTABLEWRAPPER_H #define __INTERSECTABLEWRAPPER_H #include "AxisAlignedBox3.h" #include "Intersectable.h" #include "Triangle3.h" namespace GtpVisibilityPreprocessor { class KdNode; class BvhLeaf; class Ray; class KdTree; struct VssRayContainer; struct Triangle3; struct Face; /** Wrapper used for creating a PVS compliant intersectable. */ template class IntersectableWrapper: public Intersectable { public: IntersectableWrapper(T item); /** Returns node associated with this instance. */ T GetItem() const; /** See get. */ void SetItem(T item); ///////////////////////////////////////////// //-- inherited functions from Intersectable AxisAlignedBox3 GetBox() const; int CastRay(Ray &ray); int CastSimpleRay(const SimpleRay &ray) { return 0;} int CastSimpleRay(const SimpleRay &ray, int RayIndex) { return 0;} bool IsConvex() const; bool IsWatertight() const; float IntersectionComplexity(); int NumberOfFaces() const; int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, GtpVisibilityPreprocessor::Vector3 &normal); int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, GtpVisibilityPreprocessor::Vector3 &normal, const GtpVisibilityPreprocessor::Vector3 &viewpoint, const int maxTries); std::ostream &Describe(std::ostream &s); int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); protected: T mItem; }; template IntersectableWrapper::IntersectableWrapper(T item): Intersectable(), mItem(item) { } template void IntersectableWrapper::SetItem(T item) { mItem = item; } template T IntersectableWrapper::GetItem() const { return mItem; } template AxisAlignedBox3 IntersectableWrapper::GetBox() const { // TODO matt return AxisAlignedBox3(); } template int IntersectableWrapper::CastRay(Ray &ray) { // TODO matt return 0; } template bool IntersectableWrapper::IsConvex() const { return true; } template bool IntersectableWrapper::IsWatertight() const { return true; } template float IntersectableWrapper::IntersectionComplexity() { return 1.0f; } template int IntersectableWrapper::NumberOfFaces() const { return 0; } template int IntersectableWrapper::GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) { return 0; } template int IntersectableWrapper::GetRandomEdgePoint(Vector3 &point, Vector3 &normal) { return 0; } template int IntersectableWrapper::GetRandomVisibleSurfacePoint(Vector3 &point, Vector3 &normal, const Vector3 &viewpoint, const int maxTries) { return 0; } template std::ostream &IntersectableWrapper::Describe(std::ostream &s) { s << mItem; return s; } class KdIntersectable: public IntersectableWrapper { public: KdIntersectable(KdNode *item, const AxisAlignedBox3 &box); int ComputeNumTriangles(); int Type() const { return Intersectable::KD_INTERSECTABLE; } AxisAlignedBox3 GetBox() const { return mBox; } /// the bounding box of this intersectable AxisAlignedBox3 mBox; int mGenericIdx; protected: int mNumTriangles; }; typedef std::map KdIntersectableMap; class TriangleIntersectable: public IntersectableWrapper { public: TriangleIntersectable(const Triangle3 &item): IntersectableWrapper(item) {} int CastRay(Ray &ray); int CastSimpleRay(const SimpleRay &ray); int CastSimpleRay(const SimpleRay &ray, int rayIndex); AxisAlignedBox3 GetBox() const; int NumberOfFaces() const; Vector3 GetNormal(const int idx) const; Vector3 GetNormal() const { return mItem.GetNormal();} float GetArea() const {return mItem.GetArea();} int Type() const { return Intersectable::TRIANGLE_INTERSECTABLE; } int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal); int GetRandomSurfacePoint(const float u, const float v, Vector3 &point, Vector3 &normal); int GetRandomVisibleSurfacePoint(Vector3 &point, Vector3 &normal, const Vector3 &viewpoint, const int maxTries); int GetRandomEdgePoint(Vector3 &point, Vector3 &normal); }; /** Intersectable acting as a proxy. */ class DummyIntersectable: public IntersectableWrapper { public: DummyIntersectable(const int item): IntersectableWrapper(item) { SetId(item); } int Type() const { return Intersectable::DUMMY_INTERSECTABLE; } }; /** Intersectable wrapping is a group of objects. */ class IntersectableGroup: public GtpVisibilityPreprocessor::IntersectableWrapper { public: IntersectableGroup(ObjectContainer *item): IntersectableWrapper(item) {} // hack ~IntersectableGroup() { delete mItem; } int Type() const { return Intersectable::CONTAINER_INTERSECTABLE; } }; class SceneGraphLeafIntersectable: public IntersectableWrapper { public: SceneGraphLeafIntersectable(SceneGraphLeaf *item, const AxisAlignedBox3 &box); int ComputeNumTriangles() { return 0;} int Type() const { return Intersectable::SCENEGRAPHLEAF_INTERSECTABLE; } AxisAlignedBox3 GetBox() const { return mBox; } /// the bounding box of this intersectable AxisAlignedBox3 mBox; protected: // int mNumTriangles; }; } #endif