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

Revision 2176, 5.9 KB checked in by mattausch, 17 years ago (diff)

removed using namespace std from .h

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