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

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