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