#ifndef __SIMPLERAY_H__ #define __SIMPLERAY_H__ #include using namespace std; #include "Vector3.h" #include "Ray.h" namespace GtpVisibilityPreprocessor { class Intersectable; // This is the result of ray tracing with a simple ray struct IntersectionStr { Intersectable *intersectable; float tdist; float maxt; int pad1; // aligned to 16 bytes }; struct SimpleRay { // This is stored result for the rays in the container // having 16 rays - shooting rays in both directions static IntersectionStr IntersectionRes[32]; Vector3 mOrigin; Vector3 mDirection; // 6*4 = 24B Intersectable *mOriginObject; Intersectable *mTerminationObject; // 2*4 = 8B enum {F_BIDIRECTIONAL = 1}; unsigned short mFlags; unsigned char mType; unsigned char mDistribution; // 4B // generator Id -> relative to the generating distribution! int mGeneratorId; // 4B // TOTAL = 40B - aligned by 8 Bytes only! - it might be // padding to 48 Bytes here ! //float mWeight; SimpleRay(): mType(Ray::LOCAL_RAY) { } SimpleRay(const Vector3 &o, const Vector3 &d, unsigned char distribution, float weight, unsigned char flags = F_BIDIRECTIONAL ): mOrigin(o), mDirection(d), mFlags(flags), mType(Ray::LOCAL_RAY), mDistribution(distribution) // , mWeight(weight) { // mId = sSimpleRayId++; } void Set(const Vector3 &o, const Vector3 &d, const unsigned char distribution, const float weight, const unsigned char flags = F_BIDIRECTIONAL ) { mOrigin = o; mDirection = d, mFlags = flags; mType = Ray::LOCAL_RAY; mDistribution = distribution; // , mWeight(weight) // mId = sSimpleRayId++; } bool IsBidirectional() const { return mFlags & F_BIDIRECTIONAL; } void SetBidirectional(const bool b) { if (b) mFlags |= F_BIDIRECTIONAL; else mFlags &= ~F_BIDIRECTIONAL; } float GetParam(const int axis) const { if (axis < 3) return mOrigin[axis]; else return mDirection[axis-3]; } Vector3 Extrap(const float t) const { return mOrigin + mDirection * t; } friend std::ostream &operator<<(std::ostream &s, const SimpleRay &r) { return s << "origin=" << r.mOrigin << " dir=" << r.mDirection; }; }; class SimpleRayContainer : public vector { public: SimpleRayContainer():vector() {} #if 0 void NormalizePdf(float scale = 1.0f) { iterator it = begin(); float sumPdf = 0.0f; for (; it != end(); it++) sumPdf += (*it).mPdf; float c = scale/sumPdf; for (it = begin(); it != end(); it++) { (*it).mPdf*=c; } } #endif void AddRay(const SimpleRay &ray) { push_back(ray); } }; } #endif