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