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

Revision 2575, 7.2 KB checked in by bittner, 17 years ago (diff)

big merge: preparation for havran ray caster, check if everything works

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):
[1772]196           SamplingStrategy(preprocessor){
[1891]197           mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1771]198         }
[1020]199         
[1771]200private:
[1901]201
[1867]202         virtual bool GenerateSample(SimpleRay &ray);
[1020]203};
204
[1772]205
206class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
207{
208 public:
[1884]209         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]210           SamplingStrategy(preprocessor){
[1891]211           mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1772]212         }
213         
214private:
[1867]215         virtual bool GenerateSample(SimpleRay &ray);
[1772]216};
217
218
[1763]219class ViewCellBorderBasedDistribution: public SamplingStrategy
220{
221 public:
[1884]222  ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
[1891]223        SamplingStrategy(preprocessor) {
224        mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
225
226  }
[1899]227
228private:
[1867]229  virtual bool GenerateSample(SimpleRay &ray);
[1763]230};
231
[1952]232
[1824]233class GlobalLinesDistribution: public SamplingStrategy
234{
235public:
[1899]236 
[1884]237  GlobalLinesDistribution(Preprocessor &preprocessor):
[1867]238        SamplingStrategy(preprocessor) {
239        mType = GLOBAL_LINES_DISTRIBUTION;
240  }
[1824]241 
[1899]242private:
243
[1901]244        virtual bool GenerateSample(SimpleRay &ray);
245        static HaltonSequence sHalton;
[1824]246};
[1763]247
[1824]248
[1964]249class HwGlobalLinesDistribution: public SamplingStrategy
250{
251public:
252 
[2076]253  HwGlobalLinesDistribution(Preprocessor &preprocessor);
[1964]254 
255private:
256
257        virtual bool GenerateSample(SimpleRay &ray);
258        static HaltonSequence sHalton;
259};
260
[1990]261class ViewCellBasedDistribution: public SamplingStrategy
[1020]262{
[1990]263public:
264        ViewCellBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
265        : SamplingStrategy(preprocessor), mViewCell(viewCell)
266        {
267                mType = VIEWCELL_BASED_DISTRIBUTION;
268        }
269
270private:
271
[2000]272  virtual bool GenerateSample(SimpleRay &ray);
[1990]273
274        ViewCell *mViewCell;
275        static HaltonSequence sHalton;
[1020]276};
[1883]277
[1990]278
[1899]279class MixtureDistribution: public SamplingStrategy
[1898]280{
[1883]281public:
[1899]282   
[1883]283  // container for the distributions
[2176]284        std::vector<SamplingStrategy *> mDistributions;
[1966]285 
[1884]286  MixtureDistribution(Preprocessor &preprocessor):
[1883]287        SamplingStrategy(preprocessor)
288  {
289  }
290
291  // has to called before first usage
292  void Init();
[1884]293
294  // equalize distribution contributions
295  void
296  Reset();
[1883]297 
298  // add contributions of the sample to the strategies
[1884]299  void ComputeContributions(VssRayContainer &vssRays);
300
[1942]301  // update distributions with new rays
302  // warning: some rays can get deleted (if maintained internally by the
303  // particular distribution)!
304  void UpdateDistributions(VssRayContainer &vssRays);
305
[1884]306  void
307  UpdateRatios();
308
[1901]309  // construct distribution mixture from a string describing the required distributions
[1891]310  bool
311  Construct(char *str);
312
[1900]313  virtual bool RequiresRays() {
[1949]314        for (int i=0; i < (int)mDistributions.size(); i++)
[1900]315          if (mDistributions[i]->RequiresRays())
316                return true;
317        return false;
318  }
[1966]319 
320  virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
321 
[1899]322private:
323
[1901]324        // Generate a new sample according to a mixture distribution
325        virtual bool GenerateSample(SimpleRay &ray);
[1899]326
[1901]327        // halton sequence generator for deciding between distributions
328        static HaltonSequence sHalton;
[1020]329};
330
[1883]331};
332
[1020]333#endif
Note: See TracBrowser for help on using the repository browser.