Index: GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.h	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.h	(revision 2760)
@@ -16,15 +16,9 @@
 public:
 
-	Bvh *LoadFromFile(const std::string &filename, const SceneEntityContainer &entities);
+	Bvh *Load(const std::string &filename, const SceneEntityContainer &entities);
 
 protected:
 	
-	BvhLeaf *ImportBinLeaf(std::ifstream &stream, BvhInterior *parent);
-
-	BvhInterior *ImportBinInterior(std::ifstream &stream, BvhInterior *parent);
-
 	BvhNode *LoadNextNode(std::ifstream &stream, BvhInterior *parent);
-
-
 };
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.cpp	(revision 2760)
@@ -68,5 +68,6 @@
 	if (node->IsLeaf())
 	{
-		//mNumRenderedGeometry += node->Render();
+		//mNumRenderedGeometry +=
+		mBvh->Render(node, mRenderState);
 	}
 	else 
@@ -81,5 +82,26 @@
 }
 
+
+void RenderTraverser::SetHierarchy(Bvh *bvh)
+{
+	mBvh = bvh;
+	//DelQueries();
+}
+
+
+void RenderTraverser::SetRenderState(RenderState *state)
+{
+	mRenderState = state;
+	//DelQueries();
+}
+
+
 #if 0
+
+Bvh *RenderTraverser::GetHierarchy()
+{
+	return mBvh;
+}
+
 
 void RenderTraverser::RenderVisualization()
@@ -135,15 +157,4 @@
 }
 
-void RenderTraverser::SetHierarchy(HierarchyNode *sceneRoot)
-{
-	mHierarchyRoot = sceneRoot;
-
-	DelQueries();
-}
-
-HierarchyNode *RenderTraverser::GetHierarchy()
-{
-	return mHierarchyRoot;
-}
 
 unsigned int RenderTraverser::GetOcclusionQueryResult(HierarchyNode *node) const
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2756)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.cpp	(revision 2760)
@@ -131,10 +131,12 @@
 mIndices(NULL),
 mTestIndices(NULL),
-mCurrentIndicesPtr(0)
+mCurrentIndicesPtr(0),
+mNumNodes(0),
+mMaxDepthForTestingChildren(4),
+mAreaRatioThreshold(1.4f)
 {}
 
-/*
-Bvh::Bvh(const GeometryVector &geometry, 
-		 DistanceSortedRenderAction *const renderer):
+
+Bvh::Bvh(const SceneEntityContainer &entities):
 mCamera(NULL), 
 mFrameId(-1), 
@@ -144,51 +146,25 @@
 mTestIndices(NULL),
 mCurrentIndicesPtr(0),
-{
-	mGeometry = new NodeGeometry*[geometry.size()];
-	mGeometrySize = geometry.size();
-
-	BoundingBox sceneBox;
-
-	// compute scene extent
-	for (size_t i = 0; i < mGeometrySize; ++ i)
-	{
-		mGeometry[i] = geometry[i];
-		sceneBox.combine(&mGeometry[i]->mBox);
-
-		mBvhStats.mTriangles += mGeometry[i]->mNumTriangles;
-	}
-
-
-	////////
-	//-- create root
-
-	BvhLeaf *leaf = new BvhLeaf(NULL);
-	leaf->mDepth = 0;
-	leaf->mFirst = 0;
-	leaf->mLast = (int)geometry.size() - 1;
-	leaf->mBox = sceneBox;
-
-	OUT1("geometry in root: " << leaf->mLast);
-
-	mRoot = leaf;
-	mNumNodes = 1;
-
-	// parameters
-	mMaxGeometry = Settings::Global()->get_nvocc_bvh_max_objects();
-	mMaxTriangles = Settings::Global()->get_nvocc_bvh_max_triangles();
-	mMaxDepth = Settings::Global()->get_nvocc_bvh_max_depth();
-	mSplitType = Settings::Global()->get_nvocc_bvh_split_type();
-
-	float sceneArea = sceneBox.getSurface();
-	float minAreaRatio = Settings::Global()->get_nvocc_bvh_min_area();
-
-	mMinArea = minAreaRatio * sceneArea;
-
-	mMaxDepthForTestingChildren = Settings::Global()->get_nvocc_bvh_max_depth_for_testing_children();
-		
-	mAreaRatioThreshold = Settings::Global()->get_nvocc_area_ratio_threshold();
-	mVolRatioThreshold = Settings::Global()->get_nvocc_vol_ratio_threshold();
-}
-*/
+mNumNodes(0),
+mMaxDepthForTestingChildren(4),
+mAreaRatioThreshold(1.4f)
+{
+	mGeometrySize = entities.size();
+	mGeometry = new SceneEntity*[mGeometrySize];
+	
+	mBox.Initialize();
+
+	SceneEntityContainer::const_iterator it, it_end = entities.end();
+
+	int i = 0;
+	for (it = entities.begin(); it != it_end; ++ it, ++ i)
+	{
+		mGeometry[i] = (*it);
+		mBox.Include((*it)->GetBoundingBox());
+	}
+
+	cout << "scene box: " << mBox << endl;
+}
+
 
 Bvh::~Bvh() 
@@ -801,10 +777,4 @@
 	cout << "leafNodesVolume = " << mBvhStats.mLeafVol / mRoot->mBox.GetVolume() << endl;
 
-	cout << "boundsInteriorNodesSA = " << mBvhStats.mBoundsInteriorSA / mBvhStats.mLeafSA << endl;
-	cout << "boundsLeafNodesSA = " << mBvhStats.mBoundsLeafSA / mBvhStats.mLeafSA << endl;
-	cout << "boundsInteriorNodesVolume = " << mBvhStats.mBoundsInteriorVol / mBvhStats.mLeafVol << endl;
-	cout << "boundsLeafNodesVolume = " << mBvhStats.mBoundsLeafVol / mBvhStats.mLeafVol << "\n" << endl;
-
-	cout << "boundsLeaves: " <<  (float)mBvhStats.mBoundsLeavesCount / (float)GetNumLeaves() << "\n" << endl;
 	cout << "geometry per leaf: " <<  mBvhStats.mGeometryRatio << endl;
 	cout << "triangles per leaf: " <<  mBvhStats.mTriangleRatio << endl;
@@ -828,3 +798,43 @@
 }
 
-}
+
+void Bvh::UpdateNumLeaves(BvhNode *node) const
+{
+	if (node->IsLeaf())
+	{
+		node->mNumLeaves = 1;
+	}
+	else
+	{
+		BvhNode *f = static_cast<BvhInterior *>(node)->GetFront();
+		BvhNode *b = static_cast<BvhInterior *>(node)->GetBack();
+
+		UpdateNumLeaves(f);
+		UpdateNumLeaves(b);
+
+		node->mNumLeaves = f->mNumLeaves + b->mNumLeaves;
+	}
+}
+
+
+int Bvh::Render(BvhNode *node, RenderState *state)
+{
+	//cout << "r " << node->mFirst << " " <<  node->mLast << endl;
+
+	int rendered = 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;
+}
+
+
+}
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp	(revision 2759)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Material.cpp	(revision 2760)
@@ -20,6 +20,6 @@
 	mAmbientColor = RgbColor(0.2, 0.2, 0.2);
 	mDiffuseColor = RgbColor(1, 1, 1);
-	//mSpecularColor = RgbColor(0.5, 0.5, 0.5);
-	mSpecularColor = RgbColor(1, 1, 1);
+	mSpecularColor = RgbColor(0.0, 0.0, 0.0);
+	//mSpecularColor = RgbColor(1, 1, 1);
 }
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2759)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2760)
@@ -13,4 +13,7 @@
 #include "Camera.h"
 #include "Geometry.h"
+#include "BvhLoader.h"
+#include "FrustumCullingTraverser.h"
+
 
 
@@ -30,8 +33,11 @@
 /// the scene bounding box
 AxisAlignedBox3 sceneBox;
+/// the current render state
+RenderState state;
 
 // eye near plane distance
 float nearDist = 0.1f; 
-int winWidth, winHeight;
+int winWidth = 1024;
+int winHeight = 768;
 float winAspectRatio = 1.0f;
 
@@ -44,15 +50,12 @@
 bool showCreateParams = false;
 
-
-Vector3 eyePos = Vector3(0.0f, 0.0f, 3.0f);    // eye position 
-Vector3 viewDir = Vector3(0.0f, 0.0f, -1.0f);  // eye view dir 
-Vector3 lightDir = Vector3(0.0f, 0.0f, 1.0f);  // light dir 
-
-Matrix4x4 visView; // visualisation view matrix
+int currentFrame = -1;
+
+// visualisation view matrix
+Matrix4x4 visView; 
 
 //mouse navigation state
 int xEyeBegin, yEyeBegin, yMotionBegin, verticalMotionBegin, horizontalMotionBegin = 0;
 //int renderMode = RenderTraverser::RENDER_COHERENT;
-
 
 const int renderTimeSize = 100;
@@ -100,7 +103,7 @@
 int main(int argc, char* argv[])
 {
-	camera = new Camera(800, 600);
-
-	glutInitWindowSize(800, 600);
+	camera = new Camera(winWidth, winHeight);
+
+	glutInitWindowSize(winWidth, winHeight);
 	glutInit(&argc, argv);
 	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
@@ -124,5 +127,6 @@
 
 	//const string filename("house_test.dem");
-	const string filename("city_demo.dem");
+	//const string filename("city_demo.dem");
+	const string filename("city.dem");
 
 	if (loader.Load(filename, sceneEntities))
@@ -131,13 +135,12 @@
 		cerr << "loading scene " << filename << " failed" << endl;
 
-	sceneBox.Initialize();
-
-	SceneEntityContainer::const_iterator it, it_end = sceneEntities.end();
-
-	for (it = sceneEntities.begin(); it != it_end; ++ it)
-		sceneBox.Include((*it)->GetBoundingBox());
-
-	cout << "scene box: " << sceneBox << endl;
-
+	BvhLoader bvhLoader;
+	bvh = bvhLoader.Load("city.bvh", sceneEntities);
+
+	sceneBox = bvh->GetBox();
+
+	traverser = new FrustumCullingTraverser();
+	traverser->SetHierarchy(bvh);
+	traverser->SetRenderState(&state);
 
 	//SetupProjection(800, 600, 60, sceneBox);
@@ -162,5 +165,5 @@
 void InitGLstate(void) 
 {
-	glClearColor(0.0f, 0.0f, 0.0f, 0.0);
+	glClearColor(0.5f, 0.5f, 0.8f, 0.0);
 	
 	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
@@ -171,7 +174,6 @@
 	SetupLighting();
 
-	glColor3f(1.0f, 0.0f, 0.0f);
+	glColor3f(1.0f, 1.0f, 1.0f);
 	glShadeModel(GL_SMOOTH);
-	
 	
 	glMaterialf(GL_FRONT, GL_SHININESS, 64);
@@ -190,6 +192,4 @@
 	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
 	glMaterialfv(GL_FRONT, GL_SPECULAR, specularColor);
-
-	glColor3f(1.0f, 0.0f, 0.0f);
 	//setupVisView();
 }
@@ -277,4 +277,5 @@
 	GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
 	GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0};
+	//GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
 	GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
 	    
@@ -286,5 +287,5 @@
 	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
 
-	GLfloat position[] = {0.0, 3.0, 3.0, 0.0};
+	GLfloat position[] = {1.0, 1.0, 1.0, 0.0};
 	glLightfv(GL_LIGHT0, GL_POSITION, position);
 
@@ -293,7 +294,8 @@
 	//-- second light
 
-	GLfloat ambient1[] = {0.2, 0.2, 0.2, 1.0};
+	GLfloat ambient1[] = {0.5, 0.5, 0.5, 1.0};
+	//GLfloat diffuse1[] = {1.0, 1.0, 1.0, 1.0};
 	GLfloat diffuse1[] = {0.5, 0.5, 0.5, 1.0};
-	GLfloat specular1[] = {0.0, 0.0, 0.0, 1.0};
+	GLfloat specular1[] = {0.5, 0.5, 0.5, 1.0};
 
 	glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
@@ -314,5 +316,4 @@
 void SetupEyeView(void)
 {
-	
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
@@ -323,13 +324,12 @@
 	glLoadIdentity();	
 
-	GLfloat position[] = {0.0f, 3.0f, 3.0f, 0.0f};
+	camera->SetupCameraView();
+
+	GLfloat position[] = {0.8f, 1.0f, 1.5f, 0.0f};
 	glLightfv(GL_LIGHT0, GL_POSITION, position);
 
-	GLfloat position1[] = {sceneBox.Center().x, sceneBox.Center().y, sceneBox.Center().z, 1.0f};
+	GLfloat position1[] = {sceneBox.Center().x, sceneBox.Max().y, sceneBox.Center().z, 1.0f};
+	//GLfloat position1[] = {-2.0f, 1.0f, 0.0f, 0.0f};
 	glLightfv(GL_LIGHT1, GL_POSITION, position1);
-
-	camera->SetupCameraView();
-
-
 }
 
@@ -374,4 +374,5 @@
 */
 	
+	++ currentFrame;
 
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -380,4 +381,7 @@
 	SetupEyeView();
 
+	bvh->InitFrame(camera, currentFrame);
+
+
 	InitTiming();
 
@@ -389,4 +393,6 @@
 	glEnableClientState(GL_NORMAL_ARRAY);
 
+	traverser->Render();
+/*
 	bool usesTextures = false;
 
@@ -412,5 +418,5 @@
 		entity->Render();
 	}
-
+*/
 	glDisableClientState(GL_VERTEX_ARRAY);
 	glDisableClientState(GL_NORMAL_ARRAY);
@@ -568,5 +574,5 @@
 {
 	// used to avoid vertical motion with the keys
-	Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]);
+	//Vector3 hvec = Vector3(viewDir[0], 0, viewDir[2]);
 	
 	switch(c) 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/BvhLoader.cpp	(revision 2760)
@@ -19,31 +19,4 @@
 
 
-BvhLeaf *BvhLoader::ImportBinLeaf(ifstream &stream, BvhInterior *parent)
-{
-	BvhLeaf *leaf = new BvhLeaf(parent);
-
-	int first, last;
-
-	stream.read(reinterpret_cast<char *>(&first), sizeof(int));
-	stream.read(reinterpret_cast<char *>(&last), sizeof(int));
-
-	leaf->mFirst = first;
-	leaf->mLast = last;
-
-	return leaf;
-}
-
-
-BvhInterior *BvhLoader::ImportBinInterior(ifstream &stream, BvhInterior *parent)
-{
-	BvhInterior *interior = new BvhInterior(parent);
-
-	stream.read(reinterpret_cast<char *>(&interior->mAxis), sizeof(char));
-	stream.read(reinterpret_cast<char *>(&interior->mPosition), sizeof(float));
-
-	return interior;
-}
-
-
 BvhNode *BvhLoader::LoadNextNode(ifstream &stream, BvhInterior *parent)
 {
@@ -51,22 +24,41 @@
 	stream.read(reinterpret_cast<char *>(&nodeType), sizeof(int));
 
+	BvhNode *node;
+
 	if (nodeType == TYPE_LEAF)
 	{
-		//OUT1("l");
-		return ImportBinLeaf(stream, static_cast<BvhInterior *>(parent));
+		// cout << "l";
+		node = new BvhLeaf(parent);
+	}
+	else if (nodeType == TYPE_INTERIOR)
+	{
+		//cout << "i";
+		node = new BvhInterior(parent);
+	}
+	else
+	{
+		cerr << "wrong node type: " << nodeType << endl;
+		//exit(0);
 	}
 
-	if (nodeType == TYPE_INTERIOR)
-	{
-		//OUT1("i");
-		return ImportBinInterior(stream, static_cast<BvhInterior *>(parent));
-	}
+	Vector3 bMin, bMax;
 
-	return NULL;
+	stream.read(reinterpret_cast<char *>(&(node->mFirst)), sizeof(int));
+	stream.read(reinterpret_cast<char *>(&(node->mLast)), sizeof(int));
+	stream.read(reinterpret_cast<char *>(&bMin), sizeof(Vector3));
+	stream.read(reinterpret_cast<char *>(&bMax), sizeof(Vector3));
+
+	node->mBox = AxisAlignedBox3(bMin, bMax);
+
+	node->mArea = node->mBox.SurfaceArea();
+
+	//cout << "box: " << node->mBox << " area: " << node->mArea << endl;
+
+	return node;
 }
 
 
-Bvh *BvhLoader::LoadFromFile(const string &filename,  
-							 const SceneEntityContainer &entities)
+Bvh *BvhLoader::Load(const string &filename,  
+					 const SceneEntityContainer &entities)
 {
 	// export binary version of mesh
@@ -77,12 +69,6 @@
 
 	cout << "loading bvh" << endl;
-	Bvh *bvh = new Bvh();
 
-	bvh->mGeometrySize = entities.size();
-	bvh->mGeometry = new SceneEntity*[bvh->mGeometrySize];
-
-	for (size_t i = 0; i < bvh->mGeometrySize; ++ i)
-		bvh->mGeometry[i] = entities[i];
-
+	Bvh *bvh = new Bvh(entities);
 	bvh->mRoot = LoadNextNode(stream, NULL);
 
@@ -117,14 +103,15 @@
 	cout << "... finished loading " << bvh->mNumNodes << " nodes, updating boxes" << endl;
 
-	//adjust bounding boxes
-	//bvh->UpdateBoxes(bvh->mRoot);
-	//bvh->UpdateNumLeaves(bvh->mRoot);
+	///////////
+	//-- post process
 
+	bvh->UpdateNumLeaves(bvh->mRoot);
 	// compute unique ids
-	//bvh->ComputeIds();
-	// update the indices of the geometry so we can render interiors as well
-	//bvh->UpdateInteriors(bvh->mRoot);
-	// do this once so at least the current node bounding box is tested
-	//bvh->RecomputeBounds();
+	bvh->ComputeIds();
+	// specify bounds for occlusion tests
+	bvh->RecomputeBounds();
+	// compute and print stats
+	bvh->ComputeBvhStats();
+	bvh->PrintBvhStats();
 
 	return bvh;
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp	(revision 2757)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp	(revision 2760)
@@ -13,57 +13,4 @@
 namespace CHCDemo
 {
-
-/*static STL_MAP<String,Texture *> stlm_textures;
-
-
-// clear the texture table (called on new file load)
-static void clear_textures()
-{
-	STL_MAP<String,Texture *>::iterator it, it_end = stlm_textures.end();
-
-	for (it = stlm_textures.begin(); it != it_end; ++ it)
-	{
-		it->second->unref();
-		delete [] it->first;
-
-		it ++;
-	}
-
-	stlm_textures.clear();
-}
-
-
-static Texture *get_texture(const char *filename, TextureAttributes *&myTextureAttributes)
-{
-	Texture * myTexture = NULL;
-
-	myTextureAttributes = new TextureAttributes;
-	myTextureAttributes->setTextureMode(TextureAttributes::DECAL);
-
-	// Michi: avoid multiple loading of same texture!
-	if (stlm_textures.find(filename) != stlm_textures.end())
-	{
-		myTexture = stlm_textures[filename];
-	}
-	else
-	{
-		ImageComponent *image = new ImageComponent(filename);
-		//Texture *myTexture = new Texture(Texture::BASE_LEVEL, Texture::RGB, image->getWidth(), image->getHeight());
-		myTexture = new Texture(Texture::MULTI_LEVEL_MIPMAP, ImageComponent::FORMAT_RGBP, image->getWidth(), image->getHeight());
-		myTexture->setImage(0, image);
-		
-		myTexture->setMagFilter(Texture::BASE_LEVEL_LINEAR);
-		myTexture->setMinFilter(Texture::MULTI_LEVEL_LINEAR_POINT);
-
-		myTexture->setBoundaryModeS(Texture::WRAP);
-		myTexture->setBoundaryModeT(Texture::WRAP);
-		
-		stlm_textures[filename] = myTexture;
-		/// HACK!!! (texture not deleted on reload!)
-		myTexture->ref();
-	}
-
-	return myTexture;
-}*/
 
 
@@ -98,6 +45,5 @@
 		str.read(texname, sizeof(char) * texnameSize);
 
-		cout << "loading texture " << texname << " with len " << texnameSize << " id: " << id << endl;
-
+		//cout << "loading texture " << texname << " with len " << texnameSize << " id: " << id << endl;
 		Texture *tex = new Texture(texname);
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp	(revision 2757)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.cpp	(revision 2760)
@@ -1,3 +1,5 @@
 #include "FrustumCullingTraverser.h"
+#include "SceneEntity.h"
+
 
 namespace CHCDemo
@@ -11,4 +13,7 @@
 void FrustumCullingTraverser::Render()
 {
+	mRenderState->mTexturesEnabled = false;
+	mDistanceQueue.push(mBvh->GetRoot());
+
 	while (!mDistanceQueue.empty())
 	{
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2755)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/RenderTraverser.h	(revision 2760)
@@ -12,4 +12,5 @@
 class Camera;
 class Matrix4x4;
+
 
 
@@ -83,4 +84,8 @@
 	*/
 	void SetUseOptimization(bool useOptimization);
+	/** Sets the current render state
+	*/
+	void SetRenderState(RenderState *state);
+
 
 protected:
@@ -113,4 +118,5 @@
 	void EnqueueNode(BvhNode *node);
 
+
 	////////////
 	//-- members
@@ -138,4 +144,6 @@
 	//bool mIntersects;
 	bool mUseOptimization;
+
+	RenderState *mRenderState;
 };
 
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2756)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Bvh.h	(revision 2760)
@@ -14,8 +14,9 @@
 
 ////////
-// Forward declarations
+//-- Forward declarations
 
 class SceneEntity;
 class Camera;
+class RenderState;
 
 
@@ -210,5 +211,4 @@
 	/// the bounding box
 	AxisAlignedBox3 mBox;
-
 };
 
@@ -347,8 +347,8 @@
 	/** Returns split axis of this interior node.
 	*/
-	inline int GetAxis() { return (int)mAxis; }
+	//inline int GetAxis() { return (int)mAxis; }
 	/** Returns position of the split axis.
 	*/
-	inline float GetPosition() {return (float)mPosition;}
+	//inline float GetPosition() {return (float)mPosition;}
 
 
@@ -356,5 +356,5 @@
 
 	/// the position of the split plane
-	float mPosition;
+	//float mPosition;
 	
 	BvhNode *mBack;
@@ -407,9 +407,4 @@
 		mInteriorVol(0),
 		mLeafVol(0),
-		mBoundsInteriorSA(0),
-		mBoundsLeafSA(0),
-		mBoundsInteriorVol(0),
-		mBoundsLeafVol(0),
-		mBoundsLeavesCount(0),
 		mTriangles(0),
 		mTriangleRatio(0),
@@ -423,9 +418,5 @@
 		float mInteriorVol;
 		float mLeafVol; 
-		float mBoundsInteriorSA;
-		float mBoundsLeafSA;
-		float mBoundsInteriorVol;
-		float mBoundsLeafVol;
-		int mBoundsLeavesCount;
+		
 		int mTriangles;
 
@@ -479,4 +470,7 @@
 	int RenderBoundingBoxes(const BvhNodeContainer &nodes);
 
+	/** Returns the bounding box of this bvh.
+	*/
+	inline const AxisAlignedBox3 &GetBox() { return mBox; }
 
 
@@ -535,4 +529,6 @@
 	const BvhStats &GetBvhStats() const {return mBvhStats;}
 	
+	int Render(BvhNode *node, RenderState *state);
+
 
 protected:
@@ -543,4 +539,8 @@
 	*/
 	Bvh();
+
+	/** Protected constructor taking scene geometry into account
+	*/
+	const Bvh(const SceneEntityContainer &entities);
 	
 
@@ -574,10 +574,12 @@
 	*/
 	void RecomputeBounds();
-	/** Does some postprocessing on the leaves.
-		@returns #leaves that were chosen for tighter bounds.
-	*/
-	int PostProcessLeaves(BvhLeafContainer &leaves);
-		
-	
+	/** Does some postprocessing on the nodes.
+	*/
+	//void PostProcess();
+	/** Helper method that updates the number of leaves in the subtree under
+		this node.
+	*/
+	void UpdateNumLeaves(BvhNode *node) const;
+
 	////////////////////////
 
@@ -619,4 +621,6 @@
 	int mNumNodes;
 
+	/// the bounding box
+	AxisAlignedBox3 mBox;
 
 	//////////////
Index: GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp	(revision 2756)
+++ GTP/trunk/App/Demos/Vis/CHC_revisited/Camera.cpp	(revision 2760)
@@ -12,5 +12,5 @@
 	mWidth = 100;
 	mHeight = 100;
-	mFovy = 90.0f * M_PI/180.0f;
+	mFovy = 90.0f * M_PI / 180.0f;
 }
 
@@ -21,5 +21,5 @@
 	mHeight = height;
 	
-	mFovy = fieldOfView * M_PI/180.0f;
+	mFovy = fieldOfView * M_PI / 180.0f;
 }
 
@@ -74,8 +74,5 @@
 void Camera::GetProjectionMatrix(Matrix4x4 &mat)
 {
-	//float m[16];
-	
 	glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat.x);
-	//mat = Matrix4x4((const float *)m);
 }
 
@@ -83,8 +80,5 @@
 void Camera::GetModelViewMatrix(Matrix4x4 &mat)
 {
-	//float m[16];
-
 	glGetFloatv(GL_MODELVIEW_MATRIX, (float *)mat.x);
-	//mat = Matrix4f((const float *)m);
 }
 
@@ -100,7 +94,5 @@
 	matProjectionView *= matViewing;
 
-	
 	float fInvLength;
-
 	float planes[6][4];
 
