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