[1020] | 1 | #ifndef _SamplingStategy_H__
|
---|
| 2 | #define _SamplingStategy_H__
|
---|
| 3 |
|
---|
[1883] | 4 | #include <vector>
|
---|
| 5 | using namespace std;
|
---|
| 6 |
|
---|
[1867] | 7 | #include "Halton.h"
|
---|
[1020] | 8 |
|
---|
| 9 | namespace GtpVisibilityPreprocessor {
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | class Preprocessor;
|
---|
| 13 | struct SimpleRay;
|
---|
[1771] | 14 | class SimpleRayContainer;
|
---|
[1888] | 15 | struct VssRayContainer;
|
---|
[1020] | 16 |
|
---|
| 17 | /** This class generates a specific sampling strategy.
|
---|
| 18 | */
|
---|
| 19 | class SamplingStrategy
|
---|
| 20 | {
|
---|
[1772] | 21 | public:
|
---|
[1020] | 22 |
|
---|
[1772] | 23 | /** Sample rays of particular type
|
---|
| 24 | */
|
---|
| 25 | enum
|
---|
| 26 | {
|
---|
[1883] | 27 | DUMMY_DISTRIBUTION = 0,
|
---|
| 28 | DIRECTION_BASED_DISTRIBUTION,
|
---|
[1772] | 29 | OBJECT_BASED_DISTRIBUTION,
|
---|
| 30 | DIRECTION_BOX_BASED_DISTRIBUTION,
|
---|
| 31 | SPATIAL_BOX_BASED_DISTRIBUTION,
|
---|
[1883] | 32 | VSS_BASED_DISTRIBUTION,
|
---|
[1772] | 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,
|
---|
[1824] | 40 | REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION,
|
---|
[1883] | 41 | GLOBAL_LINES_DISTRIBUTION,
|
---|
| 42 | GVS
|
---|
[1772] | 43 | };
|
---|
[1520] | 44 |
|
---|
[1772] | 45 | /** Default constructor
|
---|
| 46 | */
|
---|
[1884] | 47 | SamplingStrategy(Preprocessor &preprocessor);
|
---|
[1020] | 48 |
|
---|
[1772] | 49 | virtual ~SamplingStrategy();
|
---|
| 50 |
|
---|
| 51 | /** Each strategy has to implement this function.
|
---|
| 52 | @returns true if generated valid sample.
|
---|
| 53 | */
|
---|
| 54 |
|
---|
[1867] | 55 | virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
|
---|
[1772] | 56 |
|
---|
[1867] | 57 | virtual bool GenerateSample(SimpleRay &ray) = 0;
|
---|
[1020] | 58 |
|
---|
[1900] | 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; }
|
---|
[1884] | 63 |
|
---|
[1900] | 64 |
|
---|
[1884] | 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 |
|
---|
[1771] | 71 | public:
|
---|
[1898] | 72 |
|
---|
[1900] | 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;
|
---|
[1772] | 83 |
|
---|
[1020] | 84 | protected:
|
---|
[1772] | 85 |
|
---|
[1901] | 86 | //static HaltonSequence sHalton;
|
---|
[1898] | 87 | Preprocessor &mPreprocessor;
|
---|
[1020] | 88 | };
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | class ObjectBasedDistribution: public SamplingStrategy
|
---|
| 92 | {
|
---|
| 93 | public:
|
---|
[1899] | 94 |
|
---|
[1877] | 95 |
|
---|
[1884] | 96 | ObjectBasedDistribution(Preprocessor &preprocessor):
|
---|
[1771] | 97 | SamplingStrategy(preprocessor) {
|
---|
| 98 | mType = OBJECT_BASED_DISTRIBUTION;
|
---|
| 99 | }
|
---|
[1020] | 100 |
|
---|
[1771] | 101 | private:
|
---|
[1901] | 102 |
|
---|
| 103 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
| 104 | static HaltonSequence sHalton;
|
---|
[1020] | 105 | };
|
---|
| 106 |
|
---|
| 107 |
|
---|
[1695] | 108 | class ReverseObjectBasedDistribution: public SamplingStrategy
|
---|
| 109 | {
|
---|
| 110 | public:
|
---|
| 111 |
|
---|
[1884] | 112 | ReverseObjectBasedDistribution(Preprocessor &preprocessor):
|
---|
[1771] | 113 | SamplingStrategy(preprocessor) {
|
---|
| 114 | mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
|
---|
| 115 | }
|
---|
[1695] | 116 |
|
---|
[1771] | 117 | private:
|
---|
[1901] | 118 |
|
---|
| 119 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1695] | 120 | };
|
---|
| 121 |
|
---|
| 122 |
|
---|
[1020] | 123 | class ObjectDirectionBasedDistribution: public SamplingStrategy
|
---|
| 124 | {
|
---|
[1883] | 125 |
|
---|
| 126 | public:
|
---|
[1884] | 127 | ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
|
---|
[1771] | 128 | SamplingStrategy(preprocessor) {
|
---|
| 129 | mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
|
---|
| 130 | }
|
---|
[1899] | 131 |
|
---|
[1771] | 132 | private:
|
---|
[1899] | 133 |
|
---|
| 134 | static HaltonSequence sHalton;
|
---|
[1867] | 135 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1020] | 136 | };
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | class DirectionBasedDistribution: public SamplingStrategy
|
---|
| 140 | {
|
---|
| 141 | public:
|
---|
[1884] | 142 | DirectionBasedDistribution(Preprocessor &preprocessor):
|
---|
[1771] | 143 | SamplingStrategy(preprocessor){
|
---|
| 144 | mType = DIRECTION_BASED_DISTRIBUTION;
|
---|
| 145 | }
|
---|
| 146 | private:
|
---|
[1867] | 147 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1020] | 148 | };
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | class DirectionBoxBasedDistribution: public SamplingStrategy
|
---|
| 152 | {
|
---|
| 153 | public:
|
---|
[1884] | 154 | DirectionBoxBasedDistribution(Preprocessor &preprocessor):
|
---|
[1771] | 155 | SamplingStrategy(preprocessor){
|
---|
| 156 | mType = DIRECTION_BOX_BASED_DISTRIBUTION;
|
---|
| 157 | }
|
---|
[1020] | 158 |
|
---|
[1771] | 159 | private:
|
---|
[1867] | 160 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1020] | 161 | };
|
---|
| 162 |
|
---|
| 163 |
|
---|
| 164 | class SpatialBoxBasedDistribution: public SamplingStrategy
|
---|
| 165 | {
|
---|
| 166 | public:
|
---|
[1899] | 167 |
|
---|
| 168 | SpatialBoxBasedDistribution(Preprocessor &preprocessor):
|
---|
[1867] | 169 | SamplingStrategy(preprocessor){
|
---|
[1891] | 170 | mType = SPATIAL_BOX_BASED_DISTRIBUTION;
|
---|
[1867] | 171 | }
|
---|
| 172 |
|
---|
[1772] | 173 | private:
|
---|
[1901] | 174 |
|
---|
| 175 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
| 176 | static HaltonSequence sHalton;
|
---|
[1772] | 177 | };
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | class ViewSpaceBorderBasedDistribution: public SamplingStrategy
|
---|
| 181 | {
|
---|
| 182 | public:
|
---|
[1884] | 183 | ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
[1772] | 184 | SamplingStrategy(preprocessor){
|
---|
[1891] | 185 | mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
|
---|
[1771] | 186 | }
|
---|
[1020] | 187 |
|
---|
[1771] | 188 | private:
|
---|
[1901] | 189 |
|
---|
[1867] | 190 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1020] | 191 | };
|
---|
| 192 |
|
---|
[1772] | 193 |
|
---|
| 194 | class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
|
---|
| 195 | {
|
---|
| 196 | public:
|
---|
[1884] | 197 | ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
[1772] | 198 | SamplingStrategy(preprocessor){
|
---|
[1891] | 199 | mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
|
---|
[1772] | 200 | }
|
---|
| 201 |
|
---|
| 202 | private:
|
---|
[1867] | 203 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1772] | 204 | };
|
---|
| 205 |
|
---|
| 206 |
|
---|
[1763] | 207 | class ViewCellBorderBasedDistribution: public SamplingStrategy
|
---|
| 208 | {
|
---|
| 209 | public:
|
---|
[1884] | 210 | ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
|
---|
[1891] | 211 | SamplingStrategy(preprocessor) {
|
---|
| 212 | mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
|
---|
| 213 |
|
---|
| 214 | }
|
---|
[1899] | 215 |
|
---|
| 216 | private:
|
---|
[1867] | 217 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1763] | 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 |
|
---|
[1020] | 236 | /** This strategy generates samples inside of the objects, e.g.,
|
---|
| 237 | for sampling the inside of a colon.
|
---|
| 238 | */
|
---|
[1021] | 239 | /*class ObjectsInteriorDistribution: public SamplingStrategy
|
---|
[1020] | 240 | {
|
---|
| 241 | public:
|
---|
[1884] | 242 | ObjectsInteriorDistribution(Preprocessor &preprocessor):
|
---|
[1020] | 243 | SamplingStrategy(preprocessor) {}
|
---|
| 244 |
|
---|
[1867] | 245 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1020] | 246 | };
|
---|
[1021] | 247 | */
|
---|
[1883] | 248 |
|
---|
[1899] | 249 | class MixtureDistribution: public SamplingStrategy
|
---|
[1898] | 250 | {
|
---|
[1883] | 251 | public:
|
---|
[1899] | 252 |
|
---|
[1883] | 253 | // container for the distributions
|
---|
| 254 | vector<SamplingStrategy *> mDistributions;
|
---|
| 255 |
|
---|
[1884] | 256 | MixtureDistribution(Preprocessor &preprocessor):
|
---|
[1883] | 257 | SamplingStrategy(preprocessor)
|
---|
| 258 | {
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 | // has to called before first usage
|
---|
| 262 | void Init();
|
---|
[1884] | 263 |
|
---|
| 264 | // equalize distribution contributions
|
---|
| 265 | void
|
---|
| 266 | Reset();
|
---|
[1883] | 267 |
|
---|
| 268 | // add contributions of the sample to the strategies
|
---|
[1884] | 269 | void ComputeContributions(VssRayContainer &vssRays);
|
---|
| 270 |
|
---|
| 271 | void
|
---|
| 272 | UpdateRatios();
|
---|
| 273 |
|
---|
[1901] | 274 | // construct distribution mixture from a string describing the required distributions
|
---|
[1891] | 275 | bool
|
---|
| 276 | Construct(char *str);
|
---|
| 277 |
|
---|
[1900] | 278 | virtual bool RequiresRays() {
|
---|
| 279 | for (int i=0; i < mDistributions.size(); i++)
|
---|
| 280 | if (mDistributions[i]->RequiresRays())
|
---|
| 281 | return true;
|
---|
| 282 | return false;
|
---|
| 283 | }
|
---|
| 284 |
|
---|
[1899] | 285 | private:
|
---|
| 286 |
|
---|
[1901] | 287 | // Generate a new sample according to a mixture distribution
|
---|
| 288 | virtual bool GenerateSample(SimpleRay &ray);
|
---|
[1899] | 289 |
|
---|
[1901] | 290 | // halton sequence generator for deciding between distributions
|
---|
| 291 | static HaltonSequence sHalton;
|
---|
[1020] | 292 | };
|
---|
| 293 |
|
---|
[1883] | 294 | };
|
---|
| 295 |
|
---|
[1020] | 296 | #endif
|
---|