[420] | 1 | #include "RayInfo.h"
|
---|
| 2 | #include "Ray.h"
|
---|
| 3 | #include "VssRay.h"
|
---|
[437] | 4 | #include "Plane3.h"
|
---|
[420] | 5 |
|
---|
[863] | 6 | namespace GtpVisibilityPreprocessor {
|
---|
[860] | 7 |
|
---|
[432] | 8 | RayInfo::RayInfo(): mRay(NULL), mMinT(0),
|
---|
| 9 | #if USE_FIXEDPOINT_T
|
---|
| 10 | #define FIXEDPOINT_ONE 0x7FFE
|
---|
| 11 | // mMaxT(0xFFFF)
|
---|
| 12 | mMaxT(FIXEDPOINT_ONE)
|
---|
| 13 | #else
|
---|
| 14 | mMaxT(1.0f)
|
---|
| 15 | #endif
|
---|
[420] | 16 | {}
|
---|
| 17 |
|
---|
| 18 | RayInfo::RayInfo(VssRay *r):mRay(r), mMinT(0),
|
---|
| 19 | #if USE_FIXEDPOINT_T
|
---|
| 20 | #define FIXEDPOINT_ONE 0x7FFE
|
---|
| 21 | // mMaxT(0xFFFF)
|
---|
| 22 | mMaxT(FIXEDPOINT_ONE)
|
---|
| 23 | #else
|
---|
| 24 | mMaxT(1.0f)
|
---|
| 25 | #endif
|
---|
| 26 | {}
|
---|
| 27 |
|
---|
| 28 | RayInfo::RayInfo(VssRay *r, const float _min, const float _max):
|
---|
| 29 | mRay(r)
|
---|
| 30 | {
|
---|
| 31 | SetMinT(_min);
|
---|
| 32 | SetMaxT(_max);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | RayInfo::RayInfo(VssRay *r, const short _min, const float _max):
|
---|
| 36 | mRay(r), mMinT(_min)
|
---|
| 37 | {
|
---|
| 38 | SetMaxT(_max);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | RayInfo::RayInfo(VssRay *r, const float _min, const short _max):
|
---|
| 42 | mRay(r), mMaxT(_max)
|
---|
| 43 | {
|
---|
| 44 | SetMinT(_min);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | float RayInfo::ExtrapOrigin(const int axis) const
|
---|
| 48 | {
|
---|
[448] | 49 | return mRay->GetOrigin(axis) + GetMinT() * mRay->GetDir(axis);
|
---|
[420] | 50 | }
|
---|
| 51 |
|
---|
| 52 | float RayInfo::ExtrapTermination(const int axis) const
|
---|
| 53 | {
|
---|
[448] | 54 | return mRay->GetOrigin(axis) + GetMaxT() * mRay->GetDir(axis);
|
---|
[420] | 55 | }
|
---|
[437] | 56 |
|
---|
| 57 | Vector3 RayInfo::ExtrapOrigin() const
|
---|
| 58 | {
|
---|
[448] | 59 | return mRay->GetOrigin() + GetMinT() * mRay->GetDir();
|
---|
[437] | 60 | }
|
---|
[420] | 61 |
|
---|
[437] | 62 | Vector3 RayInfo::ExtrapTermination() const
|
---|
| 63 | {
|
---|
| 64 | return mRay->GetOrigin() + GetMaxT() * mRay->GetDir();
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[420] | 67 | #if USE_FIXEDPOINT_T
|
---|
| 68 | float RayInfo::GetMinT () const
|
---|
| 69 | {
|
---|
| 70 | return mMinT/(float)(FIXEDPOINT_ONE);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | float RayInfo::GetMaxT() const
|
---|
| 74 | {
|
---|
| 75 | return mMaxT / (float)(FIXEDPOINT_ONE);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void RayInfo::SetMinT (const float t)
|
---|
| 79 | {
|
---|
| 80 | mMinT = (short) (t * (float)(FIXEDPOINT_ONE));
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | void RayInfo::SetMaxT (const float t)
|
---|
| 84 | {
|
---|
| 85 | mMaxT = (short) (t*(float)(FIXEDPOINT_ONE));
|
---|
| 86 | ++ mMaxT;
|
---|
| 87 | // if (mMaxT!=0xFFFF)
|
---|
| 88 | // mMaxT++;
|
---|
| 89 | }
|
---|
| 90 | #else
|
---|
| 91 | float RayInfo::GetMinT () const
|
---|
| 92 | {
|
---|
| 93 | return mMinT;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | float RayInfo::GetMaxT () const
|
---|
| 97 | {
|
---|
| 98 | return mMaxT;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void RayInfo::SetMinT (const float t)
|
---|
| 102 | {
|
---|
| 103 | mMinT = t;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | void RayInfo::SetMaxT (const float t)
|
---|
| 107 | {
|
---|
| 108 | mMaxT = t;
|
---|
| 109 | }
|
---|
| 110 | #endif
|
---|
| 111 |
|
---|
[639] | 112 |
|
---|
[420] | 113 | int RayInfo::ComputeRayIntersection(const int axis, const float position, float &t) const
|
---|
| 114 | {
|
---|
| 115 | // intersect the ray with the plane
|
---|
| 116 | const float denom = mRay->GetDir(axis);
|
---|
| 117 |
|
---|
| 118 | if (fabs(denom) < 1e-20)
|
---|
| 119 | //if (denom == 0.0f)
|
---|
| 120 | return (mRay->GetOrigin(axis) > position) ? 1 : -1;
|
---|
| 121 |
|
---|
| 122 | t = (position - mRay->GetOrigin(axis)) / denom;
|
---|
| 123 |
|
---|
| 124 | if (t < GetMinT())
|
---|
| 125 | return (denom > 0) ? 1 : -1;
|
---|
| 126 |
|
---|
| 127 | if (t > GetMaxT())
|
---|
| 128 | return (denom > 0) ? -1 : 1;
|
---|
| 129 |
|
---|
| 130 | return 0;
|
---|
[437] | 131 | }
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | int RayInfo::ComputeRayIntersection(const Plane3 &splitPlane, float &t) const
|
---|
| 135 | {
|
---|
| 136 | t = splitPlane.FindT(mRay->GetOrigin(), mRay->GetTermination());
|
---|
| 137 |
|
---|
[639] | 138 | if (0)
|
---|
| 139 | Debug << "t: " << t << " mint " << GetMinT() << " maxt " << GetMaxT()
|
---|
| 140 | << " orig: " << mRay->GetOrigin() << " term " << mRay->GetTermination() << endl;
|
---|
| 141 |
|
---|
[485] | 142 | // NOTE: if plane equals end point of ray, the ray should be classified
|
---|
| 143 | // non-intersecting, otherwise polygon-plane intersections of bsp tree
|
---|
| 144 | // approaches are not eliminating any rays intersecting the polygon!
|
---|
[694] | 145 | const float thresh = 1e-6f;
|
---|
[639] | 146 |
|
---|
| 147 | // segment is not intersecting plane: fond out if on front or back side
|
---|
[801] | 148 | if (t >= (GetMaxT() - thresh))
|
---|
[639] | 149 | {
|
---|
[437] | 150 | return splitPlane.Side(ExtrapOrigin());
|
---|
[639] | 151 | }
|
---|
| 152 |
|
---|
[801] | 153 | if (t <= (GetMinT() + thresh))
|
---|
[639] | 154 | {
|
---|
[485] | 155 | return splitPlane.Side(ExtrapTermination());
|
---|
[639] | 156 | }
|
---|
| 157 |
|
---|
[437] | 158 | return 0;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
[639] | 161 |
|
---|
[437] | 162 | float RayInfo::SegmentLength() const
|
---|
| 163 | {
|
---|
| 164 | return Distance(ExtrapOrigin(), ExtrapTermination());
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[1149] | 167 |
|
---|
[437] | 168 | float RayInfo::SqrSegmentLength() const
|
---|
| 169 | {
|
---|
| 170 | return SqrDistance(ExtrapOrigin(), ExtrapTermination());
|
---|
| 171 | }
|
---|
[860] | 172 |
|
---|
[1149] | 173 |
|
---|
| 174 | void GetRayInfoSets(const RayInfoContainer &sourceRays,
|
---|
| 175 | const int maxSize,
|
---|
| 176 | RayInfoContainer &usedRays,
|
---|
| 177 | RayInfoContainer *savedRays)
|
---|
| 178 | {
|
---|
| 179 | const int limit = min(maxSize, (int)sourceRays.size());
|
---|
| 180 | const float prop = (float)limit / ((float)sourceRays.size() + Limits::Small);
|
---|
| 181 |
|
---|
| 182 | RayInfoContainer::const_iterator it, it_end = sourceRays.end();
|
---|
| 183 |
|
---|
| 184 | for (it = sourceRays.begin(); it != it_end; ++ it)
|
---|
| 185 | {
|
---|
| 186 | if (Random(1.0f) < prop)
|
---|
| 187 | usedRays.push_back(*it);
|
---|
| 188 | else if (savedRays)
|
---|
| 189 | savedRays->push_back(*it);
|
---|
| 190 | }
|
---|
| 191 | }
|
---|
| 192 |
|
---|
[860] | 193 | } |
---|