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

Revision 1492, 2.9 KB checked in by mattausch, 18 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
16
17/** Sampling based visibility preprocessing. The implementation is
18        based on heuristical sampling of view space.
19*/
20class GvsPreprocessor : public Preprocessor {
21
22public:
23
24        GvsPreprocessor();
25        ~GvsPreprocessor() {}
26
27        virtual bool ComputeVisibility();
28       
29
30protected:
31
32        struct GvsRayInfo
33        {
34                GvsRayInfo(VssRay *ray, const bool d)
35                        : mRay(ray), mFoundDiscontinuity(d)
36                {}
37
38                VssRay *mRay;
39                bool mFoundDiscontinuity;
40        };
41
42        typedef stack<GvsRayInfo> RayQueue;
43
44        struct PendingRay
45        {
46                PendingRay(VssRay *ray, const bool d)
47                        : mRay(ray), mFoundDiscontinuity(d)
48                {}
49
50                VssRay *mRay;
51                bool mFoundDiscontinuity;
52        };
53
54        typedef stack<PendingRay> PendingQueue;
55
56        /** Runs the adaptive sampling until the ray queue is empty.
57                The method starts with a number of random rays given
58                by the queue and continues as long it finds new visible geometry
59                (i.e., the queue is     not empty).
60
61                @returns the number of samples cast.
62        */
63        int ProcessQueue();
64
65        /** One pass of the sampling preprocessor.
66                Continues as long as at least passSample rays have been cast.
67                @returns the number of samples cast.
68        */
69        int Pass();
70
71        /** Generates the rays starting the adaptive visibility sampling process.
72        */
73        int CastInitialSamples(const int numSamples, const int sampleType);
74
75        /** Uses the information gained from the ray for doing adaptive border sampling.
76                This function tries to find the border of the triangle found visible by the
77                current ray. New rays are generated which sample this border.
78               
79                We use the following strategies:
80
81                a) if new triangle was found: adaptive border sampling
82                b) if triangle was found reverse sampling
83        */
84        int HandleRay(const GvsRayInfo &ray);
85
86        /** The adaptive border sampling step. It aims to find neighbouring
87                triangles of the one hit by the previous ray.
88        */     
89        int AdaptiveBorderSampling(const VssRay &prevRay);
90       
91        /** The reverse sampling step. It is started once the cast
92                ray finds a discontinuity, i.e., a closer triangle.
93                Then the process tries to find a ray from the old
94                triangle passing through a gap.
95        */
96        int ReverseSampling(const VssRay &prevRay);
97
98        /** Returns true if we sampled a closer triangle than with the previous ray.
99        */
100        const bool DiscontinuityFound(const VssRay &ray, const VssRay &prevRay) const;
101
102        /** Adds new samples to the ray queue and classifies them
103                with respect to the previous ray.
104        */
105        void EnqueueRays(VssRayContainer &samples, VssRay *prevRay = NULL);
106       
107        //////////////////////
108
109        ofstream mStats;
110
111        int mSamplesPerPass;
112        RayQueue mRayQueue;
113        int mSamplingType;
114        int mTotalSamples;
115        int mInitialSamples;
116        AxisAlignedBox3 mViewSpaceBox;
117        float mEps;
118};
119
120};
121
122#endif
Note: See TracBrowser for help on using the repository browser.