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

Revision 1964, 7.5 KB checked in by mattausch, 17 years ago (diff)

worked on global lines

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