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

Revision 1934, 4.7 KB checked in by mattausch, 18 years ago (diff)

gvs preprocessor is basicly working

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