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