Changeset 1008 for GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
- Timestamp:
- 06/09/06 09:07:40 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
r1006 r1008 9 9 #include "VssRay.h" 10 10 #include "RayInfo.h" 11 #include "ViewCellBsp.h" 12 11 #include "gzstream.h" 13 12 14 13 … … 16 15 17 16 class ViewCellLeaf; 18 //class BspViewCell;17 class VspViewCell; 19 18 class Plane3; 20 class VspBspTree;21 class BspInterior;22 class BspNode;23 19 class AxisAlignedBox3; 24 20 class Ray; … … 29 25 class ViewCellsTree; 30 26 class Environment; 27 class VspInterior; 28 class VspLeaf; 29 class VspNode; 30 31 32 /** A definition for an axis aligned plane. 33 */ 34 struct AxisAlignedPlane 35 { 36 public: 37 int mAxis; 38 float mPosition; 39 }; 40 41 42 class VspTreeStatistics: public StatisticsBase 43 { 44 public: 45 // total number of nodes 46 int nodes; 47 // number of splits 48 int splits[3]; 49 50 // totals number of rays 51 int rays; 52 // maximal reached depth 53 int maxDepth; 54 // minimal depth 55 int minDepth; 56 57 // max depth nodes 58 int maxDepthNodes; 59 // minimum depth nodes 60 int minDepthNodes; 61 // max depth nodes 62 int minPvsNodes; 63 // nodes with minimum PVS 64 int minRaysNodes; 65 // max ray contribution nodes 66 int maxRayContribNodes; 67 // minimum area nodes 68 int minProbabilityNodes; 69 /// nodes termination because of max cost ratio; 70 int maxCostNodes; 71 // max number of rays per node 72 int maxObjectRefs; 73 /// samples contributing to pvs 74 int contributingSamples; 75 /// sample contributions to pvs 76 int sampleContributions; 77 /// largest pvs 78 int maxPvs; 79 /// number of invalid leaves 80 int invalidLeaves; 81 /// accumulated number of rays refs 82 int accumRays; 83 int pvs; 84 // accumulated depth (used to compute average) 85 int accumDepth; 86 87 // Constructor 88 VspTreeStatistics() 89 { 90 Reset(); 91 } 92 93 int Nodes() const {return nodes;} 94 int Interior() const { return nodes / 2; } 95 int Leaves() const { return (nodes / 2) + 1; } 96 97 // TODO: computation wrong 98 double AvgDepth() const { return accumDepth / (double)Leaves();}; 99 double AvgRays() const { return accumRays / (double)Leaves();}; 100 101 void Reset() 102 { 103 nodes = 0; 104 for (int i = 0; i < 3; ++ i) 105 splits[i] = 0; 106 107 maxDepth = 0; 108 minDepth = 99999; 109 accumDepth = 0; 110 pvs = 0; 111 maxDepthNodes = 0; 112 minPvsNodes = 0; 113 minRaysNodes = 0; 114 maxRayContribNodes = 0; 115 minProbabilityNodes = 0; 116 maxCostNodes = 0; 117 118 contributingSamples = 0; 119 sampleContributions = 0; 120 121 maxPvs = 0; 122 invalidLeaves = 0; 123 accumRays = 0; 124 } 125 126 void Print(ostream &app) const; 127 128 friend ostream &operator<<(ostream &s, const VspTreeStatistics &stat) 129 { 130 stat.Print(s); 131 return s; 132 } 133 }; 134 135 /** 136 VspNode abstract class serving for interior and leaf node implementation 137 */ 138 class VspNode 139 { 140 141 public: 142 VspNode(); 143 virtual ~VspNode(){}; 144 VspNode(VspInterior *parent); 145 146 /** Determines whether this node is a leaf or not 147 @return true if leaf 148 */ 149 virtual bool IsLeaf() const = 0; 150 151 /** Determines whether this node is a root 152 @return true if root 153 */ 154 virtual bool IsRoot() const; 155 156 /** Returns parent node. 157 */ 158 VspInterior *GetParent(); 159 160 /** Sets parent node. 161 */ 162 void SetParent(VspInterior *parent); 163 164 /** Returns true if this node is a sibling of node n. 165 */ 166 bool IsSibling(VspNode *n) const; 167 168 /** returns depth of the node. 169 */ 170 int GetDepth() const; 171 172 /** returns true if the whole subtree is valid 173 */ 174 bool TreeValid() const; 175 176 void SetTreeValid(const bool v); 177 178 //-- mailing options 179 180 void Mail() { mMailbox = sMailId; } 181 static void NewMail() { ++ sMailId; } 182 bool Mailed() const { return mMailbox == sMailId; } 183 184 static int sMailId; 185 int mMailbox; 186 187 int mTimeStamp; 188 189 protected: 190 191 /// if this sub tree is a completely valid view space region 192 bool mTreeValid; 193 /// parent of this node 194 VspInterior *mParent; 195 }; 196 197 198 /** BSP interior node implementation 199 */ 200 class VspInterior: public VspNode 201 { 202 public: 203 /** Standard contructor taking split plane as argument. 204 */ 205 VspInterior(const AxisAlignedPlane &plane); 206 ~VspInterior(); 207 /** @return false since it is an interior node 208 */ 209 bool IsLeaf() const; 210 211 VspNode *GetBack(); 212 VspNode *GetFront(); 213 214 /** Returns split plane. 215 */ 216 AxisAlignedPlane GetPlane() const; 217 218 /** Replace front or back child with new child. 219 */ 220 void ReplaceChildLink(VspNode *oldChild, VspNode *newChild); 221 /** Replace front and back child. 222 */ 223 void SetupChildLinks(VspNode *b, VspNode *f); 224 225 friend ostream &operator<<(ostream &s, const VspInterior &A) 226 { 227 return s << A.mPlane.mAxis << " " << A.mPlane.mPosition; 228 } 229 230 protected: 231 232 /// Splitting plane corresponding to this node 233 AxisAlignedPlane mPlane; 234 235 /// back node 236 VspNode *mBack; 237 /// front node 238 VspNode *mFront; 239 }; 240 241 242 /** BSP leaf node implementation. 243 */ 244 class VspLeaf: public VspNode 245 { 246 247 public: 248 VspLeaf(); 249 VspLeaf(ViewCellLeaf *viewCell); 250 VspLeaf(VspInterior *parent); 251 VspLeaf(VspInterior *parent, ViewCellLeaf *viewCell); 252 253 ~VspLeaf(); 254 255 /** @return true since it is an interior node 256 */ 257 bool IsLeaf() const; 258 259 /** Returns pointer of view cell. 260 */ 261 ViewCellLeaf *GetViewCell() const; 262 263 /** Sets pointer to view cell. 264 */ 265 void SetViewCell(ViewCellLeaf *viewCell); 266 267 /// Rays piercing this leaf. 268 VssRayContainer mVssRays; 269 270 /// leaf pvs 271 ObjectPvs *mPvs; 272 273 /// Probability that the view point lies in this leaf 274 float mProbability; 275 276 protected: 277 278 /// if NULL this does not correspond to feasible viewcell 279 ViewCellLeaf *mViewCell; 280 }; 281 31 282 32 283 /** … … 57 308 { 58 309 friend class ViewCellsParseHandlers; 59 friend class Vsp BspViewCellsManager;310 friend class VspVspViewCellsManager; 60 311 61 312 public: 62 313 63 /** A definition for an axis aligned plane.64 */65 struct AxisAlignedPlane66 {67 public:68 int mAxis;69 float mPosition;70 };71 72 314 /** Additional data which is passed down the BSP tree during traversal. 73 315 */ … … 76 318 public: 77 319 /// the current node 78 BspNode *mNode;320 VspNode *mNode; 79 321 /// current depth 80 322 int mDepth; … … 114 356 {} 115 357 116 VspOspTraversalData( BspNode *node,358 VspOspTraversalData(VspNode *node, 117 359 const int depth, 118 360 RayInfoContainer *rays, … … 193 435 #if 1 194 436 return mRenderCost; 195 #endif 196 #if 0 437 #else 197 438 return (float) (-mDepth); // for kd tree 198 439 #endif … … 217 458 /** Returns BSP Tree statistics. 218 459 */ 219 const BspTreeStatistics &GetStatistics() const;460 const VspTreeStatistics &GetStatistics() const; 220 461 221 462 … … 233 474 @param maxPvs the maximal pvs (-1 means unlimited) 234 475 */ 235 void CollectLeaves(vector< BspLeaf *> &leaves,476 void CollectLeaves(vector<VspLeaf *> &leaves, 236 477 const bool onlyUnmailed = false, 237 478 const int maxPvs = -1) const; … … 241 482 AxisAlignedBox3 GetBoundingBox()const; 242 483 243 /** Returns root of BSPtree.244 */ 245 BspNode *GetRoot() const;484 /** Returns root of the view space partitioning tree. 485 */ 486 VspNode *GetRoot() const; 246 487 247 488 /** Collects the leaf view cells of the tree … … 259 500 /** finds neighbouring leaves of this tree node. 260 501 */ 261 int FindNeighbors( BspNode *n,262 vector< BspLeaf *> &neighbors,502 int FindNeighbors(VspNode *n, 503 vector<VspLeaf *> &neighbors, 263 504 const bool onlyUnmailed) const; 264 505 … … 266 507 @param halfspace defines the halfspace from which the leaf is taken. 267 508 */ 268 BspLeaf *GetRandomLeaf(const Plane3 &halfspace);509 VspLeaf *GetRandomLeaf(const Plane3 &halfspace); 269 510 270 511 /** Returns random leaf of BSP tree. 271 512 @param onlyUnmailed if only unmailed leaves should be returned. 272 513 */ 273 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false);514 VspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 274 515 275 516 /** Returns epsilon of this tree. … … 291 532 void SetViewCellsManager(ViewCellsManager *vcm); 292 533 293 /** Returns distance from node 1 to node 2.294 */295 int TreeDistance(BspNode *n1, BspNode *n2) const;296 534 297 535 /** Collapses the tree with respect to the view cell partition. … … 316 554 the invalid view space. 317 555 */ 318 BspViewCell *GetOutOfBoundsCell();556 VspViewCell *GetOutOfBoundsCell(); 319 557 320 558 /** Writes tree to output stream … … 332 570 int CastBeam(Beam &beam); 333 571 334 /** Finds approximate neighbours, i.e., finds correct neighbors335 in most cases but sometimes more.336 */337 int FindApproximateNeighbors(BspNode *n,338 vector<BspLeaf *> &neighbors,339 const bool onlyUnmailed) const;340 572 341 573 /** Checks if tree validity-flags are right … … 410 642 /** Evaluates render cost decrease of next split. 411 643 */ 412 float EvalRenderCostDecrease(const Plane3&candidatePlane,644 float EvalRenderCostDecrease(const AxisAlignedPlane &candidatePlane, 413 645 const VspOspTraversalData &data) const; 414 646 … … 419 651 /** Collects view cells in the subtree under root. 420 652 */ 421 void CollectViewCells( BspNode *root,653 void CollectViewCells(VspNode *root, 422 654 bool onlyValid, 423 655 ViewCellContainer &viewCells, … … 427 659 the invalid view space. If it does not exist, it is created. 428 660 */ 429 BspViewCell *GetOrCreateOutOfBoundsCell();661 VspViewCell *GetOrCreateOutOfBoundsCell(); 430 662 431 663 /** Collapses the tree with respect to the view cell partition, … … 436 668 this node otherwise 437 669 */ 438 BspNode *CollapseTree(BspNode *node, int &collapsed);670 VspNode *CollapseTree(VspNode *node, int &collapsed); 439 671 440 672 /** Helper function revalidating the view cell leaf list after merge. … … 451 683 @returns new root of the subtree 452 684 */ 453 BspNode *Subdivide(VspOspSplitQueue &tQueue,685 VspNode *Subdivide(VspOspSplitQueue &tQueue, 454 686 VspOspSplitCandidate &splitCandidate); 455 687 … … 469 701 */ 470 702 471 BspInterior *SubdivideNode(const Plane3&splitPlane,703 VspInterior *SubdivideNode(const AxisAlignedPlane &splitPlane, 472 704 VspOspTraversalData &tData, 473 705 VspOspTraversalData &frontData, … … 546 778 547 779 */ 548 void AddToPvs( BspLeaf *leaf,780 void AddToPvs(VspLeaf *leaf, 549 781 const RayInfoContainer &rays, 550 782 float &sampleContributions, … … 553 785 /** Propagates valid flag up the tree. 554 786 */ 555 void PropagateUpValidity( BspNode *node);787 void PropagateUpValidity(VspNode *node); 556 788 557 789 /** Writes the node to disk … … 559 791 */ 560 792 #if ZIPPED_VIEWCELLS 561 void ExportNode( BspNode *node, ogzstream &stream);793 void ExportNode(VspNode *node, ogzstream &stream); 562 794 #else 563 void ExportNode( BspNode *node, ofstream &stream);795 void ExportNode(VspNode *node, ofstream &stream); 564 796 #endif 565 797 … … 575 807 576 808 /// Pointer to the root of the tree 577 BspNode *mRoot;578 579 BspTreeStatistics mBspStats;809 VspNode *mRoot; 810 811 VspTreeStatistics mVspStats; 580 812 581 813 /// View cell corresponding to the space outside the valid view space 582 BspViewCell *mOutOfBoundsCell;814 VspViewCell *mOutOfBoundsCell; 583 815 584 816 /// box around the whole view domain
Note: See TracChangeset
for help on using the changeset viewer.