Changeset 2455 for GTP/trunk/Lib/Vis/OnlineCullingCHC/src
- Timestamp:
- 06/14/07 17:24:08 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/src
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
r2452 r2455 3 3 4 4 #include <time.h> 5 #include <sstream> 6 5 7 6 8 namespace GtpVisibility { 7 9 8 //----------------------------------------------------------------------- 9 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager() 10 { 11 SetAssumedVisibility(0); 12 // initialise random generator in case we use assumed visibility 13 //srand(time(NULL)); 10 11 static int batchSize = 5; 12 13 //----------------------------------------------------------------------- 14 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager(): 15 mAssumedVisibility(0) 16 { 14 17 } 15 18 //----------------------------------------------------------------------- 16 19 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager( 17 const unsigned int assumedVisibility) 18 { 19 SetAssumedVisibility(assumedVisibility); 20 // initialise random generator in case we use assumed visibility 21 //srand(time(NULL)); 20 const unsigned int assumedVisibility): 21 mAssumedVisibility(assumedVisibility) 22 { 23 } 24 //----------------------------------------------------------------------- 25 void CoherentHierarchicalCullingManager::AssignAssumedVisibility(GtpVisibility::HierarchyNode *node) 26 { 27 if (!mHierarchyInterface->IsNodeVisible(node)) 28 // previously invisible nodes: give random offset just for the first test after 29 // becoming visible to avoid that all nodes are tested in the same frame 30 mHierarchyInterface->SetNodeAssumedVisible(node, rand() * mAssumedVisibility / RAND_MAX); 31 else 32 mHierarchyInterface->SetNodeAssumedVisible(node, mAssumedVisibility); 22 33 } 23 34 //----------------------------------------------------------------------- … … 35 46 ////////// 36 47 //-- only wait for result if there are no nodes to process 48 37 49 while (!queryQueue.empty() && 38 50 (NodeInvalid(queryQueue.front().first) || … … 43 55 queryQueue.pop(); 44 56 57 // "invalid nodes" happen for hierarchies that have geometry 58 // not neccessarily in the leaves: 45 59 // parent was tested invisible => remove children from queue 46 if (NodeInvalid(node)) 47 { 48 //CullingLogManager::GetSingleton()->LogMessage("skipping this node"); 60 61 if (1 && NodeInvalid(node)) 49 62 continue; 50 } 63 51 64 // tested visible 52 65 if (visiblePixels > mVisibilityThreshold) 53 66 { 54 // in case geometry is in interior node: ensure that we only traverse once 67 // assing the #frames the node is assumed to stay visible 68 AssignAssumedVisibility(node); 69 70 // for previously visible interior node which contains geometry: 71 // ensure that we did not already traverse this node 72 // (which means that the visibility flag is set) 55 73 if (!mHierarchyInterface->IsNodeVisible(node)) 56 {57 74 mHierarchyInterface->TraverseNode(node); 58 }59 75 60 76 mHierarchyInterface->PullUpVisibility(node); … … 65 81 66 82 ++ mNumQueryCulledNodes; 67 83 68 84 if (mVisualizeCulledNodes) 69 {70 85 mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED); 71 }72 86 } 73 87 … … 76 90 } 77 91 92 //////////////// 78 93 //-- PART 2: hierarchical traversal 94 79 95 if (!mHierarchyInterface->GetQueue()->empty()) 80 96 { … … 83 99 84 100 // parent was tested invisible => remove children from queue 85 if (NodeInvalid(node)) 86 { 87 //CullingLogManager::GetSingleton()->LogMessage("skipping this node"); 101 if (1 && NodeInvalid(node)) 88 102 continue; 89 }90 103 91 104 bool intersects = false; … … 96 109 97 110 if (mVisualizeCulledNodes) 98 {99 111 mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED); 100 }101 112 } 102 113 //-- if node intersects near plane, skip query because wrong results possible … … 112 123 113 124 // if we assume node to be visible in this frame => skip query 114 const bool skipQuery = wasVisible && 115 (mAssumedVisibility > 0) && 125 const bool skipQuery = wasVisible && 116 126 DecideVisible(node) && 117 127 mHierarchyInterface->HasGeometry(node); … … 127 137 bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node); 128 138 129 // reset node's visibility classification130 // set visible if geometry in node so we only traverse once139 // set node's visibility classification 140 // we identify previously visible / invisible nodes in the query queue 131 141 mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery); 132 142 133 // skip testing previously visible nodes without geometry134 143 if (issueQuery) 135 144 { 136 145 ++ mNumQueriesIssued; 137 146 147 const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves; 148 138 149 queryQueue.push(QueryPair(node, mHierarchyInterface-> 139 IssueNodeOcclusionQuery(node, wasVisible)));150 IssueNodeOcclusionQuery(node, testGeometry))); 140 151 } 141 152 else 142 153 { 143 // update node's visited flag 154 // skip testing previously visible nodes without geometry 155 // just update node's visited flag 144 156 mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); 145 157 } … … 158 170 { 159 171 mAssumedVisibility = assumedVisibility; 160 161 if (!mAssumedVisibility)162 {163 mThreshold = 0;164 }165 else166 {167 mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;168 // fix visibility169 if (mAssumedVisibility > 100)170 mThreshold = RAND_MAX;171 }172 173 172 } 174 173 //----------------------------------------------------------------------- 175 174 inline bool CoherentHierarchicalCullingManager::DecideVisible(HierarchyNode *node) const 176 175 { 177 return rand() < mThreshold; 176 mHierarchyInterface->DecNodeAssumedVisible(node); 177 //std::stringstream d; d << "node visible: " << mHierarchyInterface->GetNodeAssumedVisible(node); 178 //CullingLogManager::GetSingleton()->LogMessage(d.str()); 179 return mHierarchyInterface->GetNodeAssumedVisible(node) > 0; 178 180 } 179 181 //----------------------------------------------------------------------- … … 196 198 !mHierarchyInterface->IsNodeVisible(parent); 197 199 } 198 } // namespace GtpVisibility 200 //----------------------------------------------------------------------- 201 void CoherentHierarchicalCullingManager::SetTestGeometryForVisibleLeaves(const bool testGeometry) 202 { 203 mTestGeometryForVisibleLeaves = testGeometry; 204 } 205 //----------------------------------------------------------------------- 206 bool CoherentHierarchicalCullingManager::GetTestGeometryForVisibleLeaves() 207 { 208 return mTestGeometryForVisibleLeaves; 209 } 210 211 } -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj
r2360 r2455 259 259 </File> 260 260 <File 261 RelativePath=".\CoherentHierarchicalCullingManager2.cpp">262 </File>263 <File264 261 RelativePath=".\CullingLogManager.cpp"> 265 262 </File> -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/HierarchyInterface.cpp
r2306 r2455 10 10 mNumTraversedNodes(0), 11 11 mHierarchyRoot(NULL), 12 mSavedNode(NULL), 13 mCurrentTestIdx(0), 14 mTestGeometryForVisibleLeaves(false) 12 mOldNode(NULL), 13 mCurrentTestIdx(0) 15 14 { 16 15 mDistanceQueue = new DistanceQueue(GtDistance<HierarchyNode *>(this)); … … 72 71 } 73 72 //----------------------------------------------------------------------- 74 void HierarchyInterface::TestGeometryForVisibleLeaves(bool testGeometry)75 {76 mTestGeometryForVisibleLeaves = testGeometry;77 }78 //-----------------------------------------------------------------------79 73 std::vector<HierarchyNode *> *HierarchyInterface::GetVisibleNodes() 80 74 { -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
r2332 r2455 13 13 14 14 const static int R_CANDIDATES = 1; 15 //----------------------------------------------------------------------- 16 RandomUpdateCullingManager::RandomUpdateCullingManager() 17 { 18 SetAssumedVisibility(0); 19 // initialise random generator in case we use assumed visibility 20 //srand(time(NULL)); 21 22 mRandomCandidates = R_CANDIDATES; 23 } 24 //----------------------------------------------------------------------- 25 RandomUpdateCullingManager::RandomUpdateCullingManager( 26 const unsigned int assumedVisibility) 27 { 28 SetAssumedVisibility(assumedVisibility); 29 // initialise random generator in case we use assumed visibility 30 //srand(time(NULL)); 31 32 mRandomCandidates = R_CANDIDATES; 15 16 //----------------------------------------------------------------------- 17 RandomUpdateCullingManager::RandomUpdateCullingManager(): mRandomCandidates(R_CANDIDATES) 18 { 19 } 20 //----------------------------------------------------------------------- 21 RandomUpdateCullingManager::RandomUpdateCullingManager(const unsigned int randomCandidates) 22 { 23 mRandomCandidates = std::max(randomCandidates, (unsigned int)1); 24 } 25 //----------------------------------------------------------------------- 26 void RandomUpdateCullingManager::SetRandomCandidates(const unsigned int randomCandidates) 27 { 28 mRandomCandidates = std::max(randomCandidates, (unsigned int)1); 33 29 } 34 30 //----------------------------------------------------------------------- … … 105 101 else 106 102 { 107 103 // fully visible subtree => render all in one bathc 108 104 if (mHierarchyInterface->IsNodeFullyVisible(node)) 109 105 { 110 #if 1 111 // node fully visible => test only random leaves 112 for (int i = 0; i < mRandomCandidates; ++ i) 113 { 114 HierarchyNode *randomLeaf = mHierarchyInterface->GetRandomLeaf(node); 115 116 if (!randomLeaf) 117 continue; 118 119 mHierarchyInterface->SetNodeVisible(randomLeaf, false); 120 121 // update node's visited flag 122 mHierarchyInterface->PullUpLastVisited(randomLeaf, mHierarchyInterface->GetFrameId()); 123 124 queryQueue.push(QueryPair(randomLeaf, 125 mHierarchyInterface->IssueNodeOcclusionQuery(node))); 126 } 127 #else 128 // test all leaves for visibility changes 106 // use different algorithm for finding random candidates 129 107 HierarchyNodeContainer mynodes; 130 108 mHierarchyInterface->CollectLeaves(node, mynodes); 131 109 110 const int p = mRandomCandidates * RAND_MAX / (int)mynodes.size(); 111 132 112 HierarchyNodeContainer::const_iterator nit, nit_end = mynodes.end(); 133 113 114 int nodesTested = 0; 134 115 for (nit = mynodes.begin(); nit != nit_end; ++ nit) 135 116 { 136 117 HierarchyNode *leaf = *nit; 118 119 if (rand() > p) 120 continue; 121 122 ++ nodesTested; 123 137 124 mHierarchyInterface->SetNodeVisible(leaf, false); 138 125 … … 140 127 mHierarchyInterface->PullUpLastVisited(leaf, mHierarchyInterface->GetFrameId()); 141 128 142 queryQueue.push(QueryPair(leaf, 143 mHierarchyInterface->IssueNodeOcclusionQuery(node))); 129 const bool testGeometry =mTestGeometryForVisibleLeaves; 130 131 mHierarchyInterface->IssueNodeOcclusionQuery(node, mTestGeometryForVisibleLeaves); 144 132 } 145 #endif 133 134 //std::stringstream d; d << "rc: " << mRandomCandidates << " tested: " << nodesTested << " of " << (int)mynodes.size(); 135 //CullingLogManager::GetSingleton()->LogMessage(d.str()); 136 146 137 mHierarchyInterface->RenderNodeRecursive(node); 147 148 138 continue; 149 139 } … … 153 143 (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1); 154 144 155 156 145 // if we assume node to be visible in this frame => skip query 157 const bool skipQuery = wasVisible && (mAssumedVisibility > 0) && 158 DecideVisible(node) && mHierarchyInterface->HasGeometry(node); 146 const bool skipQuery = false;//wasVisible && mHierarchyInterface->HasGeometry(node); 159 147 160 148 if (skipQuery) … … 181 169 ++ mNumQueriesIssued; 182 170 171 const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves; 172 183 173 queryQueue.push(QueryPair(node, mHierarchyInterface-> 184 IssueNodeOcclusionQuery(node, wasVisible)));174 IssueNodeOcclusionQuery(node, testGeometry))); 185 175 } 186 176 … … 196 186 // update the fully visible classifications 197 187 mHierarchyInterface->DetermineFullVisibility(mHierarchyInterface->GetHierarchyRoot()); 198 //mHierarchyInterface->DetermineVisibilityRatio(mHierarchyInterface->GetHierarchyRoot());199 }200 //-----------------------------------------------------------------------201 void RandomUpdateCullingManager::SetAssumedVisibility(const unsigned int assumedVisibility)202 {203 mAssumedVisibility = assumedVisibility;204 205 mThreshold = 0;206 207 if (mAssumedVisibility > 0)208 {209 mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;210 if (mAssumedVisibility > 100) // no random decicion211 mThreshold = RAND_MAX;212 }213 214 }215 //-----------------------------------------------------------------------216 inline bool RandomUpdateCullingManager::DecideVisible(HierarchyNode *node) const217 {218 return rand() < mThreshold;219 188 } 220 189 //----------------------------------------------------------------------- … … 227 196 mHierarchyInterface->TraverseNode(node); 228 197 } 198 //----------------------------------------------------------------------- 199 void RandomUpdateCullingManager::SetTestGeometryForVisibleLeaves(const bool testGeometry) 200 { 201 mTestGeometryForVisibleLeaves = testGeometry; 202 } 203 //----------------------------------------------------------------------- 204 bool RandomUpdateCullingManager::GetTestGeometryForVisibleLeaves() 205 { 206 return mTestGeometryForVisibleLeaves; 207 } 229 208 230 209 } // namespace GtpVisibility -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp
r2292 r2455 45 45 { 46 46 ++ mNumQueriesIssued; 47 48 47 unsigned int visiblePixels = 0; 49 50 mHierarchyInterface->IssueNodeOcclusionQuery(node)->GetQueryResult(visiblePixels, true);48 const bool waitForResult = true; 49 mHierarchyInterface->IssueNodeOcclusionQuery(node)->GetQueryResult(visiblePixels, waitForResult); 51 50 52 51 // node visible -
GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp
r2289 r2455 45 45 // delete old culling manager 46 46 if (mCullingManager) 47 {48 47 delete mCullingManager; 49 }50 48 51 49 mCullingManagerType = ocmType; … … 54 52 { 55 53 case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING: 56 mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc); 54 { 55 CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc); 56 chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 57 mCullingManager = chcm; 58 } 57 59 break; 58 59 60 case VisibilityEnvironment::FRUSTUM_CULLING: 60 61 mCullingManager = new FrustumCullingManager(); 61 62 break; 62 63 63 case VisibilityEnvironment::RANDOM_UPDATE_CULLING: 64 mCullingManager = new RandomUpdateCullingManager(); 64 { 65 RandomUpdateCullingManager *rum = new RandomUpdateCullingManager(mRandomCandidatesForRuc); 66 rum->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 67 mCullingManager = rum; 68 } 65 69 break; 66 67 70 case VisibilityEnvironment::STOP_AND_WAIT_CULLING: 68 71 mCullingManager = new StopAndWaitCullingManager(); 69 //mCullingManager = new RandomUpdateCullingManager();70 72 break; 71 72 73 default: 73 74 mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc); 74 75 break; 75 76 76 } 77 77 78 78 ///////// 79 79 //-- set threshold 80 80 81 mCullingManager->SetVisibilityThreshold(mVisibilityThreshold); 81 82 } … … 113 114 } 114 115 //----------------------------------------------------------------------- 115 void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 116 116 void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 117 117 { 118 118 mAssumedVisibilityForChc = assumedVisibility; 119 119 120 // in case we currently use chc 121 if (VisibilityManager::GetCullingManagerType() == 122 VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING) 120 if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING) 123 121 { 124 122 static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)-> 125 SetAssumedVisibility(assumedVisibility); 123 SetAssumedVisibility(mAssumedVisibilityForChc); 124 } 125 } 126 //----------------------------------------------------------------------- 127 void VisibilityManager::SetRandomUpdateCandidatesForRuc(unsigned int randomCandidates) 128 { 129 mRandomCandidatesForRuc = randomCandidates; 130 131 if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING) 132 { 133 static_cast<RandomUpdateCullingManager *>(mCullingManager)-> 134 SetRandomCandidates(mRandomCandidatesForRuc); 126 135 } 127 136 } … … 131 140 return mVisibilityEnvironment; 132 141 } 142 //----------------------------------------------------------------------- 143 unsigned int VisibilityManager::GetAssumedVisibilityForChc() 144 { 145 return mAssumedVisibilityForChc; 146 } 147 //----------------------------------------------------------------------- 148 unsigned int VisibilityManager::GetRandomUpdateCandidatesForRuc() 149 { 150 return mRandomCandidatesForRuc; 151 } 152 //----------------------------------------------------------------------- 153 void VisibilityManager::SetTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves) 154 { 155 mTestGeometryForVisibleLeaves = testGeometryForVisibleLeaves; 156 157 if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING) 158 { 159 static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)-> 160 SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 161 } 162 else if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING) 163 { 164 static_cast<RandomUpdateCullingManager *>(mCullingManager)-> 165 SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves); 166 } 167 } 168 //----------------------------------------------------------------------- 169 bool VisibilityManager::GetTestGeometryForVisibleLeaves() 170 { 171 return mTestGeometryForVisibleLeaves; 172 } 133 173 134 174 } // namespace GtpVisibility
Note: See TracChangeset
for help on using the changeset viewer.