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(SceneGraph *sceneGraph,
|
---|
90 | KdTree *kdTree,
|
---|
91 | const AxisAlignedBox3 &source,
|
---|
92 | const AxisAlignedBox3 &target,
|
---|
93 | const float solidAngleThreshold);
|
---|
94 | int
|
---|
95 | ComputeVisibility();
|
---|
96 |
|
---|
97 | void
|
---|
98 | ConstructInitialSamples(
|
---|
99 | const AxisAlignedBox3 &source,
|
---|
100 | const AxisAlignedBox3 &target,
|
---|
101 | vector<RayShaft *> &samples
|
---|
102 | );
|
---|
103 |
|
---|
104 | void
|
---|
105 | ConstructInitialSamples2(
|
---|
106 | const AxisAlignedBox3 &source,
|
---|
107 | const AxisAlignedBox3 &target,
|
---|
108 | vector<RayShaft *> &samples
|
---|
109 | );
|
---|
110 |
|
---|
111 | void
|
---|
112 | ConstructInitialSamples3(
|
---|
113 | const AxisAlignedBox3 &source,
|
---|
114 | const AxisAlignedBox3 &target,
|
---|
115 | vector<RayShaft *> &samples
|
---|
116 | );
|
---|
117 |
|
---|
118 | void
|
---|
119 | AddInitialSamples(
|
---|
120 | const Rectangle3 &sourceRect,
|
---|
121 | const Rectangle3 &targetRect,
|
---|
122 | vector<RayShaft *> &samples
|
---|
123 | );
|
---|
124 |
|
---|
125 | void
|
---|
126 | AddInitialSamples2(
|
---|
127 | const Rectangle3 &sourceRect,
|
---|
128 | const Rectangle3 &targetRect,
|
---|
129 | vector<RayShaft *> &samples
|
---|
130 | );
|
---|
131 |
|
---|
132 | // the split sample method contains a methodology to create new samples
|
---|
133 | // or terminate the sampling
|
---|
134 | bool
|
---|
135 | SplitSample(
|
---|
136 | const RayShaft &source,
|
---|
137 | RayShaft &sample1,
|
---|
138 | RayShaft &sample2
|
---|
139 | );
|
---|
140 | void
|
---|
141 | PerformSplit(
|
---|
142 | const RayShaft &sample,
|
---|
143 | const bool splitSource,
|
---|
144 | const int axis,
|
---|
145 | RayShaft &sample1,
|
---|
146 | RayShaft &sample2
|
---|
147 | );
|
---|
148 |
|
---|
149 |
|
---|
150 | bool
|
---|
151 | SampleTerminationCriteriaMet(
|
---|
152 | const RayShaft &sample);
|
---|
153 |
|
---|
154 | float
|
---|
155 | GetSpatialAngle(const RayShaft &sample,
|
---|
156 | const Vector3 &point
|
---|
157 | );
|
---|
158 |
|
---|
159 | int
|
---|
160 | CastRays(RayShaft &shaft);
|
---|
161 |
|
---|
162 | void
|
---|
163 | ComputeError(RayShaft &sample);
|
---|
164 |
|
---|
165 | void
|
---|
166 | ExportShafts(vector<RayShaft *> &samples, const bool singleFile);
|
---|
167 |
|
---|
168 |
|
---|
169 | };
|
---|
170 |
|
---|
171 | int
|
---|
172 | ComputeBoxVisibility(SceneGraph *sceneGraph,
|
---|
173 | KdTree *kdTree,
|
---|
174 | const AxisAlignedBox3 &source,
|
---|
175 | const AxisAlignedBox3 &target,
|
---|
176 | const float solidAngleThreshold);
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
|
---|
183 | #endif
|
---|