source: GTP/trunk/Lib/Vis/Preprocessing/src/RayInfo.cpp @ 2347

Revision 2347, 2.9 KB checked in by mattausch, 17 years ago (diff)

debug version

RevLine 
[420]1#include "RayInfo.h"
2#include "Ray.h"
3#include "VssRay.h"
[437]4#include "Plane3.h"
[420]5
[2176]6using namespace std;
7
[863]8namespace GtpVisibilityPreprocessor {
[860]9
[432]10RayInfo::RayInfo(): mRay(NULL), mMinT(0),
11#if USE_FIXEDPOINT_T
12#define FIXEDPOINT_ONE 0x7FFE
13        // mMaxT(0xFFFF)
14        mMaxT(FIXEDPOINT_ONE)
15#else
16        mMaxT(1.0f)
17#endif
[420]18{}
19               
20RayInfo::RayInfo(VssRay *r):mRay(r), mMinT(0),
21#if USE_FIXEDPOINT_T
22#define FIXEDPOINT_ONE 0x7FFE
23        // mMaxT(0xFFFF)
24        mMaxT(FIXEDPOINT_ONE)
25#else
26        mMaxT(1.0f)
27#endif
28{}
29               
30RayInfo::RayInfo(VssRay *r,     const float _min, const float _max):
31mRay(r)
32{
33        SetMinT(_min);
34        SetMaxT(_max);
35}
36               
37RayInfo::RayInfo(VssRay *r, const short _min, const float _max):
38mRay(r), mMinT(_min)
39{
40        SetMaxT(_max);
41}
42               
43RayInfo::RayInfo(VssRay *r,     const float _min, const short _max):
44mRay(r), mMaxT(_max)
45{
46        SetMinT(_min);
47}
[437]48
49
[420]50int RayInfo::ComputeRayIntersection(const int axis, const float position, float &t) const
51{               
52        // intersect the ray with the plane
53        const float denom = mRay->GetDir(axis);
54
55        if (fabs(denom) < 1e-20)
56                //if (denom == 0.0f)
57                return (mRay->GetOrigin(axis) > position) ? 1 : -1;
58
59        t = (position - mRay->GetOrigin(axis)) / denom;
60
61        if (t < GetMinT())
62                return (denom > 0) ? 1 : -1;
63
64        if (t > GetMaxT())
65                return (denom > 0) ? -1 : 1;
66
67        return 0;
[437]68}
69
70
71int RayInfo::ComputeRayIntersection(const Plane3 &splitPlane, float &t) const
72{       
73        t = splitPlane.FindT(mRay->GetOrigin(), mRay->GetTermination());
74
[639]75        if (0)
76                Debug << "t: " << t << " mint " << GetMinT() << " maxt " << GetMaxT()
77                      << " orig: " << mRay->GetOrigin() << " term " << mRay->GetTermination() << endl;
78
[485]79        // NOTE: if plane equals end point of ray, the ray should be classified
80        // non-intersecting, otherwise polygon-plane intersections of bsp tree
81        // approaches are not eliminating any rays intersecting the polygon!
[694]82        const float thresh = 1e-6f;
[639]83
84        // segment is not intersecting plane: fond out if on front or back side
[801]85        if (t >= (GetMaxT() - thresh))
[639]86        {
[437]87                return splitPlane.Side(ExtrapOrigin());
[639]88        }
89               
[801]90        if (t <= (GetMinT() + thresh))
[639]91        {
[485]92                return splitPlane.Side(ExtrapTermination());
[639]93        }
94       
[437]95        return 0;
96}
97
[639]98
[437]99float RayInfo::SegmentLength() const
100{
101        return Distance(ExtrapOrigin(), ExtrapTermination());
102}
103
[1149]104
[437]105float RayInfo::SqrSegmentLength() const
106{
107        return SqrDistance(ExtrapOrigin(), ExtrapTermination());
108}
[860]109
[1149]110
111void GetRayInfoSets(const RayInfoContainer &sourceRays,
112                    const int maxSize,
113                                        RayInfoContainer &usedRays,
114                                        RayInfoContainer *savedRays)
115{
116        const int limit = min(maxSize, (int)sourceRays.size());
117        const float prop = (float)limit / ((float)sourceRays.size() + Limits::Small);
118
119        RayInfoContainer::const_iterator it, it_end = sourceRays.end();
120
121        for (it = sourceRays.begin(); it != it_end; ++ it)
122        {
123                if (Random(1.0f) < prop)
124                        usedRays.push_back(*it);
125                else if (savedRays)
126                        savedRays->push_back(*it);
127        }
128}
129
[860]130}
Note: See TracBrowser for help on using the repository browser.