Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/include/HierarchyInterface.h	(revision 2292)
@@ -19,7 +19,10 @@
 typedef std::queue<PendingQuery> PendingQueue;
 
+typedef std::vector<HierarchyNode *> HierarchyNodeContainer;
 
-/**	Class which implements a hierarchy interface for a scene hierarchy. It has to be implemented
-	for any rendering engine to use the CHC algorithm.
+
+/**	Class which implements an interface for the operations on a hierarchy
+	of a scene. 
+	It has to be implemented for any rendering engine to use the CHC algorithm.
 */
 class HierarchyInterface
@@ -153,8 +156,10 @@
 	virtual void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const = 0;
 
-	virtual void TraverseNode2(GtpVisibility::HierarchyNode *node) = 0;
-
 	virtual HierarchyNode *GetRandomLeaf(HierarchyNode *root) = 0;
 	virtual bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const = 0;
+
+	virtual void CollectLeaves(HierarchyNode *root, HierarchyNodeContainer &nodes) = 0;
+
+	virtual void RenderNodeRecursive(HierarchyNode *node) = 0;
 
 protected:
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp	(revision 2289)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/StopAndWaitCullingManager.cpp	(revision 2292)
@@ -7,5 +7,5 @@
 void StopAndWaitCullingManager::RenderScene()
 {
-	CullingLogManager::GetSingleton()->LogMessage("swc");
+	if (0) CullingLogManager::GetSingleton()->LogMessage("swc");
 
 	while (!mHierarchyInterface->GetQueue()->empty())
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/FrustumCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/FrustumCullingManager.cpp	(revision 2289)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/FrustumCullingManager.cpp	(revision 2292)
@@ -8,5 +8,5 @@
 void FrustumCullingManager::RenderScene()
 {	
-	CullingLogManager::GetSingleton()->LogMessage("vfc");
+	if (0) CullingLogManager::GetSingleton()->LogMessage("vfc");
 
 	while (!mHierarchyInterface->GetQueue()->empty())
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp	(revision 2289)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/CoherentHierarchicalCullingManager.cpp	(revision 2292)
@@ -11,5 +11,5 @@
 	SetAssumedVisibility(0);
 	// initialise random generator in case we use assumed visibility
-	srand(time(NULL));
+	//srand(time(NULL));
 }
 //-----------------------------------------------------------------------
@@ -19,10 +19,10 @@
 	SetAssumedVisibility(assumedVisibility);
 	// initialise random generator in case we use assumed visibility
-	srand(time(NULL));
+	//srand(time(NULL));
 }
 //-----------------------------------------------------------------------
 void CoherentHierarchicalCullingManager::RenderScene()
 {
-	CullingLogManager::GetSingleton()->LogMessage("chc");
+	if (0) CullingLogManager::GetSingleton()->LogMessage("chc");
 	QueryQueue queryQueue;
 	unsigned int visiblePixels = 0;
@@ -158,5 +158,5 @@
 inline void CoherentHierarchicalCullingManager::SkipQuery(HierarchyNode *node) const
 {
-	// -- set node to be visible in this frame, then traverse it
+	//-- set node to be visible in this frame, then traverse it
 	mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId());
 	
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp	(revision 2289)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/RandomUpdateCullingManager.cpp	(revision 2292)
@@ -2,4 +2,10 @@
 #include <time.h>
 #include "CullingLogManager.h"
+#include <vector>
+//#include <iostream>
+#include <sstream>
+
+
+using namespace std;
 
 
@@ -12,5 +18,5 @@
 	SetAssumedVisibility(0);
 	// initialise random generator in case we use assumed visibility
-	srand(time(NULL));
+	//srand(time(NULL));
 
 	mRandomCandidates = R_CANDIDATES;
@@ -22,5 +28,5 @@
 	SetAssumedVisibility(assumedVisibility);
 	// initialise random generator in case we use assumed visibility
-	srand(time(NULL));
+	//srand(time(NULL));
 
 	mRandomCandidates = R_CANDIDATES;
@@ -29,5 +35,5 @@
 void RandomUpdateCullingManager::RenderScene()
 {
-	CullingLogManager::GetSingleton()->LogMessage("ruc");
+	if (0) CullingLogManager::GetSingleton()->LogMessage("ruc");
 
 	QueryQueue queryQueue;
@@ -37,10 +43,4 @@
 	//-- PART 1: process finished occlusion queries
 
-	// update the fully visible classifications
-	mHierarchyInterface->DetermineFullVisibility(mHierarchyInterface->GetHierarchyRoot());
-
-	//mHierarchyInterface->TraverseNode2(mHierarchyInterface->GetHierarchyRoot());
-	
-#if 1
 	while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty())
 	{
@@ -121,4 +121,5 @@
 				if (mHierarchyInterface->IsNodeFullyVisible(node))
 				{
+#if 1
 					// node fully visible => test only random leaves
 					for (int i = 0; i < mRandomCandidates; ++ i)
@@ -138,6 +139,24 @@
 							mHierarchyInterface->IssueNodeOcclusionQuery(node)));
 					}
-
-					mHierarchyInterface->TraverseNode2(node);
+#else
+					// test all leaves for visibility changes
+					HierarchyNodeContainer mynodes;
+					mHierarchyInterface->CollectLeaves(node, mynodes);
+
+					HierarchyNodeContainer::const_iterator nit, nit_end = mynodes.end();
+
+					for (nit = mynodes.begin(); nit != nit_end; ++ nit)
+					{
+						HierarchyNode *leaf = *nit;
+						mHierarchyInterface->SetNodeVisible(leaf, false);
+
+						// update node's visited flag
+						mHierarchyInterface->SetLastVisited(leaf, mHierarchyInterface->GetFrameId());
+
+						queryQueue.push(QueryPair(leaf, 
+							mHierarchyInterface->IssueNodeOcclusionQuery(node)));
+					}
+#endif
+					mHierarchyInterface->RenderNodeRecursive(node);
 
 					continue;
@@ -173,8 +192,11 @@
 		}
 	}
-#endif
+
 	//while (!mHierarchyInterface->GetQueue()->empty())
 	//	mHierarchyInterface->GetQueue()->pop();
-	
+
+	// update the fully visible classifications
+	// TODO: this should be done during traversal!
+	mHierarchyInterface->DetermineFullVisibility(mHierarchyInterface->GetHierarchyRoot());
 }
 //-----------------------------------------------------------------------
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOctreeHierarchyInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOctreeHierarchyInterface.h	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOctreeHierarchyInterface.h	(revision 2292)
@@ -54,6 +54,4 @@
 	void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const;
 
-	void TraverseNode2(GtpVisibility::HierarchyNode *node);
-
 	GtpVisibility::HierarchyNode *GetRandomLeaf(GtpVisibility::HierarchyNode *node);
 
@@ -62,4 +60,6 @@
 	void RenderNodeRecursive(GtpVisibility::HierarchyNode *node);
 
+	void CollectLeaves(GtpVisibility::HierarchyNode *root, 
+					   GtpVisibility::HierarchyNodeContainer &nodes);
 
 protected:
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreSceneNodeHierarchyInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreSceneNodeHierarchyInterface.h	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreSceneNodeHierarchyInterface.h	(revision 2292)
@@ -47,8 +47,10 @@
 
 	void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const {}
-	void TraverseNode2(GtpVisibility::HierarchyNode *node) {}
+
 	GtpVisibility::HierarchyNode *GetRandomLeaf(GtpVisibility::HierarchyNode *root) { return NULL;}
+
 	bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const { return false;}
 
+	void CollectLeaves(GtpVisibility::HierarchyNode *root, GtpVisibility::HierarchyNodeContainer &nodes) {};
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchyInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchyInterface.h	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchyInterface.h	(revision 2292)
@@ -95,7 +95,13 @@
 
 	void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const {}
-	void TraverseNode2(GtpVisibility::HierarchyNode *node) {}
+	
 	bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const { return false;}
+	
 	GtpVisibility::HierarchyNode *GetRandomLeaf(GtpVisibility::HierarchyNode *root) { return NULL;}
+
+	void CollectLeaves(GtpVisibility::HierarchyNode *root, 
+					   GtpVisibility::HierarchyNodeContainer &nodes) {};
+
+	void RenderNodeRecursive(GtpVisibility::HierarchyNode *node) {};
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneNode.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneNode.h	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneNode.h	(revision 2292)
@@ -23,23 +23,26 @@
 		  SceneNode(creator) {};
 
-		BvHierarchySceneNode(SceneManager *creator, const String& name):
+		  BvHierarchySceneNode(SceneManager *creator, const String& name):
 		  SceneNode(creator, name) {};
 
-		~BvHierarchySceneNode() {};
+		  ~BvHierarchySceneNode() {};
 
-		// gather info for kd-tree creation
-		virtual void computeScene(BvhPlaneEventList& events, AxisAlignedBox& aabb, int& nObjects, bool includeChildren = true);
+		  // gather info for kd-tree creation
+		  virtual void computeScene(BvhPlaneEventList& events, AxisAlignedBox& aabb, 
+			  int& nObjects, 
+			  bool includeChildren = true);
 
-		// add all contained objects to render queue
-		virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters);
+		  // add all contained objects to render queue
+		  virtual void queueObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters);
 
-		// place all entities in geometry queue (for CHC)
-		virtual void getGeometryList(GeometryVector *geometryList);
+		  // place all entities in geometry queue (for CHC)
+		  virtual void getGeometryList(GeometryVector *geometryList);
 
-		// return a bounding box enclosing all objects
-		virtual AxisAlignedBox getBoundingBox(void) const;
+		  // return a bounding box enclosing all objects
+		  virtual AxisAlignedBox getBoundingBox(void) const;
 
-		// DEBUG
-		String dumpToString(void);
+		  // DEBUG
+		  String dumpToString(void);
+
 	protected:
 		virtual void _updateBounds(void);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeHierarchyInterface.h	(revision 2292)
@@ -96,10 +96,12 @@
 	void DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const {}
 
-	void TraverseNode2(GtpVisibility::HierarchyNode *node) {}
-
 	GtpVisibility::HierarchyNode *GetRandomLeaf(GtpVisibility::HierarchyNode *root) { return NULL;}
 
 	bool IsNodeFullyVisible(GtpVisibility::HierarchyNode *node) const { return false;}
 
+	void CollectLeaves(GtpVisibility::HierarchyNode *root, 
+					   GtpVisibility::HierarchyNodeContainer &nodes) {};
+
+	void RenderNodeRecursive(GtpVisibility::HierarchyNode *node) {};
 };
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2280)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2292)
@@ -322,5 +322,5 @@
 				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\Release&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\Release&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;..\..\GtpVisibility\lib\Release;..\..\lib\Release;..\lib\Release;&quot;$(OGRE_PATH)\Dependencies\lib\Release&quot;;..\..\..\Preprocessing\lib\Release;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\Preprocessing\src\GL;&quot;$(CG_LIB_PATH)&quot;;..\..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\Lib\Vis\Preprocessing\MultiLevelRayTracing\RTWorld\Release;..\..\..\..\..\Lib\Vis\Preprocessing\MultiLevelRayTracing\RTScene\Release;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\lib\Release;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\lib\Release"
 				ModuleDefinitionFile="..\misc\OgreVisibilitySceneManager.def"
-				GenerateDebugInformation="FALSE"
+				GenerateDebugInformation="TRUE"
 				SubSystem="2"
 				OptimizeReferences="2"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp	(revision 2287)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOctreeHierarchyInterface.cpp	(revision 2292)
@@ -1,4 +1,3 @@
 #include "OgreOctreeHierarchyInterface.h"
-//#include "OgreVisibilityOctreeSceneManager.h"
 #include <OgreOctree.h>
 #include <OgreLogManager.h>
@@ -70,7 +69,4 @@
 		int z = i & 1;
 	
-		//std::stringstream d; d << x << " " << y << " " << z;
-		//Ogre::LogManager::getSingleton().logMessage(d.str());
-
 		if ((child = octree->mChildren[x][y][z]) != NULL)
 		{
@@ -78,7 +74,4 @@
 		}
 	}
-
-	//std::stringstream str; str << "nodes: " << nodes.size();
-	//Ogre::LogManager::getSingleton().logMessage(str.str());
 
 	if (nodes.empty())
@@ -87,65 +80,5 @@
 	int r = (int)(((float)rand() / RAND_MAX) * ((float)nodes.size() - 0.5f));
 
-	//std::stringstream str2;
-	//str2 << "rand: " << r;
-	//Ogre::LogManager::getSingleton().logMessage(str2.str());
-
 	return GetRandomLeaf(nodes[r]);
-	// assume that at least one child is not NULL ...
-	/*while (!child)
-	{
-		int mask = (int) (rand() * 8.0f);
-		child = octree->mChildren[(mask & 4) / 4][(mask & 2) / 2][mask & 1];
-	}
-
-	return GetRandomLeaf(child);*/
-}
-//-----------------------------------------------------------------------
-void OctreeHierarchyInterface::TraverseNode2(GtpVisibility::HierarchyNode *node)
-{
-	++ mNumTraversedNodes;
-
-	Octree *octree = static_cast<Octree *>(node);
-
-	// if we come across some renderable geometry => render it
-	//if (!octree->mNodes.empty())
-	//{
-		RenderNodeRecursive(node);
-	//}
-
-/*
-		// render everything from here
-		if (octree->isOctreeFullyVisible())
-		{		
-			RenderNodeRecursive(node);
-			return;
-		}
-
-		RenderNode(node);
-	}
-		
-	// if not all subtrees are empty
-	if (!IsLeaf(node))
-	{
-		Octree *nextChild;
-
-		if ((nextChild = octree->mChildren[0][0][0]) != NULL)
-			mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[0][0][1]) != NULL)
-			mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[0][1][0]) != NULL)
-			mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[0][1][1]) != NULL)
-           	mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[1][0][0]) != NULL)
-			mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[1][0][1]) != NULL)
-			mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[1][1][0]) != NULL)
-			mDistanceQueue->push(nextChild);
-		if ((nextChild = octree->mChildren[1][1][1]) != NULL)
-			mDistanceQueue->push(nextChild);
-	}
-	*/
 }
 //-----------------------------------------------------------------------
@@ -168,10 +101,6 @@
 	const Vector3 bmax = static_cast<Octree *>(node)->mBox.getMaximum();
 
-	const Vector3 pos = (bmax - bmin) * 0.5 + bmin;
-	
-/*	std::stringstream d; 
-	d << "a: " << (mCameraPosition - pos).squaredLength() 
-	  << " b: " << (mCullCamera->getDerivedPosition() - pos).squaredLength();
-	LogManager::getSingleton().logMessage(d.str());*/
+	const Vector3 pos = (bmax - bmin) * 0.5f + bmin;
+	
 	return (mCameraPosition - pos).squaredLength();
 }
@@ -206,20 +135,9 @@
 }
 //-----------------------------------------------------------------------
-void OctreeHierarchyInterface::DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const
+/*void OctreeHierarchyInterface::PullUpFullVisibility(GtpVisibility::HierarchyNode *node) const
 {		
-	Octree *octant = static_cast<Octree *>(node);
-
-	// leaf node: terminate recursion
-	if (IsLeaf(node))
-	{
-		octant->setOctreeFullyVisible(octant->isOctreeVisible());
-			
-		return;
-	}
-
-	octant->setOctreeFullyVisible(true);
-	
-	Octree *nextChild;
-	
+#ifdef GTP_VISIBILITY_MODIFIED_OGRE
+	Octree *octant = static_cast<Octree *>(node);
+
 	for (int i = 0; i < 8; ++ i)
 	{
@@ -228,5 +146,5 @@
 		int z = i & 1;
 		
-			if ((nextChild = octant->mChildren[x][y][z]) != NULL)
+		if ((nextChild = octant->mChildren[x][y][z]) != NULL)
 		{
 			DetermineFullVisibility(nextChild);
@@ -236,4 +154,42 @@
 		}
 	}
+
+	while (octant && !octant->isOctreeVisible())
+	{
+		octant->setOctreeVisible(true);
+		octant = octant->getParent();
+	}
+#endif
+}*/
+//-----------------------------------------------------------------------
+void OctreeHierarchyInterface::DetermineFullVisibility(GtpVisibility::HierarchyNode *node) const
+{		
+	Octree *octant = static_cast<Octree *>(node);
+
+	// leaf node: terminate recursion
+	if (IsLeaf(node))
+	{
+		octant->setOctreeFullyVisible(octant->isOctreeVisible());	
+		return;
+	}
+
+	octant->setOctreeFullyVisible(true);
+	
+	Octree *nextChild;
+	
+	for (int i = 0; i < 8; ++ i)
+	{
+		int x = (i & 4) / 4;
+		int y = (i & 2) / 2;
+		int z = i & 1;
+		
+		if ((nextChild = octant->mChildren[x][y][z]) != NULL)
+		{
+			DetermineFullVisibility(nextChild);
+			// this leaf is not fully visible => break
+			if (!nextChild->isOctreeFullyVisible())
+				octant->setOctreeFullyVisible(false);
+		}
+	}
 }
 //-----------------------------------------------------------------------
@@ -264,5 +220,5 @@
 	Octree *octant = static_cast<Octree *>(node);
 
-	if (1)//octant->lastRendered() != mFrameId)
+	if (octant->lastRendered() != mFrameId)
 	{
 		octant->setLastRendered(mFrameId);
@@ -351,4 +307,40 @@
 	}
 }
+//-----------------------------------------------------------------------
+void OctreeHierarchyInterface::CollectLeaves(GtpVisibility::HierarchyNode *root, 
+											 GtpVisibility::HierarchyNodeContainer &nodes)
+{
+	std::stack<GtpVisibility::HierarchyNode *> tStack;
+	tStack.push(root);
+
+	Octree *child;
+
+	while (!tStack.empty())
+	{
+		GtpVisibility::HierarchyNode *node = tStack.top();
+		tStack.pop();
+
+		if (IsLeaf(node))
+		{
+			nodes.push_back(node);
+		}
+		else
+		{
+			Octree *octree = static_cast<Octree *>(node);
+			
+			for (int i = 0; i < 8; ++ i)
+			{
+				int x = (i & 4) / 4;
+				int y = (i & 2) / 2;
+				int z = i & 1;
+	
+				if ((child = octree->mChildren[x][y][z]) != NULL)
+				{
+					tStack.push(child);
+				}
+			}
+		}
+	}
+}
 
 
