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

Revision 2615, 5.9 KB checked in by mattausch, 16 years ago (diff)

did some stuff for the visualization

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