Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.h	(revision 2757)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.h	(revision 2757)
@@ -0,0 +1,25 @@
+#ifndef __STOPANDWAITTRAVERSER_H
+#define __STOPANDWAITTRAVERSER_H
+
+#include "RenderTraverser.h"
+
+
+namespace CHCDemo
+{
+
+/** Abstract class implementing a scene traversal for rendering.
+*/
+class StopAndWaitTraverser: public RenderTraverser
+{
+public:
+	StopAndWaitTraverser();
+	~StopAndWaitTraverser();
+
+	/** Renders the scene with the specified method
+	*/
+	virtual void Render() = 0;
+};
+
+}
+
+#endif // __STOPANDWAITTRAVERSER_H
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp	(revision 2757)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.cpp	(revision 2757)
@@ -0,0 +1,141 @@
+#include "Texture.h"
+#include <IL/il.h>
+#include "glInterface.h"
+#include <assert.h>
+#include <iostream>
+
+
+namespace CHCDemo
+{
+
+using namespace std;
+
+
+void startil()
+{
+	ilInit();
+	assert(ilGetError() == IL_NO_ERROR);
+}
+
+
+void stopil()
+{
+	ilShutDown();
+	assert(ilGetError() == IL_NO_ERROR);
+}
+
+
+Texture::Texture(const std::string &filename):
+mWidth(0), mHeight(0), mFormat(0), mImage(NULL), mTexId(-1), mName(filename)
+{
+	startil();
+	
+	if (!ilLoadImage(ILstring(filename.c_str())))
+	{
+		cerr << "Image load error " << ilGetError() << ": " << filename << endl;
+	}
+	else
+	{
+		mWidth = ilGetInteger(IL_IMAGE_WIDTH);
+		mHeight = ilGetInteger(IL_IMAGE_HEIGHT);
+
+		mFormat = FORMAT_RGBA;
+		mImage = malloc(GetByteSize());
+
+		cout << "successfully loaded texture " << filename << endl;
+		ilCopyPixels(0, 0, 0, mWidth, mHeight, 1, IL_RGBA, IL_UNSIGNED_BYTE, mImage);
+		assert(ilGetError() == IL_NO_ERROR);
+	}
+	
+	stopil();
+
+	Create();
+}
+
+
+void Texture::Create()
+{
+	glEnable(GL_TEXTURE_2D);
+	glGenTextures(1, &mTexId);
+	glBindTexture(GL_TEXTURE_2D, mTexId);
+	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, mWidth, mHeight,
+						  GL_RGBA, GL_UNSIGNED_BYTE, mImage);
+
+	//glTexImage2D(GL_TEXTURE_2D, 0, 3, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, mImage);
+}
+
+
+int Texture::GetFormat() const
+{
+	return mFormat;
+}
+
+
+int Texture::GetWidth() const
+{
+	return mWidth;
+}
+
+
+int Texture::GetHeight() const
+{
+	return mHeight;
+}
+
+
+void *Texture::GetImage() const
+{
+	return mImage;
+}
+
+
+Texture::~Texture()
+{
+	free(mImage);
+}
+
+
+std::string Texture::GetName() const
+{
+	return mName;
+}
+
+
+int Texture::GetRowLength() const
+{
+	if (mFormat == FORMAT_RGBA)
+		return mWidth * 4 * sizeof (unsigned char);
+	else
+		return mWidth * 3 * sizeof (unsigned char);
+}
+
+
+int Texture::GetPixelSize() const
+
+{
+	if (mFormat == FORMAT_RGBA)
+		return 4 * sizeof(unsigned char);
+	else 
+		return 3 * sizeof(unsigned char);
+}
+
+
+int Texture::GetByteSize() const
+{
+	return mHeight * GetRowLength();
+}
+
+
+void Texture::Bind() const
+{
+	glBindTexture(GL_TEXTURE_2D, mTexId);
+}
+
+}
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.h	(revision 2756)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.h	(revision 2757)
@@ -1,4 +1,4 @@
-#ifndef _BinaryLoader_H__
-#define _BinaryLoader_H__
+#ifndef __BinaryLoader_H__
+#define __BinaryLoader_H__
 
 // note use forward declaration instead
@@ -6,4 +6,6 @@
 #include <iostream>
 #include <fstream>
+#include <map>
+
 #include "common.h"
 
@@ -16,4 +18,5 @@
 class Material;
 class Geometry;
+class Texture;
 
 
@@ -26,4 +29,6 @@
 protected:
 	
+	void LoadTextures(std::ifstream &str);
+
 	SceneEntity *LoadSceneEntity(std::ifstream &str);
 	Material *LoadMaterial(std::ifstream &str);
@@ -34,4 +39,6 @@
 	Geometry *LoadGeometry(igzstream &str);
 	*/
+
+	std::map<int, Texture *> mTextureTable;
 };
 
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.h	(revision 2757)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/FrustumCullingTraverser.h	(revision 2757)
@@ -0,0 +1,27 @@
+#ifndef __FRUSTUMCULLINGTRAVERSER_H
+#define __FRUSTUMCULLINGTRAVERSER_H
+
+#include "RenderTraverser.h"
+
+
+namespace CHCDemo
+{
+
+/** Abstract class implementing a scene traversal for rendering.
+*/
+class FrustumCullingTraverser: public RenderTraverser
+{
+public:
+
+	FrustumCullingTraverser();
+
+	/** Renders the scene with the specified method
+	*/
+	virtual void Render();
+};
+
+}
+
+
+
+#endif // __FRUSTUMTRAVERSER_H
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp	(revision 2757)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/StopAndWaitTraverser.cpp	(revision 2757)
@@ -0,0 +1,68 @@
+#include "StopAndWaitTraverser.h"
+
+namespace CHCDemo
+{
+StopAndWaitTraverser::StopAndWaitTraverser(): RenderTraverser() 
+{
+}
+
+
+StopAndWaitTraverser::~StopAndWaitTraverser()
+{
+	//DelQueries();
+}
+
+
+void StopAndWaitTraverser::Render()
+{
+#if 0
+	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 ++;
+		}
+	}
+#endif
+}
+
+}
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2756)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/chcdemo.cpp	(revision 2757)
@@ -146,6 +146,6 @@
 	BinaryLoader loader;
 
-	const string filename("house_test.dem");
-	//const string filename("city.dem");
+	//const string filename("house_test.dem");
+	const string filename("city.dem");
 
 	camera = new Camera(800, 600);
@@ -166,6 +166,6 @@
 
 	SetupProjection(800, 600, 60, sceneBox);
-	camera->LookAtBox(sceneBox);
-	//camera->LookInBox(sceneBox);
+	//camera->LookAtBox(sceneBox);
+	camera->LookInBox(sceneBox);
 	//camera->SetPosition(Vector3(0, 0, -3));
 	//camera->SetDirection(Vector3(0, 0, 1));
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.h	(revision 2757)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/Texture.h	(revision 2757)
@@ -0,0 +1,68 @@
+#ifndef NO_PRAGMA_ONCE
+#pragma once
+#endif
+
+#ifndef __TEXTURE_H
+#define __TEXTURE_H
+
+#include <string>
+
+namespace CHCDemo
+{
+
+///
+class Texture
+{
+public:
+	/** Constructor loading texture from file
+	*/
+	Texture(const std::string &filename);
+	/** Destroys data.
+	*/
+	~Texture();
+	/** Returns image data.
+	*/
+	void *GetImage() const;
+	
+	enum { FORMAT_INVALID, FORMAT_RGB, FORMAT_RGBA };
+	
+	/** Returns width of texture.
+	*/
+	int GetWidth() const;
+	/** Returns width of texture.
+	*/
+	int GetHeight() const;
+	/** Returns texture format. Currently only RGBA supported.
+	*/
+	int GetFormat() const;
+	/** Returns name of the texture
+	*/
+	std::string GetName() const;
+
+	int GetRowLength() const;
+
+	int GetPixelSize() const;
+	
+	int GetByteSize() const;
+	/** Bind the texture.
+	*/
+	void Bind() const;
+
+protected:
+
+	void Create();
+
+	int mFormat;
+	int mWidth;
+	int mHeight;
+
+	unsigned int mTexId;
+
+	std::string mName;
+
+	void *mImage;
+};
+
+}
+
+#endif // __TEXTURE_H
Index: /GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp	(revision 2756)
+++ /GTP/trunk/App/Demos/Vis/CHC_revisited/BinaryLoader.cpp	(revision 2757)
@@ -81,4 +81,30 @@
 
 
+void BinaryLoader::LoadTextures(ifstream &str)
+{
+	int numTextures;
+	str.read(reinterpret_cast<char *>(&numTextures), sizeof(int));
+
+	for (int i = 0; i < numTextures; ++ i)
+	{
+		// texture
+		int texnameSize;
+		int id;
+
+		str.read(reinterpret_cast<char *>(&id), sizeof(int));
+		str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int));
+
+		char *texname = new char[texnameSize];
+		str.read(texname, sizeof(char) * texnameSize);
+
+		cout << "loading texture " << texname << " with len " << texnameSize << " id: " << id << endl;
+
+		Texture *tex = new Texture(texname);
+
+		mTextureTable[id] = tex;
+	}
+}
+
+
 //Appearance *BinaryLoader::LoadMaterial(igzstream &str)
 Material *BinaryLoader::LoadMaterial(ifstream &str)
@@ -88,21 +114,13 @@
 	
 	// texture
-	int texnameSize;
-
-	str.read(reinterpret_cast<char *>(&texnameSize), sizeof(int));
-
-	if (texnameSize)
-	{
-		char *texname = new char[texnameSize];
-		str.read(texname, sizeof(char) *texnameSize);
-
-
-		cout << "loading texture " << texname << " with len " << texnameSize << endl;
-		Texture *tex = new Texture(texname);
-		
-		mat->SetTexture(tex);
-	}
-	else
-		cout << "no texture " << texnameSize << endl;
+	int texId;
+
+	str.read(reinterpret_cast<char *>(&texId), sizeof(int));
+	//cout << "texid: " << texId << endl;
+
+	if (texId >= 0)
+	{
+		mat->SetTexture(mTextureTable[texId]);
+	}
 
 	// material
@@ -158,5 +176,5 @@
 		return NULL;
 
-	cout << "vertexcount: " << vertexCount << endl;
+	//cout << "vertexcount: " << vertexCount << endl;
 
 	vertices = new Vector3[vertexCount];
@@ -171,5 +189,5 @@
 	if (texCoordCount)
 	{
-		cout << "loading texcoords of size " << texCoordCount << endl;
+		//cout << "loading texcoords of size " << texCoordCount << endl;
 		texcoords = new float[texCoordCount * 2];
 		str.read(reinterpret_cast<char *>(texcoords), sizeof(float) * vertexCount * 2);
@@ -201,4 +219,7 @@
 	if (!istr.is_open())
 		return false;
+
+	// load the texture table
+	LoadTextures(istr);
 
 	// #shapes
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 2757)
@@ -0,0 +1,40 @@
+#include "FrustumCullingTraverser.h"
+
+namespace CHCDemo
+{
+
+FrustumCullingTraverser::FrustumCullingTraverser(): RenderTraverser() 
+{
+}
+
+
+void FrustumCullingTraverser::Render()
+{
+	while (!mDistanceQueue.empty())
+	{
+		BvhNode *node = mDistanceQueue.top();
+		mDistanceQueue.pop();
+	
+		// interesting for the visualization, so rest and set
+		node->SetVisible(false);
+		//mNumTraversedNodes ++;
+
+		//bool intersects;
+	
+		if (1)//mBvh->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 ++;
+		}
+	}
+}
+
+}
