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

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