source: GTP/trunk/Lib/Vis/Preprocessing/src/ReverseGvs.h @ 2546

Revision 2546, 4.3 KB checked in by mattausch, 17 years ago (diff)

added new sampling strategies

RevLine 
[2546]1#ifndef _ReverserGvs_H__
2#define _ReverseGvs_H__
3
4#include <vector>
5//
6
7#include "common.h"
8#include "Halton.h"
9
10namespace GtpVisibilityPreprocessor {
11
12class Vector2;
13class Vector3;
14class VssRay;
15class Preprocessor;
16struct SimpleRay;
17class SimpleRayContainer;
18
19struct VssRayContainer;
20
21
22/** This algorithm can be best described as Reverse Guided Visibility Sampling. We exchange the roles of
23        objects (triangles in gvs) and view cells, in order to make Gvs feasible for
24        global sampling (where all view cells are updated in parallel).
25       
26        Algorithm idea:
27
28        We loop through the objects (instead of the view cells). For each object, there s a directional
29        random sampling step, which will find some view cells. This is again dual to Gvs.
30       
31        The view cells found in the first step are used as a seed in order to grow visibility regions towards
32        neighbouring view cells.
33        We use guided samples from the object towards these neighbouring view cells. Subsequently the algorithm
34        would explore the boundaries of the view cells where the object can still be seen. This is dual to
35        the border sampling step of Gvs.
36       
37        There will also be a reverse sampling step. We take a new point on the object, abd connect it to a view cell
38        found invisible by the border sampling. This would only make sense if the objects are reasonable large.
39       
40        The new algorithm would fully explore the global nature of the sampling. The progressive quality of the
41        algorithm could be more emphasised by looping through the objects in some kind of importance fashion,
42        where the importance comes from an initial estimate of the #view cells the object can be seen from.
43*/
44class ReverseGvs: public SamplingStrategy
45{
46public:
47  ReverseGvs(Preprocessor &preprocessor);
48  virtual void Update(VssRayContainer &vssRays);
49
50  virtual bool RequiresRays() { return true; }
51
52private:
53  virtual bool GenerateSample(SimpleRay &ray);
54
55  bool
56  GenerateMutation(const int index, SimpleRay &ray);
57
58  bool
59  GenerateMutationCandidate(const int index,
60                                                        SimpleRay &ray,
61                                                        Intersectable *object,
62                                                        const AxisAlignedBox3 &box
63                                                        );
64
65
66 
67  struct RayEntry {
68        // halton sequence for generatin gmutations of this ray
69        VssRay *mRay;
70        short mMutations;
71        short mUnsuccessfulMutations;
72        //      Halton<4> mHalton;
73        HaltonSequence mHalton;
74        float mImportance;
75        float mCdf;
76
77        Vector3 mutatedOrigin;
78        Vector3 mutatedTermination;
79       
80        float GetSamplingFactor() const { return mMutations/mImportance; }
81       
82        friend bool operator<(const RayEntry &a, const RayEntry &b) {
83          return a.GetSamplingFactor() > b.GetSamplingFactor();
84        }
85       
86        RayEntry() {}
87        RayEntry(VssRay *r):mRay(r),
88                                                mMutations(0),
89                                                mUnsuccessfulMutations(0),
90                                                mHalton(),
91                                                mImportance(1.0f)
92        {
93          ResetReverseMutation();
94        }
95
96        void ResetReverseMutation() {
97          mutatedOrigin = mutatedTermination = Vector3(0,0,0);
98        }
99        bool HasReverseMutation() const {
100          return !(mutatedOrigin == mutatedTermination);
101        }
102       
103        void SetReverseMutation(const Vector3 &a, const Vector3 &b) {
104          mutatedOrigin = a;
105          mutatedTermination = b;
106        }
107
108  };
109 
110
111  Vector3
112  ComputeOriginMutation(const VssRay &ray,
113                                                const Vector3 &U,
114                                                const Vector3 &V,
115                                                const Vector2 vr2,
116                                                const float radius
117                                                );
118
119  Vector3
120  ComputeTerminationMutation(const VssRay &ray,
121                                                         const Vector3 &U,
122                                                         const Vector3 &V,
123                                                         const Vector2 vr2,
124                                                         const float radius
125                                                         );
126
127
128  Vector3
129  ComputeSilhouetteTerminationMutation(const VssRay &ray,
130                                                                           const Vector3 &origin,
131                                                                           const AxisAlignedBox3 &box,
132                                                                           const Vector3 &U,
133                                                                           const Vector3 &V,
134                                                                           const float radius
135                                                                           );
136
137
138  bool
139  ComputeReverseMutation(
140                                                 const VssRay &oldRay,
141                                                 const VssRay &newRay,
142                                                 Vector3 &origin,
143                                                 Vector3 &termination
144                                                 );
145
146  RayEntry &GetEntry(const int index);
147
148 
149  vector<RayEntry> mRays;
150  int mBufferStart;
151  int mLastIndex;
152
153
154  int mMaxRays;
155  float mMutationRadiusOrigin;
156  float mMutationRadiusTermination;
157  bool mUseReverseSamples;
158  float mReverseSamplesDistance;
159  bool mUseSilhouetteSamples;
160  int mSilhouetteSearchSteps;
161  float mSilhouetteProb;
162  bool mUsePassImportance;
163  bool mUseUnsuccCountImportance;
164
165};
166
167
168}
169
170#endif
171
Note: See TracBrowser for help on using the repository browser.