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