Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2771)
@@ -5,4 +5,7 @@
 #include "SceneEntity.h"
 #include "RenderState.h"
+
+
+using namespace std;
 
 
@@ -35,9 +38,9 @@
 mVisibilityThreshold(0),
 mBvh(NULL), 
-mIsQueryMode(false),
 mUseOptimization(false),
 mFrameId(-1),
 mUseRenderQueue(false),
-mAssumedVisibleFrames(10)
+mAssumedVisibleFrames(10),
+mMaxBatchSize(50)
 {
 }
@@ -78,18 +81,24 @@
 void RenderTraverser::RenderNode(BvhNode *node)
 {
-	if (mUseRenderQueue)
-	{
-		int geometrySize;
-		SceneEntity **geom = mBvh->GetGeometry(node, geometrySize);
-		mRenderQueue.Enqueue(geom, geometrySize);
-		mStats.mNumRenderedGeometry += geometrySize;
-	}
-	else
-	{
-		if (mRenderState->SetState(RenderState::RENDER))
-			++ mStats.mNumStateChanges;
-
-		mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState);
-	}		
+	if (node->GetLastRenderedFrame() != mFrameId)
+	{
+		//cout << "big error!!" << endl;
+		node->SetLastRenderedFrame(mFrameId);
+
+		if (mUseRenderQueue)
+		{
+			int geometrySize;
+			SceneEntity **geom = mBvh->GetGeometry(node, geometrySize);
+			mRenderQueue.Enqueue(geom, geometrySize);
+			mStats.mNumRenderedGeometry += geometrySize;
+		}
+		else
+		{
+			if (mRenderState->SetState(RenderState::RENDER))
+				++ mStats.mNumStateChanges;
+
+			mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState);
+		}		
+	}
 }
 
@@ -130,9 +139,9 @@
 	}
 
-	// if this node is a previous visible leaf => will be rendered anyway, thus we
-	// can also test with the real geometry 
+	// if this node is a previous visible leaf:
+	// leaves will be rendered anyway => we can also test with the real geometry 
 	if (wasVisible && mUseOptimization)
 	{
-		mStats.mNumRenderedGeometry += mBvh->Render(node, mRenderState);
+		RenderNode(node);
 	}
 	else
@@ -151,23 +160,4 @@
 
 
-void RenderTraverser::SetVisibilityThreshold(int threshold)
-{
-	mVisibilityThreshold = threshold;
-}
-
-
-int RenderTraverser::GetVisibilityThreshold() const
-{
-	return mVisibilityThreshold;
-}
-
-
-void RenderTraverser::SetUseOptimization(bool useOptimization)
-{
-	mUseOptimization = useOptimization;
-}
-
-
-
 void RenderTraverser::RenderScene()
 {
@@ -182,5 +172,5 @@
 	++ mFrameId;
 
-	mBvh->InitFrame(mCamera, mFrameId);
+	mBvh->InitFrame();
 
 	mStats.Reset();
@@ -195,14 +185,4 @@
 	Traverse();
 
-	// render the rest of the objects
-	if (mUseRenderQueue)
-	{
-		if (mRenderState->SetState(RenderState::RENDER))
-			++ mStats.mNumStateChanges;
-
-		mRenderQueue.Render();
-		mRenderQueue.Clear();
-	}
-
 	mRenderState->Reset();
 
@@ -221,3 +201,18 @@
 }
 
-}
+
+
+
+void RenderTraverser::SetVisibilityThreshold(int threshold)
+{
+	mVisibilityThreshold = threshold;
+}
+
+
+void RenderTraverser::SetUseOptimization(bool useOptimization)
+{
+	mUseOptimization = useOptimization;
+}
+
+
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp	(revision 2768)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp	(revision 2771)
@@ -28,5 +28,5 @@
 
 
-RenderQueue::RenderQueue(): mState(NULL)
+RenderQueue::RenderQueue(): mState(NULL), mMinSizeForSorting(5)
 {
 }
@@ -43,5 +43,4 @@
 	for (int i = 0; i < size; ++ i)
 		mEntities.push_back(entities[i]);
-
 }
 	
@@ -62,5 +61,6 @@
 void RenderQueue::Render()
 {
-	Sort();
+	if (mEntities.size() >= mMinSizeForSorting)
+		Sort();
 	
 	//if (!mEntities.empty()) Debug << "rendering render queue" << endl;
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2771)
@@ -447,5 +447,10 @@
 	*/
 	int CountTriangles(BvhLeaf *leaf) const;
-
+	/** Sets the scene camera
+	*/
+	void SetCamera(Camera * camera) { mCamera = camera; }
+
+	///////////////
+	//-- functions collecting nodes based on some criteria
 
 	void CollectNodes(BvhNode *node, BvhNodeContainer &nodes, int depth);
@@ -490,7 +495,7 @@
 	*/
 	int	IsWithinViewFrustum(BvhNode *node);
-	/** Sets frame dependent values.
-	*/
-	void InitFrame(Camera *camera, int currentFrameId);
+	/** Sets frame dependent values
+	*/
+	void InitFrame();
 	/** This gives the orthogonal distance from the viewpoint to the nearest bounding box vertex
 		note that negative values can appear because culling is done only afterwards
@@ -618,6 +623,4 @@
 	/// the current camera
 	Camera *mCamera;
-	// current frame id
-	int mFrameId;
 	/// a vertex array used if working with indexed arrays (without vbo)
 	Vector3 *mVertices;
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.h	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/CHCTraverser.h	(revision 2771)
@@ -21,4 +21,8 @@
 	*/
 	virtual void Traverse();
+
+	/// the query queue
+	QueryQueue mQueryQueue;
+
 };
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Visualization.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Visualization.cpp	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Visualization.cpp	(revision 2771)
@@ -49,5 +49,5 @@
 		tStack.pop();
 
-		if (!node->IsLeaf())
+		if (!node->IsVirtualLeaf())
 		{
 			BvhInterior *interior = static_cast<BvhInterior *>(node);
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.h	(revision 2771)
@@ -17,4 +17,5 @@
 	//~CHCPlusPlusTraverser();
 
+
 protected:
 	/** Traverses and renders the scene with the specified method
@@ -26,5 +27,9 @@
 	void IssueMultiQueries();
 
+
 	//////////////
+
+	/// the query queue
+	QueryQueue mQueryQueue;
 
 	BvhNodeQueue mIQueue;
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2771)
@@ -124,5 +124,4 @@
 Bvh::Bvh():
 mCamera(NULL), 
-mFrameId(-1), 
 mRoot(NULL), 
 mVertices(NULL),
@@ -138,5 +137,4 @@
 Bvh::Bvh(const SceneEntityContainer &entities):
 mCamera(NULL), 
-mFrameId(-1), 
 mRoot(NULL), 
 mVertices(NULL),
@@ -349,11 +347,8 @@
 
 
-void Bvh::InitFrame(Camera *camera, int currentFrameId)
+void Bvh::InitFrame()
 {
 	// = 0011 1111 which means that at the beginning, all six planes have to frustum culled
 	mRoot->mPlaneMask = 0x3f;
-	mCamera = camera;
-
-	mFrameId = currentFrameId;
 
 	mCamera->CalcFrustum(sFrustum);
@@ -809,19 +804,13 @@
 int Bvh::Render(BvhNode *node, RenderState *state)
 {
-	//cout << "r " << node->mFirst << " " <<  node->mLast << endl;
-
-	int rendered = 0;
+	int renderedTriangles = 0;
 
 	for (int i = node->mFirst; i <= node->mLast; ++ i)
 	{
-		if (mGeometry[i]->GetLastRendered() != mFrameId)
-		{
-			mGeometry[i]->Render(state);
-			mGeometry[i]->SetLastRendered(mFrameId);
-			++ rendered;
-		}
-	}
-
-	return rendered;
+		renderedTriangles += mGeometry[i]->GetGeometry()->CountTriangles();
+		mGeometry[i]->Render(state);
+	}
+
+	return renderedTriangles;
 }
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.h	(revision 2767)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.h	(revision 2771)
@@ -48,4 +48,5 @@
 	RenderState *mState;
 	SceneEntityContainer mEntities;
+	int mMinSizeForSorting;
 };
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2771)
@@ -41,8 +41,9 @@
 /// the rendering algorithm
 int renderMode = RenderTraverser::CULL_FRUSTUM;
-/// the visibility threshold
-int threshold = 0;
 // eye near plane distance
 float nearDist = 0.1f; 
+/// the pixel threshold where a node is still considered invisible
+int threshold;
+
 
 const float keyForwardMotion = 1.0f;
@@ -71,8 +72,4 @@
 bool showBoundingVolumes = false;
 bool visMode = false;
-
-
-// visualisation view matrix
-Matrix4x4 visView; 
 
 //mouse navigation state
@@ -154,4 +151,5 @@
 	//bvh = bvhLoader.Load("house_test.bvh", sceneEntities);
 
+	bvh->SetCamera(camera);
 	ResetTraverser();
 
@@ -284,4 +282,6 @@
 	DEL_PTR(traverser);
 
+	bvh->ResetNodeClassifications();
+
 	switch (renderMode)
 	{
@@ -427,11 +427,10 @@
 		break;
 	case '+':
-		threshold = traverser->GetVisibilityThreshold() + 10;
+		threshold += 10;
 		traverser->SetVisibilityThreshold(threshold);
 		break;
 	case '-':
-		threshold = traverser->GetVisibilityThreshold() - 10;
+		threshold -= 10;
 		if(threshold < 0) threshold = 0;
-
 		traverser->SetVisibilityThreshold(threshold);		
 		break;
@@ -776,5 +775,5 @@
 	glViewport(winWidth / 2, winHeight / 2, winWidth, winHeight);
 	glPushMatrix();
-	glLoadMatrixf((float *)visView.x);
+	//glLoadMatrixf((float *)visView.x);
 	
 	glClear(GL_DEPTH_BUFFER_BIT);
@@ -859,10 +858,10 @@
 	
 	static long renderTime = traverser->GetStats().mRenderTime;
-	const float expFactor = 0.5f;
+	const float expFactor = 0.95f;
 	renderTime = traverser->GetStats().mRenderTime * expFactor + (1.0f - expFactor) * renderTime;
 
 	accumulatedTime += renderTime;
 
-	if (accumulatedTime > 200) // update every fraction of a second
+	if (accumulatedTime > 100) // update every fraction of a second
 	{	
 		accumulatedTime = 0;
@@ -877,6 +876,5 @@
 	}
 
-	sprintf_s(msg2, "threshold: %4d%s", 
-		traverser->GetVisibilityThreshold(), optstr[useOptimization]);
+	sprintf_s(msg2, "threshold: %4d%s", threshold, optstr[useOptimization]);
 
 	string str;
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/CHCPlusPlusTraverser.cpp	(revision 2771)
@@ -2,9 +2,11 @@
 #include "RenderState.h"
 
+using namespace std;
 
 namespace CHCDemo
 {
 
-CHCPlusPlusTraverser::CHCPlusPlusTraverser() 
+
+CHCPlusPlusTraverser::CHCPlusPlusTraverser()
 {
 }
@@ -16,35 +18,35 @@
 	while (!mDistanceQueue.empty() || !mQueryQueue.empty())
 	{
+		bool resultAvailable;
 		while (!mQueryQueue.empty() && 
-			   (mQueryQueue.front()->ResultAvailable() || mDistanceQueue.empty()))
-		{
-			if (mQueryQueue.front()->ResultAvailable())
-			{
-				OcclusionQuery *query = mQueryQueue.front();
-				mQueryQueue.pop();
-
-				// wait until result available
-				int visiblePixels = query->GetQueryResult();
-
-				if (visiblePixels > mVisibilityThreshold)
-				{
-					BvhNode *node = query->GetFrontNode();
-
-					node->SetVisible(true);
-					mBvh->MakeParentsVisible(node);
-					TraverseNode(node);
-				}
-				else
-				{
-					++ mStats.mNumQueryCulledNodes;
-				}
-			}
-			else if (!mVQueue.empty())
+			   (mDistanceQueue.empty() || (resultAvailable = mQueryQueue.front()->ResultAvailable())))
+		{
+			while (!resultAvailable && !mVQueue.empty())
 			{
 				BvhNode *node = mVQueue.front();
 				mVQueue.pop();
-
+				
 				OcclusionQuery *query = IssueOcclusionQuery(node, true);
 				mQueryQueue.push(query);
+				resultAvailable = mQueryQueue.front()->ResultAvailable();
+			}
+			
+			OcclusionQuery *query = mQueryQueue.front();
+			mQueryQueue.pop();
+
+			// wait until result available
+			int visiblePixels = query->GetQueryResult();
+
+			if (visiblePixels > mVisibilityThreshold)
+			{
+				BvhNode *node = query->GetFrontNode();
+
+				node->SetVisible(true);
+				mBvh->MakeParentsVisible(node);
+				TraverseNode(node);
+			}
+			else
+			{
+				++ mStats.mNumQueryCulledNodes;
 			}
 		}	
@@ -75,5 +77,5 @@
 					
 					// identify nodes that we cannot skip queries for
-					const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() /*&& (node->GetAssumedVisibleFrameId() <= mFrameId)*/));
+					const bool testFeasible = (!wasVisible || (node->IsVirtualLeaf() && (node->GetAssumedVisibleFrameId() <= mFrameId)));
 						 
 
@@ -109,9 +111,20 @@
 		}
 
+		// distance queue empty: feed the remaining multiqueries to
+		// be able to proceed traversal
 		if (mDistanceQueue.empty())
 		{
-			// issue remaining multiqueries
 			IssueMultiQueries();
 		}
+	}
+
+	// render the rest of the objects
+	if (mUseRenderQueue)
+	{
+		if (mRenderState->SetState(RenderState::RENDER))
+			++ mStats.mNumStateChanges;
+
+		mRenderQueue.Render();
+		mRenderQueue.Clear();
 	}
 
@@ -156,5 +169,5 @@
 	mIQueue.push(node);
 
-	if (mIQueue.size() > 50)
+	if (mIQueue.size() > mMaxBatchSize)
 	{
 		IssueMultiQueries();
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp	(revision 2771)
@@ -36,4 +36,11 @@
 		}
 	}
+
+	// render the rest of the objects
+	if (mUseRenderQueue)
+	{
+		mRenderQueue.Render();
+		mRenderQueue.Clear();
+	}
 }
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2770)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2771)
@@ -67,22 +67,41 @@
 	*/
 	void SetCamera(Camera *cam)  {mCamera = cam;}
+	/** Renders a visualization of the hierarchy
+	*/
+	void RenderVisualization();
+	/** Sets the current render state
+	*/
+	void SetRenderState(RenderState *state);
+	/** The traversal statistics
+	*/
+	const TraversalStatistics &GetStats() const { return mStats; }
+
+
+	//////////////////
+	//-- options for the different rendering algorithms
+
+	/** If a render queue should be used to batch up and sort scene entities before
+		rendering.
+	*/
+	void SetUseRenderQueue(bool useRenderQueue);
 	/** Sets visible pixels threshold for visibility classification
 	*/
 	void SetVisibilityThreshold(int threshold);
-	/** Returns visibility threshold
-	*/
-	int GetVisibilityThreshold() const;
-	/** renders a visualization of the hierarchy
-	*/
-	void RenderVisualization();
-	/** use optimization to take leaf nodes instead of bounding box for occlusion queries	
+
+
+	///////////////////
+	//-- CHC / CHC ++ related options
+
+
+	/** CHC optimization to query the geometry itself instead of the bounding box.
 	*/
 	void SetUseOptimization(bool useOptimization);
-	/** Sets the current render state
+	/** The number of frames a previously visible node is assumed to stay visible.
 	*/
-	void SetRenderState(RenderState *state);
+	void SetAssumedVisibleFrames(int assumedVisibleFrames);
+	/** The maximum batch size for the i-queue
+	*/
+	void SetMaxBatchSize(int batchSize);
 
-	void SetUseRenderQueue(bool useRenderQueue);
-	const TraversalStatistics &GetStats() const { return mStats; }
 
 protected:
@@ -120,14 +139,16 @@
 	/// the current frame id
 	int mFrameId;
+	/// the current render state
+	RenderState *mRenderState;
+	/// manages creation and destruction of the queries
+	QueryHandler mQueryHandler;
+	/// the statisitcs
+	TraversalStatistics mStats;
+	
+	RenderQueue mRenderQueue;
 
-	bool mIsQueryMode;
 
-	RenderState *mRenderState;
-
-	QueryHandler mQueryHandler;
-
-	TraversalStatistics mStats;
-
-	QueryQueue mQueryQueue;
+	/////////////////
+	//-- algorithm parametes
 
 	int mVisibilityThreshold;
@@ -135,9 +156,9 @@
 	bool mUseOptimization;
 
-	RenderQueue mRenderQueue;
-
 	bool mUseRenderQueue;
 
 	int mAssumedVisibleFrames;
+
+	int mMaxBatchSize;
 };
 
