- Timestamp:
- 06/18/08 17:33:16 (17 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/CHC_revisited
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
r2770 r2771 124 124 Bvh::Bvh(): 125 125 mCamera(NULL), 126 mFrameId(-1),127 126 mRoot(NULL), 128 127 mVertices(NULL), … … 138 137 Bvh::Bvh(const SceneEntityContainer &entities): 139 138 mCamera(NULL), 140 mFrameId(-1),141 139 mRoot(NULL), 142 140 mVertices(NULL), … … 349 347 350 348 351 void Bvh::InitFrame( Camera *camera, int currentFrameId)349 void Bvh::InitFrame() 352 350 { 353 351 // = 0011 1111 which means that at the beginning, all six planes have to frustum culled 354 352 mRoot->mPlaneMask = 0x3f; 355 mCamera = camera;356 357 mFrameId = currentFrameId;358 353 359 354 mCamera->CalcFrustum(sFrustum); … … 809 804 int Bvh::Render(BvhNode *node, RenderState *state) 810 805 { 811 //cout << "r " << node->mFirst << " " << node->mLast << endl; 812 813 int rendered = 0; 806 int renderedTriangles = 0; 814 807 815 808 for (int i = node->mFirst; i <= node->mLast; ++ i) 816 809 { 817 if (mGeometry[i]->GetLastRendered() != mFrameId) 818 { 819 mGeometry[i]->Render(state); 820 mGeometry[i]->SetLastRendered(mFrameId); 821 ++ rendered; 822 } 823 } 824 825 return rendered; 810 renderedTriangles += mGeometry[i]->GetGeometry()->CountTriangles(); 811 mGeometry[i]->Render(state); 812 } 813 814 return renderedTriangles; 826 815 } 827 816 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
r2770 r2771 447 447 */ 448 448 int CountTriangles(BvhLeaf *leaf) const; 449 449 /** Sets the scene camera 450 */ 451 void SetCamera(Camera * camera) { mCamera = camera; } 452 453 /////////////// 454 //-- functions collecting nodes based on some criteria 450 455 451 456 void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth); … … 490 495 */ 491 496 int IsWithinViewFrustum(BvhNode *node); 492 /** Sets frame dependent values .493 */ 494 void InitFrame( Camera *camera, int currentFrameId);497 /** Sets frame dependent values 498 */ 499 void InitFrame(); 495 500 /** This gives the orthogonal distance from the viewpoint to the nearest bounding box vertex 496 501 note that negative values can appear because culling is done only afterwards … … 618 623 /// the current camera 619 624 Camera *mCamera; 620 // current frame id621 int mFrameId;622 625 /// a vertex array used if working with indexed arrays (without vbo) 623 626 Vector3 *mVertices; -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp
r2770 r2771 2 2 #include "RenderState.h" 3 3 4 using namespace std; 4 5 5 6 namespace CHCDemo 6 7 { 7 8 8 CHCPlusPlusTraverser::CHCPlusPlusTraverser() 9 10 CHCPlusPlusTraverser::CHCPlusPlusTraverser() 9 11 { 10 12 } … … 16 18 while (!mDistanceQueue.empty() || !mQueryQueue.empty()) 17 19 { 20 bool resultAvailable; 18 21 while (!mQueryQueue.empty() && 19 (mQueryQueue.front()->ResultAvailable() || mDistanceQueue.empty())) 20 { 21 if (mQueryQueue.front()->ResultAvailable()) 22 { 23 OcclusionQuery *query = mQueryQueue.front(); 24 mQueryQueue.pop(); 25 26 // wait until result available 27 int visiblePixels = query->GetQueryResult(); 28 29 if (visiblePixels > mVisibilityThreshold) 30 { 31 BvhNode *node = query->GetFrontNode(); 32 33 node->SetVisible(true); 34 mBvh->MakeParentsVisible(node); 35 TraverseNode(node); 36 } 37 else 38 { 39 ++ mStats.mNumQueryCulledNodes; 40 } 41 } 42 else if (!mVQueue.empty()) 22 (mDistanceQueue.empty() || (resultAvailable = mQueryQueue.front()->ResultAvailable()))) 23 { 24 while (!resultAvailable && !mVQueue.empty()) 43 25 { 44 26 BvhNode *node = mVQueue.front(); 45 27 mVQueue.pop(); 46 28 47 29 OcclusionQuery *query = IssueOcclusionQuery(node, true); 48 30 mQueryQueue.push(query); 31 resultAvailable = mQueryQueue.front()->ResultAvailable(); 32 } 33 34 OcclusionQuery *query = mQueryQueue.front(); 35 mQueryQueue.pop(); 36 37 // wait until result available 38 int visiblePixels = query->GetQueryResult(); 39 40 if (visiblePixels > mVisibilityThreshold) 41 { 42 BvhNode *node = query->GetFrontNode(); 43 44 node->SetVisible(true); 45 mBvh->MakeParentsVisible(node); 46 TraverseNode(node); 47 } 48 else 49 { 50 ++ mStats.mNumQueryCulledNodes; 49 51 } 50 52 } … … 75 77 76 78 // identify nodes that we cannot skip queries for 77 const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() /*&& (node->GetAssumedVisibleFrameId() <= mFrameId)*/));79 const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() && (node->GetAssumedVisibleFrameId() <= mFrameId))); 78 80 79 81 … … 109 111 } 110 112 113 // distance queue empty: feed the remaining multiqueries to 114 // be able to proceed traversal 111 115 if (mDistanceQueue.empty()) 112 116 { 113 // issue remaining multiqueries114 117 IssueMultiQueries(); 115 118 } 119 } 120 121 // render the rest of the objects 122 if (mUseRenderQueue) 123 { 124 if (mRenderState->SetState(RenderState::RENDER)) 125 ++ mStats.mNumStateChanges; 126 127 mRenderQueue.Render(); 128 mRenderQueue.Clear(); 116 129 } 117 130 … … 156 169 mIQueue.push(node); 157 170 158 if (mIQueue.size() > 50)171 if (mIQueue.size() > mMaxBatchSize) 159 172 { 160 173 IssueMultiQueries(); -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h
r2770 r2771 17 17 //~CHCPlusPlusTraverser(); 18 18 19 19 20 protected: 20 21 /** Traverses and renders the scene with the specified method … … 26 27 void IssueMultiQueries(); 27 28 29 28 30 ////////////// 31 32 /// the query queue 33 QueryQueue mQueryQueue; 29 34 30 35 BvhNodeQueue mIQueue; -
GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.h
r2767 r2771 21 21 */ 22 22 virtual void Traverse(); 23 24 /// the query queue 25 QueryQueue mQueryQueue; 26 23 27 }; 24 28 -
GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
r2770 r2771 36 36 } 37 37 } 38 39 // render the rest of the objects 40 if (mUseRenderQueue) 41 { 42 mRenderQueue.Render(); 43 mRenderQueue.Clear(); 44 } 38 45 } 39 46 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp
r2768 r2771 28 28 29 29 30 RenderQueue::RenderQueue(): mState(NULL) 30 RenderQueue::RenderQueue(): mState(NULL), mMinSizeForSorting(5) 31 31 { 32 32 } … … 43 43 for (int i = 0; i < size; ++ i) 44 44 mEntities.push_back(entities[i]); 45 46 45 } 47 46 … … 62 61 void RenderQueue::Render() 63 62 { 64 Sort(); 63 if (mEntities.size() >= mMinSizeForSorting) 64 Sort(); 65 65 66 66 //if (!mEntities.empty()) Debug << "rendering render queue" << endl; -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.h
r2767 r2771 48 48 RenderState *mState; 49 49 SceneEntityContainer mEntities; 50 int mMinSizeForSorting; 50 51 }; 51 52 -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
r2770 r2771 5 5 #include "SceneEntity.h" 6 6 #include "RenderState.h" 7 8 9 using namespace std; 7 10 8 11 … … 35 38 mVisibilityThreshold(0), 36 39 mBvh(NULL), 37 mIsQueryMode(false),38 40 mUseOptimization(false), 39 41 mFrameId(-1), 40 42 mUseRenderQueue(false), 41 mAssumedVisibleFrames(10) 43 mAssumedVisibleFrames(10), 44 mMaxBatchSize(50) 42 45 { 43 46 } … … 78 81 void RenderTraverser::RenderNode(BvhNode *node) 79 82 { 80 if (mUseRenderQueue) 81 { 82 int geometrySize; 83 SceneEntity **geom = mBvh->GetGeometry(node, geometrySize); 84 mRenderQueue.Enqueue(geom, geometrySize); 85 mStats.mNumRenderedGeometry += geometrySize; 86 } 87 else 88 { 89 if (mRenderState->SetState(RenderState::RENDER)) 90 ++ mStats.mNumStateChanges; 91 92 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 93 } 83 if (node->GetLastRenderedFrame() != mFrameId) 84 { 85 //cout << "big error!!" << endl; 86 node->SetLastRenderedFrame(mFrameId); 87 88 if (mUseRenderQueue) 89 { 90 int geometrySize; 91 SceneEntity **geom = mBvh->GetGeometry(node, geometrySize); 92 mRenderQueue.Enqueue(geom, geometrySize); 93 mStats.mNumRenderedGeometry += geometrySize; 94 } 95 else 96 { 97 if (mRenderState->SetState(RenderState::RENDER)) 98 ++ mStats.mNumStateChanges; 99 100 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState); 101 } 102 } 94 103 } 95 104 … … 130 139 } 131 140 132 // if this node is a previous visible leaf => will be rendered anyway, thus we133 // can also test with the real geometry141 // if this node is a previous visible leaf: 142 // leaves will be rendered anyway => we can also test with the real geometry 134 143 if (wasVisible && mUseOptimization) 135 144 { 136 mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState);145 RenderNode(node); 137 146 } 138 147 else … … 151 160 152 161 153 void RenderTraverser::SetVisibilityThreshold(int threshold)154 {155 mVisibilityThreshold = threshold;156 }157 158 159 int RenderTraverser::GetVisibilityThreshold() const160 {161 return mVisibilityThreshold;162 }163 164 165 void RenderTraverser::SetUseOptimization(bool useOptimization)166 {167 mUseOptimization = useOptimization;168 }169 170 171 172 162 void RenderTraverser::RenderScene() 173 163 { … … 182 172 ++ mFrameId; 183 173 184 mBvh->InitFrame( mCamera, mFrameId);174 mBvh->InitFrame(); 185 175 186 176 mStats.Reset(); … … 195 185 Traverse(); 196 186 197 // render the rest of the objects198 if (mUseRenderQueue)199 {200 if (mRenderState->SetState(RenderState::RENDER))201 ++ mStats.mNumStateChanges;202 203 mRenderQueue.Render();204 mRenderQueue.Clear();205 }206 207 187 mRenderState->Reset(); 208 188 … … 221 201 } 222 202 223 } 203 204 205 206 void RenderTraverser::SetVisibilityThreshold(int threshold) 207 { 208 mVisibilityThreshold = threshold; 209 } 210 211 212 void RenderTraverser::SetUseOptimization(bool useOptimization) 213 { 214 mUseOptimization = useOptimization; 215 } 216 217 218 } -
GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
r2770 r2771 67 67 */ 68 68 void SetCamera(Camera *cam) {mCamera = cam;} 69 /** Renders a visualization of the hierarchy 70 */ 71 void RenderVisualization(); 72 /** Sets the current render state 73 */ 74 void SetRenderState(RenderState *state); 75 /** The traversal statistics 76 */ 77 const TraversalStatistics &GetStats() const { return mStats; } 78 79 80 ////////////////// 81 //-- options for the different rendering algorithms 82 83 /** If a render queue should be used to batch up and sort scene entities before 84 rendering. 85 */ 86 void SetUseRenderQueue(bool useRenderQueue); 69 87 /** Sets visible pixels threshold for visibility classification 70 88 */ 71 89 void SetVisibilityThreshold(int threshold); 72 /** Returns visibility threshold 73 */ 74 int GetVisibilityThreshold() const;75 / ** renders a visualization of the hierarchy76 */ 77 void RenderVisualization(); 78 /** use optimization to take leaf nodes instead of bounding box for occlusion queries90 91 92 /////////////////// 93 //-- CHC / CHC ++ related options 94 95 96 /** CHC optimization to query the geometry itself instead of the bounding box. 79 97 */ 80 98 void SetUseOptimization(bool useOptimization); 81 /** Sets the current render state99 /** The number of frames a previously visible node is assumed to stay visible. 82 100 */ 83 void SetRenderState(RenderState *state); 101 void SetAssumedVisibleFrames(int assumedVisibleFrames); 102 /** The maximum batch size for the i-queue 103 */ 104 void SetMaxBatchSize(int batchSize); 84 105 85 void SetUseRenderQueue(bool useRenderQueue);86 const TraversalStatistics &GetStats() const { return mStats; }87 106 88 107 protected: … … 120 139 /// the current frame id 121 140 int mFrameId; 141 /// the current render state 142 RenderState *mRenderState; 143 /// manages creation and destruction of the queries 144 QueryHandler mQueryHandler; 145 /// the statisitcs 146 TraversalStatistics mStats; 147 148 RenderQueue mRenderQueue; 122 149 123 bool mIsQueryMode;124 150 125 RenderState *mRenderState; 126 127 QueryHandler mQueryHandler; 128 129 TraversalStatistics mStats; 130 131 QueryQueue mQueryQueue; 151 ///////////////// 152 //-- algorithm parametes 132 153 133 154 int mVisibilityThreshold; … … 135 156 bool mUseOptimization; 136 157 137 RenderQueue mRenderQueue;138 139 158 bool mUseRenderQueue; 140 159 141 160 int mAssumedVisibleFrames; 161 162 int mMaxBatchSize; 142 163 }; 143 164 -
GTP/trunk/App/Demos/Vis/CHC_revisited/Visualization.cpp
r2767 r2771 49 49 tStack.pop(); 50 50 51 if (!node->Is Leaf())51 if (!node->IsVirtualLeaf()) 52 52 { 53 53 BvhInterior *interior = static_cast<BvhInterior *>(node); -
GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
r2770 r2771 41 41 /// the rendering algorithm 42 42 int renderMode = RenderTraverser::CULL_FRUSTUM; 43 /// the visibility threshold44 int threshold = 0;45 43 // eye near plane distance 46 44 float nearDist = 0.1f; 45 /// the pixel threshold where a node is still considered invisible 46 int threshold; 47 47 48 48 49 const float keyForwardMotion = 1.0f; … … 71 72 bool showBoundingVolumes = false; 72 73 bool visMode = false; 73 74 75 // visualisation view matrix76 Matrix4x4 visView;77 74 78 75 //mouse navigation state … … 154 151 //bvh = bvhLoader.Load("house_test.bvh", sceneEntities); 155 152 153 bvh->SetCamera(camera); 156 154 ResetTraverser(); 157 155 … … 284 282 DEL_PTR(traverser); 285 283 284 bvh->ResetNodeClassifications(); 285 286 286 switch (renderMode) 287 287 { … … 427 427 break; 428 428 case '+': 429 threshold = traverser->GetVisibilityThreshold() +10;429 threshold += 10; 430 430 traverser->SetVisibilityThreshold(threshold); 431 431 break; 432 432 case '-': 433 threshold = traverser->GetVisibilityThreshold() -10;433 threshold -= 10; 434 434 if(threshold < 0) threshold = 0; 435 436 435 traverser->SetVisibilityThreshold(threshold); 437 436 break; … … 776 775 glViewport(winWidth / 2, winHeight / 2, winWidth, winHeight); 777 776 glPushMatrix(); 778 glLoadMatrixf((float *)visView.x);777 //glLoadMatrixf((float *)visView.x); 779 778 780 779 glClear(GL_DEPTH_BUFFER_BIT); … … 859 858 860 859 static long renderTime = traverser->GetStats().mRenderTime; 861 const float expFactor = 0. 5f;860 const float expFactor = 0.95f; 862 861 renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime; 863 862 864 863 accumulatedTime += renderTime; 865 864 866 if (accumulatedTime > 200) // update every fraction of a second865 if (accumulatedTime > 100) // update every fraction of a second 867 866 { 868 867 accumulatedTime = 0; … … 877 876 } 878 877 879 sprintf_s(msg2, "threshold: %4d%s", 880 traverser->GetVisibilityThreshold(), optstr[useOptimization]); 878 sprintf_s(msg2, "threshold: %4d%s", threshold, optstr[useOptimization]); 881 879 882 880 string str;
Note: See TracChangeset
for help on using the changeset viewer.