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