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