- Timestamp:
- 06/15/08 00:27:36 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2760 r2761 81 81 mIndicesPtr(-1), 82 82 mIndices(NULL), 83 mId(0) 83 mId(0), 84 mIsMaxDepthForVirtualLeaf(false), 85 mIsVirtualLeaf(false) 86 { 87 } 88 89 90 BvhNode::~BvhNode() 84 91 { 85 92 } … … 91 98 92 99 mLastRenderedFrame = -999; 93 }94 95 96 BvhNode::~BvhNode()97 {98 100 } 99 101 … … 838 840 839 841 840 } 842 void Bvh::CollectVirtualLeaves(BvhNode *node, BvhNodeContainer &leaves) 843 { 844 stack<BvhNode *> tStack; 845 tStack.push(node); 846 847 while (!tStack.empty()) 848 { 849 BvhNode *node = tStack.top(); 850 tStack.pop(); 851 852 if (node->mIsVirtualLeaf) 853 { 854 leaves.push_back(node); 855 } 856 else if (!node->IsLeaf()) 857 { 858 BvhInterior *interior = static_cast<BvhInterior *>(node); 859 860 tStack.push(interior->mFront); 861 tStack.push(interior->mBack); 862 } 863 } 864 } 865 866 867 void Bvh::SetVirtualLeaves(int numTriangles) 868 { 869 // first invalidate old leaves 870 BvhNodeContainer leaves; 871 872 CollectVirtualLeaves(mRoot, leaves); 873 874 BvhNodeContainer::const_iterator bit, bit_end = leaves.end(); 875 876 for (bit = leaves.begin(); bit != bit_end; ++ bit) 877 { 878 (*bit)->mIsVirtualLeaf = false; 879 } 880 881 // assign new virtual leaves based on specified number of triangles per leaf 882 std::stack<BvhNode *> nodeStack; 883 nodeStack.push(mRoot); 884 885 while (!nodeStack.empty()) 886 { 887 BvhNode *node = nodeStack.top(); 888 nodeStack.pop(); 889 890 if (node->IsLeaf()) 891 { 892 BvhLeaf *leaf = static_cast<BvhLeaf *>(node); 893 leaf->mIsVirtualLeaf = true; 894 } 895 else 896 { 897 BvhInterior *interior = static_cast<BvhInterior *>(node); 898 899 BvhNode *f = interior->mFront; 900 BvhNode *b = interior->mBack; 901 902 if (node->mIsMaxDepthForVirtualLeaf || (CountTriangles(node) <= numTriangles)) 903 { 904 node->mIsVirtualLeaf = true; 905 } 906 else 907 { 908 nodeStack.push(interior->mBack); 909 nodeStack.push(interior->mFront); 910 } 911 } 912 } 913 } 914 915 916 void Bvh::PostProcess() 917 { 918 std::stack<BvhNode *> nodeStack; 919 nodeStack.push(mRoot); 920 921 while (!nodeStack.empty()) 922 { 923 BvhNode *node = nodeStack.top(); 924 nodeStack.pop(); 925 926 if (node->IsLeaf()) 927 { 928 node->mIsMaxDepthForVirtualLeaf = true; 929 } 930 else 931 { 932 BvhInterior *interior = static_cast<BvhInterior *>(node); 933 934 BvhNode *f = interior->mFront; 935 BvhNode *b = interior->mBack; 936 937 // point reached where we cannot subdivide further on object level 938 if ((f->mFirst == b->mFirst) && (f->mLast == b->mLast)) 939 { 940 node->mIsMaxDepthForVirtualLeaf = true; 941 } 942 else 943 { 944 nodeStack.push(f); 945 nodeStack.push(b); 946 } 947 } 948 } 949 } 950 951 952 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2760 r2761 79 79 virtual void ResetVisibility(); 80 80 81 virtual bool IsLeaf() = 0; //{ return BVH_NODE; } 81 virtual bool IsLeaf() const = 0; 82 83 bool IsVirtualLeaf() const { return mIsVirtualLeaf; } 82 84 83 85 … … 211 213 /// the bounding box 212 214 AxisAlignedBox3 mBox; 215 /// if this node is a virtual leaf 216 bool mIsVirtualLeaf; 217 /** This marks the maximal depth where a virtual leaf can be defined. 218 From this point on it makes no sense to traverse down further, as all 219 nodes below contain the same geometry, so no further refinement of visibility 220 can be archieved. All nodes below this point can merely used to define the 221 tighter bounds. 222 */ 223 bool mIsMaxDepthForVirtualLeaf; 213 224 }; 214 225 … … 335 346 BvhInterior(BvhNode *parent): mBack(NULL), mFront(NULL), BvhNode(parent) 336 347 {} 337 virtual bool IsLeaf() {return false;}348 virtual bool IsLeaf() const { return false; } 338 349 /** Back child. 339 350 */ 340 inline BvhNode *GetBack() { return mBack; }351 inline BvhNode *GetBack() { return mBack; } 341 352 /** Front child. 342 353 */ 343 inline BvhNode *GetFront() { return mFront; }354 inline BvhNode *GetFront() { return mFront; } 344 355 /** recursivly delete tree. 345 356 */ … … 375 386 ~BvhLeaf(); 376 387 377 virtual bool IsLeaf() { return true; }388 virtual bool IsLeaf() const { return true; } 378 389 }; 379 390 … … 450 461 void CollectNodes(BvhNode *node, BvhNodeContainer &nodes); 451 462 void CollectLeaves(BvhNode *node, BvhLeafContainer &leaves); 463 /** Collect only the virtual leaves. 464 */ 465 void CollectVirtualLeaves(BvhNode *node, BvhNodeContainer &leaves); 452 466 453 467 … … 511 525 */ 512 526 void ComputeIds(); 513 527 /** Assign virtual leaves based on specified number of triangles per leaf. 528 */ 529 void SetVirtualLeaves(int numTriangles); 514 530 515 531 //////// … … 576 592 /** Does some postprocessing on the nodes. 577 593 */ 578 //void PostProcess();594 void PostProcess(); 579 595 /** Helper method that updates the number of leaves in the subtree under 580 596 this node. -
GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp
r2760 r2761 62 62 const SceneEntityContainer &entities) 63 63 { 64 // export binary version of mesh 65 queue<BvhNode *> tStack; 64 queue<BvhNode *> tQueue; 66 65 ifstream stream(filename.c_str(), ifstream::binary); 67 66 … … 73 72 bvh->mRoot = LoadNextNode(stream, NULL); 74 73 75 t Stack.push(bvh->mRoot);74 tQueue.push(bvh->mRoot); 76 75 bvh->mNumNodes = 1; 77 76 78 while(!t Stack.empty())77 while(!tQueue.empty()) 79 78 { 80 BvhNode *node = t Stack.front();81 t Stack.pop();79 BvhNode *node = tQueue.front(); 80 tQueue.pop(); 82 81 83 82 if (!node->IsLeaf()) … … 87 86 BvhInterior *interior = static_cast<BvhInterior *>(node); 88 87 89 88 BvhNode *front = LoadNextNode(stream, interior); 90 89 BvhNode *back = LoadNextNode(stream, interior); 91 90 92 91 interior->mFront = front; 93 92 interior->mBack = back; … … 96 95 back->mDepth = interior->mDepth + 1; 97 96 98 t Stack.push(front);99 t Stack.push(back);97 tQueue.push(front); 98 tQueue.push(back); 100 99 } 101 100 } … … 104 103 105 104 /////////// 106 //-- post process 105 //-- post process nodes 106 107 bvh->PostProcess(); 108 // set virtual leaves for 500 triangles 109 bvh->SetVirtualLeaves(500); 107 110 108 111 bvh->UpdateNumLeaves(bvh->mRoot); -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
r2760 r2761 16 16 mDistanceQueue.push(mBvh->GetRoot()); 17 17 18 int traversed = 0; 18 19 while (!mDistanceQueue.empty()) 19 20 { … … 27 28 //bool intersects; 28 29 29 if ( 1)//mBvh->InsideViewFrustum(node, intersects))30 if (mBvh->IsWithinViewFrustum(node)) 30 31 { 31 32 // update node's visited flag => needed for rendering … … 33 34 //node->SetLastVisited(mFrameID); 34 35 //node->SetVisible(true); 35 36 ++ traversed; 36 37 TraverseNode(node); 37 38 } … … 41 42 } 42 43 } 44 45 std::cout << "traversed: " << traversed << std::endl; 43 46 } 44 47 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2760 r2761 66 66 void RenderTraverser::TraverseNode(BvhNode *node) 67 67 { 68 if (node->Is Leaf())68 if (node->IsVirtualLeaf()||node->IsLeaf()) 69 69 { 70 70 //mNumRenderedGeometry +=
Note: See TracChangeset
for help on using the changeset viewer.