Index: trunk/VUT/GtpVisibility/include/DistanceQueue.h
===================================================================
--- trunk/VUT/GtpVisibility/include/DistanceQueue.h	(revision 59)
+++ trunk/VUT/GtpVisibility/include/DistanceQueue.h	(revision 87)
@@ -25,5 +25,5 @@
 	bool operator() (T v1, T v2) const
 	{
-		return mHierarchyInterface->HasGreaterDistance(v1, v2);
+		return mHierarchyInterface->GetSquaredDistance(v1) > mHierarchyInterface->GetSquaredDistance(v2);
 	}
 		
Index: trunk/VUT/GtpVisibility/include/HierarchyInterface.h
===================================================================
--- trunk/VUT/GtpVisibility/include/HierarchyInterface.h	(revision 86)
+++ trunk/VUT/GtpVisibility/include/HierarchyInterface.h	(revision 87)
@@ -59,10 +59,8 @@
 	*/
 	DistanceQueue *GetQueue();
-	/** Returns true if node 1 has greater distance to the view
-		plane than node 2.
-		@param node1 the first node to be compared
-		@param node2 the second node to be compared
+	/** Returns distance of the node to the view plane.
+		@param node1 the hierarchy node
 	*/			
-	virtual bool HasGreaterDistance(HierarchyNode *node1, HierarchyNode *node2) const = 0;
+	virtual float GetSquaredDistance(HierarchyNode *node) const = 0;
 	/** Checks if the node is visible from the current view frustum.
 		@param node the current node
Index: trunk/VUT/GtpVisibility/include/OcclusionQuery.h
===================================================================
--- trunk/VUT/GtpVisibility/include/OcclusionQuery.h	(revision 86)
+++ trunk/VUT/GtpVisibility/include/OcclusionQuery.h	(revision 87)
@@ -20,8 +20,8 @@
 		@remark the query counts the number of visible pixels between it's begin and end
 	*/
-	virtual void BeginQuery() const = 0;
+	virtual void BeginQuery() = 0;
 	/** Ends occlusion query.
 	*/
-	virtual void EndQuery() const = 0;
+	virtual void EndQuery() = 0;
 };
 
Index: trunk/VUT/GtpVisibility/include/CullingManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/CullingManager.h	(revision 74)
+++ trunk/VUT/GtpVisibility/include/CullingManager.h	(revision 87)
@@ -38,10 +38,18 @@
 	*/
 	unsigned int GetNumQueryCulledNodes();
+	/** Returns number of issued occlusion queries.
+	*/
+	unsigned int GetNumQueriesIssued();
+	/** basic initializations on beginning of each frame, e.g., 
+		resets statistics.
+	*/
+	void InitFrame();
 
 protected:
-
+	
 	unsigned int mNumQueryCulledNodes;
 	unsigned int mNumFrustumCulledNodes;
 	unsigned int mVisibilityThreshold;
+	unsigned int mNumQueriesIssued;
 
 	HierarchyInterface *mHierarchyInterface;
Index: trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp	(revision 86)
+++ trunk/VUT/GtpVisibility/src/FrustumCullingManager.cpp	(revision 87)
@@ -7,6 +7,5 @@
 void FrustumCullingManager::RenderScene()
 {
-	mNumFrustumCulledNodes = mNumQueryCulledNodes = 0;
-	//OutputDebugString("Frustum Culling\n");
+	InitFrame();
 
 	while (!mHierarchyInterface->GetQueue()->empty())
Index: trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 86)
+++ trunk/VUT/GtpVisibility/src/CoherentHierarchicalCullingManager.cpp	(revision 87)
@@ -7,11 +7,10 @@
 void CoherentHierarchicalCullingManager::RenderScene()
 {
-	mNumFrustumCulledNodes = mNumQueryCulledNodes = 0;
-//	OutputDebugString("Coherent Culling\n");
+	InitFrame();
 
 	QueryQueue queryQueue;
 	unsigned int visiblePixels = 0;
 	bool isAvailable = false;
-
+	
 	//-- PART 1: process finished occlusion queries
 	while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty())
@@ -21,4 +20,6 @@
 									mHierarchyInterface->GetQueue()->empty()))
 		{
+            //if (mHierarchyInterface->GetQueue()->empty())OutputDebugString("empty\n");
+								
 			HierarchyNode *node = queryQueue.front().first;
 						
@@ -35,5 +36,5 @@
 			}
 		}
-
+		
 		//-- PART 2: hierarchical traversal
 		if (!mHierarchyInterface->GetQueue()->empty())
@@ -67,6 +68,7 @@
 				
 				// identify nodes that we cannot skip queries for
-				bool mustQuery = !wasVisible || mHierarchyInterface->HasGeometry(node) || 
-					mHierarchyInterface->IsLeaf(node);
+				// geometry not only in leaves => test for renderable geometry
+				bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node);
+					//mHierarchyInterface->IsLeaf(node);
 
 				// reset node's visibility classification 
@@ -76,9 +78,11 @@
 				mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
 			
-				// skip testing previously visible interior nodes
-				if (mustQuery)
+				// skip testing previously visible nodes without geometry
+				if (issueQuery)
 				{
-					queryQueue.push(QueryPair(node, 
-						mHierarchyInterface->IssueOcclusionQuery(node, wasVisible)));
+					mNumQueriesIssued ++;
+
+					queryQueue.push(QueryPair(node, mHierarchyInterface->
+						IssueOcclusionQuery(node, wasVisible)));
 				}
 					
Index: trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp	(revision 86)
+++ trunk/VUT/GtpVisibility/src/StopAndWaitCullingManager.cpp	(revision 87)
@@ -7,12 +7,11 @@
 void StopAndWaitCullingManager::RenderScene()
 {
-	mNumFrustumCulledNodes = mNumQueryCulledNodes = 0;
-	//OutputDebugString("Stop and Wait Culling\n");
-
+	InitFrame();
+			
 	while (!mHierarchyInterface->GetQueue()->empty())
 	{
 		HierarchyNode *node = mHierarchyInterface->GetQueue()->top();
 		mHierarchyInterface->GetQueue()->pop();
-		
+			
 		// interesting for visualization purpose
 		mHierarchyInterface->SetNodeVisible(node, false);
@@ -35,4 +34,6 @@
 			}
 
+			mNumQueriesIssued ++;
+
 			unsigned int visiblePixels = 0;
 
Index: trunk/VUT/GtpVisibility/src/CullingManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/CullingManager.cpp	(revision 74)
+++ trunk/VUT/GtpVisibility/src/CullingManager.cpp	(revision 87)
@@ -6,5 +6,5 @@
 CullingManager::CullingManager():
 mHierarchyInterface(NULL), mVisibilityThreshold(0), mNumQueryCulledNodes(0), 
-mNumFrustumCulledNodes(0)
+mNumFrustumCulledNodes(0), mNumQueriesIssued(0)
 {
 }
@@ -29,3 +29,13 @@
 	return mNumQueryCulledNodes;
 }
+//-----------------------------------------------------------------------
+unsigned int CullingManager::GetNumQueriesIssued()
+{
+	return mNumQueriesIssued;
+}
+//-----------------------------------------------------------------------
+void CullingManager::InitFrame()
+{
+	mNumFrustumCulledNodes = mNumQueryCulledNodes = mNumQueriesIssued = 0;
+}
 } // namespace GtpVisibility
