Index: trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp	(revision 147)
+++ trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp	(revision 155)
@@ -28,5 +28,5 @@
 		{		
 			mHierarchyInterface->SetNodeVisible(node, true);
-			mHierarchyInterface->TraverseNode(node);
+			mHierarchyInterface->TraverseAndRenderNode(node);
 		}
 	}
Index: trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 148)
+++ trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 155)
@@ -5,8 +5,16 @@
 
 //-----------------------------------------------------------------------
-CoherentHierarchicalCullingManager:: CoherentHierarchicalCullingManager():
-mAssumedVisibility(0), mThreshold(0)
+CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager()
 {
-	// initialise random generator because of assumed visibility
+	SetAssumedVisibility(0);
+	// initialise random generator in case we use assumed visibility
+	srand(time(NULL));
+}
+//-----------------------------------------------------------------------
+CoherentHierarchicalCullingManager::CoherentHierarchicalCullingManager(const unsigned int 
+																		assumedVisibility)
+{
+	SetAssumedVisibility(assumedVisibility);
+	// initialise random generator in case we use assumed visibility
 	srand(time(NULL));
 }
@@ -32,9 +40,9 @@
 			{
 				mHierarchyInterface->PullUpVisibility(node);
-				mHierarchyInterface->TraverseNode(node);
+				mHierarchyInterface->TraverseAndRenderNode(node);
 			}
 			else
 			{	
-				mNumQueryCulledNodes ++;
+				++ mNumQueryCulledNodes;
 				
 				if(mVisualizeCulledNodes)
@@ -62,4 +70,9 @@
 				}
 			}
+			// -- if node intersects near plane, skip query because wrong results possible
+			else if (intersects)
+			{
+				SkipQuery(node);
+			}
 			else
 			{
@@ -67,18 +80,9 @@
 				bool wasVisible = mHierarchyInterface->IsNodeVisible(node) && 
 					(mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1);
-
-				// if node is assumed to be visible in this frame => skip query
-				// if intersects near plane => also skip query because wrong results possible
-				bool assumeVisible = intersects ||
-					(wasVisible && (mAssumedVisibility > 0) && 
-					 mHierarchyInterface->HasGeometry(node) && DecideVisible(node));	
-
-				if (assumeVisible)
+					
+				// if we assume node to be visible in this frame => skip query 
+				if (wasVisible && (mAssumedVisibility > 0) &&  DecideVisible(node))// && mHierarchyInterface->HasGeometry(node))
 				{
-					// update node's visited flag
-					mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
-
-					mHierarchyInterface->PullUpVisibility(node);			
-					mHierarchyInterface->TraverseNode(node);
+					SkipQuery(node);
 
 					continue;
@@ -107,5 +111,5 @@
 				if (wasVisible)
 				{
-					mHierarchyInterface->TraverseNode(node);
+					mHierarchyInterface->TraverseAndRenderNode(node);
 				}
 			}
@@ -129,9 +133,18 @@
 bool CoherentHierarchicalCullingManager::DecideVisible(HierarchyNode *node) const
 {
-	/*bool result = rand() < mThreshold;
-	std::stringstream d; d << "Assumed vis: " << mAssumedVisibility << ", result: " << result;
+	/*bool result = rand() < mThreshold; std::stringstream d; d << "Assumed vis: " << mAssumedVisibility << ", result: " << result;
 	Ogre::LogManager::getSingleton().logMessage(d.str()); return result;*/
 	
 	return rand() < mThreshold;
 }
+//-----------------------------------------------------------------------
+void CoherentHierarchicalCullingManager::SkipQuery(HierarchyNode *node)
+{
+	// -- set node to be visible in this frame, then traverse it
+	mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
+
+	mHierarchyInterface->PullUpVisibility(node);			
+	mHierarchyInterface->TraverseAndRenderNode(node);
+}
+
 } // namespace GtpVisibility
Index: trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp	(revision 130)
+++ trunk/VUT/GtpVisibility/src/HierarchyInterface.cpp	(revision 155)
@@ -7,9 +7,9 @@
 //-----------------------------------------------------------------------
 HierarchyInterface::HierarchyInterface(): 
-mFrameId(0), mNumTraversedNodes(0), mSceneRoot(0), 
-mPreviousNode(0), mCurrentTestIdx(0), mUseOptimization(false)
-//, mIsShadowPass(false)
+mFrameId(0), mNumTraversedNodes(0), mHierarchyRoot(NULL), 
+mSavedNode(NULL), mCurrentTestIdx(0), mTestGeometryForVisibleLeaves(false)
 {	
 	mDistanceQueue = new DistanceQueue(GreaterDistance<HierarchyNode *>(this));
+	mTraversalStack = new std::stack<HierarchyNode *>;
 }
 //-----------------------------------------------------------------------
@@ -17,20 +17,28 @@
 {		
 	delete mDistanceQueue;
+	delete mTraversalStack;
 }
 //-----------------------------------------------------------------------
-void HierarchyInterface::SetSceneRoot(HierarchyNode *root)
+void HierarchyInterface::SetHierarchyRoot(HierarchyNode *root)
 {
-	mSceneRoot = root;
+	mHierarchyRoot = root;
 }
 //-----------------------------------------------------------------------
-void HierarchyInterface::InitFrame(HierarchyNode *root)
+void HierarchyInterface::InitTraversal(bool frontToBack)
 {
-	++ mFrameId;
-	mCurrentTestIdx = 0;
-	mNumTraversedNodes = 0;
-	mRenderedNodes.clear();
+	// initialise for front-to-back rendering
+	if (frontToBack)
+	{
+		++ mFrameId;
+		mCurrentTestIdx = 0;
+		mNumTraversedNodes = 0;
+		mRenderedNodes.clear();
 
-	SetSceneRoot(root);
-	mDistanceQueue->push(mSceneRoot);
+		mDistanceQueue->push(mHierarchyRoot);
+	}
+ 	else
+	{	// initialise for simple node traversal
+		mTraversalStack->push(mHierarchyRoot);
+	}
 }
 //-----------------------------------------------------------------------
@@ -51,7 +59,7 @@
 }
 //-----------------------------------------------------------------------
-HierarchyNode *HierarchyInterface::GetSceneRoot() const 
+HierarchyNode *HierarchyInterface::GetHierarchyRoot() const
 {
-	return mSceneRoot;
+	return mHierarchyRoot;
 }
 //-----------------------------------------------------------------------
@@ -66,7 +74,7 @@
 }
 //-----------------------------------------------------------------------
-void HierarchyInterface::SetUseOptimization(bool useOptimization)
+void HierarchyInterface::TestGeometryForVisibleLeaves(bool testGeometry)
 {
-	mUseOptimization = useOptimization;
+	mTestGeometryForVisibleLeaves = testGeometry;
 }
 //-----------------------------------------------------------------------
@@ -75,4 +83,3 @@
 	return &mRenderedNodes;
 }
-
 } // namespace GtpVisibility
Index: trunk/VUT/GtpVisibility/src/VisibilityManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/VisibilityManager.cpp	(revision 153)
+++ trunk/VUT/GtpVisibility/src/VisibilityManager.cpp	(revision 155)
@@ -14,5 +14,5 @@
 mPreprocessingManager(new DummyPreprocessingManager(NULL)),
 mVisibilityEnvironment(visEnvironment),
-mAssumedVisibility(0)
+mAssumedVisibilityForChc(0)
 {
 	SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
@@ -27,6 +27,6 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityManager::SetCullingManager(
-	VisibilityEnvironment::CullingManagerType ocmType)
+void VisibilityManager::SetCullingManager(VisibilityEnvironment::
+										  CullingManagerType ocmType)
 {
 	// change only if necessary
@@ -38,4 +38,5 @@
 			delete mCullingManager;
 		}
+
 		mCullingManagerType = ocmType;
 		
@@ -47,7 +48,5 @@
 
 		case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
-			mCullingManager = new CoherentHierarchicalCullingManager();
-			dynamic_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
-				SetAssumedVisibility(mAssumedVisibility);
+			mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
 			break;
 
@@ -98,14 +97,18 @@
 }
 //-----------------------------------------------------------------------
-void VisibilityManager::SetAssumedVisibility(unsigned int assumedVisibility)
+void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility) 
+									 
 {
-	mAssumedVisibility = assumedVisibility;
+	mAssumedVisibilityForChc = assumedVisibility;
 
+	// in case we currently use chc
 	if (VisibilityManager::GetCullingManagerType() == 
 		VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
 	{
 		dynamic_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
-				SetAssumedVisibility(mAssumedVisibility);
+				SetAssumedVisibility(assumedVisibility);
 	}
 }
+
+
 } // namespace GtpVisibility
Index: trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp	(revision 139)
+++ trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp	(revision 155)
@@ -27,13 +27,12 @@
 			}
 		}
+		// if intersects near plane => skip occlusion query because wrong results possible
+		else if (intersects)
+		{
+			mHierarchyInterface->SetNodeVisible(node, true);
+			mHierarchyInterface->TraverseAndRenderNode(node);
+		}
 		else
 		{
-			// if intersects near plane => skip occlusion query because wrong results possible
-			if (intersects)
-			{
-	            mHierarchyInterface->SetNodeVisible(node, true);
-				mHierarchyInterface->TraverseNode(node);
-				continue;
-			}
 
 			++ mNumQueriesIssued;
@@ -46,5 +45,5 @@
 			if (visiblePixels > mVisibilityThreshold)
 			{
-				mHierarchyInterface->TraverseNode(node);
+				mHierarchyInterface->TraverseAndRenderNode(node);
 			}
 			else
Index: trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp	(revision 144)
+++ trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp	(revision 155)
@@ -13,5 +13,5 @@
 					     bool relativeVisibility)
   {
-	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetSceneRoot(), 0, 0));
+	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetHierarchyRoot(), 0, 0));
     
 //      HierarchyInterface::MeshIterator *mi =
@@ -31,5 +31,5 @@
 						bool relativeVisibility)
   {
-	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetSceneRoot(), 0, 0));
+	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetHierarchyRoot(), 0, 0));
     
 //      HierarchyInterface::MeshIterator *mi =
