1 | #ifndef _SamplingStategy_H__
|
---|
2 | #define _SamplingStategy_H__
|
---|
3 |
|
---|
4 | #include <vector>
|
---|
5 | using namespace std;
|
---|
6 |
|
---|
7 | #include "Halton.h"
|
---|
8 |
|
---|
9 | namespace GtpVisibilityPreprocessor {
|
---|
10 |
|
---|
11 | class VssRay;
|
---|
12 | class Preprocessor;
|
---|
13 | struct SimpleRay;
|
---|
14 | class SimpleRayContainer;
|
---|
15 | struct VssRayContainer;
|
---|
16 |
|
---|
17 | /** This class generates a specific sampling strategy.
|
---|
18 | */
|
---|
19 | class SamplingStrategy
|
---|
20 | {
|
---|
21 | public:
|
---|
22 |
|
---|
23 | /** Sample rays of particular type
|
---|
24 | */
|
---|
25 | enum
|
---|
26 | {
|
---|
27 | DUMMY_DISTRIBUTION = 0,
|
---|
28 | DIRECTION_BASED_DISTRIBUTION,
|
---|
29 | OBJECT_BASED_DISTRIBUTION,
|
---|
30 | DIRECTION_BOX_BASED_DISTRIBUTION,
|
---|
31 | SPATIAL_BOX_BASED_DISTRIBUTION,
|
---|
32 | VSS_BASED_DISTRIBUTION,
|
---|
33 | RSS_BASED_DISTRIBUTION,
|
---|
34 | RSS_SILHOUETTE_BASED_DISTRIBUTION,
|
---|
35 | OBJECT_DIRECTION_BASED_DISTRIBUTION,
|
---|
36 | OBJECTS_INTERIOR_DISTRIBUTION,
|
---|
37 | REVERSE_OBJECT_BASED_DISTRIBUTION,
|
---|
38 | VIEWCELL_BORDER_BASED_DISTRIBUTION,
|
---|
39 | VIEWSPACE_BORDER_BASED_DISTRIBUTION,
|
---|
40 | REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION,
|
---|
41 | GLOBAL_LINES_DISTRIBUTION,
|
---|
42 | GVS,
|
---|
43 | MUTATION_BASED_DISTRIBUTION
|
---|
44 |
|
---|
45 | };
|
---|
46 |
|
---|
47 | /** Default constructor
|
---|
48 | */
|
---|
49 | SamplingStrategy(Preprocessor &preprocessor);
|
---|
50 |
|
---|
51 | virtual ~SamplingStrategy();
|
---|
52 |
|
---|
53 | /** Each strategy has to implement this function.
|
---|
54 | @returns true if generated valid sample.
|
---|
55 | */
|
---|
56 |
|
---|
57 | virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
|
---|
58 |
|
---|
59 | virtual bool GenerateSample(SimpleRay &ray) = 0;
|
---|
60 |
|
---|
61 | // true if the strategy keeps pointers to rays and thus they should get deleted
|
---|
62 | // outside, in that case the strategy has to use reference counting and deleting the rays
|
---|
63 | // by itself if the number of references drops to zero
|
---|
64 | virtual bool RequiresRays() { return false; }
|
---|
65 |
|
---|
66 |
|
---|
67 | virtual void Update(VssRayContainer &vssRays) {}
|
---|
68 |
|
---|
69 | friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
|
---|
70 | return a->mRatio < b->mRatio;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public:
|
---|
74 |
|
---|
75 | /// variables usefull for mixed distribution sampling
|
---|
76 | int mType;
|
---|
77 | int mRays;
|
---|
78 | float mContribution;
|
---|
79 |
|
---|
80 | int mTotalRays;
|
---|
81 | float mTotalContribution;
|
---|
82 |
|
---|
83 | float mTime;
|
---|
84 | float mRatio;
|
---|
85 |
|
---|
86 | protected:
|
---|
87 |
|
---|
88 | //static HaltonSequence sHalton;
|
---|
89 | Preprocessor &mPreprocessor;
|
---|
90 | };
|
---|
91 |
|
---|
92 |
|
---|
93 | class ObjectBasedDistribution: public SamplingStrategy
|
---|
94 | {
|
---|
95 | public:
|
---|
96 |
|
---|
97 |
|
---|
98 | ObjectBasedDistribution(Preprocessor &preprocessor):
|
---|
99 | SamplingStrategy(preprocessor) {
|
---|
100 | mType = OBJECT_BASED_DISTRIBUTION;
|
---|
101 | }
|
---|
102 |
|
---|
103 | private:
|
---|
104 |
|
---|
105 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
106 | static HaltonSequence sHalton;
|
---|
107 | };
|
---|
108 |
|
---|
109 |
|
---|
110 | class ReverseObjectBasedDistribution: public SamplingStrategy
|
---|
111 | {
|
---|
112 | public:
|
---|
113 |
|
---|
114 | ReverseObjectBasedDistribution(Preprocessor &preprocessor):
|
---|
115 | SamplingStrategy(preprocessor) {
|
---|
116 | mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
|
---|
117 | }
|
---|
118 |
|
---|
119 | private:
|
---|
120 |
|
---|
121 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | class ObjectDirectionBasedDistribution: public SamplingStrategy
|
---|
126 | {
|
---|
127 |
|
---|
128 | public:
|
---|
129 | ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
|
---|
130 | SamplingStrategy(preprocessor) {
|
---|
131 | mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
|
---|
132 | }
|
---|
133 |
|
---|
134 | private:
|
---|
135 |
|
---|
136 | static HaltonSequence sHalton;
|
---|
137 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
138 | };
|
---|
139 |
|
---|
140 |
|
---|
141 | class DirectionBasedDistribution: public SamplingStrategy
|
---|
142 | {
|
---|
143 | public:
|
---|
144 | DirectionBasedDistribution(Preprocessor &preprocessor):
|
---|
145 | SamplingStrategy(preprocessor){
|
---|
146 | mType = DIRECTION_BASED_DISTRIBUTION;
|
---|
147 | }
|
---|
148 | private:
|
---|
149 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
150 | static HaltonSequence sHalton;
|
---|
151 | };
|
---|
152 |
|
---|
153 |
|
---|
154 | class DirectionBoxBasedDistribution: public SamplingStrategy
|
---|
155 | {
|
---|
156 | public:
|
---|
157 | DirectionBoxBasedDistribution(Preprocessor &preprocessor):
|
---|
158 | SamplingStrategy(preprocessor){
|
---|
159 | mType = DIRECTION_BOX_BASED_DISTRIBUTION;
|
---|
160 | }
|
---|
161 |
|
---|
162 | private:
|
---|
163 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
164 | };
|
---|
165 |
|
---|
166 |
|
---|
167 | class SpatialBoxBasedDistribution: public SamplingStrategy
|
---|
168 | {
|
---|
169 | public:
|
---|
170 |
|
---|
171 | SpatialBoxBasedDistribution(Preprocessor &preprocessor):
|
---|
172 | SamplingStrategy(preprocessor){
|
---|
173 | mType = SPATIAL_BOX_BASED_DISTRIBUTION;
|
---|
174 | }
|
---|
175 |
|
---|
176 | private:
|
---|
177 |
|
---|
178 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
179 | static HaltonSequence sHalton;
|
---|
180 | };
|
---|
181 |
|
---|
182 |
|
---|
183 | class ViewSpaceBorderBasedDistribution: public SamplingStrategy
|
---|
184 | {
|
---|
185 | public:
|
---|
186 | ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
187 | SamplingStrategy(preprocessor){
|
---|
188 | mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
|
---|
189 | }
|
---|
190 |
|
---|
191 | private:
|
---|
192 |
|
---|
193 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
194 | };
|
---|
195 |
|
---|
196 |
|
---|
197 | class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
|
---|
198 | {
|
---|
199 | public:
|
---|
200 | ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
201 | SamplingStrategy(preprocessor){
|
---|
202 | mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
|
---|
203 | }
|
---|
204 |
|
---|
205 | private:
|
---|
206 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
207 | };
|
---|
208 |
|
---|
209 |
|
---|
210 | class ViewCellBorderBasedDistribution: public SamplingStrategy
|
---|
211 | {
|
---|
212 | public:
|
---|
213 | ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
214 | SamplingStrategy(preprocessor) {
|
---|
215 | mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
|
---|
216 |
|
---|
217 | }
|
---|
218 |
|
---|
219 | private:
|
---|
220 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
221 | };
|
---|
222 |
|
---|
223 | class MutationBasedDistribution: public SamplingStrategy
|
---|
224 | {
|
---|
225 | public:
|
---|
226 | MutationBasedDistribution(Preprocessor &preprocessor);
|
---|
227 | virtual void Update(VssRayContainer &vssRays);
|
---|
228 |
|
---|
229 | virtual bool RequiresRays() { return true; }
|
---|
230 |
|
---|
231 | private:
|
---|
232 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
233 | static HaltonSequence sHalton;
|
---|
234 | struct RayEntry {
|
---|
235 | VssRay *mRay;
|
---|
236 | int mSamples;
|
---|
237 | RayEntry();
|
---|
238 | RayEntry(VssRay *r):mRay(r), mSamples(0) {}
|
---|
239 | };
|
---|
240 |
|
---|
241 | vector<RayEntry> mRays;
|
---|
242 | int mMaxRays;
|
---|
243 | float mOriginMutationSize;
|
---|
244 | int mBufferStart;
|
---|
245 | int mLastIndex;
|
---|
246 | };
|
---|
247 |
|
---|
248 | class GlobalLinesDistribution: public SamplingStrategy
|
---|
249 | {
|
---|
250 | public:
|
---|
251 |
|
---|
252 | GlobalLinesDistribution(Preprocessor &preprocessor):
|
---|
253 | SamplingStrategy(preprocessor) {
|
---|
254 | mType = GLOBAL_LINES_DISTRIBUTION;
|
---|
255 | }
|
---|
256 |
|
---|
257 | private:
|
---|
258 |
|
---|
259 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
260 | static HaltonSequence sHalton;
|
---|
261 | };
|
---|
262 |
|
---|
263 |
|
---|
264 | /** This strategy generates samples inside of the objects, e.g.,
|
---|
265 | for sampling the inside of a colon.
|
---|
266 | */
|
---|
267 | /*class ObjectsInteriorDistribution: public SamplingStrategy
|
---|
268 | {
|
---|
269 | public:
|
---|
270 | ObjectsInteriorDistribution(Preprocessor &preprocessor):
|
---|
271 | SamplingStrategy(preprocessor) {}
|
---|
272 |
|
---|
273 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
274 | };
|
---|
275 | */
|
---|
276 |
|
---|
277 | class MixtureDistribution: public SamplingStrategy
|
---|
278 | {
|
---|
279 | public:
|
---|
280 |
|
---|
281 | // container for the distributions
|
---|
282 | vector<SamplingStrategy *> mDistributions;
|
---|
283 |
|
---|
284 | MixtureDistribution(Preprocessor &preprocessor):
|
---|
285 | SamplingStrategy(preprocessor)
|
---|
286 | {
|
---|
287 | }
|
---|
288 |
|
---|
289 | // has to called before first usage
|
---|
290 | void Init();
|
---|
291 |
|
---|
292 | // equalize distribution contributions
|
---|
293 | void
|
---|
294 | Reset();
|
---|
295 |
|
---|
296 | // add contributions of the sample to the strategies
|
---|
297 | void ComputeContributions(VssRayContainer &vssRays);
|
---|
298 |
|
---|
299 | // update distributions with new rays
|
---|
300 | // warning: some rays can get deleted (if maintained internally by the
|
---|
301 | // particular distribution)!
|
---|
302 | void UpdateDistributions(VssRayContainer &vssRays);
|
---|
303 |
|
---|
304 | void
|
---|
305 | UpdateRatios();
|
---|
306 |
|
---|
307 | // construct distribution mixture from a string describing the required distributions
|
---|
308 | bool
|
---|
309 | Construct(char *str);
|
---|
310 |
|
---|
311 | virtual bool RequiresRays() {
|
---|
312 | for (int i=0; i < (int)mDistributions.size(); i++)
|
---|
313 | if (mDistributions[i]->RequiresRays())
|
---|
314 | return true;
|
---|
315 | return false;
|
---|
316 | }
|
---|
317 |
|
---|
318 | private:
|
---|
319 |
|
---|
320 | // Generate a new sample according to a mixture distribution
|
---|
321 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
322 |
|
---|
323 | // halton sequence generator for deciding between distributions
|
---|
324 | static HaltonSequence sHalton;
|
---|
325 | };
|
---|
326 |
|
---|
327 | };
|
---|
328 |
|
---|
329 | #endif
|
---|