#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); 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); ostream &Describe(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 ostream &IntersectableWrapper::Describe(ostream &s) { s << mItem; return s; } class KdIntersectable: public IntersectableWrapper { public: AxisAlignedBox3 mBox; KdIntersectable(KdNode *item, const AxisAlignedBox3 &box); int Type() const { return Intersectable::KD_INTERSECTABLE; } AxisAlignedBox3 GetBox() const { return mBox; } }; typedef map KdIntersectableMap; class TriangleIntersectable: public IntersectableWrapper { public: TriangleIntersectable(const Triangle3 &item): IntersectableWrapper(item) {} int CastRay(Ray &ray); AxisAlignedBox3 GetBox() const; int NumberOfFaces() const; Vector3 GetNormal(const int idx) const; 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) {} int Type() const { return Intersectable::DUMMY_INTERSECTABLE; } }; /** Intersectable wrapping is a group of objects. */ class ContainerIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper { public: ContainerIntersectable(ObjectContainer *item): IntersectableWrapper(item) {} // hack ContainerIntersectable::~ContainerIntersectable() { delete mItem; } int Type() const { return Intersectable::CONTAINER_INTERSECTABLE; } }; } #endif