1 | #ifndef __MUTUAL_VISIBILITY_H
|
---|
2 | #define __MUTUAL_VISIBILITY_H
|
---|
3 |
|
---|
4 | #include "Vector3.h"
|
---|
5 | #include "Ray.h"
|
---|
6 |
|
---|
7 | namespace GtpVisibilityPreprocessor {
|
---|
8 |
|
---|
9 | class Intersectable;
|
---|
10 | class AxisAlignedBox3;
|
---|
11 | class SceneGraph;
|
---|
12 |
|
---|
13 |
|
---|
14 | struct RaySample {
|
---|
15 | /// true if the sample really intersects both boxes
|
---|
16 | float mMinT;
|
---|
17 | float mMaxT;
|
---|
18 |
|
---|
19 | RaySample():mMinT(-1.0f), mMaxT(-1.0f) {}
|
---|
20 | /// intersections of the sample with the scene
|
---|
21 | vector<Ray::Intersection> mIntersections;
|
---|
22 | void SetInvalid() {
|
---|
23 | mMinT = 0.0f;
|
---|
24 | mMaxT = -1.0f;
|
---|
25 | }
|
---|
26 | bool IsValid() const { return mMaxT > 0.0f; }
|
---|
27 | bool IsProcessed() const { return mMinT != mMaxT; }
|
---|
28 | };
|
---|
29 |
|
---|
30 | struct RayShaft {
|
---|
31 | public:
|
---|
32 | /// evaluted sampling error
|
---|
33 | float mError;
|
---|
34 | /// depth in recursion
|
---|
35 | int mDepth;
|
---|
36 | /// The source triangle
|
---|
37 | Rectangle3 mSource;
|
---|
38 | /// The target triangle
|
---|
39 | Rectangle3 mTarget;
|
---|
40 |
|
---|
41 | RaySample mSamples[4];
|
---|
42 |
|
---|
43 | void ComputeError();
|
---|
44 |
|
---|
45 | RayShaft() {}
|
---|
46 |
|
---|
47 | RayShaft (
|
---|
48 | const Rectangle3 &source,
|
---|
49 | const Rectangle3 &target)
|
---|
50 | {
|
---|
51 | Init(source, target);
|
---|
52 | }
|
---|
53 |
|
---|
54 | bool IsValid() const { return
|
---|
55 | mSamples[0].IsValid() &&
|
---|
56 | mSamples[1].IsValid() &&
|
---|
57 | mSamples[2].IsValid() &&
|
---|
58 | mSamples[3].IsValid();
|
---|
59 | }
|
---|
60 |
|
---|
61 | // initial triangle sample
|
---|
62 | void Init(
|
---|
63 | const Rectangle3 &source,
|
---|
64 | const Rectangle3 &target);
|
---|
65 |
|
---|
66 | Vector3
|
---|
67 | GetIntersectionPoint(const int rayIndex,
|
---|
68 | const int depth) const;
|
---|
69 |
|
---|
70 | void GetRay(const int rayIndex,
|
---|
71 | Vector3 &origin,
|
---|
72 | Vector3 &direction) const;
|
---|
73 |
|
---|
74 | void
|
---|
75 | GetRaySegment(const int i, Ray &ray) const;
|
---|
76 |
|
---|
77 | };
|
---|
78 |
|
---|
79 | enum { VISIBLE, INVISIBLE };
|
---|
80 |
|
---|
81 |
|
---|
82 | class MutualVisibilitySampler {
|
---|
83 | public:
|
---|
84 | SceneGraph *mSceneGraph;
|
---|
85 | KdTree *mKdTree;
|
---|
86 | AxisAlignedBox3 mSource;
|
---|
87 | AxisAlignedBox3 mTarget;
|
---|
88 | float mSolidAngleThreshold;
|
---|
89 | bool mUseBoxes;
|
---|
90 |
|
---|
91 | MutualVisibilitySampler(
|
---|
92 | SceneGraph *sceneGraph,
|
---|
93 | KdTree *kdTree,
|
---|
94 | const AxisAlignedBox3 &source,
|
---|
95 | const AxisAlignedBox3 &target,
|
---|
96 | const float solidAngleThreshold
|
---|
97 | );
|
---|
98 | int
|
---|
99 | ComputeVisibility();
|
---|
100 |
|
---|
101 | void
|
---|
102 | ConstructInitialSamples(const AxisAlignedBox3 &source,
|
---|
103 | const AxisAlignedBox3 &target,
|
---|
104 | vector<RayShaft *> &samples
|
---|
105 | );
|
---|
106 |
|
---|
107 | void
|
---|
108 | ConstructInitialSamples2(
|
---|
109 | const AxisAlignedBox3 &source,
|
---|
110 | const AxisAlignedBox3 &target,
|
---|
111 | vector<RayShaft *> &samples
|
---|
112 | );
|
---|
113 |
|
---|
114 | void
|
---|
115 | ConstructInitialSamples3(
|
---|
116 | const AxisAlignedBox3 &source,
|
---|
117 | const AxisAlignedBox3 &target,
|
---|
118 | vector<RayShaft *> &samples
|
---|
119 | );
|
---|
120 |
|
---|
121 | void
|
---|
122 | AddInitialSamples(
|
---|
123 | const Rectangle3 &sourceRect,
|
---|
124 | const Rectangle3 &targetRect,
|
---|
125 | vector<RayShaft *> &samples
|
---|
126 | );
|
---|
127 |
|
---|
128 | void
|
---|
129 | AddInitialSamples2(
|
---|
130 | const Rectangle3 &sourceRect,
|
---|
131 | const Rectangle3 &targetRect,
|
---|
132 | vector<RayShaft *> &samples
|
---|
133 | );
|
---|
134 |
|
---|
135 | // the split sample method contains a methodology to create new samples
|
---|
136 | // or terminate the sampling
|
---|
137 | bool
|
---|
138 | SplitSample(
|
---|
139 | const RayShaft &source,
|
---|
140 | RayShaft &sample1,
|
---|
141 | RayShaft &sample2
|
---|
142 | );
|
---|
143 | void
|
---|
144 | PerformSplit(
|
---|
145 | const RayShaft &sample,
|
---|
146 | const bool splitSource,
|
---|
147 | const int axis,
|
---|
148 | RayShaft &sample1,
|
---|
149 | RayShaft &sample2
|
---|
150 | );
|
---|
151 |
|
---|
152 |
|
---|
153 | bool
|
---|
154 | SampleTerminationCriteriaMet(
|
---|
155 | const RayShaft &sample);
|
---|
156 |
|
---|
157 | float
|
---|
158 | GetSpatialAngle(const RayShaft &sample,
|
---|
159 | const Vector3 &point
|
---|
160 | );
|
---|
161 |
|
---|
162 | int
|
---|
163 | CastRays(RayShaft &shaft);
|
---|
164 |
|
---|
165 | void
|
---|
166 | ComputeError(RayShaft &sample);
|
---|
167 |
|
---|
168 | void
|
---|
169 | ExportShafts(vector<RayShaft *> &samples, const bool singleFile);
|
---|
170 |
|
---|
171 |
|
---|
172 | };
|
---|
173 |
|
---|
174 | int
|
---|
175 | ComputeBoxVisibility(SceneGraph *sceneGraph,
|
---|
176 | KdTree *kdTree,
|
---|
177 | const AxisAlignedBox3 &source,
|
---|
178 | const AxisAlignedBox3 &target,
|
---|
179 | const float solidAngleThreshold);
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 |
|
---|
184 | }
|
---|
185 |
|
---|
186 | #endif
|
---|