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

Revision 2691, 7.4 KB checked in by mattausch, 16 years ago (diff)

fixed several errors

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 ViewCellBorderBasedDistribution: public SamplingStrategy
221{
222 public:
223         ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
224                 : SamplingStrategy(preprocessor), mViewCell(viewCell)
225         {
226                 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
227         }
228
229private:
230  virtual bool GenerateSample(SimpleRay &ray);
231
232  ViewCell *mViewCell;
233};
234
235
236class GlobalLinesDistribution: public SamplingStrategy
237{
238public:
239 
240  GlobalLinesDistribution(Preprocessor &preprocessor):
241        SamplingStrategy(preprocessor) {
242        mType = GLOBAL_LINES_DISTRIBUTION;
243  }
244 
245private:
246
247        virtual bool GenerateSample(SimpleRay &ray);
248        static HaltonSequence sHalton;
249};
250
251
252class HwGlobalLinesDistribution: public SamplingStrategy
253{
254public:
255 
256  HwGlobalLinesDistribution(Preprocessor &preprocessor);
257 
258private:
259
260        virtual bool GenerateSample(SimpleRay &ray);
261        static HaltonSequence sHalton;
262};
263
264class ViewCellBasedDistribution: public SamplingStrategy
265{
266public:
267        ViewCellBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
268        : SamplingStrategy(preprocessor), mViewCell(viewCell)
269        {
270                mType = VIEWCELL_BASED_DISTRIBUTION;
271        }
272
273        void SetViewCell(ViewCell *vc) { mViewCell = vc; }
274
275private:
276
277        virtual bool GenerateSample(SimpleRay &ray);
278
279        ViewCell *mViewCell;
280        static HaltonSequence sHalton;
281};
282
283
284class MixtureDistribution: public SamplingStrategy
285{
286public:
287   
288  // container for the distributions
289        std::vector<SamplingStrategy *> mDistributions;
290 
291  MixtureDistribution(Preprocessor &preprocessor):
292        SamplingStrategy(preprocessor)
293  {
294  }
295
296  // has to called before first usage
297  void Init();
298
299  // equalize distribution contributions
300  void
301  Reset();
302 
303  // add contributions of the sample to the strategies
304  void ComputeContributions(VssRayContainer &vssRays);
305
306  // update distributions with new rays
307  // warning: some rays can get deleted (if maintained internally by the
308  // particular distribution)!
309  void UpdateDistributions(VssRayContainer &vssRays);
310
311  void
312  UpdateRatios();
313
314  // construct distribution mixture from a string describing the required distributions
315  bool
316  Construct(char *str);
317
318  virtual bool RequiresRays() {
319        for (int i=0; i < (int)mDistributions.size(); i++)
320          if (mDistributions[i]->RequiresRays())
321                return true;
322        return false;
323  }
324 
325  virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
326 
327private:
328
329        // Generate a new sample according to a mixture distribution
330        virtual bool GenerateSample(SimpleRay &ray);
331
332        // halton sequence generator for deciding between distributions
333        static HaltonSequence sHalton;
334};
335
336};
337
338#endif
Note: See TracBrowser for help on using the repository browser.