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