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

Revision 2726, 7.7 KB checked in by mattausch, 16 years ago (diff)

worked on gvs efficiency

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#include "Vector3.h"
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        Vector3 origin;
266        Vector3 direction;
267        Vector3 point;
268        Vector3 normal;
269        float r[2];
270
[1990]271        static HaltonSequence sHalton;
[1020]272};
[1883]273
[1990]274
[1899]275class MixtureDistribution: public SamplingStrategy
[1898]276{
[1883]277public:
[1899]278   
[1883]279  // container for the distributions
[2176]280        std::vector<SamplingStrategy *> mDistributions;
[1966]281 
[1884]282  MixtureDistribution(Preprocessor &preprocessor):
[1883]283        SamplingStrategy(preprocessor)
284  {
285  }
286
287  // has to called before first usage
288  void Init();
[1884]289
290  // equalize distribution contributions
291  void
292  Reset();
[1883]293 
294  // add contributions of the sample to the strategies
[1884]295  void ComputeContributions(VssRayContainer &vssRays);
296
[1942]297  // update distributions with new rays
298  // warning: some rays can get deleted (if maintained internally by the
299  // particular distribution)!
300  void UpdateDistributions(VssRayContainer &vssRays);
301
[1884]302  void
303  UpdateRatios();
304
[1901]305  // construct distribution mixture from a string describing the required distributions
[1891]306  bool
307  Construct(char *str);
308
[1900]309  virtual bool RequiresRays() {
[1949]310        for (int i=0; i < (int)mDistributions.size(); i++)
[1900]311          if (mDistributions[i]->RequiresRays())
312                return true;
313        return false;
314  }
[1966]315 
[2726]316  virtual int GenerateSamples(int number, SimpleRayContainer &rays, int &invalidSamples);
[1966]317 
[1899]318private:
319
[1901]320        // Generate a new sample according to a mixture distribution
321        virtual bool GenerateSample(SimpleRay &ray);
[1899]322
[1901]323        // halton sequence generator for deciding between distributions
324        static HaltonSequence sHalton;
[1020]325};
326
[2694]327class ViewCellBorderBasedDistribution: public SamplingStrategy
328{
329 public:
330         ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
331                 : SamplingStrategy(preprocessor), mViewCell(viewCell)
332         {
333                 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
334         }
335
336        void SetViewCell(ViewCell *vc) { mViewCell = vc; }
337
338private:
339
340        // Generate a new sample according to a mixture distribution
341        virtual bool GenerateSample(SimpleRay &ray);
342
343        // halton sequence generator for deciding between distributions
344        static HaltonSequence sHalton;
345
346        ViewCell *mViewCell;
[1883]347};
348
[2694]349
350};
351
[1020]352#endif
Note: See TracBrowser for help on using the repository browser.