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