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