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

Revision 2176, 7.2 KB checked in by mattausch, 18 years ago (diff)

removed using namespace std from .h

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