Index: /trunk/VUT/GtpVisibility/include/HierarchyInterface.h
===================================================================
--- /trunk/VUT/GtpVisibility/include/HierarchyInterface.h	(revision 154)
+++ /trunk/VUT/GtpVisibility/include/HierarchyInterface.h	(revision 155)
@@ -4,4 +4,5 @@
 #include "DistanceQueue.h"
 #include "VisibilityMesh.h"
+#include <stack>
 
 namespace GtpVisibility {
@@ -13,4 +14,5 @@
 typedef std::pair<HierarchyNode *, OcclusionQuery *> QueryPair;
 typedef std::queue<QueryPair> QueryQueue;
+typedef std::stack<HierarchyNode *> TraversalStack;
 
 /**	Class which implements a hierarchy interface for a scene hierarchy.
@@ -28,8 +30,8 @@
 	*/
     virtual bool IsLeaf(HierarchyNode *node) const = 0;
-	/** Traverses the given node. 
+	/** Traverses and renders the given node. 
 		@param node the hierarchy node
 	*/
-	virtual void TraverseNode(HierarchyNode *node) = 0;
+	virtual void TraverseAndRenderNode(HierarchyNode *node) = 0;
 	/** Renders current hierarchy node.
 		@param node current hierarchy node to be rendered
@@ -49,20 +51,23 @@
 		@param root the hierarchy root
 	*/
-	void SetSceneRoot(HierarchyNode *root);
+	void SetHierarchyRoot(HierarchyNode *root);
     /** Get the root of the scene hierarchy.
 		@return the hierarchy root
 	*/
-	HierarchyNode *GetSceneRoot() const;
-	/** Sets the scene root and initialises this scene traverser for a traversal.
-		@param root current scene root
-		@remark initialises some parameters, and also the statistics.
-	*/
-	void InitFrame(HierarchyNode *root);
+	HierarchyNode *GetHierarchyRoot() const;
+	/** Sets the scene root and initialises this hierarchy interface for a traversal.
+		@param frontToBack 
+			if traversal is initialised for front-to-back rendering or
+			simple traversal of the nodes.
+		@remark also resets the statistics evaluated in the last traversal
+	*/
+	void InitTraversal(bool frontToBack = true);
 	/** Returns current frame id.
 		@returns frame id
 	*/
 	unsigned int GetFrameId() const;
-	/** Returns the current distance queue.
-		@returns current distance queue
+	/** Returns a pointer to the distance queue.
+		@returns current distance queue.
+		@remark the distance queue stores hierarchy nodes in a front-to-back order
 	*/
 	DistanceQueue *GetQueue();
@@ -112,9 +117,5 @@
 	*/
 	unsigned int GetNumRenderedNodes();
-	/** Optimization when issuing occlusion test: test is done with actual geometry 
-		rather than the bounding box
-		@param useOptimization if the optimization should be used
-	*/
-	void SetUseOptimization(bool useOptimization);
+		
 	//bool mIsShadowPass;
 
@@ -137,7 +138,10 @@
 	virtual GtpVisibility::OcclusionQuery *IssueOcclusionQuery(GtpVisibility::Mesh *mesh) = 0;
 
-	/** Returns geometry of hierarchy node. 
-	*/
-	virtual void GetGeometry(GtpVisibility::HierarchyNode *node,	
+	/** Returns the geometry of a given hierarchy node. 
+		@param node the hierarchy node containing the geometry
+		@param geometryList geometry is returned in this list
+		@param includeChildren if the geometry of the children should be taken into account
+	*/
+	virtual void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,	
 					 		 GeometryList *geometryList, 
 							 bool includeChildren) = 0;
@@ -154,20 +158,43 @@
 	*/
 	virtual int GetNodeId(HierarchyNode *node) = 0;
+
+	/** This is an optimization when issuing the occlusion test. 
+		The test is done with actual geometry rather than the bounding 
+		box of leave nodes previously marked as visible
+		@param testGeometry if this optimization should be used
+		@remark this option is only useful for the coherent hierarchical culling algorithm
+	*/
+	void TestGeometryForVisibleLeaves(bool testGeometry);
+
+	/** 
+		Traverses hierarchy and returns next node.
+		@returns next node in hierarchy.
+	*/
+	virtual HierarchyNode *GetNextNode() = 0;
+
 protected:
-	
-	bool mUseOptimization;
+	/// chc optimization for testing geometry of leaves instead of bounding box
+	bool mTestGeometryForVisibleLeaves;
+
 	unsigned int mFrameId;
 
 	int mCurrentTestIdx;
 	
-	//--- statistics
+	/// number of traversed nodes
 	unsigned int mNumTraversedNodes;
-
+	/// the distance queue used for rendering of nodes in front to back order.
 	DistanceQueue *mDistanceQueue;
-	HierarchyNode *mSceneRoot;
-	HierarchyNode *mPreviousNode;
+	/// internal structure for traversal
+	TraversalStack *mTraversalStack;
+
+	/// the root of the hierarchy
+	HierarchyNode *mHierarchyRoot;
+	
+	// buffer for a node pointer
+	HierarchyNode *mSavedNode;
 
 	std::vector<HierarchyNode *> mRenderedNodes;
 };
 } // namespace GtpVisibility
+
 #endif // GtpVisisibilityHierarchyInterface_H
Index: /trunk/VUT/GtpVisibility/include/CoherentHierarchicalCullingManager.h
===================================================================
--- /trunk/VUT/GtpVisibility/include/CoherentHierarchicalCullingManager.h	(revision 147)
+++ /trunk/VUT/GtpVisibility/include/CoherentHierarchicalCullingManager.h	(revision 155)
@@ -15,7 +15,12 @@
 public:
 	CoherentHierarchicalCullingManager();
+	/** Constructor taking the assumed visibility into account, i.e., the estimation
+		for how many frames the current visibility is considered to be valid
+	*/
+	CoherentHierarchicalCullingManager(const unsigned int assumedVisibility);
+
 	void RenderScene();
-	/** Sets assumed visibility which is a an estimation for e 
-		how many frames the visibility is considered to be valied
+	/** Sets assumed visibility (i.e., an estimation for 
+		how many frames the visibility is considered to be valid).
 		@param assumedVisibility indicates for how many frames the 
 		same visibility is be assumed.
@@ -32,4 +37,10 @@
 
 	unsigned int mAssumedVisibility;
+	
+	/** Skip query for this node.
+	*/
+	void SkipQuery(HierarchyNode *node);
+
+
 	/** Threshold for rand function to return positive result with respect to
 		mAssumedVisibility.
Index: /trunk/VUT/GtpVisibility/include/VisibilityManager.h
===================================================================
--- /trunk/VUT/GtpVisibility/include/VisibilityManager.h	(revision 146)
+++ /trunk/VUT/GtpVisibility/include/VisibilityManager.h	(revision 155)
@@ -52,11 +52,10 @@
 	void SetVisibilityCullingThreshold(unsigned int threshold);
 
-	/** Determines if optimization for coherent hierarchical culling is used.
-	*/
-	void SetUseChcOptimization(bool useOptimization);
 	/** Indicates for how long a frame is considered to be visible.
 		@param assumedVisibility estimation for how long visibility is assumed to be valid.
+		@remark this option is only valid for the coherent hierarchical culling algorithm
 	*/
-	void SetAssumedVisibility(unsigned int assumedVisibility);
+	void SetAssumedVisibilityForChc(unsigned int assumedVisibility);
+	
 	/** Sets pointer to a query manager. 
 	*/
@@ -75,5 +74,5 @@
 
 	unsigned int mVisibilityThreshold;
-	unsigned int mAssumedVisibility;
+	unsigned int mAssumedVisibilityForChc;
 };
 } // namespace GtpVisibility
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 =
Index: /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 154)
+++ /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 155)
@@ -89,5 +89,5 @@
 mShowOctree(false),
 mUseDepthPass(false),
-mUseOptimization(true),
+mTestGeometryForVisibleLeaves(true),
 mShowVisualization(false),
 mCullCamera(false),
@@ -101,5 +101,7 @@
 mShowQueryStats(false),
 mQueryManager(NULL),
-mVisibilityManager(NULL)
+mVisibilityManager(NULL),
+mDelayedQueriesIssued(0.0),
+mDelayedTraversedNodes(0.0)
 {
 	//mInputDevice = PlatformManager::getSingleton().createInputReader();
@@ -129,5 +131,5 @@
 	mAlgorithmInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AlgorithmInfo");
 	mThresholdInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ThresholdInfo");
-	mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo");
+	mTestGeometryForVisibleLeavesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TestGeometryForVisibleLeavesInfo");
 	mUseDepthPassInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseDepthPassInfo");
 	mAssumedVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/AssumedVisibilityInfo");
@@ -140,5 +142,7 @@
 	mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
 	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
-	
+	mDelayedQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/DelayedQueriesIssuedInfo");
+	mDelayedTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/DelayedTraversedNodesInfo");
+
 	mAlgorithmInfo->setCaption(": " + currentAlgorithmCaptions[mCurrentAlgorithm]);
 	mThresholdInfo->setCaption(": 0");
@@ -149,9 +153,10 @@
 	mRenderedNodesInfo->setCaption(": 0");
 	mObjectsInfo->setCaption(": 0");
-	mUseOptimizationInfo->setCaption(": true");
+	mTestGeometryForVisibleLeavesInfo->setCaption(": true");
 	mUseDepthPassInfo->setCaption(": false");
 	mQueriesIssuedInfo->setCaption(": 0");
 	mAssumedVisibilityInfo->setCaption(": 0");
-
+	mDelayedQueriesIssuedInfo->setCaption(": 0");
+	mDelayedTraversedNodesInfo->setCaption(": 0");
 
 	//-- visibility query stats overlay
@@ -170,9 +175,9 @@
 
 	// set scene manager options
-	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+	mSceneMgr->setOption("TestGeometryForVisibleLeaves", &mTestGeometryForVisibleLeaves);
 
 	// apply delayed rendering (i.e., transparents after hierarchical culling pass)
 	// only if optimization is not used 
-	bool delayRenderTransparents = !mUseOptimization;
+	bool delayRenderTransparents = !mTestGeometryForVisibleLeaves;
 
 	mSceneMgr->setOption("DelayRenderTransparents", &delayRenderTransparents);
@@ -736,6 +741,8 @@
 		mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 
 		mFrustumCulledNodesInfo->setCaption(str);
-	
-		mSceneMgr->getOption("NumQueriesIssued", &opt); sprintf(str,": %d", opt); 
+
+		// delay so there is no jump
+		mSceneMgr->getOption("NumQueriesIssued", &opt); 
+		sprintf(str,": %d", (int)opt); 
 		mQueriesIssuedInfo->setCaption(str);
 
@@ -754,4 +761,16 @@
 		sprintf(str,": %d", mTerrainContentGenerator->GetObjectCount()); 
 		mObjectsInfo->setCaption(str);
+
+		// delay so there is no jump
+		mSceneMgr->getOption("NumQueriesIssued", &opt); 
+		mDelayedQueriesIssued = mDelayedQueriesIssued * 0.8 + (float)opt * 0.2;
+		sprintf(str,": %d", (int)mDelayedQueriesIssued); 
+		mDelayedQueriesIssuedInfo->setCaption(str);
+
+		mSceneMgr->getOption("NumTraversedNodes", &opt); 
+		mDelayedTraversedNodes = mDelayedTraversedNodes * 0.8 + (float)opt * 0.2;
+		sprintf(str,": %d", (int)mDelayedTraversedNodes); 
+		mDelayedTraversedNodesInfo->setCaption(str);
+
 	}
 	catch (...)
@@ -761,22 +780,23 @@
 }
 //-----------------------------------------------------------------------
-void TerrainFrameListener::toggleUseOptimization()
-{
-	mUseOptimization = !mUseOptimization;
-	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+void TerrainFrameListener::toggleTestGeometryForVisibleLeaves()
+{
+	mTestGeometryForVisibleLeaves = !mTestGeometryForVisibleLeaves;
+	mSceneMgr->setOption("TestGeometryForVisibleLeaves", &mTestGeometryForVisibleLeaves);
 	
 	// disable optimization which tests geometry instead of aabb
 	// for delayed rendering (i.e., render transparents after all the solids)
 	// because otherwise visible transparents could be skipped
-	bool delayedRendering = !mUseOptimization;
+	bool delayedRendering = !mTestGeometryForVisibleLeaves;
+
 	mSceneMgr->setOption("DelayRenderTransparents", &delayedRendering);
 
-	if (mUseOptimization)
-	{
-		mUseOptimizationInfo->setCaption(": true");
+	if (mTestGeometryForVisibleLeaves)
+	{
+		mTestGeometryForVisibleLeavesInfo->setCaption(": true");
 	}
 	else
 	{
-		mUseOptimizationInfo->setCaption(": false");
+		mTestGeometryForVisibleLeavesInfo->setCaption(": false");
 	}
 }
@@ -898,6 +918,6 @@
 		toggleDisplayCameraDetails();
 		break;
-	case KC_O:
-		toggleUseOptimization();
+	case KC_G:
+		toggleTestGeometryForVisibleLeaves();
 		break;
 	case KC_T:
Index: /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 150)
+++ /trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 155)
@@ -162,6 +162,6 @@
 
 		// the objects are generated on the whole terrain
-		//mTerrainContentGenerator->GenerateScene(1500, "robot");
-		mTerrainContentGenerator->GenerateScene(1500, "athene");
+		mTerrainContentGenerator->GenerateScene(1500, "robot");
+		//mTerrainContentGenerator->GenerateScene(1500, "athene");
 		//mTerrainContentGenerator->GenerateScene(500, "ninja");
 	}
Index: /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 154)
+++ /trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 155)
@@ -109,5 +109,5 @@
     void changeThreshold(int incr);
 	void changeAssumedVisibility(int incr);
-	void toggleUseOptimization();
+	void toggleTestGeometryForVisibleLeaves();
 	void toggleShowOctree();
 	void toggleUseDepthPass();
@@ -159,9 +159,11 @@
     OverlayElement *mTraversedNodesInfo;
 	OverlayElement *mHierarchyNodesInfo;
-	OverlayElement *mUseOptimizationInfo;
+	OverlayElement *mTestGeometryForVisibleLeavesInfo;
 	OverlayElement *mUseDepthPassInfo;
 	OverlayElement *mRenderedNodesInfo;
 	OverlayElement *mObjectsInfo;
 	OverlayElement *mQueriesIssuedInfo;
+	OverlayElement *mDelayedQueriesIssuedInfo;
+	OverlayElement *mDelayedTraversedNodesInfo;
 
 	OverlayElement *mQueryTypeInfo;
@@ -175,5 +177,5 @@
 	TerrainContentGenerator *mTerrainContentGenerator;
 
-	bool mUseOptimization;
+	bool mTestGeometryForVisibleLeaves;
 	bool mShowOctree;
 	bool mUseDepthPass;
@@ -236,4 +238,7 @@
 	//bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
 	PlatformQueryManager *mQueryManager;
+
+	float mDelayedQueriesIssued;
+	float mDelayedTraversedNodes;
 };
 
Index: /trunk/VUT/work/TestCulling/TestCullingApplication.cpp
===================================================================
--- /trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 139)
+++ /trunk/VUT/work/TestCulling/TestCullingApplication.cpp	(revision 155)
@@ -112,5 +112,5 @@
 mShowOctree(false),
 mUseDepthPass(false),
-mUseOptimization(true),
+mTestGeometryForVisibleLeaves(true),
 mShowVisualization(false),
 mVisualizeCulledNodes(false)
@@ -137,6 +137,7 @@
 	mRenderedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/RenderedNodesInfo");
 	mObjectsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/ObjectsInfo");
-	mUseOptimizationInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/UseOptimizationInfo");
+	mTestGeometryForVisibleLeavesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/TestGeometryForVisibleLeavesInfo");
 	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
+	
 
 	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
@@ -148,10 +149,11 @@
 	mRenderedNodesInfo->setCaption(": 0");
 	mObjectsInfo->setCaption(": 0");
-	mUseOptimizationInfo->setCaption(": true");
+	mTestGeometryForVisibleLeavesInfo->setCaption(": true");
 	mQueriesIssuedInfo->setCaption(": 0");
+	
 
 	setAlgorithm(mCurrentAlgorithm);
 	
-	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
+	mSceneMgr->setOption("TestGeometryForVisibleLeaves", &mTestGeometryForVisibleLeaves);
 	mSceneMgr->setOption("UseDepthPass", &mUseDepthPass);
 	mSceneMgr->setOption("ShowVizualisation", &mShowVisualization);
@@ -236,5 +238,5 @@
 	KEY_PRESSED(KC_SUBTRACT, 0, changeThreshold(-10));
 	KEY_PRESSED(KC_ADD, 0, changeThreshold(10));
-	KEY_PRESSED(KC_O, 0.3, toggleUseOptimization());
+	KEY_PRESSED(KC_O, 0.3, toggleTestGeometryForVisibleLeaves());
 	KEY_PRESSED(KC_C, 0.3, toggleUseDepthPass());
 	KEY_PRESSED(KC_V, 0.3, toggleShowViz());
@@ -264,14 +266,14 @@
 }
 //-----------------------------------------------------------------------
-void TerrainFrameListener::toggleUseOptimization()
-{
-	mUseOptimization = !mUseOptimization;
-
-	mSceneMgr->setOption("UseOptimization", &mUseOptimization);
-
-	if(mUseOptimization)
-		mUseOptimizationInfo->setCaption(": true");
+void TerrainFrameListener::toggleTestGeometryForVisibleLeaves()
+{
+	mTestGeometryForVisibleLeaves = !mTestGeometryForVisibleLeaves;
+
+	mSceneMgr->setOption("TestGeometryForVisibleLeaves", &mTestGeometryForVisibleLeaves);
+
+	if(mTestGeometryForVisibleLeaves)
+		mTestGeometryForVisibleLeavesInfo->setCaption(": true");
 	else
-		mUseOptimizationInfo->setCaption(": false");
+		mTestGeometryForVisibleLeavesInfo->setCaption(": false");
 }
 //-----------------------------------------------------------------------
Index: /trunk/VUT/work/TestCulling/TestCullingApplication.h
===================================================================
--- /trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 133)
+++ /trunk/VUT/work/TestCulling/TestCullingApplication.h	(revision 155)
@@ -64,5 +64,5 @@
 	void changeThreshold(int incr);
 	void updateStats();
-	void toggleUseOptimization();
+	void toggleTestGeometryForVisibleLeaves();
 	void toggleShowOctree();
 	void toggleUseDepthPass();
@@ -87,10 +87,10 @@
 	OverlayElement *mRenderedNodesInfo;
 	OverlayElement *mObjectsInfo;
-	OverlayElement *mUseOptimizationInfo;
+	OverlayElement *mTestGeometryForVisibleLeavesInfo;
 	OverlayElement *mQueriesIssuedInfo;
 
 	SceneContentGenerator *mSceneContentGenerator;
 
-	bool mUseOptimization;
+	bool mTestGeometryForVisibleLeaves;
 	bool mShowOctree;
 	bool mUseDepthPass;
Index: /trunk/VUT/Ogre/include/OgreSceneNodeHierarchyInterface.h
===================================================================
--- /trunk/VUT/Ogre/include/OgreSceneNodeHierarchyInterface.h	(revision 154)
+++ /trunk/VUT/Ogre/include/OgreSceneNodeHierarchyInterface.h	(revision 155)
@@ -24,5 +24,5 @@
 	bool IsLeaf(GtpVisibility::HierarchyNode *node) const;
 	
-	void TraverseNode(GtpVisibility::HierarchyNode *node);
+	void TraverseAndRenderNode(GtpVisibility::HierarchyNode *node);
 	void RenderNode(GtpVisibility::HierarchyNode *node);
 	void PullUpVisibility(GtpVisibility::HierarchyNode *node);
@@ -46,5 +46,5 @@
 							bool includeChildren = false);*/
 	
-	void GetGeometry(GtpVisibility::HierarchyNode *node,	
+	void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,	
 					 GtpVisibility::GeometryList *geometryList, 
 					 bool includeChildren);
@@ -53,4 +53,6 @@
 	
 	int GetNodeId(GtpVisibility::HierarchyNode *node);
+
+	GtpVisibility::HierarchyNode *GetNextNode();
 };
 
Index: /trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h
===================================================================
--- /trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 153)
+++ /trunk/VUT/Ogre/include/OgreVisibilityTerrainSceneManager.h	(revision 155)
@@ -122,4 +122,6 @@
 	int mLeavePassesInQueue;
 	ShadowTechnique mSavedShadowTechnique;
+
+	bool mRenderOnlyBoundingBoxes;
 };
 
Index: /trunk/VUT/Ogre/include/OgreOctreeHierarchyInterface.h
===================================================================
--- /trunk/VUT/Ogre/include/OgreOctreeHierarchyInterface.h	(revision 154)
+++ /trunk/VUT/Ogre/include/OgreOctreeHierarchyInterface.h	(revision 155)
@@ -29,7 +29,7 @@
 	/** Traverses given node.
 		@param node current node
-		@remark pushes children on distance queue
+		@remark pushes children on a distance queue.
 	*/
-	void TraverseNode(GtpVisibility::HierarchyNode *node);
+	void TraverseAndRenderNode(GtpVisibility::HierarchyNode *node);
 	void RenderNode(GtpVisibility::HierarchyNode *node);
 	bool IsLeaf(GtpVisibility::HierarchyNode *node) const;
@@ -46,9 +46,5 @@
 							 GtpVisibility::CullingType type);
 
-	/*bool FindVisibleObjects(GtpVisibility::HierarchyNode *node,	
-							InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 
-							bool includeChildren = false);*/
-
-	void GetGeometry(GtpVisibility::HierarchyNode *node,
+	void GetNodeGeometryList(GtpVisibility::HierarchyNode *node,
 					 GtpVisibility::GeometryList *geometryList, 
 					 bool includeChildren);
@@ -57,4 +53,6 @@
 	
 	int GetNodeId(GtpVisibility::HierarchyNode *node);
+
+	GtpVisibility::HierarchyNode *GetNextNode();
 
 protected:
@@ -69,4 +67,6 @@
 	*/
 	Real GetSquaredViewDepth(const Camera* cam, const AxisAlignedBox* box) const;
+
+	int mCurrentOctreePosition;
 };
 } // namespace Ogre
Index: /trunk/VUT/Ogre/include/OgreBspHierarchyInterface.h
===================================================================
--- /trunk/VUT/Ogre/include/OgreBspHierarchyInterface.h	(revision 154)
+++ /trunk/VUT/Ogre/include/OgreBspHierarchyInterface.h	(revision 155)
@@ -22,7 +22,7 @@
 	/** Traverses given node.
 		@param node current node
-		@remark pushes children on distance queue
+		@remark pushes children on the distance queue
 	*/
-	void TraverseNode(GtpVisibility::HierarchyNode *node);
+	void TraverseAndRenderNode(GtpVisibility::HierarchyNode *node);
 	void RenderNode(GtpVisibility::HierarchyNode *node);
 	bool IsLeaf(GtpVisibility::HierarchyNode *node) const;
Index: /trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h
===================================================================
--- /trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 139)
+++ /trunk/VUT/Ogre/include/OgrePlatformHierarchyInterface.h	(revision 155)
@@ -47,11 +47,9 @@
 		@remark This is a convenience method which resets the stats, 
 				sets the current camera, and initialises the distance queue.
-		@param root root of the hierarchy
 		@param cam the actual camera definding the view frustum
 		@param cullCam the camera used for culling. 
-		@remark If null, the actual camera is used for both viewing and culling		
+		@remark If cullCam is null, the actual camera is used for both viewing and culling		
 	*/
-	void InitFrame(GtpVisibility::HierarchyNode *root, Camera *cam, Camera *cullCam = NULL, 
-		int leavePassesInQueue = 0);
+	void InitTraversal(Camera *cam, Camera *cullCam = NULL, int leavePassesInQueue = 0);
 	/** Checks if the node is visible from the current view frustum.
 		@param node the current node
@@ -95,5 +93,5 @@
 	/** see set 
 	*/
-	bool GetUseOptimization();
+	bool GetTestGeometryForVisibleLeaves();
 	/** see set
 	*/
Index: /trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 154)
+++ /trunk/VUT/Ogre/src/OgreSceneNodeHierarchyInterface.cpp	(revision 155)
@@ -17,5 +17,5 @@
 }
 //-----------------------------------------------------------------------
-void SceneNodeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
+void SceneNodeHierarchyInterface::TraverseAndRenderNode(GtpVisibility::HierarchyNode *node)
 {
 	++ mNumTraversedNodes;
@@ -121,7 +121,7 @@
 {
 	// only create renderable bounding box for new node
-	if (node != mPreviousNode)
+	if (node != mSavedNode)
 	{
-		mPreviousNode = node;
+		mSavedNode = node;
 		mBox = static_cast<SceneNode *>(node)->_getWorldAABB();
 	}
@@ -136,5 +136,5 @@
 }
 //-----------------------------------------------------------------------
-void SceneNodeHierarchyInterface::GetGeometry(GtpVisibility::HierarchyNode *node,	
+void SceneNodeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,	
 											  GtpVisibility::GeometryList *geometryList, 
 											  bool includeChildren)
@@ -151,5 +151,6 @@
 		{
 			Entity *ent = static_cast<Entity *>(movable);
-			//std::stringstream d; d << "ent " << ent->getName(); LogManager::getSingleton().logMessage(d.str());
+			//std::stringstream d; d << "ent " << ent->getName(); 
+			//LogManager::getSingleton().logMessage(d.str());
 			geometryList->push_back(ent);
 		}
@@ -166,3 +167,22 @@
 	return static_cast<SceneNode *>(node)->getId();
 }
+//-----------------------------------------------------------------------
+GtpVisibility::HierarchyNode *SceneNodeHierarchyInterface::GetNextNode()
+{
+	if (mTraversalStack->empty())
+		return NULL;
+	
+	SceneNode *node = static_cast<SceneNode *>(mTraversalStack->top());
+	mTraversalStack->pop();
+
+	// internal node: add children to priority queue for further processing
+	Node::ChildNodeIterator it = node->getChildIterator();
+				
+	while (it.hasMoreElements())			
+	{ 
+		mTraversalStack->push(it.getNext());
+	}
+
+	return node;
+} 
 } // namespace Ogre	
Index: /trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 154)
+++ /trunk/VUT/Ogre/src/OgreVisibilityTerrainSceneManager.cpp	(revision 155)
@@ -30,5 +30,6 @@
 mEnableDepthWrite(true),
 mSkipTransparents(false),
-mSavedShadowTechnique(SHADOWTYPE_NONE)
+mSavedShadowTechnique(SHADOWTYPE_NONE),
+mRenderOnlyBoundingBoxes(false)
 {
 	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
@@ -126,8 +127,7 @@
 			if (mRenderNodesForViz)
 			{
-				OctreeNode *node = *it;	
-				if ((node->numAttachedObjects() > 0) && (node->numChildren() == 0)
-					&& node->getAttachedObject(0)->getMovableType() == "Entity")
-				getRenderQueue()->addRenderable(node);
+				if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0)
+					&& (*it)->getAttachedObject(0)->getMovableType() == "Entity")
+				getRenderQueue()->addRenderable((*it));
 
 				// addbounding boxes instead of node itself
@@ -213,10 +213,14 @@
 		PrepareVisualization(cam);
 	}
-	else
+	else if (mRenderOnlyBoundingBoxes)
+	{
+	}
+	else 
 	{	
 		// for hierarchical culling, we interleave identification 
 		// and rendering of objects in _renderVisibibleObjects
 
-		// only for the shadow pass we use standard rendering
+		// for the shadow pass we use only standard rendering
+		// because of low occlusion
 		if (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
 			mIlluminationStage == IRS_RENDER_TO_TEXTURE)
@@ -225,5 +229,5 @@
 		}
 		// only shadow casters will be rendered in shadow texture pass
-		//mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
+		// mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters);
 	}
 	//TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
@@ -236,14 +240,17 @@
 void VisibilityTerrainSceneManager::_renderVisibleObjects()
 {
+	// save ambient light to reset later
 	ColourValue savedAmbient = mAmbientLight;
 
-	// visualization or shadow pass: apply standard rendering
-	if (mShowVisualization || (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && 
-		mIlluminationStage == IRS_RENDER_TO_TEXTURE))
+	// --- apply standard rendering for some cases 
+    // e.g., visualization, shadow pass
+
+	if (mShowVisualization || mRenderOnlyBoundingBoxes ||
+	   (mShadowTechnique == SHADOWTYPE_TEXTURE_MODULATIVE && mIlluminationStage == IRS_RENDER_TO_TEXTURE))
 	{	
 		IlluminationRenderStage savedStage = mIlluminationStage; 
 	
 		if (mShowVisualization) 
-			// disable illumination stage so we have no shadows in visualization
+			// disable illumination stage because we want no shadows in visualization
 			mIlluminationStage = IRS_NONE;
 
@@ -455,5 +462,5 @@
 	d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
 	  << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
-	  << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetUseOptimization()) << ", "
+	  << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
 	  << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << ", "
 	  << "Hierarchy nodes: " << mNumOctreeNodes << ", " 
@@ -699,8 +706,11 @@
 		(mLeavePassesInQueue & RenderPriorityGroup::TRANSPARENT_PASSES);
 
+	// -- initialise interface for rendering traversal of the hierarchy
+	mHierarchyInterface->SetHierarchyRoot(mOctree);
+	
 	// possible two cameras (one for culling, one for rendering)
-	mHierarchyInterface->InitFrame(mOctree, cam, 
-						mCullCamera ? getCamera("CullCamera") : NULL,
-						mLeavePassesInQueue);
+	mHierarchyInterface->InitTraversal(mCameraInProgress, 
+							mCullCamera ? getCamera("CullCamera") : NULL,
+							mLeavePassesInQueue);
 		
 	//std::stringstream d; d << "leave passes in queue: " << mLeavePassesInQueue;LogManager::getSingleton().logMessage(d.str());
Index: /trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp	(revision 146)
+++ /trunk/VUT/Ogre/src/OgreVisibilityOptionsManager.cpp	(revision 155)
@@ -26,10 +26,10 @@
 	if (key == "AssumedVisibility")
 	{
-		mVisibilityManager->SetAssumedVisibility(*static_cast<const int *>(val));
+		mVisibilityManager->SetAssumedVisibilityForChc(*static_cast<const int *>(val));
 		return true;
 	}
-	if (key == "UseOptimization")
+	if (key == "TestGeometryForVisibleLeaves")
 	{
-		mHierarchyInterface->SetUseOptimization(*static_cast<const bool *>(val));
+		mHierarchyInterface->TestGeometryForVisibleLeaves(*static_cast<const bool *>(val));
 		return true;
 	}
Index: /trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 139)
+++ /trunk/VUT/Ogre/src/OgreVisibilitySceneManager.cpp	(revision 155)
@@ -40,6 +40,6 @@
 	if (!mShowVisualization)
 	{
-		// two cameras (one for culling, one for rendering)
-		mHierarchyInterface->InitFrame(mSceneRoot, mCameraInProgress);
+		mHierarchyInterface->SetHierarchyRoot(mSceneRoot);
+		mHierarchyInterface->InitTraversal(mCameraInProgress);
 
 		// reset culling manager stats
Index: /trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 154)
+++ /trunk/VUT/Ogre/src/OgreOctreeHierarchyInterface.cpp	(revision 155)
@@ -10,9 +10,9 @@
 //-----------------------------------------------------------------------
 OctreeHierarchyInterface::OctreeHierarchyInterface(OctreeSceneManager *sm, RenderSystem *rsys): 
-SceneNodeHierarchyInterface(sm, rsys)
-{
-}
-//-----------------------------------------------------------------------
-void OctreeHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
+SceneNodeHierarchyInterface(sm, rsys), mCurrentOctreePosition(0)
+{
+}
+//-----------------------------------------------------------------------
+void OctreeHierarchyInterface::TraverseAndRenderNode(GtpVisibility::HierarchyNode *node)
 {
 	++ mNumTraversedNodes;
@@ -84,5 +84,5 @@
 	Octree *octant = static_cast<Octree *>(node);
 
-	while(octant && !octant->isOctreeVisible())
+	while (octant && !octant->isOctreeVisible())
 	{
 		octant->setOctreeVisible(true);
@@ -129,10 +129,9 @@
 AxisAlignedBox *OctreeHierarchyInterface::GetBoundingBox(GtpVisibility::HierarchyNode *node)
 {
-	if (node != mPreviousNode)	
-	{
-		mPreviousNode = node;
+	if (node != mSavedNode)
+	{
+		mSavedNode = node;
 	    //static_cast<Octree *>(node)->_getCullBounds(&mBox);
 		mBox = static_cast<Octree *>(node)->_getWorldAABB();
-		//std::stringstream d; d << mBox;LogManager::getSingleton().logMessage(d.str()); 
 	}
 
@@ -157,5 +156,5 @@
 }
 //-----------------------------------------------------------------------
-void OctreeHierarchyInterface::GetGeometry(GtpVisibility::HierarchyNode *node,	
+void OctreeHierarchyInterface::GetNodeGeometryList(GtpVisibility::HierarchyNode *node,	
 										   GtpVisibility::GeometryList *geometryList, 
 										   bool includeChildren)
@@ -166,5 +165,5 @@
 	for (nodeIt = static_cast<Octree *>(node)->mNodes.begin(); nodeIt != nodeIt_end; ++nodeIt)
 	{
-		SceneNodeHierarchyInterface::GetGeometry(*nodeIt, geometryList, includeChildren);
+		SceneNodeHierarchyInterface::GetNodeGeometryList(*nodeIt, geometryList, includeChildren);
 	}
 }
@@ -180,30 +179,25 @@
 }
 //-----------------------------------------------------------------------
-/*bool OctreeHierarchyInterface::FindVisibleObjects(GtpVisibility::HierarchyNode *node,	
-									InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry, 
-									bool includeChildren)
-{
-	bool foundVisible = false;
-
-	PlatformOcclusionQuery query(mRenderSystem);
-
-	NodeList *nodes = &static_cast<Octree *>(node)->mNodes;
+GtpVisibility::HierarchyNode *OctreeHierarchyInterface::GetNextNode()
+{
+	if (mTraversalStack->empty())
+		return NULL;
 	
-	NodeList::const_iterator nodeIt = nodes->begin(), nodeIt_end;
-	
-	nodeIt_end = nodes->end();
-
-	while (nodeIt != nodeIt_end)
-	{
-		OctreeNode *octreeNode = (*nodeIt);
-		if (SceneNodeHierarchyInterface::FindVisibleObjects(octreeNode, visibleGeometry, includeChildren))
+	Octree *octree = static_cast<Octree *>(mTraversalStack->top());
+	mTraversalStack->pop();
+		
+	for(int i=0; i<8; ++i)
+	{
+		Octree *nextChild = 
+			octree->mChildren[(i & 4) >> 2][(i & 2) >> 1][i & 1];
+
+		if (nextChild)
 		{
-			foundVisible = true;
+			mTraversalStack->push(nextChild);
 		}
-		++nodeIt;
-	}
-
-	return foundVisible;
-}*/
-
+	}
+
+	return octree;
+} 
+		
 } // namespace Ogre
Index: /trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 154)
+++ /trunk/VUT/Ogre/src/OgreVisibilityOctreeSceneManager.cpp	(revision 155)
@@ -184,8 +184,12 @@
 	bool leaveTransparentsInQueue = mDelayRenderTransparents && !mUseDepthPass;
 
+    // -- initialise interface for rendering traversal of the hierarchy
+	mHierarchyInterface->SetHierarchyRoot(mOctree);
+	
 	// possible two cameras (one for culling, one for rendering)
-	mHierarchyInterface->InitFrame(mOctree, mCameraInProgress, 
+	mHierarchyInterface->InitTraversal(mCameraInProgress, 
 							mCullCamera ? getCamera("CullCamera") : NULL,
 							leaveTransparentsInQueue);
+		
 
 	// reset culling manager stats
@@ -352,5 +356,5 @@
 	d << "Depth pass: " << StringConverter::toString(mUseDepthPass) << ", "
 	  << "Delay transparents: " << StringConverter::toString(mDelayRenderTransparents) << ", "
-	  << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetUseOptimization()) << ", "
+	  << "Use optimization: " << StringConverter::toString(mHierarchyInterface->GetTestGeometryForVisibleLeaves()) << ", "
 	  << "Algorithm type: " << mVisibilityManager->GetCullingManagerType() << "\n"
 	  << "Hierarchy nodes: " << mNumOctreeNodes << ", " 
Index: /trunk/VUT/Ogre/src/OgreBspHierarchyInterface.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreBspHierarchyInterface.cpp	(revision 87)
+++ /trunk/VUT/Ogre/src/OgreBspHierarchyInterface.cpp	(revision 155)
@@ -12,5 +12,5 @@
 }
 //-----------------------------------------------------------------------
-void BspHierarchyInterface::TraverseNode(GtpVisibility::HierarchyNode *node)
+void BspHierarchyInterface::TraverseAndRenderNode(GtpVisibility::HierarchyNode *node)
 {
 }
Index: /trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 139)
+++ /trunk/VUT/Ogre/src/OgrePlatformHierarchyInterface.cpp	(revision 155)
@@ -130,10 +130,9 @@
 }
 //-----------------------------------------------------------------------
-void PlatformHierarchyInterface::InitFrame(GtpVisibility::HierarchyNode *root, 
-										   Camera *cam, Camera *cullCam, int leavePassesInQueue)
-{
-	GtpVisibility::HierarchyInterface::InitFrame(root);
-	
-	mPreviousNode = NULL;
+void PlatformHierarchyInterface::InitTraversal(Camera *cam, Camera *cullCam, int leavePassesInQueue)
+{
+	GtpVisibility::HierarchyInterface::InitTraversal();
+	
+	mSavedNode = NULL;
 	mLeavePassesInQueue = leavePassesInQueue;
 
@@ -178,5 +177,5 @@
 	// If camera for culling is different from camera for rendering or only solids 
 	// will be rendereded => cannot optimize
-	if (mUseOptimization && (mCamera == mCullCamera) && wasVisible && IsLeaf(node)) 
+	if (mTestGeometryForVisibleLeaves && (mCamera == mCullCamera) && wasVisible && IsLeaf(node)) 
 	{
 		//LogManager::getSingleton().logMessage("render node\n");
@@ -253,7 +252,7 @@
 }
 //-----------------------------------------------------------------------
-bool PlatformHierarchyInterface::GetUseOptimization()
-{
-	return mUseOptimization;
+bool PlatformHierarchyInterface::GetTestGeometryForVisibleLeaves()
+{
+	return mTestGeometryForVisibleLeaves;
 }
 //-----------------------------------------------------------------------
Index: /trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp	(revision 154)
+++ /trunk/VUT/Ogre/src/OgreItemBufferQueryManager.cpp	(revision 155)
@@ -32,5 +32,5 @@
 	SceneManager *sm = pfHierarchyInterface->GetSceneManager();
 
-	//-- Render scene as item buffer (e.g., color coded objects)
+	// ---- Render scene as item buffer (i.e., objects with their id as color codes)
 
 	// const_cast allowed because camera is not changed in renderScene
@@ -49,8 +49,10 @@
 	mViewport->setBackgroundColour(ColourValue(0, 0, 0, 0));
 
-	//pfHierarchyInterface->GetRenderSystem()->clearFrameBuffer(FBT_COLOUR);
-	// render item buffer
+
+	// --- render item buffer
 	pfHierarchyInterface->GetSceneManager()->_renderScene(pCam, mViewport, false);
 	
+
+
 	// reset old overlay status
 	mViewport->setOverlaysEnabled(overlayEnabled);
@@ -84,7 +86,4 @@
 			((*visibleGeometry)[id]).AddVisibility(1, 1);
 		}
-		/*else {	std::stringstream d; 
-			d << "adding pixel to geometry with id: " << id << ", buf 1: " << (int)buf[idx] << ", buf 2: " << (int)buf[idx + 1] << ", buf 3: " << (int)buf[idx + 2];
-			LogManager::getSingleton().logMessage(d.str());	}*/
 	}
 
@@ -101,9 +100,11 @@
 		return;
 
+
 	mWasInitialised = true;
 
-	SceneManager::EntityIterator it = 
-		dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->
-		GetSceneManager()->getEntityIterator();
+	SceneManager *sm = 
+		dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager();
+
+	SceneManager::EntityIterator it = sm->getEntityIterator();
 
 	// TODO: make this more efficient
@@ -115,4 +116,15 @@
 		visibleGeometry->push_back(GtpVisibility::MeshInfo(it.getNext(), 0, 0));
 	}
+
+	// -- initialise hierarchy interface for simple node traversal
+	mHierarchyInterface->InitTraversal(false);
+
+	GtpVisibility::HierarchyNode *node = NULL;
+	
+	while (node = mHierarchyInterface->GetNextNode())
+	{
+		visibleNodes->push_back(GtpVisibility::NodeInfo(node, 0, 0));
+	}
 }
+
 } // namespace Ogre
Index: /trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp
===================================================================
--- /trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp	(revision 154)
+++ /trunk/VUT/Ogre/src/OgreOcclusionQueriesQueryManager.cpp	(revision 155)
@@ -83,5 +83,5 @@
 			if (i == 0)
 			{
-				mHierarchyInterface->GetGeometry(*nodeIt, &geometryList, false);
+				mHierarchyInterface->GetNodeGeometryList(*nodeIt, &geometryList, false);
 			}
 		}
@@ -105,5 +105,5 @@
 	mViewport->setOverlaysEnabled(overlayEnabled);
 
-	//---- collect results
+	// ---- collect results
 	GtpVisibility::QueryList::iterator visQueryIt, projQueryIt;
 
@@ -135,5 +135,5 @@
 	}
 
-	//---- queries for geometry
+	// ---- queries for geometry
 	geometryIt_end = geometryList.end();
 	
@@ -154,5 +154,5 @@
 		++visQueryIt;
 
-		// approximate depth ordering during rendering => 
+		// WARNING: approximate depth ordering during rendering => 
 		// geometry maybe occluded
 		if (visiblePixels > 0)
Index: /trunk/VUT/Ogre/resources/VisibilityDemo.overlay
===================================================================
--- /trunk/VUT/Ogre/resources/VisibilityDemo.overlay	(revision 147)
+++ /trunk/VUT/Ogre/resources/VisibilityDemo.overlay	(revision 155)
@@ -22,5 +22,5 @@
 		left 5 
 		top 5
-		width 400
+		width 430
 		height 90
 		material Core/StatsBlockCenter
@@ -46,7 +46,7 @@
 		element TextArea(Example/Visibility/AlgorithmInfo): Example/Visibility/Templates/BasicText
 		{
-			left 170
+			left 210
 			top 5
-			width 90
+			width 120
 			height 30
 			caption :
@@ -57,5 +57,5 @@
 			left 5
 			top 20
-			width 90
+			width 120
 			height 30
 			caption [-][+] Threshold
@@ -63,23 +63,23 @@
 		element TextArea(Example/Visibility/ThresholdInfo): Example/Visibility/Templates/BasicText
 		{
-			left 170
+			left 210
 			top 20
-			width 90
-			height 30
-			caption :
-		}
-		element TextArea(Example/Visibility/UseOptimization): Example/Visibility/Templates/BasicText
+			width 120
+			height 30
+			caption :
+		}
+		element TextArea(Example/Visibility/TestGeometryForVisibleLeaves): Example/Visibility/Templates/BasicText
 		{
 			left 5
 			top 35
-			width 90
-			height 30
-			caption [O] Optimization
-		}
-		element TextArea(Example/Visibility/UseOptimizationInfo): Example/Visibility/Templates/BasicText
-		{
-			left 170
+			width 120
+			height 30
+			caption [G] Test Geometry For Leaves
+		}
+		element TextArea(Example/Visibility/TestGeometryForVisibleLeavesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 210
 			top 35
-			width 90
+			width 120
 			height 30
 			caption :
@@ -89,5 +89,5 @@
 			left 5
 			top 50
-			width 90
+			width 120
 			height 30
 			caption [X] Depth pass
@@ -95,7 +95,7 @@
 		element TextArea(Example/Visibility/UseDepthPassInfo): Example/Visibility/Templates/BasicText
 		{
-			left 170
+			left 210
 			top 50
-			width 90
+			width 120
 			height 30
 			caption :
@@ -105,5 +105,5 @@
 			left 5
 			top 65
-			width 90
+			width 120
 			height 30
 			caption [8][9] Assumed Visibility
@@ -112,7 +112,7 @@
 		element TextArea(Example/Visibility/AssumedVisibilityInfo): Example/Visibility/Templates/BasicText
 		{
-			left 170
+			left 210
 			top 65
-			width 90
+			width 120
 			height 30
 			caption :
@@ -128,5 +128,5 @@
 		top 5
 		width 320
-		height 120
+		height 150
 		material Core/StatsBlockCenter
         	border_size 1 1 1 1
@@ -249,4 +249,36 @@
 			left 180
 			top 95
+			width 90
+			font_name TrebuchetMSBold
+			caption :			
+		}		
+		element TextArea(Example/Visibility/DelayedQueriesIssued): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 110
+			width 180
+			height 30
+			caption Avg. queries issued 
+		}	
+		element TextArea(Example/Visibility/DelayedQueriesIssuedInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 110
+			width 90
+			font_name TrebuchetMSBold
+			caption :			
+		}		
+		element TextArea(Example/Visibility/DelayedTraversedNodes): Example/Visibility/Templates/BasicText
+		{
+			left 5
+			top 125
+			width 180
+			height 30
+			caption Avg. traversed Nodes
+		}	
+		element TextArea(Example/Visibility/DelayedTraversedNodesInfo): Example/Visibility/Templates/BasicText
+		{
+			left 180
+			top 125
 			width 90
 			font_name TrebuchetMSBold
