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

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