#ifndef __RAYINFO_H__ #define __RAYINFO_H__ #include #include "VssRay.h" namespace GtpVisibilityPreprocessor { //class VssRay; class RayInfo; class Plane3; class Vector3; typedef std::vector RayInfoContainer; /** Structure holding additional info about the ray during traversal. */ class RayInfo { public: /// pointer to the actual ray VssRay *mRay; // endpoints - do we need them? #if USE_FIXEDPOINT_T short mMinT, mMaxT; #else float mMinT, mMaxT; #endif RayInfo(); RayInfo(VssRay *r); RayInfo(VssRay *r, const float _min, const float _max); RayInfo(VssRay *r, const short _min, const float _max); RayInfo(VssRay *r, const float _min, const short _max); friend bool operator<(const RayInfo &a, const RayInfo &b) { return a.mRay < b.mRay; } /** Extracts the scalar of the starting point of the ray segment that lies in the axis. */ inline float ExtrapOrigin(const int axis) const; /** Extracts the scalar of the termination point of the ray segment that lies in the axis. */ inline float ExtrapTermination(const int axis) const; /** Extracts the starting point of the ray segment. */ inline Vector3 ExtrapOrigin() const; /** Extracts the end point of the ray segment. */ inline Vector3 ExtrapTermination() const; inline float GetMinT () const; inline float GetMaxT () const; inline void SetMinT (const float t); inline void SetMaxT (const float t); float SegmentLength() const; float SqrSegmentLength() const; /** Computes intersection of this ray with the axis aligned split plane. @param axis axis of the split plane @param position scalar position of the split plane for the chosen axis @param t returns the t parameter value of the ray intersection @returns 0 if ray intersects plane, -1 if on back side of plane, 1 if on front side */ int ComputeRayIntersection(const int axis, const float position, float &t) const; /** Computes intersection of this ray with the split plane. @param splitPlane the split plane @param t returns the t parameter value of the ray intersection @returns 0 if ray intersects plane, -1 if on back side of plane, 1 if on front side */ int ComputeRayIntersection(const Plane3 &splitPlane, float &t) const; friend void GetRayInfoSets(const RayInfoContainer &sourceRays, const int maxSize, RayInfoContainer &usedRays, RayInfoContainer *savedRays = NULL); }; float RayInfo::ExtrapOrigin(const int axis) const { return mRay->GetOrigin(axis) + GetMinT() * mRay->GetDir(axis); } float RayInfo::ExtrapTermination(const int axis) const { return mRay->GetOrigin(axis) + GetMaxT() * mRay->GetDir(axis); } Vector3 RayInfo::ExtrapOrigin() const { return mRay->GetOrigin() + GetMinT() * mRay->GetDir(); } Vector3 RayInfo::ExtrapTermination() const { return mRay->GetOrigin() + GetMaxT() * mRay->GetDir(); } #if USE_FIXEDPOINT_T float RayInfo::GetMinT () const { return mMinT/(float)(FIXEDPOINT_ONE); } float RayInfo::GetMaxT() const { return mMaxT / (float)(FIXEDPOINT_ONE); } void RayInfo::SetMinT (const float t) { mMinT = (short) (t * (float)(FIXEDPOINT_ONE)); } void RayInfo::SetMaxT (const float t) { mMaxT = (short) (t*(float)(FIXEDPOINT_ONE)); ++ mMaxT; // if (mMaxT!=0xFFFF) // mMaxT++; } #else float RayInfo::GetMinT () const { return mMinT; } float RayInfo::GetMaxT () const { return mMaxT; } void RayInfo::SetMinT (const float t) { mMinT = t; } void RayInfo::SetMaxT (const float t) { mMaxT = t; } #endif } #endif