[2105] | 1 | #ifndef __SIMPLERAY_H__
|
---|
| 2 | #define __SIMPLERAY_H__
|
---|
| 3 |
|
---|
| 4 | #include <vector>
|
---|
| 5 | using namespace std;
|
---|
| 6 | #include "Vector3.h"
|
---|
[2575] | 7 | #include "Ray.h"
|
---|
[2105] | 8 |
|
---|
| 9 | namespace GtpVisibilityPreprocessor {
|
---|
| 10 |
|
---|
[2575] | 11 | class Intersectable;
|
---|
| 12 |
|
---|
| 13 | // This is the result of ray tracing with a simple ray
|
---|
| 14 | struct IntersectionStr {
|
---|
| 15 | Intersectable *intersectable;
|
---|
| 16 | float tdist;
|
---|
| 17 | float maxt;
|
---|
| 18 | int pad1; // aligned to 16 bytes
|
---|
| 19 | };
|
---|
| 20 |
|
---|
[2105] | 21 | struct SimpleRay
|
---|
| 22 | {
|
---|
[2575] | 23 | // This is stored result for the rays in the container
|
---|
| 24 | // having 16 rays - shooting rays in both directions
|
---|
| 25 | static IntersectionStr IntersectionRes[32];
|
---|
[2105] | 26 |
|
---|
| 27 | Vector3 mOrigin;
|
---|
| 28 | Vector3 mDirection;
|
---|
| 29 | // 6*4 = 24B
|
---|
| 30 |
|
---|
| 31 | Intersectable *mOriginObject;
|
---|
| 32 | Intersectable *mTerminationObject;
|
---|
| 33 | // 2*4 = 8B
|
---|
| 34 |
|
---|
| 35 | enum {F_BIDIRECTIONAL = 1};
|
---|
| 36 | unsigned short mFlags;
|
---|
| 37 | unsigned char mType;
|
---|
| 38 | unsigned char mDistribution;
|
---|
| 39 | // 4B
|
---|
| 40 |
|
---|
| 41 | // generator Id -> relative to the generating distribution!
|
---|
| 42 | int mGeneratorId;
|
---|
| 43 | // 4B
|
---|
| 44 |
|
---|
[2575] | 45 | // TOTAL = 40B - aligned by 8 Bytes only! - it might be
|
---|
| 46 | // padding to 48 Bytes here !
|
---|
[2105] | 47 |
|
---|
| 48 |
|
---|
| 49 | //float mWeight;
|
---|
| 50 |
|
---|
| 51 | SimpleRay(): mType(Ray::LOCAL_RAY)
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | SimpleRay(const Vector3 &o,
|
---|
[2588] | 56 | const Vector3 &d,
|
---|
[2726] | 57 | unsigned char distribution,
|
---|
| 58 | float weight,
|
---|
| 59 | unsigned char flags = F_BIDIRECTIONAL
|
---|
[2588] | 60 | ):
|
---|
[2575] | 61 | mOrigin(o),
|
---|
| 62 | mDirection(d),
|
---|
| 63 | mFlags(flags),
|
---|
| 64 | mType(Ray::LOCAL_RAY),
|
---|
| 65 | mDistribution(distribution)
|
---|
| 66 | // , mWeight(weight)
|
---|
[2105] | 67 | {
|
---|
[2575] | 68 | // mId = sSimpleRayId++;
|
---|
[2105] | 69 | }
|
---|
| 70 |
|
---|
[2575] | 71 | void
|
---|
| 72 | Set(const Vector3 &o,
|
---|
| 73 | const Vector3 &d,
|
---|
| 74 | const unsigned char distribution,
|
---|
| 75 | const float weight,
|
---|
| 76 | const unsigned char flags = F_BIDIRECTIONAL
|
---|
| 77 | )
|
---|
| 78 | {
|
---|
| 79 | mOrigin = o;
|
---|
| 80 | mDirection = d,
|
---|
| 81 | mFlags = flags;
|
---|
| 82 | mType = Ray::LOCAL_RAY;
|
---|
| 83 | mDistribution = distribution;
|
---|
| 84 | // , mWeight(weight)
|
---|
| 85 | // mId = sSimpleRayId++;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[2105] | 88 | bool IsBidirectional() const { return mFlags & F_BIDIRECTIONAL; }
|
---|
| 89 |
|
---|
| 90 | void SetBidirectional(const bool b) {
|
---|
[2575] | 91 | if (b)
|
---|
| 92 | mFlags |= F_BIDIRECTIONAL;
|
---|
| 93 | else
|
---|
| 94 | mFlags &= ~F_BIDIRECTIONAL;
|
---|
[2105] | 95 | }
|
---|
| 96 |
|
---|
| 97 | float GetParam(const int axis) const {
|
---|
[2575] | 98 | if (axis < 3)
|
---|
| 99 | return mOrigin[axis];
|
---|
| 100 | else
|
---|
| 101 | return mDirection[axis-3];
|
---|
[2105] | 102 | }
|
---|
| 103 |
|
---|
| 104 | Vector3 Extrap(const float t) const {
|
---|
[2575] | 105 | return mOrigin + mDirection * t;
|
---|
[2105] | 106 | }
|
---|
| 107 |
|
---|
[2176] | 108 | friend std::ostream &operator<<(std::ostream &s, const SimpleRay &r)
|
---|
[2105] | 109 | {
|
---|
[2575] | 110 | return s << "origin=" << r.mOrigin << " dir=" << r.mDirection;
|
---|
[2105] | 111 | };
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | class SimpleRayContainer : public vector<SimpleRay>
|
---|
| 115 | {
|
---|
| 116 | public:
|
---|
| 117 |
|
---|
| 118 | SimpleRayContainer():vector<SimpleRay>() {}
|
---|
| 119 |
|
---|
| 120 | #if 0
|
---|
| 121 | void NormalizePdf(float scale = 1.0f) {
|
---|
| 122 | iterator it = begin();
|
---|
| 123 | float sumPdf = 0.0f;
|
---|
| 124 | for (; it != end(); it++)
|
---|
| 125 | sumPdf += (*it).mPdf;
|
---|
| 126 |
|
---|
| 127 | float c = scale/sumPdf;
|
---|
| 128 |
|
---|
| 129 | for (it = begin(); it != end(); it++) {
|
---|
| 130 | (*it).mPdf*=c;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | #endif
|
---|
| 134 |
|
---|
| 135 | void AddRay(const SimpleRay &ray) {
|
---|
| 136 | push_back(ray);
|
---|
| 137 | }
|
---|
| 138 | };
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | #endif
|
---|
| 145 |
|
---|