Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/HierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/HierarchyInterface.cpp	(revision 2306)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/HierarchyInterface.cpp	(revision 2455)
@@ -10,7 +10,6 @@
 mNumTraversedNodes(0), 
 mHierarchyRoot(NULL), 
-mSavedNode(NULL), 
-mCurrentTestIdx(0), 
-mTestGeometryForVisibleLeaves(false)
+mOldNode(NULL), 
+mCurrentTestIdx(0)
 {	
 	mDistanceQueue = new DistanceQueue(GtDistance<HierarchyNode *>(this));
@@ -72,9 +71,4 @@
 }
 //-----------------------------------------------------------------------
-void HierarchyInterface::TestGeometryForVisibleLeaves(bool testGeometry)
-{
-	mTestGeometryForVisibleLeaves = testGeometry;
-}
-//-----------------------------------------------------------------------
 std::vector<HierarchyNode *> *HierarchyInterface::GetVisibleNodes()
 {
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp	(revision 2292)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp	(revision 2455)
@@ -45,8 +45,7 @@
 		{	
 			++ mNumQueriesIssued;
-
 			unsigned int visiblePixels = 0;
-
-			mHierarchyInterface->IssueNodeOcclusionQuery(node)->GetQueryResult(visiblePixels, true);
+			const bool waitForResult = true;
+			mHierarchyInterface->IssueNodeOcclusionQuery(node)->GetQueryResult(visiblePixels, waitForResult);
 		
 			// node visible
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp	(revision 2452)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp	(revision 2455)
@@ -3,21 +3,32 @@
 
 #include <time.h>
+#include <sstream>
+
 
 namespace GtpVisibility {
 
-//-----------------------------------------------------------------------
-CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager()
-{
-	SetAssumedVisibility(0);
-	// initialise random generator in case we use assumed visibility
-	//srand(time(NULL));
+
+static int batchSize = 5;
+
+//-----------------------------------------------------------------------
+CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager():
+mAssumedVisibility(0)
+{
 }
 //-----------------------------------------------------------------------
 CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager(
-														const unsigned int assumedVisibility)
-{
-	SetAssumedVisibility(assumedVisibility);
-	// initialise random generator in case we use assumed visibility
-	//srand(time(NULL));
+														const unsigned int assumedVisibility):
+mAssumedVisibility(assumedVisibility)
+{
+}
+//-----------------------------------------------------------------------
+void CoherentHierarchicalCullingManager::AssignAssumedVisibility(GtpVisibility::HierarchyNode *node)
+{
+	if (!mHierarchyInterface->IsNodeVisible(node))
+		// previously invisible nodes: give random offset just for the first test after
+		// becoming visible to avoid that all nodes are tested in the same frame
+		mHierarchyInterface->SetNodeAssumedVisible(node, rand() * mAssumedVisibility / RAND_MAX);
+	else
+		mHierarchyInterface->SetNodeAssumedVisible(node, mAssumedVisibility);
 }
 //-----------------------------------------------------------------------
@@ -35,4 +46,5 @@
 		//////////
 		//-- only wait for result if there are no nodes to process
+
 		while (!queryQueue.empty() && 
 			   (NodeInvalid(queryQueue.front().first) ||
@@ -43,18 +55,22 @@
 			queryQueue.pop();
 
+			// "invalid nodes" happen for hierarchies that have geometry
+			// not neccessarily in the leaves:
 			// parent was tested invisible => remove children from queue
-			if (NodeInvalid(node))
-			{
-				//CullingLogManager::GetSingleton()->LogMessage("skipping this node");
+
+			if (1 && NodeInvalid(node))
 				continue;
-			}
+
 			// tested visible
 			if (visiblePixels > mVisibilityThreshold)
 			{
-				// in case geometry is in interior node: ensure that we only traverse once
+				// assing the #frames the node is assumed to stay visible
+				AssignAssumedVisibility(node);
+
+				// for previously visible interior node which contains geometry: 
+				// ensure that we did not already traverse this node 
+				// (which means that the visibility flag is set)
 				if (!mHierarchyInterface->IsNodeVisible(node))
-				{
 					mHierarchyInterface->TraverseNode(node);
-				}
 
 				mHierarchyInterface->PullUpVisibility(node);
@@ -65,9 +81,7 @@
 
                 ++ mNumQueryCulledNodes;
-				
+
 				if (mVisualizeCulledNodes)
-				{
 					mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED);
-				}
 			}
 			
@@ -76,5 +90,7 @@
 		}
 		
+		////////////////
 		//-- PART 2: hierarchical traversal
+
 		if (!mHierarchyInterface->GetQueue()->empty())
 		{
@@ -83,9 +99,6 @@
 				
 			// parent was tested invisible => remove children from queue
-			if (NodeInvalid(node))
-			{
-				//CullingLogManager::GetSingleton()->LogMessage("skipping this node");
+			if (1 && NodeInvalid(node))
 				continue;
-			}
 
 			bool intersects = false;
@@ -96,7 +109,5 @@
 
 				if (mVisualizeCulledNodes)
-				{
 					mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED);
-				}
 			}
 			//-- if node intersects near plane, skip query because wrong results possible
@@ -112,6 +123,5 @@
 				
 				// if we assume node to be visible in this frame => skip query 
-				const bool skipQuery = wasVisible && 
-					                   (mAssumedVisibility > 0) && 
+				const bool skipQuery = wasVisible &&
 									   DecideVisible(node) && 
 									   mHierarchyInterface->HasGeometry(node);
@@ -127,19 +137,21 @@
 				bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node);
 							
-				// reset node's visibility classification
-				// set visible if geometry in node so we only traverse once
+				// set node's visibility classification
+				// we identify previously visible / invisible nodes in the query queue
 				mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery);
 
-				// skip testing previously visible nodes without geometry
 				if (issueQuery)
 				{
 					++ mNumQueriesIssued;
 					
+					const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves;
+
 					queryQueue.push(QueryPair(node, mHierarchyInterface->
-						IssueNodeOcclusionQuery(node, wasVisible)));
+						IssueNodeOcclusionQuery(node, testGeometry)));
 				}
 				else
 				{
-					// update node's visited flag
+					// skip testing previously visible nodes without geometry
+                    // just update node's visited flag
 					mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
 				}
@@ -158,22 +170,12 @@
 {
 	mAssumedVisibility = assumedVisibility;
-	
-	if (!mAssumedVisibility)
-	{
-		mThreshold = 0;
-	}
-	else
-	{
-		mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;
-		 // fix visibility
-		if (mAssumedVisibility > 100)
-			mThreshold = RAND_MAX;
-	}
-	
 }
 //-----------------------------------------------------------------------
 inline bool CoherentHierarchicalCullingManager::DecideVisible(HierarchyNode *node) const
 {
-	return rand() < mThreshold;
+	mHierarchyInterface->DecNodeAssumedVisible(node);
+	//std::stringstream d; d << "node visible: " << mHierarchyInterface->GetNodeAssumedVisible(node);
+	//CullingLogManager::GetSingleton()->LogMessage(d.str());
+	return mHierarchyInterface->GetNodeAssumedVisible(node) > 0;
 }
 //-----------------------------------------------------------------------
@@ -196,3 +198,14 @@
 		!mHierarchyInterface->IsNodeVisible(parent);
 }
-} // namespace GtpVisibility
+//-----------------------------------------------------------------------
+void CoherentHierarchicalCullingManager::SetTestGeometryForVisibleLeaves(const bool testGeometry)
+{
+	mTestGeometryForVisibleLeaves = testGeometry;
+}
+//-----------------------------------------------------------------------
+bool CoherentHierarchicalCullingManager::GetTestGeometryForVisibleLeaves()
+{
+	return mTestGeometryForVisibleLeaves;
+}
+
+}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp	(revision 2289)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp	(revision 2455)
@@ -45,7 +45,5 @@
 		// delete old culling manager
 		if (mCullingManager)
-		{
 			delete mCullingManager;
-		}
 
 		mCullingManagerType = ocmType;
@@ -54,28 +52,31 @@
 		{
 		case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
-			mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
+			{
+				CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
+				chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
+				mCullingManager = chcm;
+			}
 			break;
-
 		case VisibilityEnvironment::FRUSTUM_CULLING:
 			mCullingManager = new FrustumCullingManager();
 			break;
-
 		case VisibilityEnvironment::RANDOM_UPDATE_CULLING:
-			mCullingManager = new RandomUpdateCullingManager();	
+			{
+				RandomUpdateCullingManager *rum = new RandomUpdateCullingManager(mRandomCandidatesForRuc);
+				rum->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
+				mCullingManager = rum;
+			}
 			break;
-
 		case VisibilityEnvironment::STOP_AND_WAIT_CULLING:
 			mCullingManager = new StopAndWaitCullingManager();
-			//mCullingManager = new RandomUpdateCullingManager();
 			break;
-
 		default:
 			mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
 			break;
-
 		}
 
 		/////////
 		//-- set threshold
+
 		mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);	
 	}
@@ -113,15 +114,23 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 
-									 
+void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 									 
 {
 	mAssumedVisibilityForChc = assumedVisibility;
 
-	// in case we currently use chc
-	if (VisibilityManager::GetCullingManagerType() == 
-		VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
+	if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
 	{
 		static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
-				SetAssumedVisibility(assumedVisibility);
+				SetAssumedVisibility(mAssumedVisibilityForChc);
+	}
+}
+//-----------------------------------------------------------------------
+void VisibilityManager::SetRandomUpdateCandidatesForRuc(unsigned int randomCandidates) 									 
+{
+	mRandomCandidatesForRuc = randomCandidates;
+
+	if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING)
+	{
+		static_cast<RandomUpdateCullingManager *>(mCullingManager)->
+				SetRandomCandidates(mRandomCandidatesForRuc);
 	}
 }
@@ -131,4 +140,35 @@
 	return mVisibilityEnvironment;
 }
+//-----------------------------------------------------------------------
+unsigned int VisibilityManager::GetAssumedVisibilityForChc()
+{
+	return mAssumedVisibilityForChc;
+}
+//-----------------------------------------------------------------------
+unsigned int VisibilityManager::GetRandomUpdateCandidatesForRuc()
+{
+	return mRandomCandidatesForRuc;
+}
+//-----------------------------------------------------------------------
+void VisibilityManager::SetTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves)
+{
+	mTestGeometryForVisibleLeaves = testGeometryForVisibleLeaves;
+
+	if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
+	{
+		static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
+				SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
+	}
+	else if (mCullingManagerType == VisibilityEnvironment::RANDOM_UPDATE_CULLING)
+	{
+		static_cast<RandomUpdateCullingManager *>(mCullingManager)->
+				SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
+	}
+}
+//-----------------------------------------------------------------------
+bool VisibilityManager::GetTestGeometryForVisibleLeaves()
+{
+	return mTestGeometryForVisibleLeaves;
+}
 
 } // namespace GtpVisibility
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj	(revision 2360)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj	(revision 2455)
@@ -259,7 +259,4 @@
 			</File>
 			<File
-				RelativePath=".\CoherentHierarchicalCullingManager2.cpp">
-			</File>
-			<File
 				RelativePath=".\CullingLogManager.cpp">
 			</File>
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp	(revision 2332)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp	(revision 2455)
@@ -13,22 +13,18 @@
 
 const static int R_CANDIDATES = 1;
-//-----------------------------------------------------------------------
-RandomUpdateCullingManager::RandomUpdateCullingManager()
-{
-	SetAssumedVisibility(0);
-	// initialise random generator in case we use assumed visibility
-	//srand(time(NULL));
-
-	mRandomCandidates = R_CANDIDATES;
-}
-//-----------------------------------------------------------------------
-RandomUpdateCullingManager::RandomUpdateCullingManager(
-			const unsigned int assumedVisibility)
-{
-	SetAssumedVisibility(assumedVisibility);
-	// initialise random generator in case we use assumed visibility
-	//srand(time(NULL));
-
-	mRandomCandidates = R_CANDIDATES;
+
+//-----------------------------------------------------------------------
+RandomUpdateCullingManager::RandomUpdateCullingManager(): mRandomCandidates(R_CANDIDATES)
+{
+}
+//-----------------------------------------------------------------------
+RandomUpdateCullingManager::RandomUpdateCullingManager(const unsigned int randomCandidates)
+{	
+	mRandomCandidates = std::max(randomCandidates, (unsigned int)1);
+}
+//-----------------------------------------------------------------------
+void RandomUpdateCullingManager::SetRandomCandidates(const unsigned int randomCandidates)
+{
+	mRandomCandidates = std::max(randomCandidates, (unsigned int)1);
 }
 //-----------------------------------------------------------------------
@@ -105,34 +101,25 @@
 			else
 			{
-				
+				// fully visible subtree => render all in one bathc
 				if (mHierarchyInterface->IsNodeFullyVisible(node))
 				{
-#if 1
-					// node fully visible => test only random leaves
-					for (int i = 0; i < mRandomCandidates; ++ i)
-					{
-						HierarchyNode *randomLeaf = mHierarchyInterface->GetRandomLeaf(node);
-						
-						if (!randomLeaf)
-							continue;
-
-						mHierarchyInterface->SetNodeVisible(randomLeaf, false);
-
-						// update node's visited flag
-						mHierarchyInterface->PullUpLastVisited(randomLeaf, mHierarchyInterface->GetFrameId());
-
-						queryQueue.push(QueryPair(randomLeaf, 
-							mHierarchyInterface->IssueNodeOcclusionQuery(node)));
-					}
-#else
-					// test all leaves for visibility changes
+					// use different algorithm for finding random candidates
 					HierarchyNodeContainer mynodes;
 					mHierarchyInterface->CollectLeaves(node, mynodes);
 
+					const int p = mRandomCandidates * RAND_MAX / (int)mynodes.size();
+
 					HierarchyNodeContainer::const_iterator nit, nit_end = mynodes.end();
 
+					int nodesTested = 0;
 					for (nit = mynodes.begin(); nit != nit_end; ++ nit)
 					{
 						HierarchyNode *leaf = *nit;
+
+						if (rand() > p)
+							continue;
+
+						++ nodesTested;
+
 						mHierarchyInterface->SetNodeVisible(leaf, false);
 
@@ -140,10 +127,13 @@
 						mHierarchyInterface->PullUpLastVisited(leaf, mHierarchyInterface->GetFrameId());
 
-						queryQueue.push(QueryPair(leaf, 
-							mHierarchyInterface->IssueNodeOcclusionQuery(node)));
+						const bool testGeometry =mTestGeometryForVisibleLeaves;
+
+						mHierarchyInterface->IssueNodeOcclusionQuery(node, mTestGeometryForVisibleLeaves);
 					}
-#endif
+		
+					//std::stringstream d; d << "rc: " << mRandomCandidates << " tested: " << nodesTested << " of " << (int)mynodes.size();
+					//CullingLogManager::GetSingleton()->LogMessage(d.str());
+
 					mHierarchyInterface->RenderNodeRecursive(node);
-
 					continue;
 				}
@@ -153,8 +143,6 @@
 					(mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1);
 					
-
 				// if we assume node to be visible in this frame => skip query 
-				const bool skipQuery = wasVisible && (mAssumedVisibility > 0) && 
-					DecideVisible(node) && mHierarchyInterface->HasGeometry(node);
+				const bool skipQuery = false;//wasVisible && mHierarchyInterface->HasGeometry(node);
 
 				if (skipQuery)
@@ -181,6 +169,8 @@
 					++ mNumQueriesIssued;
 					
+					const bool testGeometry = wasVisible && mHierarchyInterface->IsLeaf(node) && mTestGeometryForVisibleLeaves;
+
 					queryQueue.push(QueryPair(node, mHierarchyInterface->
-						IssueNodeOcclusionQuery(node, wasVisible)));
+						IssueNodeOcclusionQuery(node, testGeometry)));
 				}
 				
@@ -196,25 +186,4 @@
 	// update the fully visible classifications
 	mHierarchyInterface->DetermineFullVisibility(mHierarchyInterface->GetHierarchyRoot());
-	//mHierarchyInterface->DetermineVisibilityRatio(mHierarchyInterface->GetHierarchyRoot());
-}
-//-----------------------------------------------------------------------
-void RandomUpdateCullingManager::SetAssumedVisibility(const unsigned int assumedVisibility)
-{
-	mAssumedVisibility = assumedVisibility;
-	
-	mThreshold = 0;
-
-	if (mAssumedVisibility > 0)
-	{
-		mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;
-		if (mAssumedVisibility > 100) // no random decicion
-			mThreshold = RAND_MAX;
-	}
-
-}
-//-----------------------------------------------------------------------
-inline bool RandomUpdateCullingManager::DecideVisible(HierarchyNode *node) const
-{
-	return rand() < mThreshold;
 }
 //-----------------------------------------------------------------------
@@ -227,4 +196,14 @@
 	mHierarchyInterface->TraverseNode(node);
 }
+//-----------------------------------------------------------------------
+void RandomUpdateCullingManager::SetTestGeometryForVisibleLeaves(const bool testGeometry)
+{
+	mTestGeometryForVisibleLeaves = testGeometry;
+}
+//-----------------------------------------------------------------------
+bool RandomUpdateCullingManager::GetTestGeometryForVisibleLeaves()
+{
+	return mTestGeometryForVisibleLeaves;
+}
 
 } // namespace GtpVisibility
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager2.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager2.cpp	(revision 2360)
+++ 	(revision )
@@ -1,327 +1,0 @@
-#include "CoherentHierarchicalCullingManager2.h"
-#include "CullingLogManager.h"
-
-#include <time.h>
-#include <sstream>
-
-namespace GtpVisibility {
-
-//-----------------------------------------------------------------------
-CoherentHierarchicalCullingManager2::CoherentHierarchicalCullingManager2()
-{
-	SetAssumedVisibility(0);
-	// initialise random generator in case we use assumed visibility
-	//srand(time(NULL));
-}
-//-----------------------------------------------------------------------
-CoherentHierarchicalCullingManager2::CoherentHierarchicalCullingManager2(
-														const unsigned int assumedVisibility)
-{
-	SetAssumedVisibility(assumedVisibility);
-	// initialise random generator in case we use assumed visibility
-	//srand(time(NULL));
-}
-//-----------------------------------------------------------------------
-#if 1
-
-void CoherentHierarchicalCullingManager2::RenderScene()
-{
-	//CullingLogManager::GetSingleton()->LogMessage("chc");
-	QueryQueue queryQueue;
-	unsigned int visiblePixels = 0;
-	
-	/////////////
-	//-- PART 1: process finished occlusion queries
-
-	while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty())
-	{
-		bool resultAvailable = false;
-
-		const bool nodeQueueEmpty = mHierarchyInterface->GetQueue()->empty();
-		const int queryQueueSize = (int)queryQueue.size();
-		bool queryAvailable = true;
-
-		//-- only wait for result if there are no nodes to process
-		while (!queryQueue.empty() && 
-				(queryAvailable = queryQueue.front().second->GetQueryResult(visiblePixels, false)))
-		{
-			HierarchyNode *node = queryQueue.front().first;
-			queryQueue.pop();
-
-			// render nodes if queue is still idle ...
-
-			if (1&&nodeQueueEmpty)
-			{
-				std::stringstream d; d << "qu: " << queryQueueSize;
-				CullingLogManager::GetSingleton()->LogMessage(d.str());
-			}
-
-			
-			if (visiblePixels > mVisibilityThreshold)
-			{
-				// check visibility to ensure that we traverse node only once
-				// (important for interior nodes with geometry
-				if (!mHierarchyInterface->IsNodeVisible(node))
-				{
-					mHierarchyInterface->TraverseNode(node);
-				}
-
-				mHierarchyInterface->PullUpVisibility(node);
-			}
-			else
-			{	
-				mHierarchyInterface->SetNodeVisible(node, false);
-
-				++ mNumQueryCulledNodes;
-				
-				if (mVisualizeCulledNodes)
-				{
-					mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED);
-				}
-			}
-		}
-		
-
-		if (!queryAvailable)
-		{
-			 // query not yet available => render some geometry
-			HierarchyNode *node = queryQueue.front().first;
-			
-			// check visibility to ensure that we traverse node only once
-			// (important for interior nodes with geometry
-			if (!mHierarchyInterface->IsNodeVisible(node))
-			{
-				mHierarchyInterface->SetNodeVisible(node, true);
-				mHierarchyInterface->TraverseNode(node);
-			}
-		}
-
-
-		//-- PART 2: hierarchical traversal
-		if (!mHierarchyInterface->GetQueue()->empty())
-		{
-			HierarchyNode *node = mHierarchyInterface->GetQueue()->top();
-		
-			mHierarchyInterface->GetQueue()->pop();
-				
-			bool intersects = false;
-
-			if (!mHierarchyInterface->CheckFrustumVisible(node, intersects))
-			{
-				++ mNumFrustumCulledNodes;
-
-				if (mVisualizeCulledNodes)
-				{
-					mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED);
-				}
-			}
-			//-- if node intersects near plane, skip query because wrong results possible
-			else if (intersects)
-			{
-				SkipQuery(node);
-			}
-			else
-			{
-				// identify previously visible nodes
-				bool wasVisible = mHierarchyInterface->IsNodeVisible(node) && 
-					(mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1);
-				
-				// if we assume node to be visible in this frame => skip query 
-				bool skipQuery = wasVisible && (mAssumedVisibility > 0) && 
-					DecideVisible(node) && mHierarchyInterface->HasGeometry(node);
-
-				if (skipQuery)
-				{
-					SkipQuery(node);
-					continue;
-				}
-
-                // identify nodes that we cannot skip queries for
-				// geometry not only in leaves => test for renderable geometry
-				bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node);
-							
-				// reset node's visibility classification
-				// set visibe if geometry in node so we only traverse once
-				mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery);
-
-				// update node's visited flag
-				mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
-				
-				// skip testing previously visible nodes without geometry
-				if (issueQuery)
-				{
-					++ mNumQueriesIssued;
-					
-					queryQueue.push(QueryPair(node, mHierarchyInterface->
-						IssueNodeOcclusionQuery(node, wasVisible)));
-				}
-				
-				// always traverse a node if it was visible
-				if (wasVisible)
-				{
-					mHierarchyInterface->TraverseNode(node);
-				}
-			}
-		}
-	}
-}
-
-#else
-
-void CoherentHierarchicalCullingManager2::RenderScene()
-{
-	//CullingLogManager::GetSingleton()->LogMessage("chc");
-	QueryQueue queryQueue;
-	unsigned int visiblePixels = 0;
-	
-	/////////////
-	//-- PART 1: process finished occlusion queries
-
-	while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty())
-	{
-		bool resultAvailable = false;
-
-		const bool nodeQueueEmpty = mHierarchyInterface->GetQueue()->empty();
-		const int queryQueueSize = (int)queryQueue.size();
-
-		//-- only wait for result if there are no nodes to process
-		while (!queryQueue.empty() && 
-				queryQueue.front().second->GetQueryResult(visiblePixels, 
-				nodeQueueEmpty))
-		{
-			HierarchyNode *node = queryQueue.front().first;
-			queryQueue.pop();
-
-			// render nodes if queue is still idle ...
-
-			if (1&&nodeQueueEmpty)
-			{
-				std::stringstream d; d << "qu: " << queryQueueSize;
-				CullingLogManager::GetSingleton()->LogMessage(d.str());
-			}
-
-			
-			if (visiblePixels > mVisibilityThreshold)
-			{
-				// in case geometry is in omterior node: ensure that we only traverse once
-				if (!mHierarchyInterface->IsNodeVisible(node))
-				{
-					mHierarchyInterface->TraverseNode(node);
-				}
-
-				mHierarchyInterface->PullUpVisibility(node);
-			}
-			else
-			{	
-				mHierarchyInterface->SetNodeVisible(node, false);
-
-				++ mNumQueryCulledNodes;
-				
-				if (mVisualizeCulledNodes)
-				{
-					mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED);
-				}
-			}
-		}
-		
-		//-- PART 2: hierarchical traversal
-		if (!mHierarchyInterface->GetQueue()->empty())
-		{
-			HierarchyNode *node = mHierarchyInterface->GetQueue()->top();
-			mHierarchyInterface->GetQueue()->pop();
-				
-			bool intersects = false;
-
-			if (!mHierarchyInterface->CheckFrustumVisible(node, intersects))
-			{
-				++ mNumFrustumCulledNodes;
-
-				if (mVisualizeCulledNodes)
-				{
-					mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED);
-				}
-			}
-			//-- if node intersects near plane, skip query because wrong results possible
-			else if (intersects)
-			{
-				SkipQuery(node);
-			}
-			else
-			{
-				// identify previously visible nodes
-				bool wasVisible = mHierarchyInterface->IsNodeVisible(node) && 
-					(mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1);
-				
-				// if we assume node to be visible in this frame => skip query 
-				bool skipQuery = wasVisible && (mAssumedVisibility > 0) && 
-					DecideVisible(node) && mHierarchyInterface->HasGeometry(node);
-
-				if (skipQuery)
-				{
-					SkipQuery(node);
-					continue;
-				}
-
-                // identify nodes that we cannot skip queries for
-				// geometry not only in leaves => test for renderable geometry
-				bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node);
-							
-				// reset node's visibility classification
-				// set visibe if geometry in node so we only traverse once
-				mHierarchyInterface->SetNodeVisible(node, wasVisible && issueQuery);
-
-				// update node's visited flag
-				mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
-				
-				// skip testing previously visible nodes without geometry
-				if (issueQuery)
-				{
-					++ mNumQueriesIssued;
-					
-					queryQueue.push(QueryPair(node, mHierarchyInterface->
-						IssueNodeOcclusionQuery(node, wasVisible)));
-				}
-				
-				// always traverse a node if it was visible
-				if (wasVisible)
-				{
-					mHierarchyInterface->TraverseNode(node);
-				}
-			}
-		}
-	}
-}
-
-#endif
-//-----------------------------------------------------------------------
-void CoherentHierarchicalCullingManager2::SetAssumedVisibility(const unsigned int assumedVisibility)
-{
-	mAssumedVisibility = assumedVisibility;
-	
-	mThreshold = 0;
-
-	if (mAssumedVisibility > 0)
-	{
-		mThreshold = RAND_MAX - RAND_MAX / mAssumedVisibility;
-		 // fix visibility
-		if (mAssumedVisibility > 100)
-			mThreshold = RAND_MAX;
-	}
-	
-}
-//-----------------------------------------------------------------------
-inline bool CoherentHierarchicalCullingManager2::DecideVisible(HierarchyNode *node) const
-{
-	return rand() < mThreshold;
-}
-//-----------------------------------------------------------------------
-inline void CoherentHierarchicalCullingManager2::SkipQuery(HierarchyNode *node) const
-{
-	// -- set node to be visible in this frame, then traverse it
-	mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
-	
-	mHierarchyInterface->PullUpVisibility(node);			
-	mHierarchyInterface->TraverseNode(node);
-}
-
-} // namespace GtpVisibility
