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 |
|
---|
58 | virtual bool GenerateSample(SimpleRay &ray) = 0;
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | virtual void Update(VssRayContainer &vssRays) {}
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
|
---|
67 | return a->mRatio < b->mRatio;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public:
|
---|
71 |
|
---|
72 | /// variables usefull for mixed distribution sampling
|
---|
73 | int mType;
|
---|
74 | int mRays;
|
---|
75 | float mContribution;
|
---|
76 |
|
---|
77 | int mTotalRays;
|
---|
78 | float mTotalContribution;
|
---|
79 |
|
---|
80 | float mTime;
|
---|
81 | float mRatio;
|
---|
82 |
|
---|
83 | protected:
|
---|
84 |
|
---|
85 | Preprocessor &mPreprocessor;
|
---|
86 | static HaltonSequence sHalton;
|
---|
87 | };
|
---|
88 |
|
---|
89 |
|
---|
90 | class ObjectBasedDistribution: public SamplingStrategy
|
---|
91 | {
|
---|
92 | public:
|
---|
93 | //HaltonSequence mHalton;
|
---|
94 |
|
---|
95 | ObjectBasedDistribution(Preprocessor &preprocessor):
|
---|
96 | SamplingStrategy(preprocessor) {
|
---|
97 | mType = OBJECT_BASED_DISTRIBUTION;
|
---|
98 | }
|
---|
99 |
|
---|
100 | private:
|
---|
101 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
102 | };
|
---|
103 |
|
---|
104 |
|
---|
105 | class ReverseObjectBasedDistribution: public SamplingStrategy
|
---|
106 | {
|
---|
107 | public:
|
---|
108 |
|
---|
109 | ReverseObjectBasedDistribution(Preprocessor &preprocessor):
|
---|
110 | SamplingStrategy(preprocessor) {
|
---|
111 | mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
|
---|
112 | }
|
---|
113 |
|
---|
114 | private:
|
---|
115 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
116 | };
|
---|
117 |
|
---|
118 |
|
---|
119 | class ObjectDirectionBasedDistribution: public SamplingStrategy
|
---|
120 | {
|
---|
121 | //HaltonSequence mHalton;
|
---|
122 |
|
---|
123 | public:
|
---|
124 | ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
|
---|
125 | SamplingStrategy(preprocessor) {
|
---|
126 | mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
|
---|
127 | }
|
---|
128 | private:
|
---|
129 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
130 | };
|
---|
131 |
|
---|
132 |
|
---|
133 | class DirectionBasedDistribution: public SamplingStrategy
|
---|
134 | {
|
---|
135 | public:
|
---|
136 | DirectionBasedDistribution(Preprocessor &preprocessor):
|
---|
137 | SamplingStrategy(preprocessor){
|
---|
138 | mType = DIRECTION_BASED_DISTRIBUTION;
|
---|
139 | }
|
---|
140 | private:
|
---|
141 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
142 | };
|
---|
143 |
|
---|
144 |
|
---|
145 | class DirectionBoxBasedDistribution: public SamplingStrategy
|
---|
146 | {
|
---|
147 | public:
|
---|
148 | DirectionBoxBasedDistribution(Preprocessor &preprocessor):
|
---|
149 | SamplingStrategy(preprocessor){
|
---|
150 | mType = DIRECTION_BOX_BASED_DISTRIBUTION;
|
---|
151 | }
|
---|
152 |
|
---|
153 | private:
|
---|
154 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
155 | };
|
---|
156 |
|
---|
157 |
|
---|
158 | class SpatialBoxBasedDistribution: public SamplingStrategy
|
---|
159 | {
|
---|
160 | public:
|
---|
161 | //HaltonSequence mHalton;
|
---|
162 | SpatialBoxBasedDistribution(Preprocessor &preprocessor):
|
---|
163 | SamplingStrategy(preprocessor){
|
---|
164 | mType = SPATIAL_BOX_BASED_DISTRIBUTION;
|
---|
165 | }
|
---|
166 |
|
---|
167 | private:
|
---|
168 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
169 | };
|
---|
170 |
|
---|
171 |
|
---|
172 | class ViewSpaceBorderBasedDistribution: public SamplingStrategy
|
---|
173 | {
|
---|
174 | public:
|
---|
175 | ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
176 | SamplingStrategy(preprocessor){
|
---|
177 | mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
|
---|
178 | }
|
---|
179 |
|
---|
180 | private:
|
---|
181 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
182 | };
|
---|
183 |
|
---|
184 |
|
---|
185 | class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
|
---|
186 | {
|
---|
187 | public:
|
---|
188 | ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
189 | SamplingStrategy(preprocessor){
|
---|
190 | mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
|
---|
191 | }
|
---|
192 |
|
---|
193 | private:
|
---|
194 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
195 | };
|
---|
196 |
|
---|
197 |
|
---|
198 |
|
---|
199 |
|
---|
200 | class ViewCellBorderBasedDistribution: public SamplingStrategy
|
---|
201 | {
|
---|
202 | public:
|
---|
203 | ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
204 | SamplingStrategy(preprocessor) {
|
---|
205 | mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
|
---|
206 |
|
---|
207 | }
|
---|
208 |
|
---|
209 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
210 | };
|
---|
211 |
|
---|
212 | class GlobalLinesDistribution: public SamplingStrategy
|
---|
213 | {
|
---|
214 | public:
|
---|
215 | //Halton<4> halton;
|
---|
216 | //HaltonSequence mHalton;
|
---|
217 |
|
---|
218 | GlobalLinesDistribution(Preprocessor &preprocessor):
|
---|
219 | SamplingStrategy(preprocessor) {
|
---|
220 | mType = GLOBAL_LINES_DISTRIBUTION;
|
---|
221 | }
|
---|
222 |
|
---|
223 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
224 | };
|
---|
225 |
|
---|
226 |
|
---|
227 | /** This strategy generates samples inside of the objects, e.g.,
|
---|
228 | for sampling the inside of a colon.
|
---|
229 | */
|
---|
230 | /*class ObjectsInteriorDistribution: public SamplingStrategy
|
---|
231 | {
|
---|
232 | public:
|
---|
233 | ObjectsInteriorDistribution(Preprocessor &preprocessor):
|
---|
234 | SamplingStrategy(preprocessor) {}
|
---|
235 |
|
---|
236 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
237 | };
|
---|
238 | */
|
---|
239 |
|
---|
240 | class MixtureDistribution : public SamplingStrategy
|
---|
241 | {
|
---|
242 | public:
|
---|
243 | // halton sequence generator for deciding between distributions
|
---|
244 | //HaltonSequence mHalton;
|
---|
245 |
|
---|
246 | // container for the distributions
|
---|
247 | vector<SamplingStrategy *> mDistributions;
|
---|
248 |
|
---|
249 | MixtureDistribution(Preprocessor &preprocessor):
|
---|
250 | SamplingStrategy(preprocessor)
|
---|
251 | {
|
---|
252 | }
|
---|
253 |
|
---|
254 | // has to called before first usage
|
---|
255 | void Init();
|
---|
256 |
|
---|
257 | // equalize distribution contributions
|
---|
258 | void
|
---|
259 | Reset();
|
---|
260 |
|
---|
261 | // Generate a new sample according to a mixture distribution
|
---|
262 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
263 |
|
---|
264 | // add contributions of the sample to the strategies
|
---|
265 | void ComputeContributions(VssRayContainer &vssRays);
|
---|
266 |
|
---|
267 | void
|
---|
268 | UpdateRatios();
|
---|
269 |
|
---|
270 | // construct distribution mixyure from a string describing the required distributions
|
---|
271 | bool
|
---|
272 | Construct(char *str);
|
---|
273 |
|
---|
274 |
|
---|
275 | };
|
---|
276 |
|
---|
277 | };
|
---|
278 |
|
---|
279 | #endif
|
---|