#ifndef _RayCaster_H__ #define _RayCaster_H__ #include "Containers.h" #include #include "Vector3.h" #include "VssRay.h" using namespace std; namespace GtpVisibilityPreprocessor { class Intersectable; class VssRay; class SimpleRayContainer; class AxisAlignedBox3; //class Vector3; struct VssRayContainer; class Preprocessor; struct SimpleRay; /** This class provides an interface for ray casting. */ class RayCaster { public: enum { INTERNAL_RAYCASTER = 0, INTEL_RAYCASTER }; RayCaster(const Preprocessor &preprocessor); virtual ~RayCaster(); virtual int Type() const = 0; /** Wrapper for casting single ray. @returns ray or NULL if invalid */ VssRay *CastRay(const SimpleRay &simpleRay, const AxisAlignedBox3 &box, const bool castDoubleRay); virtual int CastRay(const SimpleRay &simpleRay, VssRayContainer &vssRays, const AxisAlignedBox3 &box, const bool castDoubleRay, const bool pruneInvalidRays = true) = 0; virtual void CastRays16(SimpleRayContainer &rays, VssRayContainer &vssRays, const AxisAlignedBox3 &sbox, const bool castDoubleRay, const bool pruneInvalidRays = true) = 0; virtual void CastRays( SimpleRayContainer &rays, VssRayContainer &vssRays, const AxisAlignedBox3 &sbox, const bool castDoubleRay, const bool pruneInvalidRays = true); /*virtual void CastRaysEye4(SimpleRayContainer &rays, VssRayContainer &vssRays, const AxisAlignedBox3 &sbox, const bool castDoubleRay, const bool pruneInvalidRays = true) = 0; */ virtual void SortRays(SimpleRayContainer &rays); // pool of vss rays to be used in one pass of the sampling struct VssRayPool { VssRayPool(): mRays(NULL), mIndex(0), mNumber(0) {} ~VssRayPool() { DEL_PTR(mRays); } void Reserve(const int number) { DEL_PTR(mRays); mRays = new VssRay[number]; mNumber = number; } void Clear() { mIndex = 0; } VssRay *Alloc() { // reset pool if (mIndex == mNumber) mIndex = 0; return mRays + mIndex ++; } protected: VssRay *mRays; int mIndex; int mNumber; }; VssRayPool mVssRayPool; void ReserveVssRayPool(const int n) { mVssRayPool.Reserve(n); } void InitPass() { mVssRayPool.Clear(); } protected: void _SortRays(SimpleRayContainer &rays, const int l, const int r, const int depth, float box[12]); struct Intersection { Intersection(): mObject(NULL), mFaceId(0) {} Intersection(const Vector3 &p, const Vector3 &n, Intersectable *o, const int f): mPoint(p), mNormal(n), mObject(o), mFaceId(f) {} Intersection(const Vector3 &p): mPoint(p), mObject(NULL), mFaceId(0) {} Vector3 mPoint; Vector3 mNormal; Intersectable *mObject; int mFaceId; }; int ProcessRay(const SimpleRay &ray, Intersection &hitA, Intersection &hitB, VssRayContainer &vssRays, const AxisAlignedBox3 &box, const bool castDoubleRay, const bool pruneInvalidRays = true); /** Checks if ray is valid. I.e., the ray is in valid view space. @note: clamps the ray to valid view space. */ bool ValidateRay(const Vector3 &origin, const Vector3 &direction, const AxisAlignedBox3 &box, Intersection &hit); bool ClipToViewSpaceBox(const Vector3 &origin, const Vector3 &termination, Vector3 &clippedOrigin, Vector3 &clippedTermination); const Preprocessor &mPreprocessor; }; } #endif