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

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