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

Revision 2691, 7.4 KB checked in by mattausch, 16 years ago (diff)

fixed several errors

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,
[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]81public:
[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]95protected:
[1772]96
[1901]97        //static HaltonSequence sHalton;
[1898]98        Preprocessor &mPreprocessor;
[1020]99};
100
101
102class 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]112private:
[1901]113 
114        virtual bool GenerateSample(SimpleRay &ray);
115    static HaltonSequence sHalton;
[1020]116};
117
118
[1695]119class 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]128private:
[1901]129       
130        virtual bool GenerateSample(SimpleRay &ray);
[1695]131};
132
133
[1020]134class ObjectDirectionBasedDistribution: public SamplingStrategy
135{
[1883]136 
137public:
[1884]138         ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
[1771]139         SamplingStrategy(preprocessor) {
140           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
141         }
[1899]142
[1771]143private:
[1899]144
145        static HaltonSequence sHalton;
[1867]146        virtual bool GenerateSample(SimpleRay &ray);
[1020]147};
148
149
150class DirectionBasedDistribution: public SamplingStrategy
151{
152 public:
[1884]153  DirectionBasedDistribution(Preprocessor &preprocessor):
[1771]154        SamplingStrategy(preprocessor){
155        mType = DIRECTION_BASED_DISTRIBUTION;
156  }
157private:
[1867]158  virtual bool GenerateSample(SimpleRay &ray);
[1952]159  static HaltonSequence sHalton;
[1020]160};
161
162
163class 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]171private:
[1867]172           virtual bool GenerateSample(SimpleRay &ray);
[1020]173};
174
175
176class 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]185private:
[1901]186       
187        virtual bool GenerateSample(SimpleRay &ray);
188        static HaltonSequence sHalton;
[1772]189};
190
191
192class 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]201private:
[1901]202
[1867]203         virtual bool GenerateSample(SimpleRay &ray);
[1020]204};
205
[1772]206
207class 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         
215private:
[1867]216         virtual bool GenerateSample(SimpleRay &ray);
[1772]217};
218
219
[1763]220class ViewCellBorderBasedDistribution: public SamplingStrategy
221{
222 public:
[2691]223         ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
224                 : SamplingStrategy(preprocessor), mViewCell(viewCell)
225         {
226                 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
227         }
[1891]228
[1899]229private:
[1867]230  virtual bool GenerateSample(SimpleRay &ray);
[2691]231
232  ViewCell *mViewCell;
[1763]233};
234
[1952]235
[1824]236class GlobalLinesDistribution: public SamplingStrategy
237{
238public:
[1899]239 
[1884]240  GlobalLinesDistribution(Preprocessor &preprocessor):
[1867]241        SamplingStrategy(preprocessor) {
242        mType = GLOBAL_LINES_DISTRIBUTION;
243  }
[1824]244 
[1899]245private:
246
[1901]247        virtual bool GenerateSample(SimpleRay &ray);
248        static HaltonSequence sHalton;
[1824]249};
[1763]250
[1824]251
[1964]252class HwGlobalLinesDistribution: public SamplingStrategy
253{
254public:
255 
[2076]256  HwGlobalLinesDistribution(Preprocessor &preprocessor);
[1964]257 
258private:
259
260        virtual bool GenerateSample(SimpleRay &ray);
261        static HaltonSequence sHalton;
262};
263
[1990]264class ViewCellBasedDistribution: public SamplingStrategy
[1020]265{
[1990]266public:
267        ViewCellBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
268        : SamplingStrategy(preprocessor), mViewCell(viewCell)
269        {
270                mType = VIEWCELL_BASED_DISTRIBUTION;
271        }
272
[2691]273        void SetViewCell(ViewCell *vc) { mViewCell = vc; }
274
[1990]275private:
276
[2691]277        virtual bool GenerateSample(SimpleRay &ray);
[1990]278
279        ViewCell *mViewCell;
280        static HaltonSequence sHalton;
[1020]281};
[1883]282
[1990]283
[1899]284class MixtureDistribution: public SamplingStrategy
[1898]285{
[1883]286public:
[1899]287   
[1883]288  // container for the distributions
[2176]289        std::vector<SamplingStrategy *> mDistributions;
[1966]290 
[1884]291  MixtureDistribution(Preprocessor &preprocessor):
[1883]292        SamplingStrategy(preprocessor)
293  {
294  }
295
296  // has to called before first usage
297  void Init();
[1884]298
299  // equalize distribution contributions
300  void
301  Reset();
[1883]302 
303  // add contributions of the sample to the strategies
[1884]304  void ComputeContributions(VssRayContainer &vssRays);
305
[1942]306  // update distributions with new rays
307  // warning: some rays can get deleted (if maintained internally by the
308  // particular distribution)!
309  void UpdateDistributions(VssRayContainer &vssRays);
310
[1884]311  void
312  UpdateRatios();
313
[1901]314  // construct distribution mixture from a string describing the required distributions
[1891]315  bool
316  Construct(char *str);
317
[1900]318  virtual bool RequiresRays() {
[1949]319        for (int i=0; i < (int)mDistributions.size(); i++)
[1900]320          if (mDistributions[i]->RequiresRays())
321                return true;
322        return false;
323  }
[1966]324 
325  virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
326 
[1899]327private:
328
[1901]329        // Generate a new sample according to a mixture distribution
330        virtual bool GenerateSample(SimpleRay &ray);
[1899]331
[1901]332        // halton sequence generator for deciding between distributions
333        static HaltonSequence sHalton;
[1020]334};
335
[1883]336};
337
[1020]338#endif
Note: See TracBrowser for help on using the repository browser.