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

Revision 2694, 7.6 KB checked in by mattausch, 16 years ago (diff)

worked on moving objects

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                FILTER_BASED_DISTRIBUTION,
51                DIFFERENCE_SAMPLING_BASED_DISTRIBUTION,
52        };
53
54 
55        /** Default constructor
56        */
57        SamplingStrategy(Preprocessor &preprocessor);
58
59        virtual ~SamplingStrategy();
60
61        /** Each strategy has to implement this function.
62        @returns true if generated valid sample.
63        */
64
65        virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
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        static HaltonSequence sHalton;
265};
266
267
268class MixtureDistribution: public SamplingStrategy
269{
270public:
271   
272  // container for the distributions
273        std::vector<SamplingStrategy *> mDistributions;
274 
275  MixtureDistribution(Preprocessor &preprocessor):
276        SamplingStrategy(preprocessor)
277  {
278  }
279
280  // has to called before first usage
281  void Init();
282
283  // equalize distribution contributions
284  void
285  Reset();
286 
287  // add contributions of the sample to the strategies
288  void ComputeContributions(VssRayContainer &vssRays);
289
290  // update distributions with new rays
291  // warning: some rays can get deleted (if maintained internally by the
292  // particular distribution)!
293  void UpdateDistributions(VssRayContainer &vssRays);
294
295  void
296  UpdateRatios();
297
298  // construct distribution mixture from a string describing the required distributions
299  bool
300  Construct(char *str);
301
302  virtual bool RequiresRays() {
303        for (int i=0; i < (int)mDistributions.size(); i++)
304          if (mDistributions[i]->RequiresRays())
305                return true;
306        return false;
307  }
308 
309  virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
310 
311private:
312
313        // Generate a new sample according to a mixture distribution
314        virtual bool GenerateSample(SimpleRay &ray);
315
316        // halton sequence generator for deciding between distributions
317        static HaltonSequence sHalton;
318};
319
320class ViewCellBorderBasedDistribution: public SamplingStrategy
321{
322 public:
323         ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
324                 : SamplingStrategy(preprocessor), mViewCell(viewCell)
325         {
326                 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
327         }
328
329        void SetViewCell(ViewCell *vc) { mViewCell = vc; }
330
331private:
332
333        // Generate a new sample according to a mixture distribution
334        virtual bool GenerateSample(SimpleRay &ray);
335
336        // halton sequence generator for deciding between distributions
337        static HaltonSequence sHalton;
338
339        ViewCell *mViewCell;
340};
341
342
343};
344
345#endif
Note: See TracBrowser for help on using the repository browser.