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

Revision 1990, 5.0 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        }
41
42
43public:
44
45        int mPass;
46        int mTotalSamples;
47        int mPassContribution;
48        int mTotalContribution;
49        int mReverseSamples;
50        int mBorderSamples;
51        int mGvsPass;
52       
53        int mTotalPvs;
54        int mViewCells;
55        int mPerViewCellSamples;
56               
57        void Print(ostream &app) const;
58
59        friend ostream &operator<<(ostream &s, const GvsStatistics &stat)
60        {
61                stat.Print(s);
62                return s;
63        }
64};
65
66
67/** Sampling based visibility preprocessing. The implementation is
68        based on heuristical sampling of view space.
69*/
70class GvsPreprocessor : public Preprocessor {
71
72public:
73
74        GvsPreprocessor();
75        ~GvsPreprocessor();
76
77        virtual bool ComputeVisibility();
78       
79
80protected:
81#if 0
82        struct PendingRay
83        {
84                PendingRay(VssRay *ray, const bool d)
85                        : mRay(ray), mFoundDiscontinuity(d)
86                {}
87
88                VssRay *mRay;
89                bool mFoundDiscontinuity;
90        };
91
92        typedef stack<PendingRay> PendingQueue;
93#endif
94        typedef stack<VssRay *> RayQueue;
95
96        /** Runs the adaptive sampling until the ray queue is empty.
97                The method starts with a number of random rays given
98                by the queue and continues as long it finds new visible geometry
99                (i.e., the queue is     not empty).
100
101                @returns the number of samples cast.
102        */
103        int ProcessQueue();
104
105        /** Generates the rays starting the adaptive visibility sampling process.
106        */
107        int CastInitialSamples(const int numSamples, const int sampleType);
108
109        /** Uses the information gained from the ray for doing adaptive border sampling.
110                This function tries to find the border of the triangle found visible by the
111                current ray. New rays are generated which sample this border.
112               
113                We use the following strategies:
114
115                a) if new triangle was found: adaptive border sampling
116                b) if triangle was found reverse sampling
117        */
118        bool HandleRay(VssRay *ray);
119
120        /** The adaptive border sampling step. It aims to find neighbouring
121                triangles of the one hit by the current ray.
122        */     
123        int AdaptiveBorderSampling(const VssRay &currentRay);
124       
125        /** The reverse sampling step. It is started once the cast
126                ray finds a discontinuity, i.e., a closer triangle.
127                Then the process tries to find a ray from the old
128                triangle passing through a gap.
129        */
130        VssRay *ReverseSampling(const VssRay &currentRay,
131                                                        const Triangle3 &hitTriangle,
132                                                        const VssRay &oldRay);
133
134        /** Returns true if we sampled a closer triangle than with the previous ray.
135                Does reverse sampling if gap found.
136        */
137        bool CheckDiscontinuity(const VssRay &currentRay,
138                                                        const Triangle3 &hitTriangle,
139                                                        const VssRay &oldRay);
140
141        /** Adds new samples to the ray queue and classifies them
142                with respect to the previous ray.
143        */
144        void EnqueueRays(VssRayContainer &samples);
145
146        /** Hepler function for adaptive border sampling. It finds
147                new sample points around a triangle in a eps environment
148        */
149        void EnlargeTriangle(VertexContainer &vertices,
150                                                 const Triangle3 &hitTriangle,
151                                                 const VssRay &ray) const;
152
153        int SubdivideEdge(const Triangle3 &hitTriangle,
154                                          const Vector3 &p1,
155                                          const Vector3 &p2,
156                                          const VssRay &ray1,
157                      const VssRay &ray2,
158                                          const VssRay &oldRay);
159
160        void Visualize();
161
162        void CreateDisplacedVertices(VertexContainer &vertices,
163                                                                 const Triangle3 &hitTriangle,
164                                                                 const VssRay &ray,
165                                                                 const int index) const;
166
167        Vector3 CalcPredictedHitPoint(const VssRay &newRay,
168                                                                  const Triangle3 &hitTriangle,
169                                                                  const VssRay &oldRay) const;
170
171
172        Vector3 GetPassingPoint(const VssRay &currentRay,
173                                                        const Triangle3 &hitTriangle,
174                                                        const VssRay &oldRay) const;
175
176        bool NextViewCell();
177
178        void GlobalComputation();
179
180        void PerViewCellComputation();
181
182        void VisualizeViewCells();
183
184        void VisualizeViewCell(ViewCell *vc);
185
186        /** Exchanges view cell triangle pvs with bvh leaf pvs.
187        */
188        void UpdatePvs(ViewCell *currentViewCell);
189
190        void ProcessViewCell();
191
192        //////////////////////
193
194
195        int mSamplesPerPass;
196        int mTotalSamples;
197        int mInitialSamples;
198
199        RayQueue mRayQueue;
200        int mSamplingType;
201
202        //AxisAlignedBox3 mViewSpaceBox;
203        float mEps;
204        float mThreshold;
205        VssRayContainer mVssRays;
206       
207        ///////////
208        // stats
209
210        /*int mSampleContriPerPass;
211        int mTotalSampleContri;
212        int mReverseSamples;
213        int mBorderSamples;
214        int mGvsPass;*/
215
216        ofstream mGvsStatsStream;
217        GvsStatistics mGvsStats;
218
219        bool mPerViewCell;
220        bool mOnlyRandomSampling;
221
222        ViewCell *mCurrentViewCell;
223
224        int mNumViewCells;
225};
226
227};
228
229#endif
Note: See TracBrowser for help on using the repository browser.