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