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

Revision 1968, 7.7 KB checked in by mattausch, 17 years ago (diff)

early exit for global lines
preprocessor support

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