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

Revision 1884, 5.7 KB checked in by bittner, 18 years ago (diff)

temporary version, rss preprocessor not functional

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;
15class 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
58        virtual bool GenerateSample(SimpleRay &ray) = 0;
59 
60
61
62  virtual void Update(VssRayContainer &vssRays) {}
63
64
65
66  friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
67        return a->mRatio < b->mRatio;
68  }
69
70public:
71        /// variables usefull for mixed distribution sampling
72        int mType;
73        int mRays;
74        float mContribution;
75        float mTime;
76        float mRatio;
77
78  int mTotalRays;
79  float mTotalContribution;
80protected:
81
82  Preprocessor &mPreprocessor;
83
84};
85
86
87class ObjectBasedDistribution: public SamplingStrategy
88{
89 public:
90  HaltonSequence mHalton;
91 
92  ObjectBasedDistribution(Preprocessor &preprocessor):
93        SamplingStrategy(preprocessor) {
94        mType = OBJECT_BASED_DISTRIBUTION;
95  }
96
97private:
98  virtual bool GenerateSample(SimpleRay &ray);
99};
100
101
102class ReverseObjectBasedDistribution: public SamplingStrategy
103{
104 public:
105       
106         ReverseObjectBasedDistribution(Preprocessor &preprocessor):
107           SamplingStrategy(preprocessor) {
108           mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
109         }
110
111private:
112  virtual bool GenerateSample(SimpleRay &ray);
113};
114
115
116class ObjectDirectionBasedDistribution: public SamplingStrategy
117{
118  HaltonSequence mHalton;
119 
120public:
121         ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
122         SamplingStrategy(preprocessor) {
123           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
124         }
125private:
126        virtual bool GenerateSample(SimpleRay &ray);
127};
128
129
130class DirectionBasedDistribution: public SamplingStrategy
131{
132 public:
133  DirectionBasedDistribution(Preprocessor &preprocessor):
134        SamplingStrategy(preprocessor){
135        mType = DIRECTION_BASED_DISTRIBUTION;
136  }
137private:
138  virtual bool GenerateSample(SimpleRay &ray);
139};
140
141
142class DirectionBoxBasedDistribution: public SamplingStrategy
143{
144 public:
145         DirectionBoxBasedDistribution(Preprocessor &preprocessor):
146           SamplingStrategy(preprocessor){
147           mType = DIRECTION_BOX_BASED_DISTRIBUTION;
148         }
149           
150private:
151           virtual bool GenerateSample(SimpleRay &ray);
152};
153
154
155class SpatialBoxBasedDistribution: public SamplingStrategy
156{
157 public:
158  HaltonSequence mHalton;
159  SpatialBoxBasedDistribution(Preprocessor &preprocessor):
160        SamplingStrategy(preprocessor){
161        mType = DIRECTION_BOX_BASED_DISTRIBUTION;
162  }
163 
164private:
165           virtual bool GenerateSample(SimpleRay &ray);
166};
167
168
169class ViewSpaceBorderBasedDistribution: public SamplingStrategy
170{
171 public:
172         ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
173           SamplingStrategy(preprocessor){
174           mType = SPATIAL_BOX_BASED_DISTRIBUTION;
175         }
176         
177private:
178         virtual bool GenerateSample(SimpleRay &ray);
179};
180
181
182class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
183{
184 public:
185         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
186           SamplingStrategy(preprocessor){
187           mType = SPATIAL_BOX_BASED_DISTRIBUTION;
188         }
189         
190private:
191         virtual bool GenerateSample(SimpleRay &ray);
192};
193
194
195
196
197class ViewCellBorderBasedDistribution: public SamplingStrategy
198{
199 public:
200  ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
201        SamplingStrategy(preprocessor) {}
202 
203  virtual bool GenerateSample(SimpleRay &ray);
204};
205
206class GlobalLinesDistribution: public SamplingStrategy
207{
208public:
209  //Halton<4> halton;
210  HaltonSequence mHalton;
211
212  GlobalLinesDistribution(Preprocessor &preprocessor):
213        SamplingStrategy(preprocessor) {
214        mType = GLOBAL_LINES_DISTRIBUTION;
215  }
216 
217  virtual bool GenerateSample(SimpleRay &ray);
218};
219
220
221/** This strategy generates samples inside of the objects, e.g.,
222        for sampling the inside of a colon.
223*/
224/*class ObjectsInteriorDistribution: public SamplingStrategy
225{
226 public:
227         ObjectsInteriorDistribution(Preprocessor &preprocessor):
228         SamplingStrategy(preprocessor) {}
229         
230         virtual bool GenerateSample(SimpleRay &ray);
231};
232*/
233
234class MixtureDistribution : public SamplingStrategy {
235public:
236  // halton sequence generator for deciding between distributions
237  HaltonSequence mHalton;
238 
239  // container for the distributions
240  vector<SamplingStrategy *> mDistributions;
241
242  MixtureDistribution(Preprocessor &preprocessor):
243        SamplingStrategy(preprocessor)
244  {
245  }
246
247  // has to called before first usage
248  void Init();
249
250  // equalize distribution contributions
251  void
252  Reset();
253 
254  // Generate a new sample according to a mixture distribution
255  virtual bool GenerateSample(SimpleRay &ray);
256
257  // add contributions of the sample to the strategies
258  void ComputeContributions(VssRayContainer &vssRays);
259
260  void
261  UpdateRatios();
262
263 
264};
265
266};
267
268#endif
Note: See TracBrowser for help on using the repository browser.