[2105] | 1 | #ifndef __SIMPLERAY_H__
|
---|
| 2 | #define __SIMPLERAY_H__
|
---|
| 3 |
|
---|
| 4 | #include <vector>
|
---|
| 5 | using namespace std;
|
---|
| 6 | #include "Vector3.h"
|
---|
| 7 |
|
---|
| 8 | namespace GtpVisibilityPreprocessor {
|
---|
| 9 |
|
---|
| 10 | struct SimpleRay
|
---|
| 11 | {
|
---|
| 12 |
|
---|
| 13 | Vector3 mOrigin;
|
---|
| 14 | Vector3 mDirection;
|
---|
| 15 | // 6*4 = 24B
|
---|
| 16 |
|
---|
| 17 | Intersectable *mOriginObject;
|
---|
| 18 | Intersectable *mTerminationObject;
|
---|
| 19 | // 2*4 = 8B
|
---|
| 20 |
|
---|
| 21 | enum {F_BIDIRECTIONAL = 1};
|
---|
| 22 | unsigned short mFlags;
|
---|
| 23 | unsigned char mType;
|
---|
| 24 | unsigned char mDistribution;
|
---|
| 25 | // 4B
|
---|
| 26 |
|
---|
| 27 | // generator Id -> relative to the generating distribution!
|
---|
| 28 | int mGeneratorId;
|
---|
| 29 | // 4B
|
---|
| 30 |
|
---|
| 31 | // TOTAL = 40B
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | //float mWeight;
|
---|
| 35 |
|
---|
| 36 | SimpleRay(): mType(Ray::LOCAL_RAY)
|
---|
| 37 | {
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | SimpleRay(const Vector3 &o,
|
---|
| 41 | const Vector3 &d,
|
---|
[2116] | 42 | const unsigned char distribution,
|
---|
[2105] | 43 | const float weight,
|
---|
| 44 | const unsigned char flags = F_BIDIRECTIONAL
|
---|
| 45 | ):
|
---|
| 46 | mOrigin(o),
|
---|
| 47 | mDirection(d),
|
---|
| 48 | mFlags(flags),
|
---|
| 49 | mType(Ray::LOCAL_RAY),
|
---|
| 50 | mDistribution(distribution)
|
---|
| 51 | // , mWeight(weight)
|
---|
| 52 | {
|
---|
| 53 | // mId = sSimpleRayId++;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | bool IsBidirectional() const { return mFlags & F_BIDIRECTIONAL; }
|
---|
| 57 |
|
---|
| 58 | void SetBidirectional(const bool b) {
|
---|
| 59 | if (b)
|
---|
| 60 | mFlags |= F_BIDIRECTIONAL;
|
---|
| 61 | else
|
---|
| 62 | mFlags &= ~F_BIDIRECTIONAL;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | float GetParam(const int axis) const {
|
---|
| 66 | if (axis < 3)
|
---|
| 67 | return mOrigin[axis];
|
---|
| 68 | else
|
---|
| 69 | return mDirection[axis-3];
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | Vector3 Extrap(const float t) const {
|
---|
| 73 | return mOrigin + mDirection * t;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[2176] | 76 | friend std::ostream &operator<<(std::ostream &s, const SimpleRay &r)
|
---|
[2105] | 77 | {
|
---|
| 78 | return s << "origin=" << r.mOrigin << " dir=" << r.mDirection;
|
---|
| 79 | };
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 | class SimpleRayContainer : public vector<SimpleRay>
|
---|
| 83 | {
|
---|
| 84 | public:
|
---|
| 85 |
|
---|
| 86 | SimpleRayContainer():vector<SimpleRay>() {}
|
---|
| 87 |
|
---|
| 88 | #if 0
|
---|
| 89 | void NormalizePdf(float scale = 1.0f) {
|
---|
| 90 | iterator it = begin();
|
---|
| 91 | float sumPdf = 0.0f;
|
---|
| 92 | for (; it != end(); it++)
|
---|
| 93 | sumPdf += (*it).mPdf;
|
---|
| 94 |
|
---|
| 95 | float c = scale/sumPdf;
|
---|
| 96 |
|
---|
| 97 | for (it = begin(); it != end(); it++) {
|
---|
| 98 | (*it).mPdf*=c;
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 | #endif
|
---|
| 102 |
|
---|
| 103 | void AddRay(const SimpleRay &ray) {
|
---|
| 104 | push_back(ray);
|
---|
| 105 | }
|
---|
| 106 | };
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | #endif
|
---|
| 113 |
|
---|