[372] | 1 | #ifndef _ViewCell_H__
|
---|
| 2 | #define _ViewCell_H__
|
---|
| 3 |
|
---|
| 4 | #include "Mesh.h"
|
---|
| 5 | #include "Containers.h"
|
---|
| 6 | #include "Ray.h"
|
---|
[462] | 7 | #include "Statistics.h"
|
---|
[608] | 8 | #include "Material.h"
|
---|
[955] | 9 | #include "gzstream.h"
|
---|
[469] | 10 |
|
---|
[1010] | 11 |
|
---|
[860] | 12 | namespace GtpVisibilityPreprocessor {
|
---|
| 13 |
|
---|
[469] | 14 | struct Triangle3;
|
---|
| 15 |
|
---|
[372] | 16 | class BspInterior;
|
---|
| 17 | class BspPvs;
|
---|
| 18 | class BspLeaf;
|
---|
[1008] | 19 | class VspLeaf;
|
---|
[469] | 20 | class KdLeaf;
|
---|
[580] | 21 | class ViewCellInterior;
|
---|
| 22 | class MergeCandidate;
|
---|
| 23 | class ViewCellsManager;
|
---|
[881] | 24 | class ViewCellLeaf;
|
---|
[372] | 25 |
|
---|
[955] | 26 |
|
---|
[1264] | 27 |
|
---|
[479] | 28 | /** Statistics for a view cell partition.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | class ViewCellsStatistics: public StatisticsBase
|
---|
| 32 | {
|
---|
| 33 | public:
|
---|
| 34 |
|
---|
| 35 | /// number of view cells
|
---|
| 36 | int viewCells;
|
---|
[1709] | 37 | /// cost of the PVS
|
---|
| 38 | float pvsCost;
|
---|
[479] | 39 | /// largest PVS of all view cells
|
---|
[1709] | 40 | float maxPvs;
|
---|
[479] | 41 | /// smallest PVS of all view cells
|
---|
[1709] | 42 | float minPvs;
|
---|
[479] | 43 | /// view cells with empty PVS
|
---|
| 44 | int emptyPvs;
|
---|
| 45 | /// number of leaves covering the view space
|
---|
| 46 | int leaves;
|
---|
| 47 | /// largest number of leaves covered by one view cell
|
---|
| 48 | int maxLeaves;
|
---|
[1667] | 49 | /// number of invalid view cells
|
---|
[564] | 50 | int invalid;
|
---|
| 51 |
|
---|
[479] | 52 | // Constructor
|
---|
| 53 | ViewCellsStatistics()
|
---|
| 54 | {
|
---|
| 55 | Reset();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | double AvgLeaves() const {return (double)leaves / (double)viewCells;};
|
---|
[1709] | 59 | double AvgPvs() const {return (double)pvsCost / (double)viewCells;};
|
---|
[479] | 60 |
|
---|
| 61 | void Reset()
|
---|
| 62 | {
|
---|
| 63 | viewCells = 0;
|
---|
[1709] | 64 | pvsCost = 0;
|
---|
[479] | 65 | maxPvs = 0;
|
---|
| 66 |
|
---|
| 67 | minPvs = 999999;
|
---|
| 68 | emptyPvs = 0;
|
---|
| 69 | leaves = 0;
|
---|
| 70 | maxLeaves = 0;
|
---|
[564] | 71 | invalid = 0;
|
---|
[479] | 72 | }
|
---|
| 73 |
|
---|
| 74 | void Print(ostream &app) const;
|
---|
| 75 |
|
---|
| 76 | friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat)
|
---|
| 77 | {
|
---|
| 78 | stat.Print(s);
|
---|
| 79 | return s;
|
---|
| 80 | }
|
---|
| 81 | };
|
---|
| 82 |
|
---|
[580] | 83 |
|
---|
[1709] | 84 | class ViewCellsTreeStats
|
---|
| 85 | {
|
---|
| 86 | public:
|
---|
| 87 | int mPass;
|
---|
| 88 |
|
---|
| 89 | int mNumViewCells;
|
---|
| 90 |
|
---|
| 91 | float mRenderCostDecrease;
|
---|
| 92 |
|
---|
| 93 | float mTotalRenderCost;
|
---|
| 94 |
|
---|
| 95 | float mCurrentPvsCost;
|
---|
| 96 |
|
---|
| 97 | float mExpectedCost;
|
---|
| 98 |
|
---|
| 99 | float mAvgRenderCost;
|
---|
| 100 |
|
---|
| 101 | float mDeviation;
|
---|
| 102 |
|
---|
| 103 | float mTotalPvsCost;
|
---|
| 104 |
|
---|
| 105 | int mEntriesInPvs;
|
---|
| 106 |
|
---|
| 107 | float mMemoryCost;
|
---|
| 108 |
|
---|
| 109 | int mPvsSizeDecr;
|
---|
| 110 |
|
---|
| 111 | float mVolume;
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | void Reset()
|
---|
| 115 | {
|
---|
| 116 | mPass = 0;
|
---|
| 117 | mNumViewCells = 0;
|
---|
| 118 | mRenderCostDecrease = 0;
|
---|
| 119 | mTotalRenderCost = 0;
|
---|
| 120 | mCurrentPvsCost = 0;
|
---|
| 121 | mExpectedCost = 0;
|
---|
| 122 | mAvgRenderCost = 0;
|
---|
| 123 | mDeviation = 0;
|
---|
| 124 | mTotalPvsCost = 0;
|
---|
| 125 | mEntriesInPvs = 0;
|
---|
| 126 | mMemoryCost = 0;
|
---|
| 127 | mPvsSizeDecr = 0;
|
---|
| 128 | mVolume = 0;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 |
|
---|
| 132 | void Print(ostream &app) const;
|
---|
| 133 |
|
---|
| 134 | friend ostream &operator<<(ostream &s, const ViewCellsTreeStats &stat)
|
---|
| 135 | {
|
---|
| 136 | stat.Print(s);
|
---|
| 137 | return s;
|
---|
| 138 | }
|
---|
| 139 | };
|
---|
| 140 |
|
---|
| 141 |
|
---|
[372] | 142 | /**
|
---|
[1667] | 143 | A view cell. View cells are regions in space. The visibility informations,
|
---|
| 144 | i.e., the primitives seen by the view cell are stored in a PVs.
|
---|
| 145 | A view cell can be represented in many different ways, e.g.,
|
---|
| 146 | a mesh representation.
|
---|
[372] | 147 | */
|
---|
| 148 | class ViewCell: public MeshInstance
|
---|
| 149 | {
|
---|
[752] | 150 | friend class ViewCellsTree;
|
---|
| 151 | friend class ViewCellsManager;
|
---|
| 152 |
|
---|
[372] | 153 | public:
|
---|
| 154 | ViewCell();
|
---|
[471] | 155 |
|
---|
[372] | 156 | /** Constructor taking a mesh representing the shape of the viewcell.
|
---|
| 157 | */
|
---|
| 158 | ViewCell(Mesh *mesh);
|
---|
[462] | 159 |
|
---|
[469] | 160 | /** Default destructor.
|
---|
| 161 | */
|
---|
[1551] | 162 | virtual ~ViewCell();
|
---|
[471] | 163 | /** Returns Pvs.
|
---|
[372] | 164 | */
|
---|
[469] | 165 | const ObjectPvs &GetPvs() const;
|
---|
[1002] | 166 | /** Returns pvs.
|
---|
| 167 | */
|
---|
[469] | 168 | ObjectPvs &GetPvs();
|
---|
[1002] | 169 | /** Completely substitutes the pvs.
|
---|
| 170 | */
|
---|
[880] | 171 | void SetPvs(const ObjectPvs &pvs);
|
---|
[752] | 172 | /** Type of view cells.
|
---|
| 173 | */
|
---|
[372] | 174 | int Type() const;
|
---|
| 175 | /** Adds a passing ray to the passing ray container.
|
---|
| 176 | */
|
---|
[471] | 177 | void AddPassingRay(const Ray &ray, const int contributions);
|
---|
[469] | 178 | /** Returns volume of the view cell.
|
---|
| 179 | */
|
---|
[478] | 180 | float GetVolume() const;
|
---|
| 181 | /** Returns area of the view cell.
|
---|
[469] | 182 | */
|
---|
[478] | 183 | float GetArea() const;
|
---|
| 184 | /** Sets the volume of the view cell.
|
---|
| 185 | */
|
---|
| 186 | void SetVolume(float volume);
|
---|
| 187 | /** Sets the area of the view cell.
|
---|
| 188 | */
|
---|
| 189 | void SetArea(float area);
|
---|
[580] | 190 | /** if this view cell is the root of a view cell hierarchy
|
---|
| 191 | */
|
---|
| 192 | bool IsRoot() const;
|
---|
| 193 | /** Returns parent view cell.
|
---|
| 194 | */
|
---|
| 195 | ViewCellInterior *GetParent() const;
|
---|
[1002] | 196 | /** Sets parent of this view cell.
|
---|
| 197 | */
|
---|
| 198 | void SetParent(ViewCellInterior *parent);
|
---|
[503] | 199 | /** Sets the mesh for this view cell.
|
---|
| 200 | */
|
---|
| 201 | void SetMesh(Mesh *mesh);
|
---|
| 202 |
|
---|
[1002] | 203 | /** Sets this view cell to be a valid view cell according to some criteria.
|
---|
| 204 | */
|
---|
[547] | 205 | void SetValid(const bool valid);
|
---|
[1002] | 206 | /** Returns true if this view cell is considered to be valid according to
|
---|
| 207 | some criteria.
|
---|
| 208 | */
|
---|
[547] | 209 | bool GetValid() const;
|
---|
| 210 |
|
---|
[728] | 211 | /** Returns estimated render cost of this view cell.
|
---|
| 212 | */
|
---|
| 213 | float GetRenderCost() const;
|
---|
[580] | 214 |
|
---|
[752] | 215 | /** set color for visiualizations.
|
---|
| 216 | */
|
---|
| 217 | void SetColor(const RgbColor &color);
|
---|
[580] | 218 |
|
---|
[752] | 219 | /** get color for visualuzations.
|
---|
| 220 | */
|
---|
| 221 | RgbColor GetColor() const;
|
---|
[580] | 222 |
|
---|
[1002] | 223 | /** Adds a sample to the pvs.
|
---|
| 224 | @param sample the sample to be added
|
---|
| 225 | @param pdf a continuos measure of visibility
|
---|
| 226 | @param contribution returns the contribution of this sample to the pvs
|
---|
| 227 | */
|
---|
| 228 | bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution);
|
---|
[608] | 229 |
|
---|
[580] | 230 | /// Rays piercing this view cell.
|
---|
[1284] | 231 | //RayContainer mPiercingRays;
|
---|
[580] | 232 |
|
---|
| 233 | /** if this is a view cell correspending to a leaf in a hierarchy.
|
---|
| 234 | */
|
---|
| 235 | virtual bool IsLeaf() const = 0;
|
---|
| 236 |
|
---|
[752] | 237 | static bool SmallerPvs(const ViewCell *a, const ViewCell *b)
|
---|
| 238 | {
|
---|
[997] | 239 | // HACK: take scalar value because pvs may not have been stored properly
|
---|
| 240 | #if 1
|
---|
[1709] | 241 | return a->mPvsCost < b->mPvsCost;
|
---|
[997] | 242 | #else
|
---|
[1707] | 243 | return a->GetPvs().EvalPvsCost() < b->GetPvs().EvalPvsCost();
|
---|
[997] | 244 | #endif
|
---|
| 245 | }
|
---|
[569] | 246 |
|
---|
[997] | 247 | static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b)
|
---|
| 248 | {
|
---|
| 249 | return a->GetRenderCost() < b->GetRenderCost();
|
---|
| 250 | }
|
---|
[580] | 251 |
|
---|
[997] | 252 | static bool LargerRenderCost(const ViewCell *a, const ViewCell *b)
|
---|
| 253 | {
|
---|
| 254 | return a->GetRenderCost() > b->GetRenderCost();
|
---|
| 255 | }
|
---|
[801] | 256 |
|
---|
[1002] | 257 | /** Sets merge cost used for merging this view cell from other cells.
|
---|
| 258 | @hack The function is available for leaves also to have a common interface,
|
---|
| 259 | but it should be less than zero for leaves.
|
---|
| 260 | */
|
---|
[600] | 261 | void SetMergeCost(const float mergeCost);
|
---|
[997] | 262 |
|
---|
[1002] | 263 | /** Returns merge cost needed to merge this leaf from other cells.
|
---|
| 264 | @hack The function is available for leaves also to have a common interface,
|
---|
| 265 | but it should be less than zero for leaves.
|
---|
| 266 | */
|
---|
[600] | 267 | float GetMergeCost() const;
|
---|
[997] | 268 |
|
---|
[1002] | 269 |
|
---|
[1551] | 270 | //////////
|
---|
[1297] | 271 | //-- mailing stuff
|
---|
[1002] | 272 |
|
---|
[997] | 273 | static void NewMail(const int reserve = 1)
|
---|
| 274 | {
|
---|
[580] | 275 | sMailId += sReservedMailboxes;
|
---|
| 276 | sReservedMailboxes = reserve;
|
---|
| 277 | }
|
---|
[997] | 278 |
|
---|
[580] | 279 | void Mail() { mMailbox = sMailId; }
|
---|
| 280 | bool Mailed() const { return mMailbox == sMailId; }
|
---|
| 281 |
|
---|
| 282 | void Mail(const int mailbox) { mMailbox = sMailId + mailbox; }
|
---|
| 283 | bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; }
|
---|
| 284 |
|
---|
[1145] | 285 | int IncMail() { return ++ mMailbox - sMailId; }
|
---|
[580] | 286 |
|
---|
| 287 |
|
---|
| 288 | // last mail id -> warning not thread safe!
|
---|
| 289 | // both mailId and mailbox should be unique for each thread!!!
|
---|
| 290 | static int sMailId;
|
---|
| 291 | static int sReservedMailboxes;
|
---|
[609] | 292 |
|
---|
[1545] | 293 |
|
---|
[372] | 294 | protected:
|
---|
| 295 |
|
---|
[1002] | 296 | /// parent view cell in the view cell hierarchy
|
---|
| 297 | ViewCellInterior *mParent;
|
---|
[372] | 298 | /// the potentially visible objects
|
---|
[469] | 299 | ObjectPvs mPvs;
|
---|
[1160] | 300 | /// the volume of this view cell
|
---|
[469] | 301 | float mVolume;
|
---|
[1545] | 302 | /// the area of this view cell
|
---|
[478] | 303 | float mArea;
|
---|
[1160] | 304 | /// the cost that were paid for merging this view cells from two others.
|
---|
[600] | 305 | float mMergeCost;
|
---|
[1160] | 306 | /// if the view cell is valid view space
|
---|
[547] | 307 | bool mValid;
|
---|
[881] | 308 | /// color used for consistent visualization
|
---|
[660] | 309 | RgbColor mColor;
|
---|
[1002] | 310 | /// store pvs size, used for evaluation purpose when pvss are stored only in the leaves
|
---|
[1709] | 311 | float mPvsCost;
|
---|
[1161] | 312 | /** stores number of entries in pvs
|
---|
| 313 | this variable has the same value as mPvsSize for object pvs,
|
---|
| 314 | but usually not for kd cell based pvs
|
---|
| 315 | */
|
---|
[1160] | 316 | int mEntriesInPvs;
|
---|
[1297] | 317 | /** if the pvs size scalar (+ entries into pvs)
|
---|
| 318 | is up to date and corresponding to the real pvs size
|
---|
| 319 | */
|
---|
[752] | 320 | bool mPvsSizeValid;
|
---|
[372] | 321 | };
|
---|
| 322 |
|
---|
[580] | 323 |
|
---|
| 324 | class ViewCellInterior: public ViewCell
|
---|
| 325 | {
|
---|
[752] | 326 | friend class ViewCellsManager;
|
---|
[1284] | 327 |
|
---|
[580] | 328 | public:
|
---|
| 329 | ViewCellInterior();
|
---|
| 330 | ~ViewCellInterior();
|
---|
| 331 |
|
---|
| 332 | ViewCellInterior(Mesh *mesh);
|
---|
| 333 |
|
---|
| 334 | /** Sets pointer from parent to child and vice versa.
|
---|
| 335 | */
|
---|
| 336 | void SetupChildLink(ViewCell *l);
|
---|
[1286] | 337 | void ReplaceChildLink(ViewCell *prev, ViewCell *cur);
|
---|
| 338 |
|
---|
[586] | 339 | void RemoveChildLink(ViewCell *l);
|
---|
[580] | 340 | bool IsLeaf() const;
|
---|
| 341 |
|
---|
[1284] | 342 | void SetCost(const float c) {
|
---|
| 343 | mCost = c;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | float GetCost() const {
|
---|
| 347 | return mCost;
|
---|
| 348 | }
|
---|
[608] | 349 |
|
---|
[1284] | 350 | ViewCellContainer mChildren;
|
---|
| 351 |
|
---|
[608] | 352 | protected:
|
---|
| 353 | /** overall cost resulting from the merge */
|
---|
| 354 | float mCost;
|
---|
[580] | 355 | };
|
---|
| 356 |
|
---|
[881] | 357 |
|
---|
[469] | 358 | /**
|
---|
[881] | 359 | Leaf of the view cell.
|
---|
[469] | 360 | */
|
---|
[580] | 361 | class ViewCellLeaf: public ViewCell
|
---|
[366] | 362 | {
|
---|
| 363 | public:
|
---|
[881] | 364 | ViewCellLeaf() { mActiveViewCell = this; }
|
---|
| 365 | ViewCellLeaf(Mesh *mesh):
|
---|
| 366 | ViewCell(mesh) { mActiveViewCell = this; }
|
---|
[469] | 367 |
|
---|
[881] | 368 | bool IsLeaf() const
|
---|
| 369 | {
|
---|
| 370 | return true;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
[1551] | 373 | /** Returns active view cell, i.e. this view cell or
|
---|
| 374 | a parent view cell which is set as active view cell.
|
---|
[881] | 375 | */
|
---|
| 376 | ViewCell *GetActiveViewCell() const
|
---|
| 377 | { return mActiveViewCell; }
|
---|
| 378 |
|
---|
| 379 | /** Sets this view cell to be an active view cell.
|
---|
| 380 | */
|
---|
| 381 | void SetActiveViewCell(ViewCell *vc)
|
---|
| 382 | { mActiveViewCell = vc;}
|
---|
[605] | 383 |
|
---|
[997] | 384 | /** points to the currently active view cell. This is the
|
---|
| 385 | view cell representing the current brach.
|
---|
| 386 | */
|
---|
[881] | 387 | ViewCell *mActiveViewCell;
|
---|
| 388 | };
|
---|
[479] | 389 |
|
---|
[1732] | 390 |
|
---|
[1121] | 391 | /** Leaf of the view cell hierarchy corresponding
|
---|
| 392 | to a leaf in a spatial hierarchy.
|
---|
[881] | 393 | */
|
---|
| 394 | template<typename T>
|
---|
| 395 | class HierarchyLeafViewCell: public ViewCellLeaf
|
---|
| 396 | {
|
---|
| 397 | public:
|
---|
| 398 |
|
---|
| 399 | HierarchyLeafViewCell<T>(): ViewCellLeaf() { }
|
---|
| 400 | HierarchyLeafViewCell<T>(Mesh *mesh):
|
---|
| 401 | ViewCellLeaf(mesh) { }
|
---|
| 402 |
|
---|
[580] | 403 | bool IsLeaf() const
|
---|
| 404 | {
|
---|
| 405 | return true;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
[1551] | 408 | /// Leaves of some hierarchy which contains this view cell.
|
---|
| 409 | vector<T> mLeaves;
|
---|
[469] | 410 | };
|
---|
| 411 |
|
---|
[479] | 412 |
|
---|
[1010] | 413 | typedef HierarchyLeafViewCell<VspLeaf *> VspViewCell;
|
---|
[881] | 414 | typedef HierarchyLeafViewCell<BspLeaf *> BspViewCell;
|
---|
| 415 | typedef HierarchyLeafViewCell<KdLeaf *> KdViewCell;
|
---|
[469] | 416 |
|
---|
[366] | 417 |
|
---|
[580] | 418 |
|
---|
[1008] | 419 |
|
---|
[580] | 420 | class ViewCellsTree
|
---|
| 421 | {
|
---|
[600] | 422 | friend class ViewCellsManager;
|
---|
[1263] | 423 | friend class ViewCellsParseHandlers;
|
---|
[752] | 424 |
|
---|
[580] | 425 | public:
|
---|
[1264] | 426 | ViewCellsTree();
|
---|
[1004] | 427 | /** View cells tree constructor taking a view cell mnanager as parameter
|
---|
[997] | 428 | */
|
---|
[1004] | 429 | ViewCellsTree(ViewCellsManager *vcm);
|
---|
[580] | 430 | ~ViewCellsTree();
|
---|
| 431 |
|
---|
| 432 | /** Returns number of leaves this view cell consists of.
|
---|
| 433 | */
|
---|
[736] | 434 | int GetNumInitialViewCells(ViewCell *vc) const;
|
---|
[580] | 435 |
|
---|
| 436 | /** Collects leaves corresponding to a view cell.
|
---|
| 437 | */
|
---|
| 438 | void CollectLeaves(ViewCell *vc, ViewCellContainer &leaves) const;
|
---|
| 439 |
|
---|
| 440 | /** Merges view cells according to some cost heuristics.
|
---|
| 441 | */
|
---|
| 442 | int ConstructMergeTree(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
| 443 |
|
---|
| 444 | /** Refines view cells using shuffling, i.e., border leaves
|
---|
| 445 | of two view cells are exchanged if the resulting view cells
|
---|
| 446 | are tested to be "better" than the old ones.
|
---|
| 447 | @returns number of refined view cells
|
---|
| 448 | */
|
---|
| 449 | int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects);
|
---|
[651] | 450 |
|
---|
| 451 | /** Assign colors to the viewcells so that they can be renderered interactively without
|
---|
[997] | 452 | color flickering.
|
---|
| 453 | */
|
---|
[651] | 454 | void AssignRandomColors();
|
---|
[580] | 455 |
|
---|
[997] | 456 | /** Updates view cell stats for this particular view cell.
|
---|
[605] | 457 | */
|
---|
| 458 | void UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat);
|
---|
[580] | 459 |
|
---|
[997] | 460 | /** Get costs resulting from each merge step.
|
---|
| 461 | */
|
---|
[651] | 462 | void GetCostFunction(vector<float> &costFunction);
|
---|
[1603] | 463 |
|
---|
| 464 | /** Returns storage cost resulting from each merge step.
|
---|
| 465 | */
|
---|
| 466 | void GetStorageFunction(vector<int> &storageCost);
|
---|
| 467 |
|
---|
[580] | 468 | /** Returns optimal set of view cells for a given number of view cells.
|
---|
| 469 | */
|
---|
| 470 | void CollectBestViewCellSet(ViewCellContainer &viewCells, const int numViewCells);
|
---|
| 471 |
|
---|
[581] | 472 | /** Root of view cells tree.
|
---|
| 473 | */
|
---|
[584] | 474 | ViewCell *GetRoot() const;
|
---|
[581] | 475 |
|
---|
[584] | 476 | /** Returns pvs of view cell.
|
---|
| 477 | @note pvs is returned per reference if tree is not compressed,
|
---|
| 478 | per copy else.
|
---|
| 479 | */
|
---|
| 480 | void GetPvs(ViewCell *vc, ObjectPvs &pvs) const;
|
---|
| 481 |
|
---|
[1709] | 482 | /** Returns pvs size (i.e. the render cost of the stored objects)
|
---|
[584] | 483 | */
|
---|
[1709] | 484 | float GetPvsCost(ViewCell *vc) const;
|
---|
[584] | 485 |
|
---|
[1161] | 486 | /** Returns number of entries associated with this view cell.
|
---|
[1586] | 487 |
|
---|
| 488 | This returns the same value as the "GetPvsSize" function for object pvs
|
---|
| 489 | but most likely different values if we use object space grouping.
|
---|
| 490 | E.g., using bounding volumes.
|
---|
[584] | 491 | */
|
---|
[1161] | 492 | int GetPvsEntries(ViewCell *vc) const;
|
---|
[584] | 493 |
|
---|
[1586] | 494 | /** Returns the number of physically stored entries in the view cells sub tree.
|
---|
| 495 | This can vary based on the current storage method
|
---|
[1161] | 496 | */
|
---|
[1586] | 497 | int CountStoredPvsEntries(ViewCell *root) const;
|
---|
[1161] | 498 |
|
---|
[584] | 499 | /** Returns memory cost of this view cell.
|
---|
| 500 | */
|
---|
| 501 | float GetMemoryCost(ViewCell *vc) const;
|
---|
| 502 |
|
---|
[752] | 503 | /** Sets method of storage for view cells.
|
---|
[584] | 504 | */
|
---|
[752] | 505 | void SetViewCellsStorage(int type);
|
---|
[584] | 506 |
|
---|
[837] | 507 | /** pvs storage methods
|
---|
| 508 | */
|
---|
[752] | 509 | enum {PVS_IN_INTERIORS, COMPRESSED, PVS_IN_LEAVES};
|
---|
| 510 |
|
---|
[584] | 511 | /** If view cells in this tree have compressed pvs.
|
---|
| 512 | */
|
---|
[752] | 513 | int ViewCellsStorage() const;
|
---|
[584] | 514 |
|
---|
[660] | 515 | /** Returns active view cell that is in the path of this view cell.
|
---|
| 516 | */
|
---|
[881] | 517 | ViewCell *GetActiveViewCell(ViewCellLeaf *vc) const;
|
---|
[590] | 518 |
|
---|
[660] | 519 | /** Sets the leaves to be the currently active view cells.
|
---|
| 520 | */
|
---|
| 521 | void SetActiveSetToLeaves();
|
---|
| 522 |
|
---|
[651] | 523 | /** Propagates pvs up the tree to the root and downwards the tree.
|
---|
[610] | 524 | */
|
---|
[651] | 525 | void PropagatePvs(ViewCell *vc);
|
---|
[610] | 526 |
|
---|
[837] | 527 | /** Exports view cells to file.
|
---|
| 528 | */
|
---|
[1201] | 529 | bool Export(OUT_STREAM &stream, const bool exportPvs = false);
|
---|
[610] | 530 |
|
---|
[649] | 531 | /** Export statistics of this view cell tree.
|
---|
| 532 | */
|
---|
[660] | 533 | void ExportStats(const string &mergeStats);
|
---|
[610] | 534 |
|
---|
[650] | 535 | /** Sets root of hierarchy.
|
---|
| 536 | */
|
---|
| 537 | void SetRoot(ViewCell *root);
|
---|
| 538 |
|
---|
[651] | 539 | /** Assignes unique ids to view cells.
|
---|
| 540 | */
|
---|
| 541 | void CreateUniqueViewCellsIds();
|
---|
| 542 |
|
---|
[660] | 543 | /** Resets pvs of whole tree.
|
---|
| 544 | */
|
---|
| 545 | void ResetPvs();
|
---|
[651] | 546 |
|
---|
[1121] | 547 | /** Counts pvs of the view cell taking the kd cells into account.
|
---|
| 548 | */
|
---|
| 549 | int CountKdPvs(const ViewCellLeaf *vc) const;
|
---|
| 550 |
|
---|
[1551] | 551 | /** Sets pointer to view cells manager.
|
---|
| 552 | */
|
---|
| 553 | void SetViewCellsManager(ViewCellsManager *vcm);
|
---|
[1264] | 554 |
|
---|
[1603] | 555 | void Update();
|
---|
[1586] | 556 |
|
---|
[580] | 557 | protected:
|
---|
| 558 |
|
---|
[1586] | 559 | /** Reads the environment and sets member variables.
|
---|
| 560 | */
|
---|
[1264] | 561 | void ReadEnvironment();
|
---|
[580] | 562 |
|
---|
[997] | 563 | /////////////////////////////////////////////////////////////////
|
---|
| 564 | // merge related stuff //
|
---|
| 565 | /////////////////////////////////////////////////////////////////
|
---|
[580] | 566 |
|
---|
[729] | 567 | /** Computes render cost of the merged pvs.
|
---|
| 568 | */
|
---|
| 569 | float ComputeMergedPvsCost(const ObjectPvs &pvs1, const ObjectPvs &pvs2) const;
|
---|
| 570 |
|
---|
[580] | 571 | /** Returns cost of this leaf according to current heuristics.
|
---|
| 572 | */
|
---|
| 573 | float GetCostHeuristics(ViewCell *vc) const;
|
---|
| 574 |
|
---|
| 575 | /** Returns cost of leaf.
|
---|
| 576 | */
|
---|
| 577 | float GetRenderCost(ViewCell *vc) const;
|
---|
| 578 |
|
---|
| 579 | /** Evaluates the merge cost of this merge candidate pair.
|
---|
| 580 | */
|
---|
| 581 | void EvalMergeCost(MergeCandidate &mc) const;
|
---|
| 582 |
|
---|
| 583 | /** Variance of leaf.
|
---|
| 584 | */
|
---|
| 585 | float GetVariance(ViewCell *vc) const;
|
---|
| 586 |
|
---|
| 587 | /** Standard deviation of leaf.
|
---|
| 588 | */
|
---|
| 589 | float GetDeviation(ViewCell *vc) const;
|
---|
| 590 |
|
---|
[582] | 591 | /** Tries to set this merge candidate to valid.
|
---|
| 592 | @returns false if both view cells are the same
|
---|
[580] | 593 | */
|
---|
[582] | 594 | bool ValidateMergeCandidate(MergeCandidate &mc) const;
|
---|
[580] | 595 |
|
---|
| 596 | /** Merge view cells of leaves l1 and l2.
|
---|
| 597 | @returns difference in pvs size
|
---|
| 598 | */
|
---|
[1709] | 599 | ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, float &pvsDiff); //const;
|
---|
[580] | 600 |
|
---|
| 601 | /** Shuffles, i.e. takes border leaf from view cell 1 and adds it
|
---|
| 602 | to view cell 2.
|
---|
| 603 | */
|
---|
[586] | 604 | void ShuffleLeaf(ViewCell *leaf, ViewCellInterior *vc1, ViewCellInterior *vc2) const;
|
---|
[580] | 605 |
|
---|
| 606 | /** Shuffles the leaves, i.e., tests if exchanging
|
---|
| 607 | the leaves helps in improving the view cells.
|
---|
| 608 | */
|
---|
[586] | 609 | bool ShuffleLeaves(MergeCandidate &mc) const;
|
---|
[580] | 610 |
|
---|
| 611 | /** Calculates cost for merge of view cell 1 and 2.
|
---|
| 612 | */
|
---|
[586] | 613 | float EvalShuffleCost(ViewCell *leaf,
|
---|
| 614 | ViewCellInterior *vc1,
|
---|
| 615 | ViewCellInterior *vc2) const;
|
---|
[580] | 616 |
|
---|
| 617 | /** Exports a snapshot of the merged view cells to disc.
|
---|
| 618 | */
|
---|
| 619 | void ExportMergedViewCells(ViewCellContainer &viewCells,
|
---|
| 620 | const ObjectContainer &objects,
|
---|
| 621 | const int numNewViewCells);
|
---|
| 622 |
|
---|
[997] | 623 | /** Merge queue must be reset after some time because expected value
|
---|
[580] | 624 | may not be valid.
|
---|
| 625 | */
|
---|
| 626 | void ResetMergeQueue();
|
---|
| 627 |
|
---|
[1551] | 628 | /** Updates the current cut of view cells.
|
---|
[582] | 629 | @returns number of newly merged view cells
|
---|
[580] | 630 | */
|
---|
[582] | 631 | int UpdateActiveViewCells(ViewCellContainer &viewCells);
|
---|
[580] | 632 |
|
---|
[997] | 633 | /** Helper function pullling pvs as high up in the tree as possible.
|
---|
| 634 | */
|
---|
[610] | 635 | void PullUpVisibility(ViewCellInterior *interior);
|
---|
[580] | 636 |
|
---|
[997] | 637 | /** Compress pvs of view cell and children.
|
---|
| 638 | */
|
---|
[584] | 639 | void CompressViewCellsPvs(ViewCell *root);
|
---|
[580] | 640 |
|
---|
[582] | 641 | /** Returns memory usage of view cells.
|
---|
| 642 | */
|
---|
| 643 | float GetMemUsage() const;
|
---|
[837] | 644 |
|
---|
| 645 | /** Exports single view cell.
|
---|
[610] | 646 | NOTE: should be in exporter!!
|
---|
| 647 | */
|
---|
[1201] | 648 | void ExportViewCell(ViewCell *viewCell, OUT_STREAM &stream, const bool exportPvs);
|
---|
[581] | 649 |
|
---|
[837] | 650 | /** Exports pvs of a view cell.
|
---|
| 651 | */
|
---|
[1201] | 652 | void ExportPvs(ViewCell *viewCell, OUT_STREAM &stream);
|
---|
[582] | 653 |
|
---|
[1586] | 654 | /** Counts the logical number of entries in the pvs this view cell.
|
---|
| 655 | The pvs is assumed to be stored using lossless compression.
|
---|
| 656 | */
|
---|
[1166] | 657 | int GetEntriesInPvsForCompressedStorage(ViewCell *vc) const;
|
---|
[1586] | 658 |
|
---|
| 659 | /** Computes pvs size of this view cell.
|
---|
| 660 | The pvs is assumed to be stored using lossless compression.
|
---|
| 661 | */
|
---|
[1709] | 662 | float GetPvsCostForCompressedStorage(ViewCell *vc) const;
|
---|
[1586] | 663 |
|
---|
| 664 | /** Computes pvs size of this view cell.
|
---|
| 665 | The pvs is assumed to be stored in the leaves.
|
---|
| 666 | */
|
---|
[1709] | 667 | float GetPvsCostForLeafStorage(ViewCell *vc) const;
|
---|
[1586] | 668 |
|
---|
| 669 | /** Counts the logical number of entries in the pvs this view cell.
|
---|
| 670 | The pvs is assumed to be stored using the leaves.
|
---|
| 671 | */
|
---|
[1166] | 672 | int GetEntriesInPvsForLeafStorage(ViewCell *vc) const;
|
---|
[610] | 673 |
|
---|
[1586] | 674 | /** Update stats for the log.
|
---|
| 675 | */
|
---|
[1653] | 676 | void UpdateStats(ofstream &stats,
|
---|
[1709] | 677 | const ViewCellsTreeStats &vcStats);
|
---|
[1166] | 678 |
|
---|
[1586] | 679 |
|
---|
| 680 | //////////////////////////////////////
|
---|
| 681 |
|
---|
[584] | 682 | /// if the view cell tree hold compressed pvs
|
---|
[752] | 683 | int mViewCellsStorage;
|
---|
[1551] | 684 | /// pointer to the view cells manager
|
---|
[580] | 685 | ViewCellsManager *mViewCellsManager;
|
---|
[1551] | 686 | /// the root of the view cells hierarchy
|
---|
[580] | 687 | ViewCell *mRoot;
|
---|
| 688 |
|
---|
| 689 | /// if merge visualization should be shown
|
---|
| 690 | bool mExportMergedViewCells;
|
---|
[837] | 691 | /// intermediate container of merged view cells.
|
---|
[582] | 692 | ViewCellContainer mMergedViewCells;
|
---|
[837] | 693 | /// if merged view cells are refined.
|
---|
[586] | 694 | bool mRefineViewCells;
|
---|
[580] | 695 | /// weights between variance and render cost increase (must be between zero and one)
|
---|
| 696 | float mRenderCostWeight;
|
---|
| 697 |
|
---|
| 698 | /// overall cost used to normalize cost ratio
|
---|
| 699 | float mOverallCost;
|
---|
| 700 | float mExpectedCost;
|
---|
| 701 | float mDeviation;
|
---|
| 702 | float mAvgRenderCost;
|
---|
[1551] | 703 |
|
---|
[837] | 704 | /// the area is used for pvs heuristics
|
---|
[580] | 705 | int mUseAreaForPvs;
|
---|
[1551] | 706 | /// number of currently active view cells (=current cut)
|
---|
[582] | 707 | int mNumActiveViewCells;
|
---|
[580] | 708 | /// minimal number of view cells
|
---|
| 709 | int mMergeMinViewCells;
|
---|
| 710 | /// maximal cost ratio for the merge
|
---|
| 711 | float mMergeMaxCostRatio;
|
---|
| 712 |
|
---|
| 713 | typedef priority_queue<MergeCandidate> MergeQueue;
|
---|
| 714 |
|
---|
| 715 | MergeQueue mMergeQueue;
|
---|
| 716 |
|
---|
[582] | 717 | float mMaxMemory;
|
---|
[580] | 718 |
|
---|
[938] | 719 | int mMaxMergesPerPass;
|
---|
| 720 | float mAvgCostMaxDeviation;
|
---|
[580] | 721 | };
|
---|
| 722 |
|
---|
| 723 |
|
---|
| 724 | /**
|
---|
| 725 | Candidate for leaf merging based on priority.
|
---|
| 726 | */
|
---|
| 727 | class MergeCandidate
|
---|
| 728 | {
|
---|
| 729 | friend class ViewCellsTree;
|
---|
| 730 |
|
---|
| 731 | public:
|
---|
| 732 |
|
---|
| 733 | MergeCandidate(ViewCell *l, ViewCell *r);
|
---|
| 734 |
|
---|
| 735 | /** If this merge pair is still valid.
|
---|
| 736 | */
|
---|
| 737 | bool IsValid() const;
|
---|
| 738 |
|
---|
| 739 |
|
---|
| 740 | friend bool operator<(const MergeCandidate &leafa, const MergeCandidate &leafb)
|
---|
| 741 | {
|
---|
| 742 | return leafb.GetMergeCost() < leafa.GetMergeCost();
|
---|
| 743 | }
|
---|
| 744 |
|
---|
| 745 | void SetLeftViewCell(ViewCell *l);
|
---|
| 746 | void SetRightViewCell(ViewCell *l);
|
---|
| 747 |
|
---|
| 748 | ViewCell *GetLeftViewCell() const;
|
---|
| 749 | ViewCell *GetRightViewCell() const;
|
---|
| 750 |
|
---|
[703] | 751 | /** Returns leaf view cell initially associated with this merge candidate.
|
---|
| 752 | */
|
---|
[580] | 753 | ViewCell *GetInitialLeftViewCell() const;
|
---|
[1133] | 754 | /** Returns leaf view cell initially associated with this merge candidate.
|
---|
| 755 | */
|
---|
[580] | 756 | ViewCell *GetInitialRightViewCell() const;
|
---|
| 757 |
|
---|
| 758 | /** Returns the increase of the standard deviation of this merge candidate.
|
---|
| 759 | */
|
---|
| 760 | float GetDeviationIncr() const;
|
---|
| 761 |
|
---|
| 762 | /** Merge cost of this candidate pair.
|
---|
| 763 | */
|
---|
| 764 | float GetMergeCost() const;
|
---|
| 765 |
|
---|
| 766 | /** Render cost of this candidate.
|
---|
| 767 | */
|
---|
| 768 | float GetRenderCost() const;
|
---|
| 769 |
|
---|
| 770 | static float sRenderCostWeight;
|
---|
| 771 |
|
---|
| 772 | protected:
|
---|
| 773 |
|
---|
| 774 | /// render cost increase by this merge
|
---|
| 775 | float mRenderCost;
|
---|
| 776 | /// increase / decrease of standard deviation
|
---|
| 777 | float mDeviationIncr;
|
---|
| 778 |
|
---|
| 779 | ViewCell *mLeftViewCell;
|
---|
| 780 | ViewCell *mRightViewCell;
|
---|
| 781 |
|
---|
| 782 | ViewCell *mInitialLeftViewCell;
|
---|
| 783 | ViewCell *mInitialRightViewCell;
|
---|
| 784 | };
|
---|
| 785 |
|
---|
| 786 |
|
---|
| 787 | class MergeStatistics: public StatisticsBase
|
---|
| 788 | {
|
---|
| 789 | public:
|
---|
| 790 |
|
---|
| 791 | int merged;
|
---|
| 792 | int siblings;
|
---|
| 793 | int candidates;
|
---|
| 794 | int nodes;
|
---|
| 795 |
|
---|
| 796 | int accTreeDist;
|
---|
| 797 | int maxTreeDist;
|
---|
| 798 |
|
---|
| 799 | Real collectTime;
|
---|
| 800 | Real mergeTime;
|
---|
| 801 |
|
---|
| 802 | Real overallCost;
|
---|
| 803 |
|
---|
| 804 | Real expectedRenderCost;
|
---|
| 805 | Real deviation;
|
---|
| 806 | Real heuristics;
|
---|
| 807 |
|
---|
| 808 | // Constructor
|
---|
| 809 | MergeStatistics()
|
---|
| 810 | {
|
---|
| 811 | Reset();
|
---|
| 812 | }
|
---|
| 813 |
|
---|
| 814 | double AvgTreeDist() const {return (double)accTreeDist / (double)merged;};
|
---|
| 815 |
|
---|
| 816 | void Reset()
|
---|
| 817 | {
|
---|
| 818 | nodes = 0;
|
---|
| 819 | merged = 0;
|
---|
| 820 | siblings = 0;
|
---|
| 821 | candidates = 0;
|
---|
| 822 |
|
---|
| 823 | accTreeDist = 0;
|
---|
| 824 | maxTreeDist = 0;
|
---|
| 825 |
|
---|
| 826 | collectTime = 0;
|
---|
| 827 | mergeTime = 0;
|
---|
| 828 | overallCost = 0;
|
---|
| 829 |
|
---|
| 830 | expectedRenderCost = 0;
|
---|
| 831 | deviation = 0;
|
---|
| 832 | heuristics = 0;
|
---|
| 833 |
|
---|
| 834 | }
|
---|
| 835 |
|
---|
| 836 | void Print(ostream &app) const;
|
---|
| 837 |
|
---|
| 838 | friend ostream &operator<<(ostream &s, const MergeStatistics &stat)
|
---|
| 839 | {
|
---|
| 840 | stat.Print(s);
|
---|
| 841 | return s;
|
---|
| 842 | }
|
---|
| 843 | };
|
---|
| 844 |
|
---|
[860] | 845 | }
|
---|
| 846 |
|
---|
[372] | 847 | #endif
|
---|