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

Revision 1942, 6.6 KB checked in by bittner, 18 years ago (diff)

tmp commit

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
11
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,
42          GVS
[1772]43        };
[1520]44
[1772]45        /** Default constructor
46        */
[1884]47        SamplingStrategy(Preprocessor &preprocessor);
[1020]48
[1772]49        virtual ~SamplingStrategy();
50
51        /** Each strategy has to implement this function.
52        @returns true if generated valid sample.
53        */
54
[1867]55        virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
[1772]56
[1867]57        virtual bool GenerateSample(SimpleRay &ray) = 0;
[1020]58
[1900]59  // true if the strategy keeps pointers to rays and thus they should get deleted
60  // outside, in that case the strategy has to use reference counting and deleting the rays
61  // by itself if the number of references drops to zero
62  virtual bool RequiresRays() { return false; }
[1884]63
[1900]64
[1884]65  virtual void Update(VssRayContainer &vssRays) {}
66
67  friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
68        return a->mRatio < b->mRatio;
69  }
70
[1771]71public:
[1898]72
[1900]73  /// variables usefull for mixed distribution sampling
74  int mType;
75  int mRays;
76  float mContribution;
77 
78  int mTotalRays;
79  float mTotalContribution;
80 
81  float mTime;
82  float mRatio;
[1772]83
[1020]84protected:
[1772]85
[1901]86        //static HaltonSequence sHalton;
[1898]87        Preprocessor &mPreprocessor;
[1020]88};
89
90
91class ObjectBasedDistribution: public SamplingStrategy
92{
93 public:
[1899]94 
[1877]95 
[1884]96  ObjectBasedDistribution(Preprocessor &preprocessor):
[1771]97        SamplingStrategy(preprocessor) {
98        mType = OBJECT_BASED_DISTRIBUTION;
99  }
[1020]100
[1771]101private:
[1901]102 
103        virtual bool GenerateSample(SimpleRay &ray);
104    static HaltonSequence sHalton;
[1020]105};
106
107
[1695]108class ReverseObjectBasedDistribution: public SamplingStrategy
109{
110 public:
111       
[1884]112         ReverseObjectBasedDistribution(Preprocessor &preprocessor):
[1771]113           SamplingStrategy(preprocessor) {
114           mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
115         }
[1695]116
[1771]117private:
[1901]118       
119        virtual bool GenerateSample(SimpleRay &ray);
[1695]120};
121
122
[1020]123class ObjectDirectionBasedDistribution: public SamplingStrategy
124{
[1883]125 
126public:
[1884]127         ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
[1771]128         SamplingStrategy(preprocessor) {
129           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
130         }
[1899]131
[1771]132private:
[1899]133
134        static HaltonSequence sHalton;
[1867]135        virtual bool GenerateSample(SimpleRay &ray);
[1020]136};
137
138
139class DirectionBasedDistribution: public SamplingStrategy
140{
141 public:
[1884]142  DirectionBasedDistribution(Preprocessor &preprocessor):
[1771]143        SamplingStrategy(preprocessor){
144        mType = DIRECTION_BASED_DISTRIBUTION;
145  }
146private:
[1867]147  virtual bool GenerateSample(SimpleRay &ray);
[1020]148};
149
150
151class DirectionBoxBasedDistribution: public SamplingStrategy
152{
153 public:
[1884]154         DirectionBoxBasedDistribution(Preprocessor &preprocessor):
[1771]155           SamplingStrategy(preprocessor){
156           mType = DIRECTION_BOX_BASED_DISTRIBUTION;
157         }
[1020]158           
[1771]159private:
[1867]160           virtual bool GenerateSample(SimpleRay &ray);
[1020]161};
162
163
164class SpatialBoxBasedDistribution: public SamplingStrategy
165{
166 public:
[1899]167         
168         SpatialBoxBasedDistribution(Preprocessor &preprocessor):
[1867]169        SamplingStrategy(preprocessor){
[1891]170        mType = SPATIAL_BOX_BASED_DISTRIBUTION;
[1867]171  }
172 
[1772]173private:
[1901]174       
175        virtual bool GenerateSample(SimpleRay &ray);
176        static HaltonSequence sHalton;
[1772]177};
178
179
180class ViewSpaceBorderBasedDistribution: public SamplingStrategy
181{
182 public:
[1884]183         ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]184           SamplingStrategy(preprocessor){
[1891]185           mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1771]186         }
[1020]187         
[1771]188private:
[1901]189
[1867]190         virtual bool GenerateSample(SimpleRay &ray);
[1020]191};
192
[1772]193
194class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
195{
196 public:
[1884]197         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]198           SamplingStrategy(preprocessor){
[1891]199           mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1772]200         }
201         
202private:
[1867]203         virtual bool GenerateSample(SimpleRay &ray);
[1772]204};
205
206
[1763]207class ViewCellBorderBasedDistribution: public SamplingStrategy
208{
209 public:
[1884]210  ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
[1891]211        SamplingStrategy(preprocessor) {
212        mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
213
214  }
[1899]215
216private:
[1867]217  virtual bool GenerateSample(SimpleRay &ray);
[1763]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
[1020]236/** This strategy generates samples inside of the objects, e.g.,
237        for sampling the inside of a colon.
238*/
[1021]239/*class ObjectsInteriorDistribution: public SamplingStrategy
[1020]240{
241 public:
[1884]242         ObjectsInteriorDistribution(Preprocessor &preprocessor):
[1020]243         SamplingStrategy(preprocessor) {}
244         
[1867]245         virtual bool GenerateSample(SimpleRay &ray);
[1020]246};
[1021]247*/
[1883]248
[1899]249class MixtureDistribution: public SamplingStrategy
[1898]250{
[1883]251public:
[1899]252   
[1883]253  // container for the distributions
254  vector<SamplingStrategy *> mDistributions;
255
[1884]256  MixtureDistribution(Preprocessor &preprocessor):
[1883]257        SamplingStrategy(preprocessor)
258  {
259  }
260
261  // has to called before first usage
262  void Init();
[1884]263
264  // equalize distribution contributions
265  void
266  Reset();
[1883]267 
268  // add contributions of the sample to the strategies
[1884]269  void ComputeContributions(VssRayContainer &vssRays);
270
[1942]271  // update distributions with new rays
272  // warning: some rays can get deleted (if maintained internally by the
273  // particular distribution)!
274  void UpdateDistributions(VssRayContainer &vssRays);
275
[1884]276  void
277  UpdateRatios();
278
[1901]279  // construct distribution mixture from a string describing the required distributions
[1891]280  bool
281  Construct(char *str);
282
[1900]283  virtual bool RequiresRays() {
284        for (int i=0; i < mDistributions.size(); i++)
285          if (mDistributions[i]->RequiresRays())
286                return true;
287        return false;
288  }
289
[1899]290private:
291
[1901]292        // Generate a new sample according to a mixture distribution
293        virtual bool GenerateSample(SimpleRay &ray);
[1899]294
[1901]295        // halton sequence generator for deciding between distributions
296        static HaltonSequence sHalton;
[1020]297};
298
[1883]299};
300
[1020]301#endif
Note: See TracBrowser for help on using the repository browser.