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

Revision 2690, 6.5 KB checked in by mattausch, 16 years ago (diff)

strange errors!!

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