[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;
|
---|
[1990] | 36 |
|
---|
| 37 | mTotalPvs = 0;
|
---|
| 38 | mViewCells = 0;
|
---|
| 39 | mPerViewCellSamples = 0;
|
---|
[1934] | 40 | }
|
---|
[1473] | 41 |
|
---|
[1489] | 42 |
|
---|
[1934] | 43 | public:
|
---|
| 44 |
|
---|
| 45 | int mPass;
|
---|
| 46 | int mTotalSamples;
|
---|
| 47 | int mPassContribution;
|
---|
| 48 | int mTotalContribution;
|
---|
| 49 | int mReverseSamples;
|
---|
| 50 | int mBorderSamples;
|
---|
| 51 | int mGvsPass;
|
---|
[1990] | 52 |
|
---|
| 53 | int mTotalPvs;
|
---|
| 54 | int mViewCells;
|
---|
| 55 | int mPerViewCellSamples;
|
---|
[1934] | 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 |
|
---|
[1473] | 67 | /** Sampling based visibility preprocessing. The implementation is
|
---|
| 68 | based on heuristical sampling of view space.
|
---|
| 69 | */
|
---|
[1460] | 70 | class GvsPreprocessor : public Preprocessor {
|
---|
| 71 |
|
---|
| 72 | public:
|
---|
[1473] | 73 |
|
---|
| 74 | GvsPreprocessor();
|
---|
[1990] | 75 | ~GvsPreprocessor();
|
---|
[1473] | 76 |
|
---|
| 77 | virtual bool ComputeVisibility();
|
---|
| 78 |
|
---|
| 79 |
|
---|
[1460] | 80 | protected:
|
---|
[1500] | 81 | #if 0
|
---|
[1492] | 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;
|
---|
[1500] | 93 | #endif
|
---|
| 94 | typedef stack<VssRay *> RayQueue;
|
---|
[1492] | 95 |
|
---|
[1489] | 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).
|
---|
[1473] | 100 |
|
---|
| 101 | @returns the number of samples cast.
|
---|
| 102 | */
|
---|
[1489] | 103 | int ProcessQueue();
|
---|
[1473] | 104 |
|
---|
| 105 | /** Generates the rays starting the adaptive visibility sampling process.
|
---|
| 106 | */
|
---|
[1489] | 107 | int CastInitialSamples(const int numSamples, const int sampleType);
|
---|
[1473] | 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 | */
|
---|
[1521] | 118 | bool HandleRay(VssRay *ray);
|
---|
[1473] | 119 |
|
---|
[1489] | 120 | /** The adaptive border sampling step. It aims to find neighbouring
|
---|
[1500] | 121 | triangles of the one hit by the current ray.
|
---|
[1473] | 122 | */
|
---|
[1500] | 123 | int AdaptiveBorderSampling(const VssRay ¤tRay);
|
---|
[1473] | 124 |
|
---|
[1489] | 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 | */
|
---|
[1500] | 130 | VssRay *ReverseSampling(const VssRay ¤tRay,
|
---|
| 131 | const Triangle3 &hitTriangle,
|
---|
| 132 | const VssRay &oldRay);
|
---|
[1473] | 133 |
|
---|
[1500] | 134 | /** Returns true if we sampled a closer triangle than with the previous ray.
|
---|
| 135 | Does reverse sampling if gap found.
|
---|
[1473] | 136 | */
|
---|
[1500] | 137 | bool CheckDiscontinuity(const VssRay ¤tRay,
|
---|
| 138 | const Triangle3 &hitTriangle,
|
---|
| 139 | const VssRay &oldRay);
|
---|
[1473] | 140 |
|
---|
[1489] | 141 | /** Adds new samples to the ray queue and classifies them
|
---|
| 142 | with respect to the previous ray.
|
---|
| 143 | */
|
---|
[1500] | 144 | void EnqueueRays(VssRayContainer &samples);
|
---|
| 145 |
|
---|
[1522] | 146 | /** Hepler function for adaptive border sampling. It finds
|
---|
[1500] | 147 | new sample points around a triangle in a eps environment
|
---|
| 148 | */
|
---|
| 149 | void EnlargeTriangle(VertexContainer &vertices,
|
---|
| 150 | const Triangle3 &hitTriangle,
|
---|
[1932] | 151 | const VssRay &ray) const;
|
---|
[1500] | 152 |
|
---|
[1932] | 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);
|
---|
[1500] | 159 |
|
---|
[1522] | 160 | void Visualize();
|
---|
[1545] | 161 |
|
---|
[1932] | 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 ¤tRay,
|
---|
| 173 | const Triangle3 &hitTriangle,
|
---|
| 174 | const VssRay &oldRay) const;
|
---|
| 175 |
|
---|
[1982] | 176 | bool NextViewCell();
|
---|
| 177 |
|
---|
| 178 | void GlobalComputation();
|
---|
| 179 |
|
---|
| 180 | void PerViewCellComputation();
|
---|
| 181 |
|
---|
| 182 | void VisualizeViewCells();
|
---|
| 183 |
|
---|
[1990] | 184 | void VisualizeViewCell(ViewCell *vc);
|
---|
[1982] | 185 |
|
---|
[1990] | 186 | /** Exchanges view cell triangle pvs with bvh leaf pvs.
|
---|
| 187 | */
|
---|
| 188 | void UpdatePvs(ViewCell *currentViewCell);
|
---|
| 189 |
|
---|
| 190 | void ProcessViewCell();
|
---|
| 191 |
|
---|
[1473] | 192 | //////////////////////
|
---|
| 193 |
|
---|
[1486] | 194 |
|
---|
[1473] | 195 | int mSamplesPerPass;
|
---|
[1545] | 196 | int mTotalSamples;
|
---|
| 197 | int mInitialSamples;
|
---|
| 198 |
|
---|
[1473] | 199 | RayQueue mRayQueue;
|
---|
| 200 | int mSamplingType;
|
---|
[1545] | 201 |
|
---|
[1563] | 202 | //AxisAlignedBox3 mViewSpaceBox;
|
---|
[1486] | 203 | float mEps;
|
---|
[1500] | 204 | float mThreshold;
|
---|
[1522] | 205 | VssRayContainer mVssRays;
|
---|
[1545] | 206 |
|
---|
| 207 | ///////////
|
---|
| 208 | // stats
|
---|
[1932] | 209 |
|
---|
[1934] | 210 | /*int mSampleContriPerPass;
|
---|
[1533] | 211 | int mTotalSampleContri;
|
---|
| 212 | int mReverseSamples;
|
---|
| 213 | int mBorderSamples;
|
---|
[1934] | 214 | int mGvsPass;*/
|
---|
[1932] | 215 |
|
---|
[1934] | 216 | ofstream mGvsStatsStream;
|
---|
| 217 | GvsStatistics mGvsStats;
|
---|
| 218 |
|
---|
[1976] | 219 | bool mPerViewCell;
|
---|
[1934] | 220 | bool mOnlyRandomSampling;
|
---|
[1977] | 221 |
|
---|
| 222 | ViewCell *mCurrentViewCell;
|
---|
[1982] | 223 |
|
---|
| 224 | int mNumViewCells;
|
---|
[1460] | 225 | };
|
---|
| 226 |
|
---|
| 227 | };
|
---|
| 228 |
|
---|
| 229 | #endif
|
---|