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

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