Changeset 2555 for GTP/trunk/Lib/Vis/OnlineCullingCHC/src
- Timestamp:
- 10/05/07 15:36:52 (17 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
r2455 r2555 9 9 10 10 11 static int batchSize = 5;12 11 13 12 //----------------------------------------------------------------------- … … 36 35 { 37 36 if (0) CullingLogManager::GetSingleton()->LogMessage("chc"); 38 QueryQueue queryQueue;39 37 unsigned int visiblePixels = 0; 40 38 … … 42 40 //-- PART 1: process finished occlusion queries 43 41 44 while (!mHierarchyInterface->GetQueue()->empty() || ! queryQueue.empty())42 while (!mHierarchyInterface->GetQueue()->empty() || !mQueryQueue.empty()) 45 43 { 46 44 ////////// 47 45 //-- only wait for result if there are no nodes to process 48 46 49 while (! queryQueue.empty() &&50 (NodeInvalid( queryQueue.front().first) ||51 queryQueue.front().second->GetQueryResult(47 while (!mQueryQueue.empty() && 48 (NodeInvalid(mQueryQueue.front().first) || 49 mQueryQueue.front().second->GetQueryResult( 52 50 visiblePixels, mHierarchyInterface->GetQueue()->empty()))) 53 51 { 54 HierarchyNode *node = queryQueue.front().first;55 queryQueue.pop();52 HierarchyNode *node = mQueryQueue.front().first; 53 mQueryQueue.pop(); 56 54 57 55 // "invalid nodes" happen for hierarchies that have geometry … … 145 143 ++ mNumQueriesIssued; 146 144 147 const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves; 148 149 queryQueue.push(QueryPair(node, mHierarchyInterface-> 145 const bool testGeometry = 146 wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves; 147 148 mQueryQueue.push(QueryPair(node, mHierarchyInterface-> 150 149 IssueNodeOcclusionQuery(node, testGeometry))); 151 150 } … … 192 191 { 193 192 // parent was tested invisible in this frame 194 HierarchyNode *parent = mHierarchyInterface->GetParent(node); 195 return196 parent&&197 (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId()) &&198 !mHierarchyInterface->IsNodeVisible(parent);193 return ( 194 mHierarchyInterface->GetParent(node) && 195 (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId()) && 196 !mHierarchyInterface->IsNodeVisible(mHierarchyInterface->GetParent(node)) 197 ); 199 198 } 200 199 //----------------------------------------------------------------------- -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingPlusPlusManager.cpp
r2553 r2555 1 #include "BatchedQueriesCullingManager.h" 1 #include "CoherentHierarchicalCullingPlusPlusManager.h" 2 #include "CullingLogManager.h" 3 4 #include <time.h> 5 #include <sstream> 6 2 7 3 8 4 9 namespace GtpVisibility { 5 10 6 //----------------------------------------------------------------------- 7 BatchedQueriesCullingManager::BatchedQueriesCullingManager(): 8 mMaxPending(5) 9 { 10 } 11 //----------------------------------------------------------------------- 12 BatchedQueriesCullingManager::BatchedQueriesCullingManager(const unsigned int 13 assumedVisibility): 14 CoherentHierarchicalCullingManager(assumedVisibility), mMaxPending(5) 15 { 16 } 17 18 //----------------------------------------------------------------------- 19 void BatchedQueriesCullingManager::RenderScene() 20 { 21 QueryQueue queryQueue; 11 12 static const bool CULL_INVALID_NODES = false; 13 14 //----------------------------------------------------------------------- 15 CoherentHierarchicalCullingPlusPlusManager::CoherentHierarchicalCullingPlusPlusManager(): 16 mAssumedVisibility(0), mMaxInvisibleNodesSize(50) 17 { 18 } 19 //----------------------------------------------------------------------- 20 CoherentHierarchicalCullingPlusPlusManager::CoherentHierarchicalCullingPlusPlusManager( 21 const unsigned int assumedVisibility): 22 mAssumedVisibility(assumedVisibility), mMaxInvisibleNodesSize(50) 23 { 24 } 25 //----------------------------------------------------------------------- 26 void CoherentHierarchicalCullingPlusPlusManager::AssignAssumedVisibility(GtpVisibility::HierarchyNode *node) 27 { 28 if (!mHierarchyInterface->IsNodeVisible(node)) 29 // previously invisible nodes: give random offset just for the first test after 30 // becoming visible to avoid that all nodes are tested in the same frame 31 mHierarchyInterface->SetNodeAssumedVisible(node, rand() * mAssumedVisibility / RAND_MAX); 32 else 33 mHierarchyInterface->SetNodeAssumedVisible(node, mAssumedVisibility); 34 } 35 //----------------------------------------------------------------------- 36 void CoherentHierarchicalCullingPlusPlusManager::RenderScene() 37 { 38 if (0) CullingLogManager::GetSingleton()->LogMessage("chc++"); 39 22 40 unsigned int visiblePixels = 0; 23 41 24 PendingQueue pendingQueue; 25 42 ///////////// 26 43 //-- PART 1: process finished occlusion queries 27 while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty() ||!pendingQueue.empty()) 44 45 while (!mHierarchyInterface->GetQueue()->empty() || !mQueryQueue.empty() || 46 !mInvisibleNodes.empty() || !mVisibleNodes.empty()) 28 47 { 29 while (!queryQueue.empty() && 30 queryQueue.front().second->GetQueryResult(visiblePixels, 31 mHierarchyInterface->GetQueue()->empty())) 48 ////////// 49 //-- only wait for result if there are no nodes to process 50 51 bool resultAvailable = false; 52 while ( 53 !mQueryQueue.empty() && 54 (NodeInvalid(mQueryQueue.front().first) || 55 mHierarchyInterface->GetQueue()->empty() || 56 (resultAvailable = mQueryQueue.front().second->GetQueryResult(visiblePixels, false))) 57 ) 32 58 { 33 HierarchyNode *node = queryQueue.front().first; 34 35 queryQueue.pop(); 36 59 HierarchyNode *node = mQueryQueue.front().first; 60 61 // "invalid nodes" happen for hierarchies that store geometry in the interiors 62 // parent was tested invisible => remove children from queue 63 if (NodeInvalid(node)) {mQueryQueue.pop(); continue;} 64 65 // during the wait time issue nodes from visible queue 66 while (!mVisibleNodes.empty() && !resultAvailable) 67 { 68 HierarchyNode *vn = mVisibleNodes.front(); 69 mVisibleNodes.pop(); 70 IssueQuery(vn, false); 71 72 // check if result is already availalbe 73 resultAvailable = mQueryQueue.front().second->GetQueryResult(visiblePixels, false); 74 } 75 76 if (!resultAvailable) 77 mQueryQueue.front().second->GetQueryResult(visiblePixels, true); 78 79 resultAvailable = false; 80 mQueryQueue.pop(); 81 82 // tested visible 37 83 if (visiblePixels > mVisibilityThreshold) 38 84 { 39 // ensure that we only traverse once if geometry in node 85 // assing the #frames the node is assumed to stay visible 86 AssignAssumedVisibility(node); 87 88 // for previously visible interior node which contains geometry: 89 // ensure that we did not already traverse this node 90 // (which means that the visibility flag is set) 40 91 if (!mHierarchyInterface->IsNodeVisible(node)) 41 mHierarchyInterface->TraverseNode (node);92 mHierarchyInterface->TraverseNode2(node); 42 93 43 94 mHierarchyInterface->PullUpVisibility(node); … … 50 101 51 102 if (mVisualizeCulledNodes) 52 {53 103 mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED); 54 104 } 55 } 105 106 // update node's visited flag 107 mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); 56 108 } 57 109 110 //////////////// 58 111 //-- PART 2: hierarchical traversal 112 59 113 if (!mHierarchyInterface->GetQueue()->empty()) 60 114 { … … 62 116 mHierarchyInterface->GetQueue()->pop(); 63 117 118 // parent was tested invisible => remove children from queue 119 if (NodeInvalid(node)) continue; 120 64 121 bool intersects = false; 65 122 … … 69 126 70 127 if (mVisualizeCulledNodes) 71 {72 128 mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED); 73 } 74 } 75 // -- if node intersects near plane, skip query because wrong results possible 129 } 76 130 else if (intersects) 77 131 { 132 //-- if node intersects near plane, skip query because wrong results possible 78 133 SkipQuery(node); 79 134 } … … 85 140 86 141 // if we assume node to be visible in this frame => skip query 87 bool skipQuery = wasVisible && (mAssumedVisibility > 0) && 88 DecideVisible(node) && mHierarchyInterface->HasGeometry(node); 142 const bool skipQuery = wasVisible && 143 DecideVisible(node) && 144 mHierarchyInterface->HasGeometry(node); 89 145 90 146 if (skipQuery) … … 96 152 // identify nodes that we cannot skip queries for 97 153 // geometry not only in leaves => test for renderable geometry 98 bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node);154 const bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node); 99 155 100 // reset node's visibility classification101 // set visible if geometry in node so we only traverse once156 // set node's visibility classification 157 // we identify previously visible / invisible nodes in the query queue 102 158 mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery); 103 159 104 // update node's visited flag105 mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());106 107 // skip testing previously visible nodes without geometry108 160 if (issueQuery) 109 161 { 110 162 ++ mNumQueriesIssued; 111 // add to the pending queue instead of immediate query 112 if ((int)pendingQueue.size() < mMaxPending) 113 pendingQueue.push(PendingQuery(node, wasVisible)); 163 164 if (!wasVisible) 165 { 166 mInvisibleNodes.push_back(node); 167 168 if ((int)mInvisibleNodes.size() >= mMaxInvisibleNodesSize) 169 { 170 mHierarchyInterface->RenderQueue(); 171 // issue the batched queries 172 IssueBatchedQuery(mInvisibleNodes); 173 } 174 } 114 175 else 115 176 { 116 IssueMultipleQueries(pendingQueue, queryQueue); 177 mVisibleNodes.push(node); 178 //IssueQuery(node, false); 117 179 } 180 } 181 else 182 { 183 // skip testing previously visible nodes without geometry 184 // just update node's visited flag 185 mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); 118 186 } 119 187 … … 121 189 if (wasVisible) 122 190 { 123 mHierarchyInterface->TraverseNode (node);191 mHierarchyInterface->TraverseNode2(node); 124 192 } 125 193 } 126 194 } 127 195 128 // issue rest of queries 129 IssueMultipleQueries(pendingQueue, queryQueue); 196 197 if (mHierarchyInterface->GetQueue()->empty() && !mInvisibleNodes.empty()) 198 { 199 if (0) 200 { 201 std::stringstream d; 202 d << "inv nodes: " << (int)mInvisibleNodes.size(); 203 CullingLogManager::GetSingleton()->LogMessage(d.str()); 204 } 205 206 mHierarchyInterface->RenderQueue(); 207 IssueBatchedQuery(mInvisibleNodes); 208 } 209 210 // issue rest of nodes from nodes from visible queue 211 if (mHierarchyInterface->GetQueue()->empty() && mQueryQueue.empty() && !mVisibleNodes.empty()) 212 { 213 if (0) 214 { 215 std::stringstream d; 216 d << "vis nodes: " << (int)mVisibleNodes.size(); 217 CullingLogManager::GetSingleton()->LogMessage(d.str()); 218 } 219 220 while (!mVisibleNodes.empty()) 221 { 222 IssueQuery(mVisibleNodes.front(), false); 223 mVisibleNodes.pop(); 224 } 225 } 130 226 } 131 } 132 133 void BatchedQueriesCullingManager::IssueMultipleQueries(PendingQueue &pendingQueue, 134 QueryQueue &queryQueue) 135 { 136 while (!pendingQueue.empty()) 227 228 229 if (0) 137 230 { 138 HierarchyNode *node = pendingQueue.front().first; 139 const bool wasVisible = pendingQueue.front().second; 140 141 pendingQueue.pop(); 142 143 queryQueue.push(QueryPair(node, mHierarchyInterface-> 144 IssueNodeOcclusionQuery(node, wasVisible))); 231 std::stringstream d; 232 d << "queries: " << (int)mQueryQueue.size() << " vis: " << (int)mVisibleNodes.size() << " inv: " << (int)mInvisibleNodes.size(); 233 CullingLogManager::GetSingleton()->LogMessage(d.str()); 145 234 } 146 } 147 148 void BatchedQueriesCullingManager::SetMaxPending(int maxPending) 149 { 150 mMaxPending = maxPending; 151 } 152 153 } // namespace GtpVisibility 235 236 // render rest 237 mHierarchyInterface->RenderQueue(); 238 } 239 //----------------------------------------------------------------------- 240 void CoherentHierarchicalCullingPlusPlusManager::SetAssumedVisibility(const unsigned int assumedVisibility) 241 { 242 mAssumedVisibility = assumedVisibility; 243 } 244 //----------------------------------------------------------------------- 245 inline bool CoherentHierarchicalCullingPlusPlusManager::DecideVisible(HierarchyNode *node) const 246 { 247 mHierarchyInterface->DecNodeAssumedVisible(node); 248 //std::stringstream d; d << "node visible: " << mHierarchyInterface->GetNodeAssumedVisible(node); 249 //CullingLogManager::GetSingleton()->LogMessage(d.str()); 250 return mHierarchyInterface->GetNodeAssumedVisible(node) > 0; 251 } 252 //----------------------------------------------------------------------- 253 inline void CoherentHierarchicalCullingPlusPlusManager::SkipQuery(HierarchyNode *node) const 254 { 255 //-- set node to be visible in this frame, then traverse it 256 mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); 257 258 mHierarchyInterface->PullUpVisibility(node); 259 mHierarchyInterface->TraverseNode2(node); 260 } 261 //----------------------------------------------------------------------- 262 inline bool CoherentHierarchicalCullingPlusPlusManager::NodeInvalid(HierarchyNode *node) const 263 { 264 if (!CULL_INVALID_NODES) return false; 265 266 // parent was tested invisible in this frame 267 return ( 268 mHierarchyInterface->GetParent(node) && 269 (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId()) && 270 !mHierarchyInterface->IsNodeVisible(mHierarchyInterface->GetParent(node)) 271 ); 272 } 273 //----------------------------------------------------------------------- 274 void CoherentHierarchicalCullingPlusPlusManager::SetTestGeometryForVisibleLeaves(const bool testGeometry) 275 { 276 mTestGeometryForVisibleLeaves = testGeometry; 277 } 278 //----------------------------------------------------------------------- 279 bool CoherentHierarchicalCullingPlusPlusManager::GetTestGeometryForVisibleLeaves() 280 { 281 return mTestGeometryForVisibleLeaves; 282 } 283 //----------------------------------------------------------------------- 284 inline void CoherentHierarchicalCullingPlusPlusManager::IssueQuery(HierarchyNode *node, 285 const bool queryGeometry) 286 { 287 mQueryQueue.push(QueryPair(node, mHierarchyInterface-> 288 IssueNodeOcclusionQuery(node, queryGeometry))); 289 } 290 //----------------------------------------------------------------------- 291 void CoherentHierarchicalCullingPlusPlusManager::IssueBatchedQuery(HierarchyNodeContainer &nodes) 292 { 293 HierarchyNodeContainer::const_iterator nit, nit_end = nodes.end(); 294 295 for (nit = nodes.begin(); nit != nit_end; ++ nit) 296 IssueQuery(*nit, false); 297 298 nodes.clear(); 299 } 300 301 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/FrustumCullingManager.cpp
r2292 r2555 31 31 { 32 32 mHierarchyInterface->SetNodeVisible(node, true); 33 mHierarchyInterface->TraverseNode (node);33 mHierarchyInterface->TraverseNode2(node); 34 34 } 35 35 } 36 mHierarchyInterface->RenderQueue(); 36 37 } 37 38 } // namespace GtpVisibility -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj
r2542 r2555 253 253 UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> 254 254 <File 255 RelativePath="..\src\BatchedQueriesCullingManager.cpp">256 </File>257 <File258 255 RelativePath="..\src\CoherentHierarchicalCullingManager.cpp"> 256 </File> 257 <File 258 RelativePath=".\CoherentHierarchicalCullingPlusPlusManager.cpp"> 259 259 </File> 260 260 <File … … 297 297 UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> 298 298 <File 299 RelativePath="..\include\BatchedQueriesCullingManager.h">300 </File>301 <File302 299 RelativePath="..\include\CoherentHierarchicalCullingManager.h"> 303 300 </File> 304 301 <File 305 RelativePath="..\include\CoherentHierarchicalCulling Manager2.h">302 RelativePath="..\include\CoherentHierarchicalCullingPlusPlusManager.h"> 306 303 </File> 307 304 <File -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp
r2455 r2555 5 5 #include "DummyPreprocessingManager.h" 6 6 #include "RandomUpdateCullingManager.h" 7 #include "CoherentHierarchicalCullingPlusPlusManager.h" 7 8 #include "CullingLogManager.h" 8 9 … … 19 20 mAssumedVisibilityForChc(0) 20 21 { 21 #if 122 22 SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING); 23 #endif24 #if 025 SetCullingManager(VisibilityEnvironment::STOP_AND_WAIT_CULLING);26 #endif27 #if 028 SetCullingManager(VisibilityEnvironment::FRUSTUM_CULLING);29 #endif30 23 } 31 24 //----------------------------------------------------------------------- … … 61 54 mCullingManager = new FrustumCullingManager(); 62 55 break; 63 case VisibilityEnvironment:: RANDOM_UPDATE_CULLING:56 case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS: 64 57 { 65 RandomUpdateCullingManager *rum = new RandomUpdateCullingManager(mRandomCandidatesForRuc);66 rum->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);67 mCullingManager = rum;58 CoherentHierarchicalCullingPlusPlusManager *chcm = 59 new CoherentHierarchicalCullingPlusPlusManager(mAssumedVisibilityForChc); 60 mCullingManager = chcm; 68 61 } 69 62 break; … … 118 111 mAssumedVisibilityForChc = assumedVisibility; 119 112 120 if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)113 switch (mCullingManagerType) 121 114 { 115 case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING: 122 116 static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)-> 123 117 SetAssumedVisibility(mAssumedVisibilityForChc); 118 break; 119 case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS: 120 static_cast<CoherentHierarchicalCullingPlusPlusManager *>(mCullingManager)-> 121 SetAssumedVisibility(mAssumedVisibilityForChc); 122 break; 124 123 } 125 124 } … … 129 128 mRandomCandidatesForRuc = randomCandidates; 130 129 131 if (mCullingManagerType == VisibilityEnvironment:: RANDOM_UPDATE_CULLING)130 if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS) 132 131 { 133 132 static_cast<RandomUpdateCullingManager *>(mCullingManager)-> … … 160 159 SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 161 160 } 162 else if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING)161 /*else if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS) 163 162 { 164 163 static_cast<RandomUpdateCullingManager *>(mCullingManager)-> 165 164 SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 166 } 165 }*/ 167 166 } 168 167 //-----------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.