[1237] | 1 | #ifndef _HierarchyManager_H__
|
---|
| 2 | #define _HierarchyManager_H__
|
---|
| 3 |
|
---|
| 4 | #include <stack>
|
---|
| 5 |
|
---|
| 6 | #include "Mesh.h"
|
---|
| 7 | #include "Containers.h"
|
---|
| 8 | #include "Statistics.h"
|
---|
| 9 | #include "VssRay.h"
|
---|
| 10 | #include "RayInfo.h"
|
---|
| 11 | #include "gzstream.h"
|
---|
[1239] | 12 | #include "SubdivisionCandidate.h"
|
---|
[1237] | 13 |
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | namespace GtpVisibilityPreprocessor {
|
---|
| 17 |
|
---|
| 18 | class ViewCellLeaf;
|
---|
| 19 | class OspTree;
|
---|
| 20 | class VspTree;
|
---|
| 21 | class Plane3;
|
---|
| 22 | class AxisAlignedBox3;
|
---|
| 23 | class Ray;
|
---|
| 24 | class ViewCellsStatistics;
|
---|
| 25 | class ViewCellsManager;
|
---|
| 26 | class MergeCandidate;
|
---|
| 27 | class Beam;
|
---|
| 28 | class ViewCellsTree;
|
---|
| 29 | class Environment;
|
---|
| 30 | class VspInterior;
|
---|
| 31 | class VspLeaf;
|
---|
| 32 | class VspNode;
|
---|
| 33 | class KdNode;
|
---|
| 34 | class KdInterior;
|
---|
| 35 | class KdLeaf;
|
---|
| 36 | class OspTree;
|
---|
| 37 | class KdIntersectable;
|
---|
| 38 | class KdTree;
|
---|
| 39 | class VspTree;
|
---|
| 40 | class KdTreeStatistics;
|
---|
[1259] | 41 | class BvHierarchy;
|
---|
[1287] | 42 | class Exporter;
|
---|
[1667] | 43 | class ViewCellsParseHandlers;
|
---|
[2094] | 44 | class TraversalTree;
|
---|
[2116] | 45 | class ObjectPvs;
|
---|
[1237] | 46 |
|
---|
[1667] | 47 |
|
---|
[2237] | 48 | #define COUNT_ORIGIN_OBJECTS 1
|
---|
[2227] | 49 | #define USE_AVGRAYCONTRI 0
|
---|
[1911] | 50 |
|
---|
[2227] | 51 | #define BOUND_RENDERCOST 0
|
---|
[1911] | 52 |
|
---|
[2227] | 53 | static const float MIN_RENDERCOST = 100.0f;
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 |
|
---|
[1551] | 57 | /** View space / object space hierarchy statistics.
|
---|
[1288] | 58 | */
|
---|
| 59 | class HierarchyStatistics: public StatisticsBase
|
---|
| 60 | {
|
---|
| 61 | public:
|
---|
[1576] | 62 | /// total number of entries in the pvs
|
---|
[1624] | 63 | int mPvsEntries;
|
---|
[1640] | 64 | /// storage cost in MB
|
---|
| 65 | float mMemory;
|
---|
[1288] | 66 | /// total number of nodes
|
---|
[1624] | 67 | int mNodes;
|
---|
[1288] | 68 | /// maximal reached depth
|
---|
[1624] | 69 | int mMaxDepth;
|
---|
[1288] | 70 | /// accumulated depth
|
---|
[1624] | 71 | int mAccumDepth;
|
---|
[1449] | 72 | /// time spent for queue repair
|
---|
[1624] | 73 | float mRepairTime;
|
---|
| 74 |
|
---|
[1449] | 75 | // global cost ratio violations
|
---|
| 76 | int mGlobalCostMisses;
|
---|
[1624] | 77 | /// total cost of subdivision
|
---|
| 78 | float mTotalCost;
|
---|
| 79 | /// render cost decrease of subdivision
|
---|
| 80 | float mRenderCostDecrease;
|
---|
[1313] | 81 |
|
---|
[1288] | 82 | // Constructor
|
---|
| 83 | HierarchyStatistics()
|
---|
| 84 | {
|
---|
| 85 | Reset();
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[1624] | 88 | int Nodes() const {return mNodes;}
|
---|
[1640] | 89 | int Interior() const { return mNodes / 2 - 1; }
|
---|
[1624] | 90 | int Leaves() const { return (mNodes / 2) + 1; }
|
---|
[1288] | 91 |
|
---|
| 92 | // TODO: computation wrong
|
---|
[1624] | 93 | double AvgDepth() const { return mAccumDepth / (double)Leaves();}
|
---|
[1288] | 94 |
|
---|
[1449] | 95 | void Reset()
|
---|
[1288] | 96 | {
|
---|
[1449] | 97 | mGlobalCostMisses = 0;
|
---|
[1624] | 98 | mTotalCost = 0;
|
---|
| 99 | mRenderCostDecrease = 0;
|
---|
| 100 |
|
---|
| 101 | mNodes = 0;
|
---|
| 102 | mMaxDepth = 0;
|
---|
| 103 | mAccumDepth = 0;
|
---|
| 104 | mRepairTime = 0;
|
---|
| 105 | mMemory = 0;
|
---|
| 106 | mPvsEntries = 0;
|
---|
[1288] | 107 | }
|
---|
| 108 |
|
---|
[2176] | 109 | void Print(std::ostream &app) const;
|
---|
[1288] | 110 |
|
---|
[2176] | 111 | friend std::ostream &operator<<(std::ostream &s, const HierarchyStatistics &stat)
|
---|
[1288] | 112 | {
|
---|
| 113 | stat.Print(s);
|
---|
| 114 | return s;
|
---|
| 115 | }
|
---|
| 116 | };
|
---|
| 117 |
|
---|
| 118 |
|
---|
[1723] | 119 | class HierarchySubdivisionStats
|
---|
| 120 | {
|
---|
| 121 | public:
|
---|
| 122 |
|
---|
| 123 | int mNumSplits;
|
---|
| 124 |
|
---|
| 125 | float mRenderCostDecrease;
|
---|
| 126 |
|
---|
| 127 | float mTotalRenderCost;
|
---|
| 128 |
|
---|
| 129 | int mEntriesInPvs;
|
---|
| 130 |
|
---|
| 131 | float mMemoryCost;
|
---|
| 132 |
|
---|
| 133 | float mFullMemory;
|
---|
| 134 |
|
---|
| 135 | int mViewSpaceSplits;
|
---|
| 136 |
|
---|
| 137 | int mObjectSpaceSplits;
|
---|
| 138 |
|
---|
[1744] | 139 | float mPriority;
|
---|
[1723] | 140 |
|
---|
| 141 | float VspOspRatio() const { return (float)mViewSpaceSplits / (float)mObjectSpaceSplits; }
|
---|
| 142 |
|
---|
| 143 | float FpsPerMb() const { return 1.0f / (mTotalRenderCost * mMemoryCost); }
|
---|
| 144 |
|
---|
| 145 | HierarchySubdivisionStats() { Reset(); }
|
---|
| 146 |
|
---|
| 147 | void Reset()
|
---|
| 148 | {
|
---|
| 149 | mNumSplits = 0;
|
---|
| 150 | mRenderCostDecrease = 0;
|
---|
| 151 | mTotalRenderCost = 0;
|
---|
| 152 | mEntriesInPvs = 0;
|
---|
| 153 | mMemoryCost = 0;
|
---|
| 154 | mFullMemory = 0;
|
---|
| 155 | mViewSpaceSplits = 0;
|
---|
| 156 | mObjectSpaceSplits = 0;
|
---|
[1744] | 157 | mPriority = 0;
|
---|
[1723] | 158 | }
|
---|
| 159 |
|
---|
| 160 |
|
---|
[2176] | 161 | void Print(std::ostream &app) const;
|
---|
[1723] | 162 |
|
---|
[2176] | 163 | friend std::ostream &operator<<(std::ostream &s, const HierarchySubdivisionStats &stat)
|
---|
[1723] | 164 | {
|
---|
| 165 | stat.Print(s);
|
---|
| 166 | return s;
|
---|
| 167 | }
|
---|
| 168 | };
|
---|
| 169 |
|
---|
| 170 |
|
---|
[1237] | 171 | /** This class implements a structure holding two different hierarchies,
|
---|
| 172 | one for object space partitioning and one for view space partitioning.
|
---|
| 173 |
|
---|
| 174 | The object space and the view space are subdivided using a cost heuristics.
|
---|
| 175 | If an object space split or a view space split is chosen is also evaluated
|
---|
| 176 | based on the heuristics.
|
---|
| 177 |
|
---|
| 178 | The view space heuristics is evaluated by weighting and adding the pvss of the back and
|
---|
| 179 | front node of each specific split. unlike for the standalone method vspbsp tree,
|
---|
| 180 | the pvs of an object would not be the pvs of single object but that of all objects
|
---|
| 181 | which are contained in the same leaf of the object subdivision. This could be done
|
---|
| 182 | by storing the pointer to the object space partition parent, which would allow access to all children.
|
---|
| 183 | Another possibility is to include traced kd-cells in the ray casing process.
|
---|
| 184 |
|
---|
| 185 | Accordingly, the object space heuristics is evaluated by storing a pvs of view cells with each object.
|
---|
| 186 | the contribution to an object to the pvs is the number of view cells it can be seen from.
|
---|
| 187 |
|
---|
| 188 | @note
|
---|
| 189 | There is a potential efficiency problem involved in a sense that once a certain type
|
---|
| 190 | of split is chosen for view space / object space, the candidates for the next split of
|
---|
| 191 | object space / view space must be reevaluated.
|
---|
| 192 | */
|
---|
| 193 | class HierarchyManager
|
---|
| 194 | {
|
---|
[2124] | 195 | friend class VspOspViewCellsManager;
|
---|
| 196 |
|
---|
[1237] | 197 | public:
|
---|
[2124] | 198 |
|
---|
[1421] | 199 | /** Constructor with the view space partition tree and
|
---|
| 200 | the object space hierarchy type as argument.
|
---|
[1237] | 201 | */
|
---|
[1421] | 202 | HierarchyManager(const int objectSpaceHierarchyType);
|
---|
[2124] | 203 |
|
---|
[1279] | 204 | /** Hack: OspTree will copy the content from this kd tree.
|
---|
| 205 | Only view space hierarchy will be constructed.
|
---|
| 206 | */
|
---|
[1421] | 207 | HierarchyManager(KdTree *kdTree);
|
---|
[1237] | 208 |
|
---|
[1421] | 209 | /** Deletes space partition and view space partition.
|
---|
| 210 | */
|
---|
[1286] | 211 | ~HierarchyManager();
|
---|
| 212 |
|
---|
[1237] | 213 | /** Constructs the view space and object space subdivision from a given set of rays
|
---|
| 214 | and a set of objects.
|
---|
| 215 | @param sampleRays the set of sample rays the construction is based on
|
---|
| 216 | @param objects the set of objects
|
---|
| 217 | */
|
---|
[1308] | 218 | void Construct(
|
---|
[1293] | 219 | const VssRayContainer &sampleRays,
|
---|
| 220 | const ObjectContainer &objects,
|
---|
| 221 | AxisAlignedBox3 *forcedViewSpace);
|
---|
[1237] | 222 |
|
---|
[1259] | 223 | enum
|
---|
| 224 | {
|
---|
| 225 | NO_OBJ_SUBDIV,
|
---|
| 226 | KD_BASED_OBJ_SUBDIV,
|
---|
| 227 | BV_BASED_OBJ_SUBDIV
|
---|
| 228 | };
|
---|
[1237] | 229 |
|
---|
[1370] | 230 | enum
|
---|
| 231 | {
|
---|
| 232 | NO_VIEWSPACE_SUBDIV,
|
---|
| 233 | KD_BASED_VIEWSPACE_SUBDIV
|
---|
| 234 | };
|
---|
| 235 |
|
---|
[1259] | 236 | /** The type of object space subdivison
|
---|
| 237 | */
|
---|
[1370] | 238 | int GetObjectSpaceSubdivisionType() const;
|
---|
[2003] | 239 |
|
---|
[1370] | 240 | /** The type of view space space subdivison
|
---|
| 241 | */
|
---|
| 242 | int GetViewSpaceSubdivisionType() const;
|
---|
[2003] | 243 |
|
---|
[1370] | 244 | /** Sets a pointer to the view cells manager.
|
---|
| 245 | */
|
---|
[1279] | 246 | void SetViewCellsManager(ViewCellsManager *vcm);
|
---|
[2003] | 247 |
|
---|
[1370] | 248 | /** Sets a pointer to the view cells tree.
|
---|
| 249 | */
|
---|
[1279] | 250 | void SetViewCellsTree(ViewCellsTree *vcTree);
|
---|
[2003] | 251 |
|
---|
[1370] | 252 | /** Exports the object hierarchy to disc.
|
---|
| 253 | */
|
---|
[1279] | 254 | void ExportObjectSpaceHierarchy(OUT_STREAM &stream);
|
---|
[1764] | 255 |
|
---|
[1421] | 256 | /** Print out statistics.
|
---|
| 257 | */
|
---|
[2176] | 258 | void PrintHierarchyStatistics(std::ostream &stream) const;
|
---|
[1279] | 259 |
|
---|
[1421] | 260 | /** Returns the view space partition tree.
|
---|
| 261 | */
|
---|
[1379] | 262 | VspTree *GetVspTree();
|
---|
[1279] | 263 |
|
---|
[1421] | 264 | /** Returns object space bounding box.
|
---|
| 265 | */
|
---|
[1416] | 266 | AxisAlignedBox3 GetObjectSpaceBox() const;
|
---|
[1379] | 267 |
|
---|
[1421] | 268 | /** Exports object space hierarchy for visualization.
|
---|
| 269 | */
|
---|
[1626] | 270 | void ExportObjectSpaceHierarchy(Exporter *exporter,
|
---|
| 271 | const ObjectContainer &objects,
|
---|
[1764] | 272 | AxisAlignedBox3 *bbox,
|
---|
[1920] | 273 | const float maxRenderCost,
|
---|
[1626] | 274 | const bool exportBounds = true) const;
|
---|
[1279] | 275 |
|
---|
[1421] | 276 | /** Returns intersectable pierced by this ray.
|
---|
| 277 | */
|
---|
[1626] | 278 | Intersectable *GetIntersectable(const VssRay &ray, const bool isTermination) const;
|
---|
[1743] | 279 |
|
---|
[1889] | 280 | Intersectable *GetIntersectable(Intersectable *obj, const Vector3 &point) const;
|
---|
| 281 |
|
---|
[1626] | 282 | /** Export object space partition bounding boxes.
|
---|
| 283 | */
|
---|
| 284 | void ExportBoundingBoxes(OUT_STREAM &stream, const ObjectContainer &objects);
|
---|
| 285 |
|
---|
[2176] | 286 | friend std::ostream &operator<<(std::ostream &s, const HierarchyManager &hm)
|
---|
[1419] | 287 | {
|
---|
[1421] | 288 | hm.PrintHierarchyStatistics(s);
|
---|
[1419] | 289 | return s;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
[1667] | 292 | HierarchyStatistics &GetHierarchyStats() { return mHierarchyStats; };
|
---|
| 293 |
|
---|
| 294 | inline bool ConsiderMemory() const { return mConsiderMemory; }
|
---|
[1686] | 295 |
|
---|
| 296 | void EvaluateSubdivision(const VssRayContainer &sampleRays,
|
---|
| 297 | const ObjectContainer &objects,
|
---|
[2176] | 298 | const std::string &filename);
|
---|
[1676] | 299 |
|
---|
[2176] | 300 | void EvaluateSubdivision2(std::ofstream &splitsStats,
|
---|
[1745] | 301 | const int splitsStepSize,
|
---|
[1919] | 302 | const bool useFilter,
|
---|
| 303 | const bool useHisto,
|
---|
| 304 | const int histoMem,
|
---|
| 305 | const int pass);
|
---|
[1709] | 306 |
|
---|
| 307 |
|
---|
[1718] | 308 | void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects);
|
---|
| 309 |
|
---|
[1845] | 310 | int CompressObjectSpace();
|
---|
[1843] | 311 | void CreateUniqueObjectIds();
|
---|
| 312 |
|
---|
[1912] | 313 | float EvalCorrectedPvs(const float pvsFront,
|
---|
| 314 | const float totalPvs,
|
---|
[2227] | 315 | const float raysPerObjects) const;
|
---|
[1843] | 316 |
|
---|
[1686] | 317 |
|
---|
[2094] | 318 | /** Casts line segment into the view cells tree.
|
---|
| 319 | @param origin the origin of the line segment
|
---|
| 320 | @param termination the end point of the line segment
|
---|
| 321 | @returns view cells intersecting the line segment.
|
---|
| 322 | */
|
---|
| 323 | int CastLineSegment(const Vector3 &origin,
|
---|
| 324 | const Vector3 &termination,
|
---|
| 325 | ViewCellContainer &viewcells,
|
---|
| 326 | const bool useMailboxing = true);
|
---|
| 327 |
|
---|
[1237] | 328 | protected:
|
---|
| 329 |
|
---|
[2187] | 330 | void PrintTimings(const bool osp);
|
---|
| 331 |
|
---|
[1625] | 332 | /** Returns true if the global termination criteria were met.
|
---|
| 333 | */
|
---|
[1237] | 334 | bool GlobalTerminationCriteriaMet(SubdivisionCandidate *candidate) const;
|
---|
| 335 |
|
---|
| 336 | /** Prepare construction of the hierarchies, set parameters, compute
|
---|
| 337 | first split candidates.
|
---|
| 338 | */
|
---|
[1779] | 339 | void PrepareObjectSpaceSubdivision(SplitQueue &tQueue,
|
---|
| 340 | const VssRayContainer &sampleRays,
|
---|
| 341 | const ObjectContainer &objects);
|
---|
[1237] | 342 |
|
---|
[1625] | 343 |
|
---|
[1640] | 344 | /** Create bounding box and root.
|
---|
| 345 | */
|
---|
| 346 | void InitialiseObjectSpaceSubdivision(const ObjectContainer &objects);
|
---|
| 347 |
|
---|
| 348 | /** Returns memory usage of object space hierarchy.
|
---|
| 349 | */
|
---|
| 350 | float GetObjectSpaceMemUsage() const;
|
---|
| 351 |
|
---|
[1667] | 352 |
|
---|
[1625] | 353 | //////////////////////////////
|
---|
| 354 | // the main loop
|
---|
| 355 |
|
---|
| 356 | /** This is for interleaved construction / sequential construction.
|
---|
| 357 | */
|
---|
| 358 | void RunConstruction(const bool repairQueue,
|
---|
| 359 | const VssRayContainer &sampleRays,
|
---|
| 360 | const ObjectContainer &objects,
|
---|
[1640] | 361 | AxisAlignedBox3 *forcedViewSpace);
|
---|
[1449] | 362 |
|
---|
[1625] | 363 | /** This is for interleaved construction using some objects
|
---|
| 364 | and some view space splits.
|
---|
| 365 | */
|
---|
| 366 | int RunConstruction(SplitQueue &splitQueue,
|
---|
| 367 | SubdivisionCandidateContainer &chosenCandidates,
|
---|
[1667] | 368 | //const float minRenderCostDecr,
|
---|
| 369 | SubdivisionCandidate *oldCandidate,
|
---|
[1676] | 370 | const int minSteps,
|
---|
| 371 | const int maxSteps);
|
---|
[1625] | 372 |
|
---|
| 373 | /** Default subdivision method.
|
---|
| 374 | */
|
---|
[1449] | 375 | void RunConstruction(const bool repairQueue);
|
---|
[2094] | 376 |
|
---|
| 377 |
|
---|
[1625] | 378 | ////////////////////////////////////////////////
|
---|
| 379 |
|
---|
[1580] | 380 | /** Evaluates the subdivision candidate and executes the split.
|
---|
| 381 | */
|
---|
[1625] | 382 | bool ApplySubdivisionCandidate(SubdivisionCandidate *sc,
|
---|
| 383 | SplitQueue &splitQueue,
|
---|
[2224] | 384 | //const bool repairQueue,
|
---|
| 385 | std::vector<SubdivisionCandidate *> &dirtyList
|
---|
| 386 | );
|
---|
[1237] | 387 |
|
---|
[1625] | 388 | /** Tests if hierarchy construction is finished.
|
---|
| 389 | */
|
---|
[1237] | 390 | bool FinishedConstruction() const;
|
---|
| 391 |
|
---|
[1625] | 392 | /** Returns next subdivision candidate from the split queue.
|
---|
| 393 | */
|
---|
| 394 | SubdivisionCandidate *NextSubdivisionCandidate(SplitQueue &splitQueue);
|
---|
[1237] | 395 |
|
---|
[1625] | 396 | /** Repairs the dirty entries of the subdivision candidate queue. The
|
---|
| 397 | list of entries is given in the dirty list.
|
---|
[1736] | 398 |
|
---|
| 399 | @returns number of repaired candidates
|
---|
[1580] | 400 | */
|
---|
[1736] | 401 | int RepairQueue(const SubdivisionCandidateContainer &dirtyList,
|
---|
| 402 | SplitQueue &splitQueue,
|
---|
| 403 | const bool recomputeSplitPlaneOnRepair);
|
---|
[1237] | 404 |
|
---|
[1625] | 405 | /** Collect subdivision candidates which were affected by the splits from the
|
---|
| 406 | chosenCandidates list.
|
---|
| 407 | */
|
---|
| 408 | void CollectDirtyCandidates(const SubdivisionCandidateContainer &chosenCandidates,
|
---|
| 409 | SubdivisionCandidateContainer &dirtyList);
|
---|
| 410 |
|
---|
[1580] | 411 | /** Evaluate subdivision stats for log.
|
---|
| 412 | */
|
---|
[1624] | 413 | void EvalSubdivisionStats();
|
---|
[1237] | 414 |
|
---|
[1625] | 415 | void AddSubdivisionStats(const int splits,
|
---|
| 416 | const float renderCostDecr,
|
---|
| 417 | const float totalRenderCost,
|
---|
| 418 | const int totalPvsEntries,
|
---|
[1640] | 419 | const float memory,
|
---|
[1654] | 420 | const float renderCostPerStorage,
|
---|
| 421 | const float vspOspRatio);
|
---|
[1237] | 422 |
|
---|
[1625] | 423 | /** Collect affected view space candidates.
|
---|
| 424 | */
|
---|
| 425 | void CollectViewSpaceDirtyList(SubdivisionCandidate *sc,
|
---|
| 426 | SubdivisionCandidateContainer &dirtyList);
|
---|
[1259] | 427 |
|
---|
[1625] | 428 | /** Collect affected object space candidates.
|
---|
| 429 | */
|
---|
| 430 | void CollectObjectSpaceDirtyList(SubdivisionCandidate *sc,
|
---|
| 431 | SubdivisionCandidateContainer &dirtyList);
|
---|
[1259] | 432 |
|
---|
[1625] | 433 | /** Export object space partition tree.
|
---|
| 434 | */
|
---|
| 435 | void ExportOspTree(Exporter *exporter,
|
---|
| 436 | const ObjectContainer &objects) const;
|
---|
[1259] | 437 |
|
---|
[1625] | 438 | /** Parse the environment variables.
|
---|
| 439 | */
|
---|
[1418] | 440 | void ParseEnvironment();
|
---|
[1415] | 441 |
|
---|
[1418] | 442 | bool StartObjectSpaceSubdivision() const;
|
---|
| 443 | bool StartViewSpaceSubdivision() const;
|
---|
| 444 |
|
---|
[1667] | 445 |
|
---|
[1625] | 446 | ////////////////////////////
|
---|
| 447 | // Helper function for preparation of subdivision
|
---|
[1286] | 448 |
|
---|
[1625] | 449 | /** Prepare bv hierarchy for subdivision
|
---|
| 450 | */
|
---|
[1779] | 451 | void PrepareBvHierarchy(SplitQueue &tQueue,
|
---|
| 452 | const VssRayContainer &sampleRays,
|
---|
| 453 | const ObjectContainer &objects);
|
---|
[1286] | 454 |
|
---|
[1625] | 455 | /** Prepare object space kd tree for subdivision.
|
---|
| 456 | */
|
---|
[1779] | 457 | void PrepareOspTree(SplitQueue &tQueue,
|
---|
| 458 | const VssRayContainer &sampleRays,
|
---|
| 459 | const ObjectContainer &objects);
|
---|
[1308] | 460 |
|
---|
[1625] | 461 | /** Prepare view space subdivision and add candidate to queue.
|
---|
| 462 | */
|
---|
[1779] | 463 | void PrepareViewSpaceSubdivision(SplitQueue &tQueue,
|
---|
| 464 | const VssRayContainer &sampleRays,
|
---|
| 465 | const ObjectContainer &objects);
|
---|
[1625] | 466 |
|
---|
| 467 | /** Was object space subdivision already constructed?
|
---|
| 468 | */
|
---|
[1313] | 469 | bool ObjectSpaceSubdivisionConstructed() const;
|
---|
[1625] | 470 |
|
---|
| 471 | /** Was view space subdivision already constructed?
|
---|
| 472 | */
|
---|
[1329] | 473 | bool ViewSpaceSubdivisionConstructed() const;
|
---|
[1311] | 474 |
|
---|
[1625] | 475 | /** Reset the split queue, i.e., reevaluate the split candidates.
|
---|
| 476 | */
|
---|
[1640] | 477 | void ResetQueue(SplitQueue &splitQueue, const bool recomputeSplitPlane);
|
---|
[1313] | 478 |
|
---|
[1625] | 479 | /** After the suddivision has ended, do some final tasks.
|
---|
| 480 | */
|
---|
[1654] | 481 | void FinishObjectSpaceSubdivision(const ObjectContainer &objects,
|
---|
| 482 | const bool removeRayRefs = true) const;
|
---|
[1313] | 483 |
|
---|
[1625] | 484 | /** Returns depth of object space subdivision.
|
---|
| 485 | */
|
---|
[1370] | 486 | int GetObjectSpaceSubdivisionDepth() const;
|
---|
| 487 |
|
---|
[1640] | 488 | /** Returns number of leaves in object space subdivision.
|
---|
| 489 | */
|
---|
| 490 | int GetObjectSpaceSubdivisionLeaves() const;
|
---|
[1663] | 491 | int GetObjectSpaceSubdivisionNodes() const;
|
---|
[1640] | 492 |
|
---|
[1625] | 493 | /** Construct object space partition interleaved with view space partition.
|
---|
| 494 | Each time the best object or view space candidate is selected
|
---|
| 495 | for the next split.
|
---|
| 496 | */
|
---|
[1626] | 497 | void ConstructInterleaved(const VssRayContainer &sampleRays,
|
---|
| 498 | const ObjectContainer &objects,
|
---|
| 499 | AxisAlignedBox3 *forcedViewSpace);
|
---|
[1449] | 500 |
|
---|
[1625] | 501 | /** Construct object space partition interleaved with view space partition.
|
---|
| 502 | The method chooses a number candidates of each type for subdivision.
|
---|
| 503 | The number is determined by the "gradient", i.e., the render cost decrease.
|
---|
| 504 | Once this render cost decrease is lower than the render cost decrease
|
---|
| 505 | for the splits of previous type, the method will stop current subdivision and
|
---|
| 506 | evaluate if view space or object space would be the beneficial for the
|
---|
| 507 | next number of split.
|
---|
| 508 | */
|
---|
[1626] | 509 | void ConstructInterleavedWithGradient(const VssRayContainer &sampleRays,
|
---|
| 510 | const ObjectContainer &objects,
|
---|
| 511 | AxisAlignedBox3 *forcedViewSpace);
|
---|
[1624] | 512 |
|
---|
[1548] | 513 | /** Use iteration to construct the object space hierarchy.
|
---|
| 514 | */
|
---|
[1626] | 515 | void ConstructMultiLevel(const VssRayContainer &sampleRays,
|
---|
| 516 | const ObjectContainer &objects,
|
---|
| 517 | AxisAlignedBox3 *forcedViewSpace);
|
---|
[1449] | 518 |
|
---|
[1640] | 519 | /** Based on a given subdivision, we try to optimize using an
|
---|
| 520 | multiple iteration over view and object space.
|
---|
| 521 | */
|
---|
| 522 | void OptimizeMultiLevel(const VssRayContainer &sampleRays,
|
---|
| 523 | const ObjectContainer &objects,
|
---|
| 524 | AxisAlignedBox3 *forcedViewSpace);
|
---|
| 525 |
|
---|
[1548] | 526 | /** Reset the object space subdivision.
|
---|
| 527 | E.g., deletes hierarchy and resets stats.
|
---|
| 528 | so construction can be restarted.
|
---|
| 529 | */
|
---|
[1779] | 530 | void ResetObjectSpaceSubdivision(SplitQueue &tQueue,
|
---|
| 531 | const VssRayContainer &rays,
|
---|
| 532 | const ObjectContainer &objects);
|
---|
[1449] | 533 |
|
---|
[1779] | 534 | void ResetViewSpaceSubdivision(SplitQueue &tQueue,
|
---|
| 535 | const VssRayContainer &rays,
|
---|
| 536 | const ObjectContainer &objects,
|
---|
| 537 | AxisAlignedBox3 *forcedViewSpace);
|
---|
[1557] | 538 |
|
---|
[2073] | 539 | void CreateTraversalTree();
|
---|
[1614] | 540 |
|
---|
[1686] | 541 | ///////////////////////////
|
---|
[1680] | 542 |
|
---|
[2176] | 543 | void ExportStats(std::ofstream &stats,
|
---|
[1779] | 544 | SplitQueue &tQueue,
|
---|
| 545 | const ObjectContainer &objects);
|
---|
[1686] | 546 |
|
---|
[1706] | 547 | void CollectBestSet(const int maxSplits,
|
---|
| 548 | const float maxMemoryCost,
|
---|
[1707] | 549 | ViewCellContainer &viewCells,
|
---|
[1706] | 550 | vector<BvhNode *> &bvhNodes);
|
---|
| 551 |
|
---|
[1713] | 552 | int ExtractStatistics(const int maxSplits,
|
---|
| 553 | const float maxMemoryCost,
|
---|
| 554 | float &renderCost,
|
---|
| 555 | float &memory,
|
---|
[1718] | 556 | int &pvsEntries,
|
---|
| 557 | int &viewSpaceSplits,
|
---|
[1745] | 558 | int &objectSpaceSplits,
|
---|
[1919] | 559 | const bool useFilter,
|
---|
| 560 | const bool useHisto,
|
---|
| 561 | const int histoMem,
|
---|
| 562 | const int pass,
|
---|
| 563 | bool &histoUsed);
|
---|
[1709] | 564 |
|
---|
[1745] | 565 | void ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries);
|
---|
[1787] | 566 | void GetPvsIncrementially(ViewCell *vc, ObjectPvs &pvs) const;
|
---|
[1786] | 567 | void PullUpPvsIncrementally(ViewCell *viewCell) const;
|
---|
| 568 | void GetPvsRecursive(ViewCell *vc, ObjectPvs &pvs) const;
|
---|
[1787] | 569 | void GetPvsEfficiently(ViewCell *vc, ObjectPvs &pvs) const;
|
---|
| 570 |
|
---|
[1830] | 571 | float EvalFullMem() const;
|
---|
| 572 |
|
---|
[1843] | 573 |
|
---|
[1237] | 574 | protected:
|
---|
| 575 |
|
---|
[1627] | 576 | /** construction types
|
---|
| 577 | sequential: construct first view space, then object space
|
---|
| 578 | interleaved: construct view space and object space fully interleaved
|
---|
| 579 | gradient: construct view space / object space until a threshold is reached
|
---|
| 580 | multilevel: iterate until subdivisions converge to the optimum.
|
---|
| 581 | */
|
---|
| 582 | enum {SEQUENTIAL, INTERLEAVED, GRADIENT, MULTILEVEL};
|
---|
| 583 |
|
---|
[1580] | 584 | /// type of hierarchy construction
|
---|
| 585 | int mConstructionType;
|
---|
| 586 |
|
---|
| 587 | /// Type of object space partition
|
---|
[1308] | 588 | int mObjectSpaceSubdivisionType;
|
---|
[1580] | 589 | /// Type of view space partition
|
---|
[1329] | 590 | int mViewSpaceSubdivisionType;
|
---|
| 591 |
|
---|
[1589] | 592 | /// the traversal queue
|
---|
| 593 | SplitQueue mTQueue;
|
---|
| 594 |
|
---|
[1580] | 595 | ////////////
|
---|
| 596 | //-- helper variables
|
---|
| 597 |
|
---|
| 598 | // the original osp type
|
---|
[1323] | 599 | int mSavedObjectSpaceSubdivisionType;
|
---|
[1580] | 600 | // the original vsp type
|
---|
[1329] | 601 | int mSavedViewSpaceSubdivisionType;
|
---|
[1911] | 602 |
|
---|
[1323] | 603 |
|
---|
[1580] | 604 | ///////////////////
|
---|
| 605 | // Hierarchies
|
---|
| 606 |
|
---|
| 607 | /// view space hierarchy
|
---|
[1259] | 608 | VspTree *mVspTree;
|
---|
[1580] | 609 | /// object space partition kd tree
|
---|
[1259] | 610 | OspTree *mOspTree;
|
---|
[1625] | 611 |
|
---|
[1911] | 612 | float mInitialRenderCost;
|
---|
| 613 |
|
---|
[2227] | 614 | //float mMaxAvgRayContri;
|
---|
| 615 | //float mMinAvgRayContri;
|
---|
[1911] | 616 |
|
---|
[2227] | 617 | float mMaxAvgRaysPerObject;
|
---|
| 618 | float mMinAvgRaysPerObject;
|
---|
[1911] | 619 |
|
---|
[1895] | 620 | // quick hack:
|
---|
| 621 | public:
|
---|
[1580] | 622 | /// bounding volume hierarchy
|
---|
[1259] | 623 | BvHierarchy *mBvHierarchy;
|
---|
[1580] | 624 |
|
---|
[2130] | 625 | bool mUseTraversalTree;
|
---|
| 626 |
|
---|
[2228] | 627 | float mMinRenderCost;
|
---|
| 628 |
|
---|
[1589] | 629 | protected:
|
---|
[1237] | 630 |
|
---|
| 631 |
|
---|
[1580] | 632 | //////////
|
---|
[1576] | 633 | //-- global termination criteria
|
---|
| 634 |
|
---|
[1580] | 635 | /// the mininal acceptable cost ratio for a split
|
---|
[1237] | 636 | float mTermMinGlobalCostRatio;
|
---|
[1580] | 637 | /// the threshold for global cost miss tolerance
|
---|
[1237] | 638 | int mTermGlobalCostMissTolerance;
|
---|
[1580] | 639 | /// maximum number of leaves
|
---|
| 640 | int mTermMaxLeaves;
|
---|
[1649] | 641 | /// Maximal allowed memory consumption.
|
---|
| 642 | float mTermMaxMemory;
|
---|
[1580] | 643 |
|
---|
[1667] | 644 |
|
---|
[1576] | 645 | ////////////////////
|
---|
| 646 |
|
---|
[1667] | 647 | /// number of minimal steps of the same type
|
---|
[1640] | 648 | int mMinStepsOfSameType;
|
---|
[1684] | 649 | int mMaxStepsOfSameType;
|
---|
[1640] | 650 |
|
---|
[1580] | 651 | /// statistics about the hierarchy
|
---|
[1288] | 652 | HierarchyStatistics mHierarchyStats;
|
---|
| 653 |
|
---|
[1308] | 654 | int mMinDepthForObjectSpaceSubdivion;
|
---|
[1370] | 655 | int mMinDepthForViewSpaceSubdivion;
|
---|
[1580] | 656 |
|
---|
[1625] | 657 | //int mMinRenderCostDecrease;
|
---|
[1624] | 658 |
|
---|
[2176] | 659 | std::ofstream mSubdivisionStats;
|
---|
[1314] | 660 |
|
---|
[1580] | 661 | /// if the queue should be repaired after a subdivision steps
|
---|
[1314] | 662 | bool mRepairQueue;
|
---|
[1370] | 663 |
|
---|
| 664 | bool mStartWithObjectSpace;
|
---|
[1580] | 665 | /** if multi level construction method should be used
|
---|
| 666 | where we iterate over both hierarchies until we
|
---|
| 667 | converge to the optimum.
|
---|
| 668 | */
|
---|
[1449] | 669 | bool mUseMultiLevelConstruction;
|
---|
[1640] | 670 |
|
---|
[1580] | 671 | /// number of iteration steps for multilevel approach
|
---|
| 672 | int mNumMultiLevels;
|
---|
[1640] | 673 |
|
---|
[1633] | 674 | /** if split plane should be recomputed for the repair.
|
---|
| 675 | Otherwise only the priority is recomputed, the
|
---|
| 676 | split plane itself stays the same
|
---|
| 677 | */
|
---|
| 678 | bool mRecomputeSplitPlaneOnRepair;
|
---|
[1662] | 679 |
|
---|
| 680 | /** If memory should be considered during choosing
|
---|
| 681 | of the next split type during gradient method.
|
---|
| 682 | */
|
---|
| 683 | bool mConsiderMemory;
|
---|
[1666] | 684 |
|
---|
[2094] | 685 | TraversalTree *mTraversalTree;
|
---|
| 686 |
|
---|
[1727] | 687 | int mMaxRepairs;
|
---|
| 688 |
|
---|
[1679] | 689 | int mTimeStamp;
|
---|
[1667] | 690 | friend VspTree;
|
---|
| 691 | friend OspTree;
|
---|
| 692 | friend BvHierarchy;
|
---|
[1744] | 693 |
|
---|
| 694 | float mPriority;
|
---|
| 695 |
|
---|
[1667] | 696 | friend ViewCellsParseHandlers;
|
---|
| 697 |
|
---|
[1750] | 698 | ViewCellContainer mOldViewCells;
|
---|
[1237] | 699 | };
|
---|
| 700 |
|
---|
| 701 | }
|
---|
| 702 |
|
---|
| 703 | #endif
|
---|