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

Revision 1974, 8.3 KB checked in by bittner, 18 years ago (diff)

mutation updates, ray sorting, merge

RevLine 
[1020]1#ifndef _SamplingStategy_H__
2#define _SamplingStategy_H__
3
[1883]4#include <vector>
5using namespace std;
6
[1867]7#include "Halton.h"
[1020]8namespace GtpVisibilityPreprocessor {
9
[1974]10class Vector2;
11class Vector3;
12class VssRay;
[1020]13class Preprocessor;
14struct SimpleRay;
[1771]15class SimpleRayContainer;
[1974]16
[1888]17struct VssRayContainer;
[1020]18
19/** This class generates a specific sampling strategy.
20*/
21class SamplingStrategy
22{
[1772]23public:
[1020]24
[1772]25        /** Sample rays of particular type
26        */
27        enum
28        {
[1968]29                DUMMY_DISTRIBUTION = 0,
30                DIRECTION_BASED_DISTRIBUTION,
[1772]31                OBJECT_BASED_DISTRIBUTION,
32                DIRECTION_BOX_BASED_DISTRIBUTION,
33                SPATIAL_BOX_BASED_DISTRIBUTION,
[1883]34                VSS_BASED_DISTRIBUTION,
[1772]35                RSS_BASED_DISTRIBUTION,
36                RSS_SILHOUETTE_BASED_DISTRIBUTION,
37                OBJECT_DIRECTION_BASED_DISTRIBUTION,
38                OBJECTS_INTERIOR_DISTRIBUTION,
39                REVERSE_OBJECT_BASED_DISTRIBUTION,
40                VIEWCELL_BORDER_BASED_DISTRIBUTION,
41                VIEWSPACE_BORDER_BASED_DISTRIBUTION,
[1824]42                REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION,
[1968]43                GLOBAL_LINES_DISTRIBUTION,
44                GVS,
45                MUTATION_BASED_DISTRIBUTION,
46                HW_GLOBAL_LINES_DISTRIBUTION
[1772]47        };
[1520]48
[1772]49        /** Default constructor
50        */
[1884]51        SamplingStrategy(Preprocessor &preprocessor);
[1020]52
[1772]53        virtual ~SamplingStrategy();
54
55        /** Each strategy has to implement this function.
56        @returns true if generated valid sample.
57        */
58
[1867]59        virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
[1772]60
[1867]61        virtual bool GenerateSample(SimpleRay &ray) = 0;
[1020]62
[1964]63        // true if the strategy keeps pointers to rays and thus they should get deleted
64        // outside, in that case the strategy has to use reference counting and deleting the rays
65        // by itself if the number of references drops to zero
66        virtual bool RequiresRays() { return false; }
[1884]67
[1900]68
[1964]69        virtual void Update(VssRayContainer &vssRays) {}
[1884]70
[1964]71        friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
72                return a->mRatio < b->mRatio;
73        }
[1884]74
[1771]75public:
[1898]76
[1900]77  /// variables usefull for mixed distribution sampling
78  int mType;
79  int mRays;
80  float mContribution;
81 
82  int mTotalRays;
[1966]83  int mGeneratedRays;
[1900]84  float mTotalContribution;
85 
86  float mTime;
87  float mRatio;
[1772]88
[1020]89protected:
[1772]90
[1901]91        //static HaltonSequence sHalton;
[1898]92        Preprocessor &mPreprocessor;
[1020]93};
94
95
96class ObjectBasedDistribution: public SamplingStrategy
97{
98 public:
[1899]99 
[1877]100 
[1884]101  ObjectBasedDistribution(Preprocessor &preprocessor):
[1771]102        SamplingStrategy(preprocessor) {
103        mType = OBJECT_BASED_DISTRIBUTION;
104  }
[1020]105
[1771]106private:
[1901]107 
108        virtual bool GenerateSample(SimpleRay &ray);
109    static HaltonSequence sHalton;
[1020]110};
111
112
[1695]113class ReverseObjectBasedDistribution: public SamplingStrategy
114{
115 public:
116       
[1884]117         ReverseObjectBasedDistribution(Preprocessor &preprocessor):
[1771]118           SamplingStrategy(preprocessor) {
119           mType = REVERSE_OBJECT_BASED_DISTRIBUTION;
120         }
[1695]121
[1771]122private:
[1901]123       
124        virtual bool GenerateSample(SimpleRay &ray);
[1695]125};
126
127
[1020]128class ObjectDirectionBasedDistribution: public SamplingStrategy
129{
[1883]130 
131public:
[1884]132         ObjectDirectionBasedDistribution(Preprocessor &preprocessor):
[1771]133         SamplingStrategy(preprocessor) {
134           mType = OBJECT_DIRECTION_BASED_DISTRIBUTION;
135         }
[1899]136
[1771]137private:
[1899]138
139        static HaltonSequence sHalton;
[1867]140        virtual bool GenerateSample(SimpleRay &ray);
[1020]141};
142
143
144class DirectionBasedDistribution: public SamplingStrategy
145{
146 public:
[1884]147  DirectionBasedDistribution(Preprocessor &preprocessor):
[1771]148        SamplingStrategy(preprocessor){
149        mType = DIRECTION_BASED_DISTRIBUTION;
150  }
151private:
[1867]152  virtual bool GenerateSample(SimpleRay &ray);
[1952]153  static HaltonSequence sHalton;
[1020]154};
155
156
157class DirectionBoxBasedDistribution: public SamplingStrategy
158{
159 public:
[1884]160         DirectionBoxBasedDistribution(Preprocessor &preprocessor):
[1771]161           SamplingStrategy(preprocessor){
162           mType = DIRECTION_BOX_BASED_DISTRIBUTION;
163         }
[1020]164           
[1771]165private:
[1867]166           virtual bool GenerateSample(SimpleRay &ray);
[1020]167};
168
169
170class SpatialBoxBasedDistribution: public SamplingStrategy
171{
172 public:
[1899]173         
174         SpatialBoxBasedDistribution(Preprocessor &preprocessor):
[1867]175        SamplingStrategy(preprocessor){
[1891]176        mType = SPATIAL_BOX_BASED_DISTRIBUTION;
[1867]177  }
178 
[1772]179private:
[1901]180       
181        virtual bool GenerateSample(SimpleRay &ray);
182        static HaltonSequence sHalton;
[1772]183};
184
185
186class ViewSpaceBorderBasedDistribution: public SamplingStrategy
187{
188 public:
[1884]189         ViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]190           SamplingStrategy(preprocessor){
[1891]191           mType = VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1771]192         }
[1020]193         
[1771]194private:
[1901]195
[1867]196         virtual bool GenerateSample(SimpleRay &ray);
[1020]197};
198
[1772]199
200class ReverseViewSpaceBorderBasedDistribution: public SamplingStrategy
201{
202 public:
[1884]203         ReverseViewSpaceBorderBasedDistribution(Preprocessor &preprocessor):
[1772]204           SamplingStrategy(preprocessor){
[1891]205           mType = REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION;
[1772]206         }
207         
208private:
[1867]209         virtual bool GenerateSample(SimpleRay &ray);
[1772]210};
211
212
[1763]213class ViewCellBorderBasedDistribution: public SamplingStrategy
214{
215 public:
[1884]216  ViewCellBorderBasedDistribution(Preprocessor &preprocessor):
[1891]217        SamplingStrategy(preprocessor) {
218        mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
219
220  }
[1899]221
222private:
[1867]223  virtual bool GenerateSample(SimpleRay &ray);
[1763]224};
225
[1952]226class MutationBasedDistribution: public SamplingStrategy
227{
228public:
229  MutationBasedDistribution(Preprocessor &preprocessor);
230  virtual void Update(VssRayContainer &vssRays);
231
232  virtual bool RequiresRays() { return true; }
233
234private:
235  virtual bool GenerateSample(SimpleRay &ray);
[1966]236
[1952]237  struct RayEntry {
[1966]238        // halton sequence for generatin gmutations of this ray
[1952]239        VssRay *mRay;
240        int mSamples;
[1966]241        HaltonSequence mHalton;
[1974]242        float mImportance;
243        float mCdf;
[1966]244
[1974]245        float GetSamplingFactor() const { return mSamples/mImportance; }
[1966]246        RayEntry() {}
[1974]247        RayEntry(VssRay *r):mRay(r), mSamples(0), mHalton(), mImportance(1.0f) {}
[1952]248  };
[1974]249
250
251  Vector3
252  ComputeOriginMutation(const VssRay &ray,
253                                                const Vector3 &U,
254                                                const Vector3 &V,
255                                                const Vector2 vr2,
256                                                const float radius
257                                                );
258
259  Vector3
260  ComputeTerminationMutation(const VssRay &ray,
261                                                         const Vector3 &U,
262                                                         const Vector3 &V,
263                                                         const Vector2 vr2,
264                                                         const float radius
265                                                         );
266
267  RayEntry &GetEntry(const int index) {
268        return mRays[(mBufferStart+index)%mRays.size()];
269  }
[1952]270 
271  vector<RayEntry> mRays;
272  int mMaxRays;
273  float mOriginMutationSize;
274  int mBufferStart;
275  int mLastIndex;
276};
277
[1824]278class GlobalLinesDistribution: public SamplingStrategy
279{
280public:
[1899]281 
[1884]282  GlobalLinesDistribution(Preprocessor &preprocessor):
[1867]283        SamplingStrategy(preprocessor) {
284        mType = GLOBAL_LINES_DISTRIBUTION;
285  }
[1824]286 
[1899]287private:
288
[1901]289        virtual bool GenerateSample(SimpleRay &ray);
290        static HaltonSequence sHalton;
[1824]291};
[1763]292
[1824]293
[1964]294class HwGlobalLinesDistribution: public SamplingStrategy
295{
296public:
297 
298  HwGlobalLinesDistribution(Preprocessor &preprocessor):
299        SamplingStrategy(preprocessor) {
300        //mType = HW_GLOBAL_LINES_DISTRIBUTION;
301  }
302 
303private:
304
305        virtual bool GenerateSample(SimpleRay &ray);
306        static HaltonSequence sHalton;
307};
308
[1020]309/** This strategy generates samples inside of the objects, e.g.,
310        for sampling the inside of a colon.
311*/
[1021]312/*class ObjectsInteriorDistribution: public SamplingStrategy
[1020]313{
314 public:
[1884]315         ObjectsInteriorDistribution(Preprocessor &preprocessor):
[1020]316         SamplingStrategy(preprocessor) {}
317         
[1867]318         virtual bool GenerateSample(SimpleRay &ray);
[1020]319};
[1021]320*/
[1883]321
[1899]322class MixtureDistribution: public SamplingStrategy
[1898]323{
[1883]324public:
[1899]325   
[1883]326  // container for the distributions
327  vector<SamplingStrategy *> mDistributions;
[1966]328 
[1884]329  MixtureDistribution(Preprocessor &preprocessor):
[1883]330        SamplingStrategy(preprocessor)
331  {
332  }
333
334  // has to called before first usage
335  void Init();
[1884]336
337  // equalize distribution contributions
338  void
339  Reset();
[1883]340 
341  // add contributions of the sample to the strategies
[1884]342  void ComputeContributions(VssRayContainer &vssRays);
343
[1942]344  // update distributions with new rays
345  // warning: some rays can get deleted (if maintained internally by the
346  // particular distribution)!
347  void UpdateDistributions(VssRayContainer &vssRays);
348
[1884]349  void
350  UpdateRatios();
351
[1901]352  // construct distribution mixture from a string describing the required distributions
[1891]353  bool
354  Construct(char *str);
355
[1900]356  virtual bool RequiresRays() {
[1949]357        for (int i=0; i < (int)mDistributions.size(); i++)
[1900]358          if (mDistributions[i]->RequiresRays())
359                return true;
360        return false;
361  }
[1966]362 
363  virtual int GenerateSamples(const int number, SimpleRayContainer &rays);
364 
[1899]365private:
366
[1901]367        // Generate a new sample according to a mixture distribution
368        virtual bool GenerateSample(SimpleRay &ray);
[1899]369
[1901]370        // halton sequence generator for deciding between distributions
371        static HaltonSequence sHalton;
[1020]372};
373
[1883]374};
375
[1020]376#endif
Note: See TracBrowser for help on using the repository browser.