source: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h @ 1996

Revision 1996, 5.4 KB checked in by mattausch, 17 years ago (diff)
  • Property svn:executable set to *
Line 
1#ifndef _GvsPreprocessor_H__
2#define _GvsPreprocessor_H__
3
4#include <fstream>
5#include <stack>
6using namespace std;
7
8#include "Preprocessor.h"
9
10namespace GtpVisibilityPreprocessor {
11
12class Exporter;
13class VssRay;
14
15/** View space partition statistics.
16*/
17class GvsStatistics: public StatisticsBase
18{
19public:
20       
21        /// Constructor
22        GvsStatistics()
23        {
24                Reset();
25        }
26       
27        void Reset()
28        {
29                mPass = 0;
30                mTotalSamples = 0;
31                mPassContribution = 0;
32                mTotalContribution = 0;
33                mReverseSamples = 0;
34                mBorderSamples = 0;
35                mGvsPass = 0;
36
37                mTotalPvs = 0;
38                mViewCells = 0;
39                mPerViewCellSamples = 0;
40                mPerViewCellPvs = 0;
41                mTrianglePvs = 0;
42                mViewCellId = 0;
43        }
44
45
46public:
47
48        int mPass;
49        int mTotalSamples;
50        int mPassContribution;
51        int mTotalContribution;
52        int mReverseSamples;
53        int mBorderSamples;
54        int mGvsPass;
55       
56        int mTotalPvs;
57        int mViewCells;
58        int mPerViewCellSamples;
59        int mPerViewCellPvs;
60        int mTrianglePvs;
61        int mViewCellId;
62       
63        float RaysPerSec() const { if (!Time()) return 0; return (float)mTotalSamples / Time() * 1e-6f; }
64
65        void Print(ostream &app) const;
66
67        friend ostream &operator<<(ostream &s, const GvsStatistics &stat)
68        {
69                stat.Print(s);
70                return s;
71        }
72};
73
74
75/** Sampling based visibility preprocessing. The implementation is
76        based on heuristical sampling of view space.
77*/
78class GvsPreprocessor : public Preprocessor {
79
80public:
81
82        GvsPreprocessor();
83        ~GvsPreprocessor();
84
85        virtual bool ComputeVisibility();
86       
87
88protected:
89#if 0
90        struct PendingRay
91        {
92                PendingRay(VssRay *ray, const bool d)
93                        : mRay(ray), mFoundDiscontinuity(d)
94                {}
95
96                VssRay *mRay;
97                bool mFoundDiscontinuity;
98        };
99
100        typedef stack<PendingRay> PendingQueue;
101#endif
102        typedef stack<VssRay *> RayQueue;
103
104        /** Runs the adaptive sampling until the ray queue is empty.
105                The method starts with a number of random rays given
106                by the queue and continues as long it finds new visible geometry
107                (i.e., the queue is     not empty).
108
109                @returns the number of samples cast.
110        */
111        int ProcessQueue();
112
113        /** Generates the rays starting the adaptive visibility sampling process.
114        */
115        int CastInitialSamples(const int numSamples, const int sampleType);
116
117        /** Uses the information gained from the ray for doing adaptive border sampling.
118                This function tries to find the border of the triangle found visible by the
119                current ray. New rays are generated which sample this border.
120               
121                We use the following strategies:
122
123                a) if new triangle was found: adaptive border sampling
124                b) if triangle was found reverse sampling
125        */
126        bool HandleRay(VssRay *ray);
127
128        /** The adaptive border sampling step. It aims to find neighbouring
129                triangles of the one hit by the current ray.
130        */     
131        int AdaptiveBorderSampling(const VssRay &currentRay);
132       
133        /** The reverse sampling step. It is started once the cast
134                ray finds a discontinuity, i.e., a closer triangle.
135                Then the process tries to find a ray from the old
136                triangle passing through a gap.
137        */
138        VssRay *ReverseSampling(const VssRay &currentRay,
139                                                        const Triangle3 &hitTriangle,
140                                                        const VssRay &oldRay);
141
142        /** Returns true if we sampled a closer triangle than with the previous ray.
143                Does reverse sampling if gap found.
144        */
145        int CheckDiscontinuity(const VssRay &currentRay,
146                                                   const Triangle3 &hitTriangle,
147                                                   const VssRay &oldRay);
148
149        /** Adds new samples to the ray queue and classifies them
150                with respect to the previous ray.
151        */
152        void EnqueueRays(VssRayContainer &samples);
153
154        /** Hepler function for adaptive border sampling. It finds
155                new sample points around a triangle in a eps environment
156        */
157        void EnlargeTriangle(VertexContainer &vertices,
158                                                 const Triangle3 &hitTriangle,
159                                                 const VssRay &ray) const;
160
161        int SubdivideEdge(const Triangle3 &hitTriangle,
162                                          const Vector3 &p1,
163                                          const Vector3 &p2,
164                                          const VssRay &ray1,
165                      const VssRay &ray2,
166                                          const VssRay &oldRay);
167
168        void Visualize();
169
170        void CreateDisplacedVertices(VertexContainer &vertices,
171                                                                 const Triangle3 &hitTriangle,
172                                                                 const VssRay &ray,
173                                                                 const int index) const;
174
175        Vector3 CalcPredictedHitPoint(const VssRay &newRay,
176                                                                  const Triangle3 &hitTriangle,
177                                                                  const VssRay &oldRay) const;
178
179        bool GetPassingPoint(const VssRay &currentRay,
180                                                 const Triangle3 &occluder,
181                                                 const VssRay &oldRay,
182                                                 Vector3 &newPoint) const;
183
184        bool NextViewCell();
185
186        void GlobalComputation();
187
188        void PerViewCellComputation();
189
190        void VisualizeViewCells();
191
192        void VisualizeViewCell(ViewCell *vc);
193
194        /** Exchanges view cell triangle pvs with bvh leaf pvs.
195        */
196        void UpdatePvs(ViewCell *currentViewCell);
197
198        void ProcessViewCell();
199        void ClearRayQueue();
200
201        void CompileViewCellsList();
202
203
204        //////////////////////
205
206
207        int mSamplesPerPass;
208        int mTotalSamples;
209        int mInitialSamples;
210
211        RayQueue mRayQueue;
212        int mSamplingType;
213
214        //AxisAlignedBox3 mViewSpaceBox;
215        float mEps;
216        float mThreshold;
217        VssRayContainer mVssRays;
218       
219        ///////////
220        // stats
221
222        /*int mSampleContriPerPass;
223        int mTotalSampleContri;
224        int mReverseSamples;
225        int mBorderSamples;
226        int mGvsPass;*/
227
228        ofstream mGvsStatsStream;
229        GvsStatistics mGvsStats;
230
231        bool mPerViewCell;
232        bool mOnlyRandomSampling;
233
234        ViewCell *mCurrentViewCell;
235
236        int mProcessedViewCells;
237
238        int mMinContribution;
239
240        ViewCellContainer mViewCells;
241
242        int mMaxViewCells;
243};
244
245};
246
247#endif
Note: See TracBrowser for help on using the repository browser.