source: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h @ 2176

Revision 2176, 7.2 KB checked in by mattausch, 18 years ago (diff)

removed using namespace std from .h

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