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

Revision 1966, 7.7 KB checked in by bittner, 17 years ago (diff)

samplign preprocessor updates, merge

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  int mGeneratedRays;
82  float mTotalContribution;
83 
84  float mTime;
85  float mRatio;
86
87protected:
88
89        //static HaltonSequence sHalton;
90        Preprocessor &mPreprocessor;
91};
92
93
94class ObjectBasedDistribution: public SamplingStrategy
95{
96 public:
97 
98 
99  ObjectBasedDistribution(Preprocessor &preprocessor):
100        SamplingStrategy(preprocessor) {
101        mType = OBJECT_BASED_DISTRIBUTION;
102  }
103
104private:
105 
106        virtual bool GenerateSample(SimpleRay &ray);
107    static HaltonSequence sHalton;
108};
109
110
111class ReverseObjectBasedDistribution: public SamplingStrategy
112{
113 public:
114       
115         ReverseObjectBasedDistribution(Preprocessor &preprocessor):
116           SamplingStrategy(preprocessor) {
117           mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
118         }
119
120private:
121       
122        virtual bool GenerateSample(SimpleRay &ray);
123};
124
125
126class ObjectDirectionBasedDistribution: public SamplingStrategy
127{
128 
129public:
130         ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
131         SamplingStrategy(preprocessor) {
132           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
133         }
134
135private:
136
137        static HaltonSequence sHalton;
138        virtual bool GenerateSample(SimpleRay &ray);
139};
140
141
142class DirectionBasedDistribution: public SamplingStrategy
143{
144 public:
145  DirectionBasedDistribution(Preprocessor &preprocessor):
146        SamplingStrategy(preprocessor){
147        mType = DIRECTION_BASED_DISTRIBUTION;
148  }
149private:
150  virtual bool GenerateSample(SimpleRay &ray);
151  static HaltonSequence sHalton;
152};
153
154
155class DirectionBoxBasedDistribution: public SamplingStrategy
156{
157 public:
158         DirectionBoxBasedDistribution(Preprocessor &preprocessor):
159           SamplingStrategy(preprocessor){
160           mType = DIRECTION_BOX_BASED_DISTRIBUTION;
161         }
162           
163private:
164           virtual bool GenerateSample(SimpleRay &ray);
165};
166
167
168class SpatialBoxBasedDistribution: public SamplingStrategy
169{
170 public:
171         
172         SpatialBoxBasedDistribution(Preprocessor &preprocessor):
173        SamplingStrategy(preprocessor){
174        mType = SPATIAL_BOX_BASED_DISTRIBUTION;
175  }
176 
177private:
178       
179        virtual bool GenerateSample(SimpleRay &ray);
180        static HaltonSequence sHalton;
181};
182
183
184class ViewSpaceBorderBasedDistribution: public SamplingStrategy
185{
186 public:
187         ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
188           SamplingStrategy(preprocessor){
189           mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
190         }
191         
192private:
193
194         virtual bool GenerateSample(SimpleRay &ray);
195};
196
197
198class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
199{
200 public:
201         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
202           SamplingStrategy(preprocessor){
203           mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
204         }
205         
206private:
207         virtual bool GenerateSample(SimpleRay &ray);
208};
209
210
211class ViewCellBorderBasedDistribution: public SamplingStrategy
212{
213 public:
214  ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
215        SamplingStrategy(preprocessor) {
216        mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
217
218  }
219
220private:
221  virtual bool GenerateSample(SimpleRay &ray);
222};
223
224class MutationBasedDistribution: public SamplingStrategy
225{
226public:
227  MutationBasedDistribution(Preprocessor &preprocessor);
228  virtual void Update(VssRayContainer &vssRays);
229
230  virtual bool RequiresRays() { return true; }
231
232private:
233  virtual bool GenerateSample(SimpleRay &ray);
234
235  struct RayEntry {
236        // halton sequence for generatin gmutations of this ray
237        VssRay *mRay;
238        int mSamples;
239        HaltonSequence mHalton;
240
241        RayEntry() {}
242        RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton() {}
243  };
244 
245  vector<RayEntry> mRays;
246  int mMaxRays;
247  float mOriginMutationSize;
248  int mBufferStart;
249  int mLastIndex;
250};
251
252class GlobalLinesDistribution: public SamplingStrategy
253{
254public:
255 
256  GlobalLinesDistribution(Preprocessor &preprocessor):
257        SamplingStrategy(preprocessor) {
258        mType = GLOBAL_LINES_DISTRIBUTION;
259  }
260 
261private:
262
263        virtual bool GenerateSample(SimpleRay &ray);
264        static HaltonSequence sHalton;
265};
266
267
268class HwGlobalLinesDistribution: public SamplingStrategy
269{
270public:
271 
272  HwGlobalLinesDistribution(Preprocessor &preprocessor):
273        SamplingStrategy(preprocessor) {
274        //mType = HW_GLOBAL_LINES_DISTRIBUTION;
275  }
276 
277private:
278
279        virtual bool GenerateSample(SimpleRay &ray);
280        static HaltonSequence sHalton;
281};
282
283/** This strategy generates samples inside of the objects, e.g.,
284        for sampling the inside of a colon.
285*/
286/*class ObjectsInteriorDistribution: public SamplingStrategy
287{
288 public:
289         ObjectsInteriorDistribution(Preprocessor &preprocessor):
290         SamplingStrategy(preprocessor) {}
291         
292         virtual bool GenerateSample(SimpleRay &ray);
293};
294*/
295
296class MixtureDistribution: public SamplingStrategy
297{
298public:
299   
300  // container for the distributions
301  vector<SamplingStrategy *> mDistributions;
302 
303  MixtureDistribution(Preprocessor &preprocessor):
304        SamplingStrategy(preprocessor)
305  {
306  }
307
308  // has to called before first usage
309  void Init();
310
311  // equalize distribution contributions
312  void
313  Reset();
314 
315  // add contributions of the sample to the strategies
316  void ComputeContributions(VssRayContainer &vssRays);
317
318  // update distributions with new rays
319  // warning: some rays can get deleted (if maintained internally by the
320  // particular distribution)!
321  void UpdateDistributions(VssRayContainer &vssRays);
322
323  void
324  UpdateRatios();
325
326  // construct distribution mixture from a string describing the required distributions
327  bool
328  Construct(char *str);
329
330  virtual bool RequiresRays() {
331        for (int i=0; i < (int)mDistributions.size(); i++)
332          if (mDistributions[i]->RequiresRays())
333                return true;
334        return false;
335  }
336 
337  virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
338 
339private:
340
341        // Generate a new sample according to a mixture distribution
342        virtual bool GenerateSample(SimpleRay &ray);
343
344        // halton sequence generator for deciding between distributions
345        static HaltonSequence sHalton;
346};
347
348};
349
350#endif
Note: See TracBrowser for help on using the repository browser.