Changeset 406 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellKd.h
- Timestamp:
- 11/11/05 21:28:02 (19 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellKd.h
r405 r406 1 #ifndef _ KdTree_H__2 #define _ KdTree_H__1 #ifndef _ViewCellKdTree_H__ 2 #define _ViewCellKdTree_H__ 3 3 4 4 #include <functional> … … 11 11 12 12 13 class KdNode;14 class KdLeaf;15 class KdInterior;13 class ViewCellKdNode; 14 class ViewCellKdLeaf; 15 class ViewCellKdInterior; 16 16 class Intersectable; 17 17 … … 20 20 // Static statistics for kd-tree search 21 21 // -------------------------------------------------------------- 22 class KdTreeStatistics22 class ViewCellKdTreeStatistics 23 23 { 24 24 public: … … 51 51 52 52 // Constructor 53 KdTreeStatistics() {53 ViewCellKdTreeStatistics() { 54 54 Reset(); 55 55 } … … 75 75 Print(ostream &app) const; 76 76 77 friend ostream &operator<<(ostream &s, const KdTreeStatistics &stat) {77 friend ostream &operator<<(ostream &s, const ViewCellKdTreeStatistics &stat) { 78 78 stat.Print(s); 79 79 return s; … … 83 83 84 84 85 class KdInterior;85 class ViewCellKdInterior; 86 86 /** Abstract class for kd-tree node */ 87 class KdNode {87 class ViewCellKdNode { 88 88 public: 89 89 static int mailID; … … 95 95 96 96 97 KdNode(KdInterior *parent);97 ViewCellKdNode(ViewCellKdInterior *parent); 98 98 99 99 /** Determines whether this node is a leaf or interior node … … 111 111 /** Parent of the node - the parent is a little overhead for maintanance of the tree, 112 112 but allows various optimizations of tree traversal algorithms */ 113 KdInterior *mParent;113 ViewCellKdInterior *mParent; 114 114 int mDepth; 115 115 }; 116 116 117 117 /** Implementation of the kd-tree interior node */ 118 class KdInterior : publicKdNode {118 class ViewCellKdInterior : public ViewCellKdNode { 119 119 120 120 public: 121 121 122 KdInterior(KdInterior *parent):KdNode(parent), mBack(NULL), mFront(NULL) {}123 124 /** \sa KdNode::IsLeaf() */122 ViewCellKdInterior(ViewCellKdInterior *parent):ViewCellKdNode(parent), mBack(NULL), mFront(NULL) {} 123 124 /** \sa ViewCellKdNode::IsLeaf() */ 125 125 virtual bool IsLeaf() const { return false; } 126 126 … … 133 133 134 134 /** back node */ 135 KdNode *mBack;135 ViewCellKdNode *mBack; 136 136 /** front node */ 137 KdNode *mFront;138 139 void SetupChildLinks( KdNode *b,KdNode *f) {137 ViewCellKdNode *mFront; 138 139 void SetupChildLinks(ViewCellKdNode *b, ViewCellKdNode *f) { 140 140 mBack = b; 141 141 mFront = f; … … 143 143 } 144 144 145 void ReplaceChildLink( KdNode *oldChild,KdNode *newChild) {145 void ReplaceChildLink(ViewCellKdNode *oldChild, ViewCellKdNode *newChild) { 146 146 if (mBack == oldChild) 147 147 mBack = newChild; … … 155 155 156 156 /** Implementation of the kd-tree leaf node */ 157 class KdLeaf : publicKdNode {157 class ViewCellKdLeaf : public ViewCellKdNode { 158 158 public: 159 KdLeaf(KdInterior *parent, const int objects):KdNode(parent) {159 ViewCellKdLeaf(ViewCellKdInterior *parent, const int objects):ViewCellKdNode(parent) { 160 160 mObjects.reserve(objects); 161 161 } … … 176 176 } 177 177 178 /** \sa KdNode::IsLeaf() */178 /** \sa ViewCellKdNode::IsLeaf() */ 179 179 virtual bool IsLeaf() const { return true; } 180 180 … … 191 191 PassingRaySet mPassingRays; 192 192 193 /** PVS consisting of visible KdTreenodes */194 KdPvs mKdPvs;193 /** PVS consisting of visible ViewCellKd nodes */ 194 ViewCellKdPvs mKdPvs; 195 195 196 196 /** PVS consisting of visible objects */ … … 200 200 201 201 202 /** KdTreefor indexing scene entities - occluders/occludees/viewcells */203 class KdTree{202 /** ViewCellKd for indexing scene entities - occluders/occludees/viewcells */ 203 class ViewCellKd { 204 204 205 205 protected: 206 206 struct TraversalData 207 207 { 208 KdNode *mNode;208 ViewCellKdNode *mNode; 209 209 AxisAlignedBox3 mBox; 210 210 int mDepth; … … 213 213 TraversalData() {} 214 214 215 TraversalData( KdNode *n, const float p):215 TraversalData(ViewCellKdNode *n, const float p): 216 216 mNode(n), mPriority(p) 217 217 {} 218 218 219 TraversalData( KdNode *n,219 TraversalData(ViewCellKdNode *n, 220 220 const AxisAlignedBox3 &b, 221 221 const int d): … … 225 225 bool operator<( 226 226 const TraversalData &b) const { 227 KdLeaf *leafa = (KdLeaf *) mNode;228 KdLeaf *leafb = (KdLeaf *) b.mNode;227 ViewCellKdLeaf *leafa = (ViewCellKdLeaf *) mNode; 228 ViewCellKdLeaf *leafb = (ViewCellKdLeaf *) b.mNode; 229 229 return 230 230 leafa->mObjects.size()*mBox.SurfaceArea() … … 254 254 SPLIT_SAH}; 255 255 256 KdTree();256 ViewCellKd(); 257 257 258 258 … … 274 274 were already met 275 275 */ 276 virtual KdNode *Subdivide(const TraversalData &tdata);276 virtual ViewCellKdNode *Subdivide(const TraversalData &tdata); 277 277 278 278 /** Get the root of the tree */ 279 KdNode *GetRoot() const {279 ViewCellKdNode *GetRoot() const { 280 280 return mRoot; 281 281 } … … 289 289 ); 290 290 291 const KdTreeStatistics &GetStatistics() const {291 const ViewCellKdTreeStatistics &GetStatistics() const { 292 292 return mStat; 293 293 } 294 294 295 295 void 296 CollectObjects( KdNode *n, ObjectContainer &objects);296 CollectObjects(ViewCellKdNode *n, ObjectContainer &objects); 297 297 298 298 void 299 CollectLeaves(vector< KdLeaf *> &leaves);300 301 AxisAlignedBox3 GetBox(const KdNode *node) const {302 KdInterior *parent = node->mParent;299 CollectLeaves(vector<ViewCellKdLeaf *> &leaves); 300 301 AxisAlignedBox3 GetBox(const ViewCellKdNode *node) const { 302 ViewCellKdInterior *parent = node->mParent; 303 303 if (parent == NULL) 304 304 return mBox; 305 305 306 306 if (!node->IsLeaf()) 307 return (( KdInterior *)node)->mBox;307 return ((ViewCellKdInterior *)node)->mBox; 308 308 309 309 AxisAlignedBox3 box(parent->mBox); … … 315 315 } 316 316 317 KdNode *318 FindRandomNeighbor( KdNode *n,317 ViewCellKdNode * 318 FindRandomNeighbor(ViewCellKdNode *n, 319 319 bool onlyUnmailed 320 320 ); 321 321 322 KdNode *323 KdTree::GetRandomLeaf(const Plane3 &halfspace);324 325 KdNode *322 ViewCellKdNode * 323 ViewCellKd::GetRandomLeaf(const Plane3 &halfspace); 324 325 ViewCellKdNode * 326 326 GetRandomLeaf(const bool onlyUnmailed = false); 327 327 328 328 int 329 FindNeighbors( KdNode *n,330 vector< KdNode *> &neighbors,329 FindNeighbors(ViewCellKdNode *n, 330 vector<ViewCellKdNode *> &neighbors, 331 331 bool onlyUnmailed 332 332 ); … … 419 419 420 420 struct RayTraversalData { 421 KdNode *mNode;421 ViewCellKdNode *mNode; 422 422 Vector3 mExitPoint; 423 423 float mMaxT; 424 424 425 425 RayTraversalData() {} 426 RayTraversalData( KdNode *n,426 RayTraversalData(ViewCellKdNode *n, 427 427 const Vector3 &p, 428 428 const float maxt): … … 460 460 float 461 461 BestCostRatio( 462 KdLeaf *node,462 ViewCellKdLeaf *node, 463 463 const AxisAlignedBox3 &box, 464 464 const int axis, … … 470 470 void 471 471 SortSplitCandidates( 472 KdLeaf *node,472 ViewCellKdLeaf *node, 473 473 const int axis 474 474 ); … … 477 477 EvaluateLeafStats(const TraversalData &data); 478 478 479 KdNode *479 ViewCellKdNode * 480 480 SubdivideNode( 481 KdLeaf *leaf,481 ViewCellKdLeaf *leaf, 482 482 const AxisAlignedBox3 &box, 483 483 AxisAlignedBox3 &backBBox, … … 486 486 487 487 bool 488 TerminationCriteriaMet(const KdLeaf *leaf);488 TerminationCriteriaMet(const ViewCellKdLeaf *leaf); 489 489 490 490 int 491 SelectPlane( KdLeaf *leaf,491 SelectPlane(ViewCellKdLeaf *leaf, 492 492 const AxisAlignedBox3 &box, 493 493 float &position … … 504 504 bool mSahUseFaces; 505 505 /// root of the tree 506 KdNode *mRoot;506 ViewCellKdNode *mRoot; 507 507 /// bounding box of the tree root 508 508 AxisAlignedBox3 mBox; 509 KdTreeStatistics mStat;509 ViewCellKdTreeStatistics mStat; 510 510 511 511 }; 512 513 514 515 516 517 512 518 513 #endif
Note: See TracChangeset
for help on using the changeset viewer.