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

Revision 2728, 7.6 KB checked in by mattausch, 16 years ago (diff)
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"
[2726]9
[2728]10
[1020]11namespace GtpVisibilityPreprocessor {
12
[1974]13class Vector2;
14class Vector3;
15class VssRay;
[1020]16class Preprocessor;
17struct SimpleRay;
[1771]18class SimpleRayContainer;
[1990]19class ViewCell;
[1974]20
[1888]21struct VssRayContainer;
[1020]22
23/** This class generates a specific sampling strategy.
24*/
25class SamplingStrategy
26{
[1772]27public:
[1020]28
[1772]29        /** Sample rays of particular type
30        */
31        enum
32        {
[1968]33                DUMMY_DISTRIBUTION = 0,
34                DIRECTION_BASED_DISTRIBUTION,
[1772]35                OBJECT_BASED_DISTRIBUTION,
36                DIRECTION_BOX_BASED_DISTRIBUTION,
37                SPATIAL_BOX_BASED_DISTRIBUTION,
[1883]38                VSS_BASED_DISTRIBUTION,
[1772]39                RSS_BASED_DISTRIBUTION,
40                RSS_SILHOUETTE_BASED_DISTRIBUTION,
41                OBJECT_DIRECTION_BASED_DISTRIBUTION,
42                OBJECTS_INTERIOR_DISTRIBUTION,
43                REVERSE_OBJECT_BASED_DISTRIBUTION,
44                VIEWCELL_BORDER_BASED_DISTRIBUTION,
45                VIEWSPACE_BORDER_BASED_DISTRIBUTION,
[1824]46                REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION,
[1968]47                GLOBAL_LINES_DISTRIBUTION,
48                GVS,
49                MUTATION_BASED_DISTRIBUTION,
[1990]50                HW_GLOBAL_LINES_DISTRIBUTION,
[2548]51                VIEWCELL_BASED_DISTRIBUTION,
[2575]52                FILTER_BASED_DISTRIBUTION,
[2548]53                DIFFERENCE_SAMPLING_BASED_DISTRIBUTION,
[1772]54        };
[1520]55
[1993]56 
[1772]57        /** Default constructor
58        */
[1884]59        SamplingStrategy(Preprocessor &preprocessor);
[1020]60
[1772]61        virtual ~SamplingStrategy();
62
[2726]63        virtual int GenerateSamples(int number, SimpleRayContainer &rays, int &invalidSamples);
[1772]64        /** Each strategy has to implement this function.
[2726]65                @returns true if generated valid sample.
[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
[1824]220class GlobalLinesDistribution: public SamplingStrategy
221{
222public:
[1899]223 
[1884]224  GlobalLinesDistribution(Preprocessor &preprocessor):
[1867]225        SamplingStrategy(preprocessor) {
226        mType = GLOBAL_LINES_DISTRIBUTION;
227  }
[1824]228 
[1899]229private:
230
[1901]231        virtual bool GenerateSample(SimpleRay &ray);
232        static HaltonSequence sHalton;
[1824]233};
[1763]234
[1824]235
[1964]236class HwGlobalLinesDistribution: public SamplingStrategy
237{
238public:
239 
[2076]240  HwGlobalLinesDistribution(Preprocessor &preprocessor);
[1964]241 
242private:
243
244        virtual bool GenerateSample(SimpleRay &ray);
245        static HaltonSequence sHalton;
246};
247
[1990]248class ViewCellBasedDistribution: public SamplingStrategy
[1020]249{
[1990]250public:
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]259private:
260
[2691]261        virtual bool GenerateSample(SimpleRay &ray);
[1990]262
263        ViewCell *mViewCell;
[2726]264
265
[1990]266        static HaltonSequence sHalton;
[1020]267};
[1883]268
[1990]269
[1899]270class MixtureDistribution: public SamplingStrategy
[1898]271{
[1883]272public:
[1899]273   
[1883]274  // container for the distributions
[2176]275        std::vector<SamplingStrategy *> mDistributions;
[1966]276 
[1884]277  MixtureDistribution(Preprocessor &preprocessor):
[1883]278        SamplingStrategy(preprocessor)
279  {
280  }
281
282  // has to called before first usage
283  void Init();
[1884]284
285  // equalize distribution contributions
286  void
287  Reset();
[1883]288 
289  // add contributions of the sample to the strategies
[1884]290  void ComputeContributions(VssRayContainer &vssRays);
291
[1942]292  // update distributions with new rays
293  // warning: some rays can get deleted (if maintained internally by the
294  // particular distribution)!
295  void UpdateDistributions(VssRayContainer &vssRays);
296
[1884]297  void
298  UpdateRatios();
299
[1901]300  // construct distribution mixture from a string describing the required distributions
[1891]301  bool
302  Construct(char *str);
303
[1900]304  virtual bool RequiresRays() {
[1949]305        for (int i=0; i < (int)mDistributions.size(); i++)
[1900]306          if (mDistributions[i]->RequiresRays())
307                return true;
308        return false;
309  }
[1966]310 
[2726]311  virtual int GenerateSamples(int number, SimpleRayContainer &rays, int &invalidSamples);
[1966]312 
[1899]313private:
314
[1901]315        // Generate a new sample according to a mixture distribution
316        virtual bool GenerateSample(SimpleRay &ray);
[1899]317
[1901]318        // halton sequence generator for deciding between distributions
319        static HaltonSequence sHalton;
[1020]320};
321
[2694]322class ViewCellBorderBasedDistribution: public SamplingStrategy
323{
324 public:
325         ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
326                 : SamplingStrategy(preprocessor), mViewCell(viewCell)
327         {
328                 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
329         }
330
331        void SetViewCell(ViewCell *vc) { mViewCell = vc; }
332
333private:
334
335        // Generate a new sample according to a mixture distribution
336        virtual bool GenerateSample(SimpleRay &ray);
337
338        // halton sequence generator for deciding between distributions
339        static HaltonSequence sHalton;
340
341        ViewCell *mViewCell;
[1883]342};
343
[2694]344
345};
346
[1020]347#endif
Note: See TracBrowser for help on using the repository browser.