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