Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 3236)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Shape.cpp	(revision 3238)
@@ -15,7 +15,7 @@
 mGeometry(geometry), 
 mMaterial(mat)
-{	std::cout<<"i";
+{	
 	mCenter = GetBoundingBox().Center();
-	std::cout<<"R";
+	
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3237)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp	(revision 3238)
@@ -109,14 +109,9 @@
 			int shapeId;
 			str.read(reinterpret_cast<char *>(&shapeId), sizeof(int));
-cout<<"x";
 
 			Geometry *geom = mGeometryTable[shapeId];
-cout<<"y";
-
 			Material *mat = mMaterialTable[shapeId];
-cout<<"z";
 			// create shape
 			Shape *shape = new Shape(geom, mat);
-cout<<"w";
 
 			mShapes.push_back(shape);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3114)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp	(revision 3238)
@@ -50,6 +50,4 @@
 	if (tech->IsDepthWriteEnabled() != mBuckets[idx]->mDepthWriteEnabled) { return false; }
 
-	//if (tech->IsColorWriteEnabled()) cout << "x";
-
 	const bool hasTexture = (tech->GetTexture() != NULL);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3237)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3238)
@@ -58,5 +58,4 @@
 #include "WalkThroughRecorder.h"
 #include "StatsWriter.h"
-#include "Halton.h"
 
 
@@ -127,4 +126,7 @@
 string statsFilename("stats");
 
+string filename("city");
+
+
 /// the walkThroughRecorder
 WalkThroughRecorder *walkThroughRecorder = NULL;
@@ -428,4 +430,5 @@
 		env.GetStringParam(string("recordedFramesSuffix"), recordedFramesSuffix);
 		env.GetStringParam(string("statsFilename"), statsFilename);
+		env.GetStringParam(string("filename"), filename);
 
 		//env.GetStringParam(string("modelPath"), model_path);
@@ -458,4 +461,5 @@
 		cout << "recorded frames suffix: " << recordedFramesSuffix << endl;
 		cout << "stats filename: " << statsFilename << endl;
+		cout << "filename: " << filename << endl;
 
 		//cout << "model path: " << model_path << endl;
@@ -528,5 +532,5 @@
 	//-- load the static scene geometry
 
-	LoadModel("city.dem", sceneEntities);
+	LoadModel(filename + ".dem", sceneEntities);
 
 
@@ -587,5 +591,5 @@
 	//-- load the associated static bvh
 
-	const string bvh_filename = string(model_path + "city.bvh");
+	const string bvh_filename = string(model_path + filename + ".bvh");
 
 	BvhLoader bvhLoader;
@@ -660,11 +664,7 @@
 	frameTimer.Start();
 
-	Halton::TestHalton(7, 1);
-	Halton::TestHalton(7, 2);
-
-	HaltonSequence::TestHalton(15, 2);
-	HaltonSequence::TestHalton(15, 1);
-
-	Halton::TestPrime();
+	//Halton::TestHalton(7, 2);
+	//HaltonSequence::TestHalton(15, 2);
+	//Halton::TestPrime();
 
 	// the rendering loop
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj	(revision 3019)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/MainApp.vcproj	(revision 3238)
@@ -196,4 +196,12 @@
 				>
 			</File>
+			<File
+				RelativePath=".\default.env"
+				>
+			</File>
+			<File
+				RelativePath=".\Readme.txt"
+				>
+			</File>
 		</Filter>
 		<Filter
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3232)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.vcproj	(revision 3238)
@@ -888,12 +888,4 @@
 			</File>
 		</Filter>
-		<File
-			RelativePath=".\default.env"
-			>
-		</File>
-		<File
-			RelativePath=".\ReadMe.txt"
-			>
-		</File>
 	</Files>
 	<Globals>
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3230)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3238)
@@ -7,4 +7,5 @@
 # misc stuff
 
+filename=city
 useLODs=1
 # shadow map size
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h	(revision 3235)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h	(revision 3238)
@@ -110,5 +110,20 @@
 	bool ReadDummyTree(FILE *fr);
 
+	bool ReadObj(const std::string &filename,
+		         VertexArray &vertices,
+				 VertexArray &normals,
+				 std::vector<TexCoord> &texcoords);
+	
+	bool ReadSimpleObj(const std::string &filename,
+		               VertexArray &vertices,
+					   VertexArray &normals,
+					   std::vector<TexCoord> &texcoords);
 
+	bool ReadBinObj(const std::string &filename,
+                    VertexArray &vertices,
+					float scale);
+
+	bool ExportBinObj(const std::string &filename,
+                      const VertexArray &vertices);
 
 	//////////////////////////////////
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp	(revision 3235)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp	(revision 3238)
@@ -23,5 +23,5 @@
 	}
 	
-	std::cin.get();
+	//std::cin.get();
 	cout << "conversion successful" << endl;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3236)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3238)
@@ -14,4 +14,23 @@
 
 #define BVH_VERSION 2.1
+
+const int maxVertices = 20000000;
+
+
+
+static string ReplaceSuffix(const string &str, 
+							const string &a, 
+							const string &b)
+{
+	string result = str;
+
+	int pos = (int)str.rfind(a, (int)str.size() - 1);
+	if (pos == str.size() - a.size()) 
+	{
+		result.replace(pos, a.size(), b);
+	}
+
+	return result;
+}
 
 
@@ -92,14 +111,8 @@
 		if (indices.size() > 2)
 		{
-			// change orientation of faces?
-#if 1
 			int idx1 = 0;
 			int idx2 = (int)indices.size() - 2;
 			int idx3 = (int)indices.size() - 1;
-#else
-			int idx3 = 0;
-			int idx2 = (int)indices.size() - 2;
-			int idx1 = (int)indices.size() - 1;
-#endif
+
 			faceVertices.push_back(vertices[indices[idx1]]);
 			faceVertices.push_back(vertices[indices[idx2]]);
@@ -172,9 +185,8 @@
 	geom->mTexcoordCount = (int)texCoords.size();
 
-	cout << "number of vertices=" << numElements << endl;
+	//cout << "number of vertices=" << numElements << endl;
 
 	for (int i = 0; i < numElements; ++ i)
 	{
-#if 1
 		// convert to our camera system: change y and z
 		geom->mVertices[i].x =  vertices[i].x;
@@ -186,15 +198,4 @@
 		geom->mNormals[i].z =  normals[i].y;
 
-#else
-		geom->mVertices[i].x = vertices[i].x;
-		geom->mVertices[i].y = vertices[i].y;
-		geom->mVertices[i].z = vertices[i].z;
-	
-		geom->mNormals[i].x = normals[i].x;
-		geom->mNormals[i].y = normals[i].y;
-		geom->mNormals[i].z = normals[i].z;
-
-#endif
-
 		if (i < geom->mTexcoordCount)
 		{
@@ -229,5 +230,5 @@
 	if (!LoadSolution(bvhInputFilename))
 	{
-		cerr << "could not read file" << endl;
+		cerr << "could not read solution file" << endl;
 		return false;
 	}
@@ -255,20 +256,33 @@
 
 
-bool VisibilitySolutionConverter::ReadScene(const string &filename) 
+bool VisibilitySolutionConverter::ReadScene(const string &filename)
+{
+	VertexArray vertices;
+	VertexArray normals;
+	vector<TexCoord> texCoords;
+
+	if (ReadSimpleObj(filename, vertices, normals, texCoords))
+	//if (ReadObj(filename, vertices, normals, texCoords)) 
+	{
+		ConstructBvhObjects(vertices, normals, texCoords);
+		return true;
+	}
+
+	return false;
+}
+
+
+bool VisibilitySolutionConverter::ReadObj(const string &filename,
+										  VertexArray &vertices,
+										  VertexArray &normals,
+										  vector<TexCoord> &texcoords) 
 {
 	FILE *file;
 
-	if ((file = fopen(filename.c_str(), "r")) == NULL)
-	{	
-		return false;
-	}
-	
-	VertexArray faceVertices; 
-	VertexArray faceNormals;
-	vector<TexCoord> faceTexcoords;
-
-	VertexArray vertices; 
-	VertexArray normals;
-	vector<TexCoord> texcoords;
+	if ((file = fopen(filename.c_str(), "r")) == NULL) return false;
+	
+	VertexArray tempVertices; 
+	VertexArray tempNormals;
+	vector<TexCoord> tempTexcoords;
 
 	vector<int> indices;
@@ -280,5 +294,5 @@
 	while (fgets(str, len, file) != NULL)
 	{
-		if (line % 1000000 == 0)
+		if (line % 500000 == 0)
 			cout << line << " " << str << endl;
 
@@ -291,5 +305,5 @@
 				float x, y, z;
 
-				if (vertices.size() >= 1000000 * 3) continue;
+				//if (tempVertices.size() >= maxVertices * 3) continue;
 
 				switch (str[1]) 
@@ -297,9 +311,9 @@
 				case 'n' :
 					sscanf(str + 2, "%f %f %f", &x, &y, &z);
-					normals.push_back(SimpleVec(x, y, z));
+					tempNormals.push_back(SimpleVec(x, y, z));
 					break;
 				case 't':
 					sscanf(str + 2, "%f %f", &x, &y);
-					texcoords.push_back(pair<float, float>(x, y));
+					tempTexcoords.push_back(pair<float, float>(x, y));
 					break;
 				default:
@@ -307,5 +321,5 @@
 					//const float scale = 5e-3f;
 					const float scale = 0.1f;
-					vertices.push_back(SimpleVec(x * scale, y * scale, z * scale));
+					tempVertices.push_back(SimpleVec(x * scale, y * scale, z * scale));
 					//cout <<"v " << x << " " << y << " "<< z << " ";
 				}
@@ -317,9 +331,8 @@
 				//-- indices in the current line
 
-				if (faceVertices.size() >= 1000000 * 3) continue;
-
+				//if (tempVertices.size() >= maxVertices * 3) continue;
 				LoadIndices(str, 
-					        vertices, normals, texcoords, 
-					        faceVertices, faceNormals, faceTexcoords);
+					        tempVertices, tempNormals, tempTexcoords, 
+					        vertices, normals, texcoords);
 
 				break;
@@ -332,19 +345,75 @@
 	}
 
-	if (!faceVertices.empty())
-	{
-		++ mNumShapes;
-
-		ConstructBvhObjects(faceVertices, faceNormals, faceTexcoords);
-
-		faceVertices.clear();
-		faceNormals.clear();
-		faceTexcoords.clear();
-	}
-
 	fclose(file);
-	
-	return true;
-}
+
+	return !vertices.empty();
+}
+
+
+bool VisibilitySolutionConverter::ReadSimpleObj(const string &filename,
+												VertexArray &vertices,
+												VertexArray &normals,
+												vector<TexCoord> &texcoords)
+{
+	const string binFilename = ReplaceSuffix(filename, ".obj", ".bn");
+
+	if (!ReadBinObj(binFilename, vertices, 1))
+	{
+		cout << "binary dump " << binFilename << " not available, loading ascii obj" << endl;
+
+		FILE *file;
+		if ((file = fopen(filename.c_str(), "r")) == NULL) return false;
+
+		int line = 0;
+		const int len = 10000;
+		char str[len];
+
+		while (fgets(str, len, file) != NULL)
+		{
+			if (line % 500000 == 0)
+				cout << line << " " << str << endl;
+
+			++ line;
+
+			switch (str[0])
+			{
+			case 'v': // vertex or normal
+				{
+					float x, y, z;
+
+					sscanf(str + 1, "%f %f %f", &x, &y, &z);
+					const float scale = 0.1f;
+					vertices.push_back(SimpleVec(x * scale, y * scale, z * scale));
+					break;
+				}
+			default:
+				// throw away line
+				break;
+			}
+		}
+
+		fclose(file);
+
+		cout << "dumping " << vertices.size() << " to binary " << binFilename << endl;
+		ExportBinObj(binFilename, vertices);
+	}
+
+	for (size_t i = 0; i < vertices.size(); i += 3)
+	{
+		// no face normals? => create normals
+		const SimpleTri tri(vertices[i + 0],
+    	                    vertices[i + 1], 
+							vertices[i + 2]);
+
+		const SimpleVec n = tri.GetNormal();
+
+		normals.push_back(n);
+		normals.push_back(n);
+		normals.push_back(n);
+	}
+
+	return !vertices.empty();
+}
+
 
 
@@ -473,29 +542,24 @@
 													  const vector<TexCoord> &texCoords)
 {
-	cout << "vtx: " << vertices.size() << endl;
+	VertexArray _vertices;
+	VertexArray _normals;
+	vector<TexCoord> _texCoords;
 
 	for (size_t i = 0; i < mBvhNodes.size(); ++ i)
 	{
-		VertexArray _vertices;
-		VertexArray _normals;
-		vector<TexCoord> _texCoords;
-
 		BvhNode *node = mBvhNodes[i];
 
 		//for (size_t j = 0; j < node->mTriangleIds.size(); ++ j)
-		for (int j = node->first; j < node->last; ++ j)
+		for (int j = node->first; j <= node->last; ++ j)
 		{
 			const int idx = 3 * mGlobalTriangleIds[j];
 
-			//cout << "idx: " << idx << " ";
-
-			if (idx < 1000000 * 3)
+			//if (idx >= maxVertices * 3) continue;
+
+			for (int k = 0; k < 3; ++ k)
 			{
-				for (int k = 0; k < 3; ++ k)
-				{
-					_vertices.push_back(vertices[idx + k]);
-					_normals.push_back(normals[idx + k]);
-					//_texCoords.push_back(texCoords[idx + k]);
-				}
+				_vertices.push_back(vertices[idx + k]);
+				_normals.push_back(normals[idx + k]);
+				//_texCoords.push_back(texCoords[idx + k]);
 			}
 		}
@@ -506,4 +570,8 @@
 			LoadShape(_vertices, _normals, _texCoords);
 		}
+
+		_vertices.clear();
+		_normals.clear();
+		_texCoords.clear();
 	}
 }
@@ -663,24 +731,9 @@
 	fread(&totalTime, sizeof(float), 1, fr);
 
-	//viewCellsTree = new ViewCellsTree;
-	//bool ok = viewCellsTree->_LoadFromFile(fr);
-
+	// just need to convert objects => read dummy visibility tree
 	bool ok = ReadDummyTree(fr);
 
-	if (ok) 
-	{
-		//AllocateLeafViewCells();
-		
-		//objectsTree = new Bvh(*scene);
-		//ok = objectsTree->_LoadFromFile(fr);
-		ok = ReadBvh(fr);
-
-		/*if (ok) 
-		{ 
-		    AllocatePvsObjects();
-			ok = LoadPvs(fr);
-		}
-		*/
-	}
+	// read bvh to optain objects (= the leaves of the bvh)
+	if (ok) ok = ReadBvh(fr);
 
 	fclose(fr);
@@ -695,83 +748,74 @@
 
 
-#if 0
-bool VisibilitySolution::LoadPvs(FILE *fw)
-{  
-	int number, entries;
-  
-	fread(&number, sizeof(int), 1, fw);
-
-	if (number == 0) 
-	{
-		Message("Info: Warning empty PVSs in visibility solution");
-		return true;
-	}
-
-	if (number != viewCells.size()) 
-	{
-		Message("Info: Number of view cells does not match when loading PVSs!");
-		return false;
-	}
-
-	for (int i=0; i < number; i++) 
-	{
-		fread(&entries, sizeof(int), 1, fw);
+bool VisibilitySolutionConverter::ReadBinObj(const string &filename,
+											 VertexArray &vertices,
+											 float scale)
+{
+	igzstream inStream(filename.c_str());
+	
+	if (!inStream.is_open()) return false;
+
+	cout << "binary obj dump available, loading " << filename.c_str() << endl;
+	
+	// read in triangle size
+	int numTriangles;
+
+	const int t = 500000;
+	inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int));
+	vertices.reserve(numTriangles * 3);
+	cout << "loading " << numTriangles * 3 << " vertices (" 
+		 << numTriangles * 3 * sizeof(SimpleVec) /	(1024 * 1024) << " MB)" << endl;
+
+	int i = 0;
+
+	while (1)
+	{
+		SimpleVec v;
 		
-		for (int j=0; j < entries; j++) 
-		{
-			int objectId;
-			float time;
-			fread(&objectId, sizeof(int), 1, fw);
-			fread(&time, sizeof(float), 1, fw);
-			viewCells[i]->pvs.Insert(objectId, time);
-		}
-	}
+		inStream.read(reinterpret_cast<char *>(&v), sizeof(SimpleVec));
+
+		// end of file reached
+		if (inStream.eof())	break;
+		
+		//v *= scale;
+		vertices.push_back(v);
+
+		if (((i ++) % t) == 0)
+			 cout << "\r" << i << "/" << numTriangles * 3 << "\r";
+	}
+	
+	cout << "finished loading vertices" << endl;
+
+	if (i != numTriangles * 3)
+		cerr << "warning: " << numTriangles * 3 << " != " << i << endl;
+
+	inStream.close();
+
 	return true;
 }
 
 
-bool ViewCellsTree::_LoadFromFile(FILE *fr)
-{
-	int buffer[256]; 
-	fread(buffer, sizeof(int), 3, fr);
-
-	if (buffer[0] != MAGIC) 
-	{
-		Message( "Error: Wrong file type");
-		return false;
-	}
-
-	if (buffer[1] != (int)(1000*VIEWCELLS_VERSION)) 
-	{
-		Message( "Error: Wrong viewcells version" );
-		
-		return false;
-	}
-
-	// get the bounding box
-	fread(&box, sizeof(AxisAlignedBox3), 1, fr);
-
-	stack<ViewCellsTreeNode **> nodeStack;
-	nodeStack.push(&root);
-
-	while(!nodeStack.empty()) 
-	{
-		ViewCellsTreeNode *&node = *nodeStack.top();
-		
-		nodeStack.pop();
-		node = new ViewCellsTreeNode;
-		
-		fread(&node->axis, sizeof(int), 1, fr);
-		
-		if (!node->IsLeaf()) 
-		{
-			fread(&node->position, sizeof(float), 1, fr);
-			
-			nodeStack.push(&node->front);
-			nodeStack.push(&node->back);
-		}
-	}
-  
+bool VisibilitySolutionConverter::ExportBinObj(const string &filename,
+											   const VertexArray &vertices)
+{	
+	ogzstream ofile(filename.c_str());
+	if (!ofile.is_open()) return false;
+
+	int numTriangles = (int)vertices.size() / 3;
+
+	ofile.write(reinterpret_cast<char *>(&numTriangles), sizeof(int));
+
+	VertexArray::const_iterator it, it_end = vertices.end();
+
+	for (it = vertices.begin(); it != it_end; ++ it)
+	{
+		SimpleVec v = *it;
+		ofile.write(reinterpret_cast<char *>(&v), sizeof(SimpleVec));
+	}
+
+	cout << "exported " << numTriangles * 3 << " vertices" << endl;
+
+	ofile.close();
+
 	return true;
 }
-#endif
