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

Revision 1952, 7.2 KB checked in by bittner, 18 years ago (diff)

mutation strategy

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        {
[1883]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,
[1883]41          GLOBAL_LINES_DISTRIBUTION,
[1952]42          GVS,
43          MUTATION_BASED_DISTRIBUTION
44
[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
[1900]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
[1884]67  virtual void Update(VssRayContainer &vssRays) {}
68
69  friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
70        return a->mRatio < b->mRatio;
71  }
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;
81  float mTotalContribution;
82 
83  float mTime;
84  float mRatio;
[1772]85
[1020]86protected:
[1772]87
[1901]88        //static HaltonSequence sHalton;
[1898]89        Preprocessor &mPreprocessor;
[1020]90};
91
92
93class ObjectBasedDistribution: public SamplingStrategy
94{
95 public:
[1899]96 
[1877]97 
[1884]98  ObjectBasedDistribution(Preprocessor &preprocessor):
[1771]99        SamplingStrategy(preprocessor) {
100        mType = OBJECT_BASED_DISTRIBUTION;
101  }
[1020]102
[1771]103private:
[1901]104 
105        virtual bool GenerateSample(SimpleRay &ray);
106    static HaltonSequence sHalton;
[1020]107};
108
109
[1695]110class ReverseObjectBasedDistribution: public SamplingStrategy
111{
112 public:
113       
[1884]114         ReverseObjectBasedDistribution(Preprocessor &preprocessor):
[1771]115           SamplingStrategy(preprocessor) {
116           mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
117         }
[1695]118
[1771]119private:
[1901]120       
121        virtual bool GenerateSample(SimpleRay &ray);
[1695]122};
123
124
[1020]125class ObjectDirectionBasedDistribution: public SamplingStrategy
126{
[1883]127 
128public:
[1884]129         ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
[1771]130         SamplingStrategy(preprocessor) {
131           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
132         }
[1899]133
[1771]134private:
[1899]135
136        static HaltonSequence sHalton;
[1867]137        virtual bool GenerateSample(SimpleRay &ray);
[1020]138};
139
140
141class DirectionBasedDistribution: public SamplingStrategy
142{
143 public:
[1884]144  DirectionBasedDistribution(Preprocessor &preprocessor):
[1771]145        SamplingStrategy(preprocessor){
146        mType = DIRECTION_BASED_DISTRIBUTION;
147  }
148private:
[1867]149  virtual bool GenerateSample(SimpleRay &ray);
[1952]150  static HaltonSequence sHalton;
[1020]151};
152
153
154class DirectionBoxBasedDistribution: public SamplingStrategy
155{
156 public:
[1884]157         DirectionBoxBasedDistribution(Preprocessor &preprocessor):
[1771]158           SamplingStrategy(preprocessor){
159           mType = DIRECTION_BOX_BASED_DISTRIBUTION;
160         }
[1020]161           
[1771]162private:
[1867]163           virtual bool GenerateSample(SimpleRay &ray);
[1020]164};
165
166
167class SpatialBoxBasedDistribution: public SamplingStrategy
168{
169 public:
[1899]170         
171         SpatialBoxBasedDistribution(Preprocessor &preprocessor):
[1867]172        SamplingStrategy(preprocessor){
[1891]173        mType = SPATIAL_BOX_BASED_DISTRIBUTION;
[1867]174  }
175 
[1772]176private:
[1901]177       
178        virtual bool GenerateSample(SimpleRay &ray);
179        static HaltonSequence sHalton;
[1772]180};
181
182
183class ViewSpaceBorderBasedDistribution: public SamplingStrategy
184{
185 public:
[1884]186         ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]187           SamplingStrategy(preprocessor){
[1891]188           mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1771]189         }
[1020]190         
[1771]191private:
[1901]192
[1867]193         virtual bool GenerateSample(SimpleRay &ray);
[1020]194};
195
[1772]196
197class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
198{
199 public:
[1884]200         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]201           SamplingStrategy(preprocessor){
[1891]202           mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1772]203         }
204         
205private:
[1867]206         virtual bool GenerateSample(SimpleRay &ray);
[1772]207};
208
209
[1763]210class ViewCellBorderBasedDistribution: public SamplingStrategy
211{
212 public:
[1884]213  ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
[1891]214        SamplingStrategy(preprocessor) {
215        mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
216
217  }
[1899]218
219private:
[1867]220  virtual bool GenerateSample(SimpleRay &ray);
[1763]221};
222
[1952]223class MutationBasedDistribution: public SamplingStrategy
224{
225public:
226  MutationBasedDistribution(Preprocessor &preprocessor);
227  virtual void Update(VssRayContainer &vssRays);
228
229  virtual bool RequiresRays() { return true; }
230
231private:
232  virtual bool GenerateSample(SimpleRay &ray);
233  static HaltonSequence sHalton;
234  struct RayEntry {
235        VssRay *mRay;
236        int mSamples;
237        RayEntry();
238        RayEntry(VssRay *r):mRay(r), mSamples(0) {}
239  };
240 
241  vector<RayEntry> mRays;
242  int mMaxRays;
243  float mOriginMutationSize;
244  int mBufferStart;
245  int mLastIndex;
246};
247
[1824]248class GlobalLinesDistribution: public SamplingStrategy
249{
250public:
[1899]251 
[1884]252  GlobalLinesDistribution(Preprocessor &preprocessor):
[1867]253        SamplingStrategy(preprocessor) {
254        mType = GLOBAL_LINES_DISTRIBUTION;
255  }
[1824]256 
[1899]257private:
258
[1901]259        virtual bool GenerateSample(SimpleRay &ray);
260        static HaltonSequence sHalton;
[1824]261};
[1763]262
[1824]263
[1020]264/** This strategy generates samples inside of the objects, e.g.,
265        for sampling the inside of a colon.
266*/
[1021]267/*class ObjectsInteriorDistribution: public SamplingStrategy
[1020]268{
269 public:
[1884]270         ObjectsInteriorDistribution(Preprocessor &preprocessor):
[1020]271         SamplingStrategy(preprocessor) {}
272         
[1867]273         virtual bool GenerateSample(SimpleRay &ray);
[1020]274};
[1021]275*/
[1883]276
[1899]277class MixtureDistribution: public SamplingStrategy
[1898]278{
[1883]279public:
[1899]280   
[1883]281  // container for the distributions
282  vector<SamplingStrategy *> mDistributions;
283
[1884]284  MixtureDistribution(Preprocessor &preprocessor):
[1883]285        SamplingStrategy(preprocessor)
286  {
287  }
288
289  // has to called before first usage
290  void Init();
[1884]291
292  // equalize distribution contributions
293  void
294  Reset();
[1883]295 
296  // add contributions of the sample to the strategies
[1884]297  void ComputeContributions(VssRayContainer &vssRays);
298
[1942]299  // update distributions with new rays
300  // warning: some rays can get deleted (if maintained internally by the
301  // particular distribution)!
302  void UpdateDistributions(VssRayContainer &vssRays);
303
[1884]304  void
305  UpdateRatios();
306
[1901]307  // construct distribution mixture from a string describing the required distributions
[1891]308  bool
309  Construct(char *str);
310
[1900]311  virtual bool RequiresRays() {
[1949]312        for (int i=0; i < (int)mDistributions.size(); i++)
[1900]313          if (mDistributions[i]->RequiresRays())
314                return true;
315        return false;
316  }
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
[1883]327};
328
[1020]329#endif
Note: See TracBrowser for help on using the repository browser.