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

Revision 1883, 6.0 KB checked in by bittner, 18 years ago (diff)

mixture distribution initial coding

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