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

Revision 2735, 8.2 KB checked in by mattausch, 16 years ago (diff)

added new importance sampling method for gvs

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