Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2746)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2754)
@@ -4,20 +4,14 @@
 
 
-#if TOIMPLEMENT
+namespace CHCDemo
+{
 
 RenderTraverser::RenderTraverser(): 
 mFrameID(1), 
 mVisibilityThreshold(0),
-mHierarchyRoot(NULL), 
-mOcclusionQueries(NULL), 
-mCurrentQueryIdx(0), 
+mBvh(NULL), 
 mIsQueryMode(false),
-mNumTraversedNodes(0), 
-mNumQueryCulledNodes(0), 
-mNumFrustumCulledNodes(0),
-mRenderTime(0), 
-mNumRenderedGeometry(0), 
 mUseOptimization(true),
-mUseArbQueries(false)
+mCurrentQueryIdx(0)
 {
 }
@@ -26,9 +20,9 @@
 RenderTraverser::~RenderTraverser()
 {
-	DelQueries();
-}
-
-
-void RenderTraverser::Render(int mode)
+	//DelQueries();
+}
+
+
+/*void RenderTraverser::Render(int mode)
 {
 	mDistanceQueue.push(mHierarchyRoot);
@@ -61,172 +55,7 @@
 
 	finishTiming();
-}
-
-/**
-	This is the standard render traversal algorithm doing only frustum culling
-*/
-void RenderTraverser::RenderCullFrustum()
-{
-	while(!mDistanceQueue.empty())
-	{
-		HierarchyNode *node = mDistanceQueue.top();
-		mDistanceQueue.pop();
-	
-		// interesting for the visualization, so rest and set
-		node->SetVisible(false);
-		mNumTraversedNodes ++;
-
-		bool intersects;
-	
-		if(InsideViewFrustum(node, intersects))
-		{
-			// update node's visited flag => needed for rendering
-			// so set it also here
-			node->SetLastVisited(mFrameID);
-			node->SetVisible(true);
-			TraverseNode(node);
-		}
-		else
-		{
-			mNumFrustumCulledNodes ++;
-		}
-	}
-}
-
-void RenderTraverser::RenderStopAndWait()
-{
-	while(! mDistanceQueue.empty())
-	{
-		HierarchyNode *node = mDistanceQueue.top();
-		mDistanceQueue.pop();
-		mNumTraversedNodes ++;
-		// interesting for the visualization, so rest and set
-		node->SetVisible(false);
-
-		bool intersects;
-		
-		if(InsideViewFrustum(node, intersects))
-		{
-			// update node's visited flag
-			node->SetLastVisited(mFrameID);
-
-			// for near plane intersecting abbs possible 
-			// wrong results => skip occlusion query
-			if(intersects)
-			{
-				node->SetVisible(true);
-				TraverseNode(node);
-			}
-			else
-			{
-				IssueOcclusionQuery(node, false);
-				
-				// wait if result not available
-				int visiblePixels = GetOcclusionQueryResult(node);
-				
-				// node visible
-				if(visiblePixels > mVisibilityThreshold)
-				{
-					node->SetVisible(true);
-					TraverseNode(node);
-				}
-				else
-				{
-					mNumQueryCulledNodes ++;
-				}
-			}					
-		}
-		else
-		{
-			mNumFrustumCulledNodes ++;
-		}
-	}
-}
-
-void RenderTraverser::RenderCoherentWithQueue()
-{
-	QueryQueue queryQueue;
-
-	//-- PART 1: process finished occlusion queries
-	while (!mDistanceQueue.empty() || !queryQueue.empty())
-	{
-		while (!queryQueue.empty() && 
-			   (ResultAvailable(queryQueue.front()) || mDistanceQueue.empty()))
-		{
-			HierarchyNode *node = queryQueue.front();
-			queryQueue.pop();
-			
-			// wait until result available
-			int visiblePixels = GetOcclusionQueryResult(node);
-
-			if(visiblePixels > mVisibilityThreshold)
-			{
-				PullUpVisibility(node);
-				TraverseNode(node);
-			}
-			else
-			{
-				mNumQueryCulledNodes ++;
-			}
-		}	
-
-		//-- PART 2: hierarchical traversal
-		if (!mDistanceQueue.empty())
-		{
-			HierarchyNode *node = mDistanceQueue.top();
-
-			mDistanceQueue.pop();
-	
-			mNumTraversedNodes ++;
-
-			bool intersects;
-			
-			if (InsideViewFrustum(node, intersects))
-			{
-				// for near plane intersecting bounding box possible 
-				// wrong results => skip occlusion query
-				if(intersects)
-				{
-					// update node's visited flag
-					node->SetLastVisited(mFrameID);
-					node->SetVisible(true);
-					PullUpVisibility(node);
-					TraverseNode(node);
-				}
-				else
-				{		
-					// identify previously visible nodes
-					bool wasVisible = node->Visible() && (node->LastVisited() == mFrameID - 1);
-					
-					// identify nodes that we cannot skip queries for
-					bool leafOrWasInvisible = (node->LastVisited() != mFrameID) && (!wasVisible || node->IsLeaf());
-
-					// reset node's visibility classification 
-					node->SetVisible(false);
-
-					// update node's visited flag
-					node->SetLastVisited(mFrameID);
-					
-					// skip testing previously visible interior nodes
-					if(leafOrWasInvisible)
-					{
-						IssueOcclusionQuery(node, wasVisible);
-						queryQueue.push(node);
-					}
-					
-					// always traverse a node if it was visible
-					if(wasVisible)
-						TraverseNode(node);
-				}
-			}
-			else
-			{
-				// for stats
-				mNumFrustumCulledNodes ++;
-			}
-		}
-	}
-}
-	
+}*/
+
+#if 0
 void RenderTraverser::TraverseNode(HierarchyNode *node)
 {
@@ -533,8 +362,6 @@
 
 
-int RenderTraverser::GetVisibilityThreshold()
-{
-	return mVisibilityThreshold;
-}
+#endif
+
 
 void RenderTraverser::SetUseOptimization(bool useOptimization)
@@ -544,4 +371,3 @@
 }
 
-
-#endif
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj	(revision 2753)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chc_revisited.vcproj	(revision 2754)
@@ -307,4 +307,28 @@
 			>
 			<File
+				RelativePath=".\CHCPlusPlusTraverser.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\CHCPlusPlusTraverser.h"
+				>
+			</File>
+			<File
+				RelativePath=".\CHCTraverser.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\CHCTraverser.h"
+				>
+			</File>
+			<File
+				RelativePath=".\FrustumCullingTraverser.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\FrustumCullingTraverser.h"
+				>
+			</File>
+			<File
 				RelativePath=".\RenderTraverser.cpp"
 				>
@@ -312,4 +336,12 @@
 			<File
 				RelativePath=".\RenderTraverser.h"
+				>
+			</File>
+			<File
+				RelativePath=".\StopAndWaitTraverser.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\StopAndWaitTraverser.h"
 				>
 			</File>
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2753)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2754)
@@ -1,22 +1,54 @@
-#ifndef RENDERTRAVERSER_H
-#define RENDERTRAVERSER_H
-
-
-
-#if TOIMPLEMENT
-
-#include "glInterface.h"
-#include "HierarchyNode.h"
+#ifndef __RENDERTRAVERSER_H
+#define __RENDERTRAVERSER_H
 
 #include <queue>
 #include <stack>
+#include "glInterface.h"
+
 
 namespace CHCDemo
 {
 
+class BvhNode;
+class Bvh;
+class Camera;
+class Matrix4x4;
+
+
+struct TraversalStatistics
+{
+	friend class RenderTraverser;
+
+public:
+
+	//////////
+	//-- several statistics for a rendering pass
+
+	long GetRenderTime();
+	int GetNumTraversedNodes();
+	int GetNumQueryCulledNodes();
+	int GetNumFrustumCulledNodes();
+	int GetNumRenderedGeometry();
+	
+protected:
+
+	// statistics
+	int mNumTraversedNodes;
+	int mNumQueryCulledNodes;
+	int mNumFrustumCulledNodes;
+	int mNumRenderedGeometry;
+
+	long mRenderTime;
+};
+
+
+//typedef std::priority_queue<BvhNode *, std::vector<BvhNode *>, myless<std::vector<BvhNode *>::value_type> > TraversalQueue;
+
+/** Abstract class implementing a scene traversal for rendering.
+*/
 class RenderTraverser
 {
 public:
-	enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
+	//enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};
 
 	RenderTraverser();
@@ -30,64 +62,52 @@
 		RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm
 	*/
-	void Render(int mode=RENDER_CULL_FRUSTUM);
-	//! sets the scene hierarchy.
-	void SetHierarchy(HierarchyNode *sceneRoot);
-	//! sets viewpoint
-	void SetViewpoint(Vector3 const &viewpoint);
-	//! sets view projection matrix
-	void SetProjViewMatrix(Matrix4x4 const &projViewMatrix);
-	//! returns root of hierarchy
-	HierarchyNode *GetHierarchy();
-	//! sets visible pixels threshold for visibility classification
+	virtual void Render() = 0;
+	/** Sets the scene hierarchy.
+	*/
+	void SetHierarchy(Bvh *bvh);
+	/** Sets the camera.
+	*/
+	void SetCamera(Camera *camera);
+	/** sets view projection matrix
+	*/
+	//void SetProjViewMatrix(Matrix4x4 const &projViewMatrix);
+	/** Sets visible pixels threshold for visibility classification
+	*/
 	void SetVisibilityThreshold(int threshold);
-	//! returns visibility threshold
-	int GetVisibilityThreshold();
-
-	// several statistics for a rendering pass
-	long GetRenderTime();
-	int GetNumTraversedNodes();
-	int GetNumQueryCulledNodes();
-	int GetNumFrustumCulledNodes();
-	int GetNumRenderedGeometry();
-
-	//! renders a visualization of the hierarchy
+	/** 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	
+	/** use optimization to take leaf nodes instead of bounding box for occlusion queries	
+	*/
 	void SetUseOptimization(bool useOptimization);
-
-	//! if arb queries should be used instead of nv
-	void SetUseArbQueries(const bool useArbQueries);
-	//!	see set
-	bool GetUseArbQueries() const;
 
 protected:
 
-	//! renders the scene with view frustum culling only
-	void RenderCullFrustum();
-	//! renders the scene with the hierarchical stop and wait algorithm
-	void RenderStopAndWait();
-	//! renders the scene with the coherent hierarchical algorithm and the query queye
-	void RenderCoherentWithQueue();
-	//! does some importand initialisations
+	/** does some important initializations
+	*/
 	void Preprocess();
-	
-	//! returns occlusion query result for specified node
-	unsigned int GetOcclusionQueryResult(HierarchyNode *node) const;
-	//! the node is traversed as usual
-	void TraverseNode(HierarchyNode *node);
-	//! visibility is pulled up from visibility of children 
-	void PullUpVisibility(HierarchyNode *node);
-	//! is result available from query queue?
-	bool ResultAvailable(HierarchyNode *node) const;
-	//! issues occlusion query for specified node
-	void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible);
-	//! resets occlusion queries after a traversal
+	/** Hierarchy traversal
+	*/
+	void TraverseNode(BvhNode *node);
+	/** Visibility is pulled up from visibility of children 
+	*/
+	void PullUpVisibility(BvhNode *node);
+	/** Issues occlusion query for specified node
+	*/
+	void IssueOcclusionQuery(BvhNode *node, bool wasVisible);
+	/** Resets occlusion queries after a traversal
+	*/
 	void DelQueries();
-	//! does view frustum culling. returns intersect (if intersects view plane)
-	bool InsideViewFrustum(HierarchyNode *node, bool &intersects);
-	//! switches to normal render mode
+	/** Does view frustum culling. returns intersect (if intersects view plane)
+	*/
+	bool InsideViewFrustum(BvhNode *node, bool &intersects);
+	/** switches to normal render mode
+	*/
 	void Switch2GLRenderState();
-	//! switches to occlusion query mode (geometry not rendered on the screen)
+	/** switches to occlusion query mode (geometry not rendered on the screen)
+	*/
 	void Switch2GLQueryState();
 
@@ -95,37 +115,25 @@
 protected:
 
-	/// if arb queries should be instead of nv
-	bool mUseArbQueries;
+	// /the current clip planes of the view frustum
+	//VecPlane mClipPlanes;
+	/// the indices of the np-vertices of the bounding box for view frustum culling
+	//int mNPVertexIndices[12];
 
-	// the current clip planes of the view frustum
-	VecPlane mClipPlanes;
-	// the indices of the np-vertices of the bounding box for view frustum culling
-	int mNPVertexIndices[12];
-
-	// the current view point
-	Vector3 mViewpoint;
-	Matrix4x4 mProjViewMatrix;
-	// the root of the scene hierarchy
-	HierarchyNode *mHierarchyRoot;
-	//TraversalStack mTraversalStack;
-	PriorityQueue mDistanceQueue; // use a priority queue rather than a renderstack
+	/// the current camera
+	Camera *mCamera;
+	//Matrix4x4 mProjViewMatrix;
+	/// the root of the scene hierarchy
+	Bvh *mBvh;
+	/// use a priority queue rather than a renderstack
+	//PriorityQueue mDistanceQueue; 
 	
-	//priority_queue<vector<HierarchyNode *>, HierarchyNode *> mPriorityQueue;
 	int mFrameID;
 	int mVisibilityThreshold;
-	unsigned int *mOcclusionQueries;
+	
+	//unsigned int *mOcclusionQueries;
 	int mCurrentQueryIdx;
 	bool mIsQueryMode;
 	
-	bool mIntersects;
-
-	// statistics
-	int mNumTraversedNodes;
-	int mNumQueryCulledNodes;
-	int mNumFrustumCulledNodes;
-	int mNumRenderedGeometry;
-
-	long mRenderTime;
-
+	//bool mIntersects;
 	bool mUseOptimization;
 };
@@ -133,5 +141,4 @@
 }
 
-#endif
 
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/common.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/common.h	(revision 2753)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/common.h	(revision 2754)
@@ -469,15 +469,14 @@
 
 typedef std::queue<OcclusionQuery *> QueryQueue;
-//typedef std::priority_queue<BvhNode *, vector<BvhNode *>, myless<vector<BvhNode *>::value_type> > TraversalQueue;
-
-}
-
-#endif
-
-
-
-
-
-
-
-
+
+}
+
+#endif
+
+
+
+
+
+
+
+
