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