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

Revision 1952, 7.2 KB checked in by bittner, 18 years ago (diff)

mutation strategy

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
264/** This strategy generates samples inside of the objects, e.g.,
265        for sampling the inside of a colon.
266*/
267/*class ObjectsInteriorDistribution: public SamplingStrategy
268{
269 public:
270         ObjectsInteriorDistribution(Preprocessor &preprocessor):
271         SamplingStrategy(preprocessor) {}
272         
273         virtual bool GenerateSample(SimpleRay &ray);
274};
275*/
276
277class MixtureDistribution: public SamplingStrategy
278{
279public:
280   
281  // container for the distributions
282  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
318private:
319
320        // Generate a new sample according to a mixture distribution
321        virtual bool GenerateSample(SimpleRay &ray);
322
323        // halton sequence generator for deciding between distributions
324        static HaltonSequence sHalton;
325};
326
327};
328
329#endif
Note: See TracBrowser for help on using the repository browser.