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