[1460] | 1 | #ifndef _GvsPreprocessor_H__
|
---|
| 2 | #define _GvsPreprocessor_H__
|
---|
| 3 |
|
---|
| 4 | #include <fstream>
|
---|
[1473] | 5 | #include <stack>
|
---|
[1460] | 6 | using namespace std;
|
---|
| 7 |
|
---|
| 8 | #include "Preprocessor.h"
|
---|
| 9 |
|
---|
| 10 | namespace GtpVisibilityPreprocessor {
|
---|
| 11 |
|
---|
| 12 | class Exporter;
|
---|
[1473] | 13 | class VssRay;
|
---|
[1460] | 14 |
|
---|
[1934] | 15 | /** View space partition statistics.
|
---|
| 16 | */
|
---|
| 17 | class GvsStatistics: public StatisticsBase
|
---|
| 18 | {
|
---|
| 19 | public:
|
---|
| 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 | }
|
---|
[1473] | 37 |
|
---|
[1489] | 38 |
|
---|
[1934] | 39 | public:
|
---|
| 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 |
|
---|
[1473] | 59 | /** Sampling based visibility preprocessing. The implementation is
|
---|
| 60 | based on heuristical sampling of view space.
|
---|
| 61 | */
|
---|
[1460] | 62 | class GvsPreprocessor : public Preprocessor {
|
---|
| 63 |
|
---|
| 64 | public:
|
---|
[1473] | 65 |
|
---|
| 66 | GvsPreprocessor();
|
---|
| 67 | ~GvsPreprocessor() {}
|
---|
| 68 |
|
---|
| 69 | virtual bool ComputeVisibility();
|
---|
| 70 |
|
---|
| 71 |
|
---|
[1460] | 72 | protected:
|
---|
[1500] | 73 | #if 0
|
---|
[1492] | 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;
|
---|
[1500] | 85 | #endif
|
---|
| 86 | typedef stack<VssRay *> RayQueue;
|
---|
[1492] | 87 |
|
---|
[1489] | 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).
|
---|
[1473] | 92 |
|
---|
| 93 | @returns the number of samples cast.
|
---|
| 94 | */
|
---|
[1489] | 95 | int ProcessQueue();
|
---|
[1473] | 96 |
|
---|
[1489] | 97 | /** One pass of the sampling preprocessor.
|
---|
| 98 | Continues as long as at least passSample rays have been cast.
|
---|
[1473] | 99 | @returns the number of samples cast.
|
---|
| 100 | */
|
---|
[1486] | 101 | int Pass();
|
---|
[1473] | 102 |
|
---|
| 103 | /** Generates the rays starting the adaptive visibility sampling process.
|
---|
| 104 | */
|
---|
[1489] | 105 | int CastInitialSamples(const int numSamples, const int sampleType);
|
---|
[1473] | 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 | */
|
---|
[1521] | 116 | bool HandleRay(VssRay *ray);
|
---|
[1473] | 117 |
|
---|
[1489] | 118 | /** The adaptive border sampling step. It aims to find neighbouring
|
---|
[1500] | 119 | triangles of the one hit by the current ray.
|
---|
[1473] | 120 | */
|
---|
[1500] | 121 | int AdaptiveBorderSampling(const VssRay ¤tRay);
|
---|
[1473] | 122 |
|
---|
[1489] | 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 | */
|
---|
[1500] | 128 | VssRay *ReverseSampling(const VssRay ¤tRay,
|
---|
| 129 | const Triangle3 &hitTriangle,
|
---|
| 130 | const VssRay &oldRay);
|
---|
[1473] | 131 |
|
---|
[1500] | 132 | /** Returns true if we sampled a closer triangle than with the previous ray.
|
---|
| 133 | Does reverse sampling if gap found.
|
---|
[1473] | 134 | */
|
---|
[1500] | 135 | bool CheckDiscontinuity(const VssRay ¤tRay,
|
---|
| 136 | const Triangle3 &hitTriangle,
|
---|
| 137 | const VssRay &oldRay);
|
---|
[1473] | 138 |
|
---|
[1489] | 139 | /** Adds new samples to the ray queue and classifies them
|
---|
| 140 | with respect to the previous ray.
|
---|
| 141 | */
|
---|
[1500] | 142 | void EnqueueRays(VssRayContainer &samples);
|
---|
| 143 |
|
---|
[1522] | 144 | /** Hepler function for adaptive border sampling. It finds
|
---|
[1500] | 145 | new sample points around a triangle in a eps environment
|
---|
| 146 | */
|
---|
| 147 | void EnlargeTriangle(VertexContainer &vertices,
|
---|
| 148 | const Triangle3 &hitTriangle,
|
---|
[1932] | 149 | const VssRay &ray) const;
|
---|
[1500] | 150 |
|
---|
[1932] | 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);
|
---|
[1500] | 157 |
|
---|
[1522] | 158 | void Visualize();
|
---|
[1545] | 159 |
|
---|
[1932] | 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 ¤tRay,
|
---|
| 171 | const Triangle3 &hitTriangle,
|
---|
| 172 | const VssRay &oldRay) const;
|
---|
| 173 |
|
---|
[1473] | 174 | //////////////////////
|
---|
| 175 |
|
---|
[1486] | 176 |
|
---|
[1473] | 177 | int mSamplesPerPass;
|
---|
[1545] | 178 | int mTotalSamples;
|
---|
| 179 | int mInitialSamples;
|
---|
| 180 |
|
---|
[1473] | 181 | RayQueue mRayQueue;
|
---|
| 182 | int mSamplingType;
|
---|
[1545] | 183 |
|
---|
[1563] | 184 | //AxisAlignedBox3 mViewSpaceBox;
|
---|
[1486] | 185 | float mEps;
|
---|
[1500] | 186 | float mThreshold;
|
---|
[1522] | 187 | VssRayContainer mVssRays;
|
---|
[1545] | 188 |
|
---|
| 189 | ///////////
|
---|
| 190 | // stats
|
---|
[1932] | 191 |
|
---|
[1934] | 192 | /*int mSampleContriPerPass;
|
---|
[1533] | 193 | int mTotalSampleContri;
|
---|
| 194 | int mReverseSamples;
|
---|
| 195 | int mBorderSamples;
|
---|
[1934] | 196 | int mGvsPass;*/
|
---|
[1932] | 197 |
|
---|
[1934] | 198 | ofstream mGvsStatsStream;
|
---|
| 199 | GvsStatistics mGvsStats;
|
---|
| 200 |
|
---|
| 201 | bool mOnlyRandomSampling;
|
---|
[1460] | 202 | };
|
---|
| 203 |
|
---|
| 204 | };
|
---|
| 205 |
|
---|
| 206 | #endif
|
---|