Changeset 2755 for GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
- Timestamp:
- 06/12/08 01:09:23 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2753 r2755 5 5 6 6 #include "Geometry.h" 7 //#include "FlexibleHeap.h"8 7 9 8 … … 14 13 // Forward declarations 15 14 16 class Scene Geometry;15 class SceneEntity; 17 16 class Camera; 18 17 … … 23 22 { 24 23 friend class Bvh; 24 friend class BvhLoader; 25 friend class myless; 25 26 26 27 public: … … 52 53 */ 53 54 BvhNode(BvhNode *parent); 54 55 55 /** Returns true if this node is a leaf. 56 56 */ … … 75 75 virtual void ResetVisibility(); 76 76 77 virtual int GetType() = 0; //{ return BVH_NODE; }78 79 80 //////////////// /////77 virtual bool IsLeaf() = 0; //{ return BVH_NODE; } 78 79 80 //////////////// 81 81 //-- visibility culling related functions 82 82 83 83 inline int GetLastVisitedFrame() const; 84 84 85 inline void SetLastVisitedFrame( constint lastVisited);85 inline void SetLastVisitedFrame(int lastVisited); 86 86 /** If this node is considered visible. 87 87 */ … … 89 89 /** Set visibility flag of the node. 90 90 */ 91 inline void SetVisible( constbool visible);91 inline void SetVisible(bool visible); 92 92 /** The assumed visible time span of this node. 93 93 */ 94 inline void SetAssumedVisibleFrames( constint t);94 inline void SetAssumedVisibleFrames(int t); 95 95 /** See set. 96 96 */ … … 108 108 109 109 inline int GetTimesInvisible() const; 110 inline void SetTimesInvisible( constint t);110 inline void SetTimesInvisible(int t); 111 111 112 112 inline int GetTurnedVisibleFrame() const; 113 inline void SetTurnedVisibleFrame( constint turnedVisibleFrame);113 inline void SetTurnedVisibleFrame(int turnedVisibleFrame); 114 114 115 115 inline int GetLastTestedFrame(); 116 inline void SetLastTestedFrame( constint lastTested);116 inline void SetLastTestedFrame(int lastTested); 117 117 118 118 inline bool IsViewFrustumCulled() const; 119 inline void SetViewFrustumCulled( constbool frustumCulled);119 inline void SetViewFrustumCulled(bool frustumCulled); 120 120 121 121 inline bool IsNew() const; 122 inline void SetIsNew(const bool isNew); 122 inline void SetIsNew(bool isNew); 123 124 125 /** Returns the bounding box of this node. 126 */ 127 inline const AxisAlignedBox3 &GetBox() { return mBox; } 128 /** Return index of this node. 129 */ 130 inline int GetId() const { return mId; } 131 /** See get 132 */ 133 inline void SetId(int id) { mId = id; } 123 134 124 135 … … 152 163 /// the parent node 153 164 BvhNode *mParent; 154 /// stores the visibility related parameters165 /// stores the visibility related info 155 166 VisibilityInfo mVisibility; 156 167 … … 181 192 /// these nodes can be tested instead of the current node 182 193 int mTestNodesIdx; 194 183 195 int mNumTestNodes; 196 184 197 int mIndicesPtr; 198 185 199 /// Area of this node 186 200 float mArea; 201 /// distance to the camera 202 float mDistance; 203 /// the index of this node 204 unsigned int mId; 205 /// indices used for draw array rendering 206 unsigned int *mIndices; 207 /// the bounding box 208 AxisAlignedBox3 mBox; 209 187 210 }; 188 211 … … 302 325 class BvhInterior: public BvhNode 303 326 { 304 friend class Bvh; 327 friend class Bvh; 328 friend class BvhLoader; 305 329 306 330 public: 331 307 332 BvhInterior(BvhNode *parent): mBack(NULL), mFront(NULL), BvhNode(parent) 308 333 {} … … 319 344 /** Returns split axis of this interior node. 320 345 */ 321 inline int GetAxis() { return (int)mAxis;}346 inline int GetAxis() { return (int)mAxis; } 322 347 /** Returns position of the split axis. 323 348 */ … … 337 362 class BvhLeaf: public BvhNode 338 363 { 339 friend class Bvh; 364 friend class Bvh; 365 friend class BvhLoader; 340 366 341 367 public: … … 347 373 348 374 virtual bool IsLeaf() { return true; } 375 }; 376 377 378 /** This class implements the compare operator for the priority queue. 379 a lower distance has a higher value in the queue 380 */ 381 class myless 382 { 383 public: 384 bool operator() (BvhNode *v1, BvhNode *v2) const 385 { 386 return (v1->mDistance > v2->mDistance); 387 } 349 388 }; 350 389 … … 354 393 class Bvh 355 394 { 395 friend class BvhLoader; 396 356 397 /** Bvh properties 357 398 */ … … 401 442 */ 402 443 inline int GetNumLeaves() const {return mNumNodes / 2 + 1;} 403 /** Constructs the bounding volume hierarchy.404 */405 void Construct();406 444 /** Returns root node of the bvh. 407 445 */ 408 BvhNode *GetRoot() { return mRoot;}446 BvhNode *GetRoot() { return mRoot; } 409 447 /** Counts the triangle in this leaf. 410 448 */ … … 412 450 413 451 452 void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth); 453 void CollectNodes(BvhNode *node, BvhNodeContainer &nodes); 454 void CollectLeaves(BvhNode *node, BvhLeafContainer &leaves); 455 456 414 457 ////////////////////// 415 458 416 459 /** Returns geometry by reference (faster). 417 460 */ 418 Scene Geometry **GetGeometry(BvhNode *node, int &size);461 SceneEntity **GetGeometry(BvhNode *node, int &size); 419 462 420 463 … … 442 485 */ 443 486 int IsWithinViewFrustum(BvhNode *node); 444 /** sets frame dependent values.445 */ 446 void InitFrame(Camera *camera, constint currentFrameId);447 /** this gives the orthogonal distance from the viewpoint to the nearest bounding box vertex487 /** Sets frame dependent values. 488 */ 489 void InitFrame(Camera *camera, int currentFrameId); 490 /** This gives the orthogonal distance from the viewpoint to the nearest bounding box vertex 448 491 note that negative values can appear because culling is done only afterwards 449 492 */ 450 493 float CalcDistance(BvhNode *node) const; 451 /** Sets maximal depth for taking the bounding boxes to test the452 visibility of a node. The deeper the more the box fits to the geometry.453 */454 void SetMaxDepthForTestingChildren(const int maxDepth);455 /** Pulls up the fully visible classification in the bvh.456 */457 void UpdateFullVisibility(BvhNode *node) const;458 494 /** Pulls up the last visited classification in the bvh. 459 495 */ 460 void PullUpLastVisited(BvhNode *node, constint frameId) const;496 void PullUpLastVisited(BvhNode *node, int frameId) const; 461 497 /** Resets the node classifications in the tree. 462 498 */ … … 465 501 wireframes for visualization purpose. 466 502 */ 467 void RenderBoundingBoxesForViz(const int mode); 468 /** Returns squared min distance to the view point. 469 */ 470 float GetSquareDistance(BvhNode *node) const; 503 //void RenderBoundingBoxesForViz(int mode); 471 504 /** Count triangles the node contains. 472 505 */ … … 477 510 478 511 479 //////////// 480 //-- functions that change the boundaries of the nodes 481 482 void SetUseTighterBoundsForTests(bool tighterBoundsForTests); 483 484 void SetAreaRatioThresholdForTestingChildren(const float ratio); 485 486 512 //////// 513 //-- functions influencing tighter bounds 514 515 516 /** Sets maximal depth for taking the bounding boxes to test the 517 visibility of a node. 518 Deeper => the bounds adapt more to the geometry. 519 */ 520 void SetMaxDepthForTestingChildren(int maxDepth); 521 522 void SetAreaRatioThresholdForTestingChildren(float ratio); 523 524 /** Returns stats. 525 */ 487 526 const BvhStats &GetBvhStats() const {return mBvhStats;} 488 489 void SetCollectTighterBoundsWithMaxLevel(bool t);490 491 492 //////////////493 494 static unsigned int sCurrentVboId;495 527 496 528 497 529 protected: 498 530 499 /** Small struct representing a frustum.500 */501 struct Frustum502 {503 /// the 6 clip planes504 float mClipPlane[6][4];505 };506 507 508 509 531 //////////////////// 510 532 511 /** Constructor loading the bvh from disc512 */513 Bvh(const std::string &filename);514 533 /** protected constructor: do nothing. 515 534 */ 516 //Bvh(): mCamera(NULL), mFrameId(-1), mVertices(NULL), mRenderer(NULL) {}535 Bvh(); 517 536 /** Destructor. 518 537 */ … … 534 553 void RenderBoundingBoxesWithDrawArrays(int numNodes); 535 554 536 int RenderBoundingBoxesImmediate(const BvhNodeContainer &nodes);537 /** Renders a bounding box in immediate mode using index restart538 and restarts the strip only if wished.539 */540 void RenderBoundingBoxImmediate(const AxisAlignedBox3 &box, bool restartStrip);541 555 /** Create the indices that each node needs to use vbo rendering. 542 556 */ … … 550 564 */ 551 565 void UpdateInteriors(BvhNode *node); 552 /** Recomputes the boundaries of the nodes. This function is always called if553 566 /** Recomputes the boundaries of the nodes. 567 This function is always called if some boundary options are changed. 554 568 */ 555 569 void RecomputeBounds(); … … 558 572 */ 559 573 int PostProcessLeaves(BvhLeafContainer &leaves); 560 561 562 int IsWithinViewFrustumLocal(BvhNode *node); 563 564 int IsWithinViewFrustum(const AxisAlignedBox3 &box, int planeMask, int preferredPlane); 565 566 float GetMinSquareDistance(const AxisAlignedBox3 &box) const; 567 574 568 575 569 576 //////////////////////// … … 572 579 BvhNode *mRoot; 573 580 /// pointers to the geometry associated with this node 574 Scene Geometry **mGeometry;581 SceneEntity **mGeometry; 575 582 /// #of entities 576 583 size_t mGeometrySize; … … 579 586 //////////////// 580 587 581 582 /// these values are valid for all nodes583 char mClipPlaneAABBVertexIndices[6][2];584 /// the current view frustum585 Frustum mFrustum;586 588 /// the current camera 587 589 Camera *mCamera; … … 589 591 int mFrameId; 590 592 /// a vertex array used if working with indexed arrays (without vbo) 591 //Point3f*mVertices;593 Vector3 *mVertices; 592 594 /// indices used for draw array rendering 593 595 unsigned int *mIndices; … … 599 601 600 602 float mAreaRatioThreshold; 601 float mVolRatioThreshold; 603 602 604 603 605 BvhStats mBvhStats; 604 606 605 //HierarchyNodeContainer mTestNodes;607 BvhNodeContainer mTestNodes; 606 608 607 609 unsigned int *mTestIndices; … … 609 611 int mCurrentIndicesPtr; 610 612 611 float mScale;612 613 Vector3 mNearPlane;614 float mNearPlaneD;615 613 int mNumNodes; 614 615 616 ////////////// 617 618 static unsigned int sCurrentVboId; 616 619 }; 617 620
Note: See TracChangeset
for help on using the changeset viewer.