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

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