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