1 | #ifndef __RAYINFO_H__
|
---|
2 | #define __RAYINFO_H__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | #include "VssRay.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace GtpVisibilityPreprocessor {
|
---|
9 |
|
---|
10 | //class VssRay;
|
---|
11 | class RayInfo;
|
---|
12 | class Plane3;
|
---|
13 | class Vector3;
|
---|
14 |
|
---|
15 |
|
---|
16 | typedef std::vector<RayInfo> RayInfoContainer;
|
---|
17 |
|
---|
18 |
|
---|
19 | /** Structure holding additional info about
|
---|
20 | the ray during traversal.
|
---|
21 | */
|
---|
22 | class RayInfo
|
---|
23 | {
|
---|
24 | public:
|
---|
25 | /// pointer to the actual ray
|
---|
26 | VssRay *mRay;
|
---|
27 |
|
---|
28 | // endpoints - do we need them?
|
---|
29 | #if USE_FIXEDPOINT_T
|
---|
30 | short mMinT, mMaxT;
|
---|
31 | #else
|
---|
32 | float mMinT, mMaxT;
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | RayInfo();
|
---|
36 |
|
---|
37 | RayInfo(VssRay *r);
|
---|
38 |
|
---|
39 | RayInfo(VssRay *r, const float _min, const float _max);
|
---|
40 |
|
---|
41 | RayInfo(VssRay *r, const short _min, const float _max);
|
---|
42 |
|
---|
43 | RayInfo(VssRay *r, const float _min, const short _max);
|
---|
44 |
|
---|
45 | friend bool operator<(const RayInfo &a, const RayInfo &b)
|
---|
46 | {
|
---|
47 | return a.mRay < b.mRay;
|
---|
48 | }
|
---|
49 |
|
---|
50 | /** Extracts the scalar of the starting point of the ray segment
|
---|
51 | that lies in the axis.
|
---|
52 | */
|
---|
53 | inline float ExtrapOrigin(const int axis) const;
|
---|
54 | /** Extracts the scalar of the termination point of the ray segment
|
---|
55 | that lies in the axis.
|
---|
56 | */
|
---|
57 | inline float ExtrapTermination(const int axis) const;
|
---|
58 |
|
---|
59 | /** Extracts the starting point of the ray segment.
|
---|
60 | */
|
---|
61 | inline Vector3 ExtrapOrigin() const;
|
---|
62 |
|
---|
63 | /** Extracts the end point of the ray segment.
|
---|
64 | */
|
---|
65 | inline Vector3 ExtrapTermination() const;
|
---|
66 |
|
---|
67 | inline float GetMinT () const;
|
---|
68 | inline float GetMaxT () const;
|
---|
69 |
|
---|
70 | inline void SetMinT (const float t);
|
---|
71 | inline void SetMaxT (const float t);
|
---|
72 |
|
---|
73 | float SegmentLength() const;
|
---|
74 | float SqrSegmentLength() const;
|
---|
75 |
|
---|
76 | /** Computes intersection of this ray with the axis aligned split plane.
|
---|
77 |
|
---|
78 | @param axis axis of the split plane
|
---|
79 | @param position scalar position of the split plane for the chosen axis
|
---|
80 | @param t returns the t parameter value of the ray intersection
|
---|
81 |
|
---|
82 | @returns 0 if ray intersects plane, -1 if on back side of plane, 1 if on front side
|
---|
83 | */
|
---|
84 | int ComputeRayIntersection(const int axis, const float position, float &t) const;
|
---|
85 |
|
---|
86 | /** Computes intersection of this ray with the split plane.
|
---|
87 |
|
---|
88 | @param splitPlane the split plane
|
---|
89 | @param t returns the t parameter value of the ray intersection
|
---|
90 |
|
---|
91 | @returns 0 if ray intersects plane, -1 if on back side of plane, 1 if on front side
|
---|
92 | */
|
---|
93 | int ComputeRayIntersection(const Plane3 &splitPlane, float &t) const;
|
---|
94 |
|
---|
95 | friend void GetRayInfoSets(const RayInfoContainer &sourceRays,
|
---|
96 | const int maxSize,
|
---|
97 | RayInfoContainer &usedRays,
|
---|
98 | RayInfoContainer *savedRays = NULL);
|
---|
99 | };
|
---|
100 |
|
---|
101 |
|
---|
102 | float RayInfo::ExtrapOrigin(const int axis) const
|
---|
103 | {
|
---|
104 | return mRay->GetOrigin(axis) + GetMinT() * mRay->GetDir(axis);
|
---|
105 | }
|
---|
106 |
|
---|
107 | float RayInfo::ExtrapTermination(const int axis) const
|
---|
108 | {
|
---|
109 | return mRay->GetOrigin(axis) + GetMaxT() * mRay->GetDir(axis);
|
---|
110 | }
|
---|
111 |
|
---|
112 | Vector3 RayInfo::ExtrapOrigin() const
|
---|
113 | {
|
---|
114 | return mRay->GetOrigin() + GetMinT() * mRay->GetDir();
|
---|
115 | }
|
---|
116 |
|
---|
117 | Vector3 RayInfo::ExtrapTermination() const
|
---|
118 | {
|
---|
119 | return mRay->GetOrigin() + GetMaxT() * mRay->GetDir();
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 | #if USE_FIXEDPOINT_T
|
---|
125 | float RayInfo::GetMinT () const
|
---|
126 | {
|
---|
127 | return mMinT/(float)(FIXEDPOINT_ONE);
|
---|
128 | }
|
---|
129 |
|
---|
130 | float RayInfo::GetMaxT() const
|
---|
131 | {
|
---|
132 | return mMaxT / (float)(FIXEDPOINT_ONE);
|
---|
133 | }
|
---|
134 |
|
---|
135 | void RayInfo::SetMinT (const float t)
|
---|
136 | {
|
---|
137 | mMinT = (short) (t * (float)(FIXEDPOINT_ONE));
|
---|
138 | }
|
---|
139 |
|
---|
140 | void RayInfo::SetMaxT (const float t)
|
---|
141 | {
|
---|
142 | mMaxT = (short) (t*(float)(FIXEDPOINT_ONE));
|
---|
143 | ++ mMaxT;
|
---|
144 | // if (mMaxT!=0xFFFF)
|
---|
145 | // mMaxT++;
|
---|
146 | }
|
---|
147 | #else
|
---|
148 | float RayInfo::GetMinT () const
|
---|
149 | {
|
---|
150 | return mMinT;
|
---|
151 | }
|
---|
152 |
|
---|
153 | float RayInfo::GetMaxT () const
|
---|
154 | {
|
---|
155 | return mMaxT;
|
---|
156 | }
|
---|
157 |
|
---|
158 | void RayInfo::SetMinT (const float t)
|
---|
159 | {
|
---|
160 | mMinT = t;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void RayInfo::SetMaxT (const float t)
|
---|
164 | {
|
---|
165 | mMaxT = t;
|
---|
166 | }
|
---|
167 | #endif
|
---|
168 | }
|
---|
169 | #endif
|
---|
170 |
|
---|