Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 3212)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/FriendlyCulling.sln	(revision 3235)
@@ -17,4 +17,6 @@
 		{03661866-4093-4B02-B26A-028EA91AF023} = {03661866-4093-4B02-B26A-028EA91AF023}
 	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VisibilitySolutionConverter", "VisibilitySolutionConverter.vcproj", "{A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}"
 EndProject
 Global
@@ -44,4 +46,8 @@
 		{91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.ActiveCfg = Release|Win32
 		{91680C49-A358-48AE-A02C-66CB884B7D7F}.Release|Win32.Build.0 = Release|Win32
+		{A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Debug|Win32.ActiveCfg = Debug|Win32
+		{A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Debug|Win32.Build.0 = Debug|Win32
+		{A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Release|Win32.ActiveCfg = Release|Win32
+		{A07AEF7C-5A28-4881-AE56-F9C5FFA3FEC4}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg	(revision 3232)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/depthOfField.cg	(revision 3235)
@@ -7,15 +7,23 @@
 
 
-float2 ComputeBlurFactors(float4 color, float sceneRange)
+float2 ComputeBlurFactors(float4 color, float sceneRange, float zFocus)
 {
 	float2 result;
 
+	const float m = 1.0f;
+	const float focalLen = 1.0f;
+
+	const float scale = 5e4f;
+
 	// Compute blur factor based on the CoC size scaled and normalized to 0..1 range
-	//float pixCoC = abs(Dlens * focalLen * (Zfocus - v.fDepth) / (Zfocus * (v.fDepth - focalLen)));
+	//float blur = abs(dLens * focalLen * (zFocus - color.w)) / (1e-6f + abs(zFocus * (color.w - focalLen)));
+
+	const float dist = abs(zFocus - color.w);
+	const float blur = scale * m * focalLen * dist / (sceneRange * (1e-6f + abs(color.w + dist * step(0, zFocus - color.w))));
 	
-	//float blur = saturate(pixCoC * scale / maxCoC);
+	//float blur = saturate(blur * scale / maxCoC);
 	
 	// Depth/blurriness value scaled to 0..1 range
-	//result = float2(v.fDepth / sceneRange, blur);
+	result = float2(color.w / sceneRange, blur);
 
 	return result;
@@ -30,10 +38,10 @@
 			)
 {
-	float average = .0f;
+	float4 avgCol = float4(.0f);
 	float total_w = .0f;
 
 	for (int i = 0; i < NUM_DOF_TABS; ++ i)
 	{
-		float2 sampleTexCoord = texCoords + filterOffs[i];
+		float2 sampleTexCoord = texCoords + filterOffs[i] * blurFactors.y;
 		float4 sampleCol = tex2Dlod(colorsTex, float4(sampleTexCoord, 0, 0));
 		
@@ -41,11 +49,11 @@
 		float w = 1;
 		
-		average += sampleCol * w;
+		avgCol += sampleCol * w;
 		total_w += w;
 	}
 
-	average /= max(total_w, 1e-6f);
+	avgCol /= max(total_w, 1e-6f);
 
-	return saturate(average);
+	return avgCol;
 }
 
@@ -54,5 +62,6 @@
 					uniform sampler2D colorsTex,
 					uniform float2 filterOffs[NUM_DOF_TABS],
-					uniform float sceneRange
+					uniform float sceneRange,
+					uniform float zFocus
 					 ): COLOR
 {
@@ -60,5 +69,8 @@
 	const float4 color = tex2Dlod(colorsTex, float4(IN.texCoords, 0, 0));
 	
-	float2 blurFactors = ComputeBlurFactors(color, sceneRange);
+	zFocus = min(zFocus, sceneRange * 0.5f);
+	float2 blurFactors = ComputeBlurFactors(color, sceneRange, zFocus);
+
+	//float4 outCol = float4(color.x, color.y, blurFactors.y, color.w);
 	float4 outCol = Blur(color, IN.texCoords, blurFactors, colorsTex, filterOffs);
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3234)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SampleGenerator.cpp	(revision 3235)
@@ -109,5 +109,5 @@
 	}
 
-	cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;
+	//cout << "minDist after= " << (float)minDist / mNumSamples<< " #tries: " << tries << endl;
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3232)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.h	(revision 3235)
@@ -88,4 +88,6 @@
 	void SetSaveFrame(const std::string &suffix, int frameNumber);
 
+	void SetMaxDistance(float maxDist);
+
 
 	// hack: store the color buffer idx for the currently used flip flop-MRT here
@@ -158,4 +160,5 @@
 
 
+
 	////////////
 
@@ -205,4 +208,6 @@
 	int mSavedFrameNumber;
 	std::string mSavedFrameSuffix;
+
+	float mMaxDistance;
 };
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3214)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3235)
@@ -1326,4 +1326,5 @@
 	{
 		while (mGeometry[i]->GetWorldCenter()[axis] < position) ++ i;
+		//while ((j > 0) && (position < mGeometry[j]->GetWorldCenter()[axis])) -- j;
 		while (position < mGeometry[j]->GetWorldCenter()[axis]) -- j;
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/irradiance.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/irradiance.cpp	(revision 3216)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/irradiance.cpp	(revision 3235)
@@ -1153,4 +1153,5 @@
 		deferredShader->SetUseTemporalCoherence(useTemporalCoherence);
 		deferredShader->SetSortSamples(sortSamples);
+		deferredShader->SetMaxDistance(traverser->GetMaxVisibleDistance());
 
 		ShadowMap *sm = showShadowMap ? shadowMap : NULL;
@@ -2017,5 +2018,5 @@
 		{
 			// usethe maximal visible distance to focus shadow map
-			float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance());
+			const float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance());
 			RenderShadowMap(maxVisibleDist);
 		}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3227)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3235)
@@ -541,4 +541,5 @@
 	//LoadModel("fisch.dem", dynamicObjects);
 	LoadModel("hbuddha.dem", dynamicObjects);
+
 	//LoadModel("venusm.dem", dynamicObjects);
 	//LoadModel("camel.dem", dynamicObjects);
@@ -575,4 +576,8 @@
 		dynamicObjects.push_back(ent);
 	}
+
+
+	//LoadModel("vienna_full_hp.dem", dynamicObjects);
+	//dynamicObjects.back()->GetTransform()->SetMatrix(transl);
 
 
@@ -2276,6 +2281,6 @@
 		{
 			// usethe maximal visible distance to focus shadow map
-			float maxVisibleDist = min(camera->GetFar(), traverser->GetMaxVisibleDistance());
-			RenderShadowMap(maxVisibleDist);
+			const float newFar = min(camera->GetFar(), traverser->GetMaxVisibleDistance());
+			RenderShadowMap(newFar);
 		}
 		// initialize deferred rendering
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3233)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/DeferredRenderer.cpp	(revision 3235)
@@ -301,5 +301,6 @@
 mSunVisiblePixels(0),
 mSavedFrameNumber(-1),
-mSavedFrameSuffix("")
+mSavedFrameSuffix(""),
+mMaxDistance(1e6f)
 {
 	///////////
@@ -488,7 +489,7 @@
 	////////////////
 	
-	string dofParams[] = {"colorsTex", "filterOffs", "sceneRange"};
-
-	sCgDOFProgram->AddParameters(dofParams, 0, 3);
+	string dofParams[] = {"colorsTex", "filterOffs", "sceneRange", "zFocus"};
+
+	sCgDOFProgram->AddParameters(dofParams, 0, 4);
 
 
@@ -520,5 +521,11 @@
 	// todo matt: it is stupid to put num samples and width of kernel into constructor => change this!!!
 	PoissonDiscSampleGenerator2D poisson3(NUM_DOF_TABS, 1.0f);
-	poisson2.Generate((float *)dofSamples);
+	poisson3.Generate((float *)dofSamples);
+
+	for (int i = 0; i < NUM_DOF_TABS; ++ i)
+	{
+		dofSamples[i].x *= 1.0f / mWidth;
+		dofSamples[i].y *= 1.0f / mHeight;
+	}
 
 	//float dofWeights[NUM_PCF_TABS];
@@ -567,4 +574,7 @@
 	}
 
+	/// do depth of field
+	DepthOfField(fbo);
+
 	if (useToneMapping)
 	{
@@ -574,8 +584,4 @@
 		ToneMap(fbo, imageKey, whiteLum, middleGrey);
 	}
-
-
-	/// do depth of field
-	DepthOfField(fbo);
 
 	/// compute lense flare
@@ -1312,11 +1318,12 @@
 	FlipFbos(fbo);
 
-	float sceneRange = 1.0f;
-
 	int i = 0;
+
+	const float zFocus = 7.0f;
 
 	sCgDOFProgram->SetTexture(i ++, colorsTex);
 	sCgDOFProgram->SetArray2f(i ++, (float *)dofSamples, NUM_DOF_TABS);
-	sCgDOFProgram->SetValue1f(i ++, mCamera->GetFar() - mCamera->GetNear());
+	sCgDOFProgram->SetValue1f(i ++, min(mCamera->GetFar(), mMaxDistance) - mCamera->GetNear());
+	sCgDOFProgram->SetValue1f(i ++, zFocus);
 
 	DrawQuad(sCgDOFProgram);
@@ -1442,4 +1449,10 @@
 
 
+void DeferredRenderer::SetMaxDistance(float maxDist) 
+{
+	mMaxDistance = maxDist;
+}
+
+
 void DeferredRenderer::SetSaveFrame(const string &suffix, int frameNumber)
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter.vcproj	(revision 3220)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VboFormatConverter.vcproj	(revision 3235)
@@ -98,6 +98,6 @@
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)$\VboFormatConverter\(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)\VboFormatConverter"
+			OutputDirectory="$(SolutionDir)$\$(ProjectName)\(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)\$(ProjectName)"
 			ConfigurationType="1"
 			CharacterSet="1"
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj	(revision 3107)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/Converter.vcproj	(revision 3235)
@@ -98,6 +98,6 @@
 		<Configuration
 			Name="Release|Win32"
-			OutputDirectory="$(SolutionDir)\Converter\$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)\Converter"
+			OutputDirectory="$(SolutionDir)\$(ProjectName)\$(ConfigurationName)"
+			IntermediateDirectory="$(ConfigurationName)\$(ProjectName)"
 			ConfigurationType="1"
 			CharacterSet="1"
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 3235)
@@ -0,0 +1,131 @@
+#ifndef _VISIBILITYSOLUTIONCONVERTER_H
+#define _VISIBILITYSOLUTIONCONVERTER_H
+
+
+#include "SimpleVec.h"
+#include <string>
+#include <vector>
+
+
+
+typedef std::vector<SimpleVec> VertexArray;
+typedef std::pair<float, float> TexCoord;
+
+class ogzstream;
+
+
+struct BvhNode
+{
+	int id;
+	char axis;
+	unsigned char depth;
+	short flags;
+
+	// indices to first and last triangle in the triangle array
+	// assumes the traingle are placed in continuous chunk of memory
+	// however this need not be a global array!
+	int first;
+	// one after the last triangle!
+	int last;
+
+	BvhNode(): axis(-1), first(-1), flags(0) {}
+
+	bool IsLeaf() { return axis == -1; }
+	bool Empty() const { return first == -1; }
+	int Count() const { return last - first + 1; }
+
+	std::vector<int> mTriangleIds;
+};
+
+
+struct BvhInterior: public BvhNode
+{
+	BvhInterior():back(NULL), front(NULL) { }
+	BvhNode *back;
+	BvhNode *front;
+};
+
+
+struct BvhLeaf: public BvhNode
+{
+	//Color color;
+	int texture;
+
+	BvhLeaf(): BvhNode(), texture(0) {}
+};
+
+
+/** Converts obj format into objects readable by our format
+*/
+class VisibilitySolutionConverter
+{
+public:
+
+	VisibilitySolutionConverter();
+
+	~VisibilitySolutionConverter();
+
+	bool Convert(const std::string &sceneInputFilename,
+				 const std::string &sceneOutputFilename,
+				 const std::string &bvhInputFilename,
+		         const std::string &bvhOutputFilename);
+	
+
+
+protected:
+
+	struct Geometry
+	{
+		SimpleVec *mVertices;
+		SimpleVec *mNormals;
+		TexCoord *mTexCoords;
+
+		int mVertexCount;
+		int mTexcoordCount;
+	};
+
+	void LoadShape(const VertexArray &vertices,
+		           const VertexArray &normals,
+				   const std::vector<TexCoord> &texCoords);
+
+	void WriteGeometry(ogzstream &str, Geometry *geom);
+
+	bool ReadScene(const std::string &iFilename);
+
+	bool WriteScene(const std::string &oFilename);
+
+	bool ReadBvh(FILE *fr);
+
+	bool WriteBvh(const std::string &oFilename);
+
+	void ConstructBvhObjects(const VertexArray &vertices,
+		                     const VertexArray &normals,
+							 const std::vector<TexCoord> &texCoords);
+
+	bool LoadSolution(const std::string &filename);
+
+
+	BvhNode *LoadNode(FILE *fr, int depth);
+
+	bool ReadDummyTree(FILE *fr);
+
+
+
+	//////////////////////////////////
+
+	std::vector<Geometry *> mGeometry;
+
+	int mNumShapes;
+
+	std::vector<int> mGlobalTriangleIds;
+
+	std::vector<BvhNode *> mBvhNodes;
+
+	BvhNode *mRoot;
+
+	int mNumNodes;
+};
+
+
+
+#endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp	(revision 3234)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/main.cpp	(revision 3235)
@@ -1,3 +1,3 @@
-#include "ObjConverter.h"
+#include "VisibilitySolutionConverter.h"
 #include <iostream>
 #include <time.h>
@@ -11,9 +11,9 @@
 	int returnCode = 0;
 
-	ObjConverter converter;
+	VisibilitySolutionConverter converter;
 
 	cout << "converting obj to dem format" << endl;
 
-	if (!converter.Convert(model_path + argv[1], model_path + argv[2]))
+	if (!converter.Convert(model_path + argv[1], model_path + argv[2], model_path + argv[3], model_path + argv[4]))
 	{
 		cerr << "conversion failed" << endl;
@@ -22,5 +22,6 @@
 		exit(0);
 	}
-	//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 3235)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3235)
@@ -0,0 +1,884 @@
+#include "VisibilitySolutionConverter.h"
+#include "SimpleTri.h"
+#include "SimpleVec.h"
+#include "gzstream.h"
+#include <iostream>
+
+
+using namespace std;
+
+// MAGIC of all bin exports
+#ifndef MAGIC 
+#define MAGIC 0x827923
+#endif
+
+#define BVH_VERSION 2.1
+
+
+static void LoadIndices(char *str, 
+						const VertexArray &vertices, 
+						const VertexArray &normals, 
+						const vector<pair<float, float> > &texCoords,
+						VertexArray &faceVertices,
+						VertexArray &faceNormals,
+						vector<TexCoord> &faceTexCoords
+						)
+{
+	vector<string> triples;
+
+	char *next_token;
+
+	// extract the triples of the form v/t/n v/t/n ...
+	char *pch = strtok_s(str + 1, " ", &next_token);
+
+	while (pch)
+	{
+		string s(pch);
+		//s += "\n",
+		triples.push_back(s);
+		
+		pch = strtok_s(NULL, " ", &next_token);	  
+	}
+
+	vector<int> indices;
+	vector<int> nIndices;
+	vector<int> tIndices;
+
+	char seps[] = " /\t\n";
+
+	for (size_t i = 0; i < triples.size(); ++ i)
+	{
+		static int dummy = 0;
+
+		size_t found;
+		found = triples[i].find_first_of(seps);
+		size_t prevfound = 0;
+		// vertex, normal, texture indices
+		string str = triples[i].substr(prevfound, found);
+
+		int index = (int)strtol(str.c_str(), NULL, 10) - 1;
+
+		int tIndex = index;
+		int nIndex = index;	
+		
+		prevfound = found;
+		found = triples[i].find_first_of(seps, found + 1);  
+
+		if (found != string::npos)
+		{
+			str = triples[i].substr(prevfound, found);
+
+			int idx = (int)strtol(str.c_str(), NULL, 10) - 1;
+			if (idx > 0) tIndex = idx;
+		}
+
+		if ((found + 1) < triples[i].size())
+		{
+			str = triples[i].substr(found + 1);
+
+			int idx = (int)strtol(str.c_str(), NULL, 10) - 1;
+			if (idx > 0) nIndex = idx;
+		}
+
+		// store indices
+		if (index >= 0)
+		{
+			indices.push_back(index);
+			nIndices.push_back(nIndex);
+			tIndices.push_back(tIndex);
+		}
+
+		// new triangle found
+		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]]);
+			faceVertices.push_back(vertices[indices[idx3]]);
+
+
+			if (!normals.empty())
+			{
+				faceNormals.push_back(normals[nIndices[idx1]]);
+				faceNormals.push_back(normals[nIndices[idx2]]);
+				faceNormals.push_back(normals[nIndices[idx3]]);
+			}
+			else
+			{
+				// no face normals? => create normals
+				const SimpleTri tri(vertices[indices[idx1]],
+					                vertices[indices[idx2]], 
+									vertices[indices[idx3]]);
+
+				const SimpleVec n = tri.GetNormal();
+
+				faceNormals.push_back(n);
+				faceNormals.push_back(n);
+				faceNormals.push_back(n);
+			}
+
+			if (!texCoords.empty())
+			{
+				faceTexCoords.push_back(texCoords[tIndices[idx1]]);
+				faceTexCoords.push_back(texCoords[tIndices[idx2]]);
+				faceTexCoords.push_back(texCoords[tIndices[idx3]]);
+			}
+		}
+	}
+}
+
+
+VisibilitySolutionConverter::VisibilitySolutionConverter()
+{}
+
+
+VisibilitySolutionConverter::~VisibilitySolutionConverter()
+{
+	for (size_t i = 0; i < mGeometry.size(); ++ i)
+	{
+		delete [] mGeometry[i]->mVertices;
+		delete [] mGeometry[i]->mNormals;
+		delete [] mGeometry[i]->mTexCoords;
+
+		delete mGeometry[i];
+	}
+	
+	mGeometry.clear();
+}
+
+
+void VisibilitySolutionConverter::LoadShape(const VertexArray &vertices,
+											const VertexArray &normals,
+											const vector<TexCoord> &texCoords)
+{
+	int numElements = (int)vertices.size();
+	Geometry *geom = new Geometry();
+
+	// convert the triangles to geometry
+	geom->mVertices = new SimpleVec[numElements];
+	geom->mNormals = new SimpleVec[numElements];
+	geom->mTexCoords = new TexCoord[numElements];
+
+	geom->mVertexCount = numElements;
+	geom->mTexcoordCount = (int)texCoords.size();
+
+	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;
+		geom->mVertices[i].y = -vertices[i].z;
+		geom->mVertices[i].z =  vertices[i].y;
+	
+		geom->mNormals[i].x =  normals[i].x;
+		geom->mNormals[i].y = -normals[i].z;
+		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)
+		{
+			geom->mTexCoords[i].first = texCoords[i].first;
+			geom->mTexCoords[i].second = texCoords[i].second;
+		}
+	}
+
+	mGeometry.push_back(geom);
+}
+
+
+bool VisibilitySolutionConverter::Convert(const std::string &sceneInputFilename,
+										  const std::string &sceneOutputFilename,
+										  const std::string &bvhInputFilename,
+										  const std::string &bvhOutputFilename)
+{
+	mNumShapes = 0;
+	
+	// delete previous geometry
+	for (size_t i = 0; i < mGeometry.size(); ++ i)
+	{
+		delete [] mGeometry[i]->mVertices;
+		delete [] mGeometry[i]->mNormals;
+		delete [] mGeometry[i]->mTexCoords;
+
+		delete mGeometry[i];
+	}
+	
+	mGeometry.clear();
+
+	if (!LoadSolution(bvhInputFilename))
+	{
+		cerr << "could not read file" << endl;
+		return false;
+	}
+
+	if (!ReadScene(sceneInputFilename))
+	{
+		cerr << "could not read file" << endl;
+		return false;
+	}
+
+	if (!WriteScene(sceneOutputFilename))
+	{
+		cerr << "could not write file" << endl;
+		return false;
+	}
+
+	/*if (!WriteBvh(bvhOutputFilename))
+	{
+		cerr << "could not write file" << endl;
+		return false;
+	}*/
+
+	return true;
+}
+
+
+bool VisibilitySolutionConverter::ReadScene(const string &filename) 
+{
+	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;
+
+	vector<int> indices;
+
+	int line = 0;
+	const int len = 10000;
+	char str[len];
+
+	while (fgets(str, len, file) != NULL)
+	{
+		if (line % 1000000 == 0)
+			cout << line << " " << str << endl;
+
+		++ line;
+
+		switch (str[0])
+		{
+		case 'v': // vertex or normal
+			{
+				float x, y, z;
+
+				if (vertices.size() >= 1000000 * 3) continue;
+
+				switch (str[1]) 
+				{
+				case 'n' :
+					sscanf(str + 2, "%f %f %f", &x, &y, &z);
+					normals.push_back(SimpleVec(x, y, z));
+					break;
+				case 't':
+					sscanf(str + 2, "%f %f", &x, &y);
+					texcoords.push_back(pair<float, float>(x, y));
+					break;
+				default:
+					sscanf(str + 1, "%f %f %f", &x, &y, &z);
+					//const float scale = 5e-3f;
+					const float scale = 0.1f;
+					vertices.push_back(SimpleVec(x * scale, y * scale, z * scale));
+					//cout <<"v " << x << " " << y << " "<< z << " ";
+				}
+				break;
+			}
+		case 'f': 
+			{
+				//////////
+				//-- indices in the current line
+
+				if (faceVertices.size() >= 1000000 * 3) continue;
+
+				LoadIndices(str, 
+					        vertices, normals, texcoords, 
+					        faceVertices, faceNormals, faceTexcoords);
+
+				break;
+			}  
+			break;
+		default:
+			// throw away line
+			break;
+		}
+	}
+
+	if (!faceVertices.empty())
+	{
+		++ mNumShapes;
+
+		ConstructBvhObjects(faceVertices, faceNormals, faceTexcoords);
+
+		faceVertices.clear();
+		faceNormals.clear();
+		faceTexcoords.clear();
+	}
+
+	fclose(file);
+	
+	return true;
+}
+
+
+static inline float RandomColor(float x)
+{
+	return x + (1.0f - x) * (float)rand() / RAND_MAX; 
+}
+
+
+void VisibilitySolutionConverter::WriteGeometry(ogzstream &str, Geometry *geom)
+{
+	int vertexCount = geom->mVertexCount;
+	str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int));
+  
+	str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(SimpleVec) * vertexCount);
+	str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(SimpleVec) * vertexCount);
+
+	int texCoordCount = geom->mTexcoordCount;
+	str.write(reinterpret_cast<char *>(&texCoordCount), sizeof(int));
+
+	if (texCoordCount)
+	{
+		str.write(reinterpret_cast<char *>(geom->mTexCoords), sizeof(float) * texCoordCount * 2);
+	}
+
+	///////
+	//-- texture
+
+#ifdef USE_TEXTURE
+	int texId = 0;
+#else
+	int texId = -1;
+#endif
+
+	str.write(reinterpret_cast<char *>(&texId), sizeof(int));
+
+	bool alphaTestEnabled = false;
+	//bool cullFaceEnabled = false;
+	bool cullFaceEnabled = true;
+
+	str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
+	str.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
+
+	// material
+	bool hasMaterial = true;
+	//bool hasMaterial = false;
+	str.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
+	
+	if (hasMaterial)
+	{
+		SimpleVec ambient, diffuse, spec, emm;
+
+		ambient.x = ambient.y = ambient.z = 0.2f;
+		//diffuse.x = diffuse.y = diffuse.z = 1.0f;
+
+		diffuse.x = RandomColor(0.5f); 
+		diffuse.y = RandomColor(0.5f);
+		diffuse.z = RandomColor(0.5f);
+
+		spec.x    = spec.y    = spec.z    =  .0f;
+		emm = spec;
+
+		// only write rgb part of the material
+		str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec));
+		str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec));
+		str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec));
+		str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec));
+	}
+}
+
+
+bool VisibilitySolutionConverter::WriteScene(const string &filename)
+{
+	ogzstream ofile(filename.c_str());
+
+	if (!ofile.is_open())
+		return false;
+	
+
+	/////////
+	//-- write textures
+
+#ifdef USE_TEXTURE
+	int textureCount = 1;
+#else
+	int textureCount = 0;
+#endif
+	ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int));
+
+	if (textureCount > 0)
+	{
+		// hack
+		const string texName("wood.jpg");
+
+		int texnameSize = (int)texName.length() + 1;
+		ofile.write(reinterpret_cast<char *>(&texnameSize), sizeof(int));
+
+		ofile.write(texName.c_str(), sizeof(char) * texnameSize);
+
+		int boundS = 1, boundT = 1;
+
+		ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int));
+		ofile.write(reinterpret_cast<char *>(&boundT), sizeof(int));
+	}
+
+
+	///////////
+	//-- write shapes
+
+	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+
+	vector<Geometry *>::const_iterator it, it_end = mGeometry.end();
+
+	for (it = mGeometry.begin(); it != it_end; ++ it)
+	{
+		WriteGeometry(ofile, *it);
+	}
+
+
+	int entityCount = 1;
+	ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int));
+
+
+	//////////
+	//-- write single scene entity
+
+	// no transformation
+	bool hasTrafo = false;
+	ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool));
+
+	// a dummy lod
+	int numLODs = 1;
+	ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int));
+
+	float dist = 0;
+	ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
+
+	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+
+	// all shapes belong to this scene entity
+	for (int i = 0; i < mNumShapes; ++ i)
+	{
+		int shapeId = i;
+		ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int));
+	}
+
+	return true;
+}
+
+
+void VisibilitySolutionConverter::ConstructBvhObjects(const VertexArray &vertices,
+													  const VertexArray &normals,
+													  const vector<TexCoord> &texCoords)
+{
+	cout << "vtx: " << vertices.size() << endl;
+/*	BvhNode n;
+	
+	mGlobalTriangleIds.clear();
+	for (size_t i = 0; i < vertices.size() / 3; ++ i)
+	{
+		mGlobalTriangleIds.push_back((int)i);
+	}
+
+	for (size_t i = 0; i < vertices.size() / 3; ++ i)
+		n.mTriangleIds.push_back((int)i);
+
+	mBvhNodes.push_back(n);
+*/
+	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)
+		{
+			const int idx = 3 * mGlobalTriangleIds[j];
+
+			//cout << "idx: " << idx << " ";
+
+			if (idx < 1000000 * 3)
+			{
+				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]);
+				}
+			}
+		}
+
+		LoadShape(_vertices, _normals, _texCoords);
+	}
+}
+
+
+bool VisibilitySolutionConverter::WriteBvh(const string &filename)
+{
+	ogzstream ofile(filename.c_str());
+
+	if (!ofile.is_open())
+		return false;
+	
+
+	/////////
+	//-- write textures
+
+#ifdef USE_TEXTURE
+	int textureCount = 1;
+#else
+	int textureCount = 0;
+#endif
+	ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int));
+
+	if (textureCount > 0)
+	{
+		// hack
+		const string texName("wood.jpg");
+
+		int texnameSize = (int)texName.length() + 1;
+		ofile.write(reinterpret_cast<char *>(&texnameSize), sizeof(int));
+
+		ofile.write(texName.c_str(), sizeof(char) * texnameSize);
+
+		int boundS = 1, boundT = 1;
+
+		ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int));
+		ofile.write(reinterpret_cast<char *>(&boundT), sizeof(int));
+	}
+
+
+	///////////
+	//-- write shapes
+
+	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+
+	vector<Geometry *>::const_iterator it, it_end = mGeometry.end();
+
+	for (it = mGeometry.begin(); it != it_end; ++ it)
+	{
+		WriteGeometry(ofile, *it);
+	}
+
+
+	int entityCount = 1;
+	ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int));
+
+
+	//////////
+	//-- write single scene entity
+
+	// no transformation
+	bool hasTrafo = false;
+	ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool));
+
+	// a dummy lod
+	int numLODs = 1;
+	ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int));
+
+	float dist = 0;
+	ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
+
+	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
+
+	// all shapes belong to this scene entity
+	for (int i = 0; i < mNumShapes; ++ i)
+	{
+		int shapeId = i;
+		ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int));
+	}
+
+	return true;
+}
+
+
+bool VisibilitySolutionConverter::ReadBvh(FILE *fr) 
+{
+	int buffer[6]; 
+	fread(buffer, sizeof(int), 6, fr);
+
+	if (buffer[0] != MAGIC) 
+	{
+		cerr << "Error: Wrong file type" << endl;
+		return false;
+	}
+
+	if (buffer[1] != (int)(1000 * BVH_VERSION)) 
+	{
+		cerr << "Error: Wrong BVH version" << endl;
+		return false;
+	}
+
+	// load triangle ids
+	size_t numTriangles = buffer[2];
+
+	for (size_t i = 0; i < numTriangles; ++i) 
+	{
+		int id;
+		fread(&id, sizeof(int), 1, fr);
+		mGlobalTriangleIds[i] = id;
+		//triangles[i] = scene->triangles[id];
+	}
+
+	//if (mRoot) delete mRoot;
+
+	mNumNodes = 0; // this was set to 1 in constructor!
+
+	mRoot = LoadNode(fr, 0);
+
+	if (mNumNodes != buffer[5]) 
+	{
+		cerr << "Warning: Loaded " << mNumNodes <<
+			    " bvh nodes instead of " << buffer[5] << endl;
+	}
+
+	fclose(fr);
+	
+	return true;
+}
+
+
+BvhNode *VisibilitySolutionConverter::LoadNode(FILE *fr, int depth)
+{
+	++ mNumNodes;
+	
+	int buffer[4];
+	fread(buffer, sizeof(int), 4, fr);
+
+	if (buffer[2] != -1) 
+	{
+		BvhInterior *interior = new BvhInterior();
+		
+		interior->first = buffer[0];
+		interior->last  = buffer[1];
+		interior->axis  = buffer[2];
+		interior->id    = buffer[3];
+		interior->depth = depth;
+
+		BvhNode *front, *back;
+
+		front = LoadNode(fr, depth + 1);
+		back  = LoadNode(fr, depth + 1);
+
+		// front->parent = (BvhNode *)interior;
+		// back->parent = (BvhNode *)interior;
+		interior->front = front;
+		interior->back = back;
+
+		//interior->box = Union(front->box, back->box);
+	
+		return (BvhNode *)interior;
+	}
+	else 
+	{
+		// leaf
+		//Debug << "Info: Loading leaf (id: " << numberOfNodes << ", depth: " << depth << ")" << endl;
+		BvhLeaf *leaf = new BvhLeaf();
+		leaf->first = buffer[0];
+		leaf->last  = buffer[1];
+		leaf->axis  = buffer[2];
+		leaf->id  = buffer[3];
+
+		leaf->depth = depth;
+		//UpdateLeafBox(leaf);
+
+		mBvhNodes.push_back(leaf);
+		// leaf->id = numberOfNodes;
+		return (BvhNode *)leaf;
+	}
+}
+
+
+bool VisibilitySolutionConverter::ReadDummyTree(FILE *fr)
+{
+	int buffer[256]; 
+	fread(buffer, sizeof(int), 3, fr);
+
+	// read dummy bounding box
+	float dummy[6];
+	fread(dummy, sizeof(float) * 6, 1, fr);
+
+	int stack = 1;
+
+	// read dummy tree
+	while (stack)
+	{
+		int axis;
+		fread(&axis, sizeof(int), 1, fr);
+		-- stack;
+
+		if (axis != - 1) 
+		{
+			float dummy;
+			fread(&dummy, sizeof(float), 1, fr);
+			
+			stack += 2;
+		}
+	}
+  
+	return true;
+}
+
+
+
+bool VisibilitySolutionConverter::LoadSolution(const string &filename)
+{
+	FILE *fr = fopen(filename.c_str(), "rb");
+
+	cerr << "Info: Loading visibility solution from file '" + filename + "'" << endl;
+  
+	if (fr == NULL) 
+	{
+		cerr << "Error: Cannot open file for reading" << endl;
+		return false;
+	}
+
+	float totalSamples, totalTime;
+
+	fread(&totalSamples, sizeof(float), 1, fr);
+	fread(&totalTime, sizeof(float), 1, fr);
+
+	//viewCellsTree = new ViewCellsTree;
+	//bool ok = viewCellsTree->_LoadFromFile(fr);
+
+	bool ok = ReadDummyTree(fr);
+
+	if (ok) 
+	{
+		//AllocateLeafViewCells();
+		
+		//objectsTree = new Bvh(*scene);
+		//ok = objectsTree->_LoadFromFile(fr);
+		ok = ReadBvh(fr);
+
+		/*if (ok) 
+		{ 
+		    AllocatePvsObjects();
+			ok = LoadPvs(fr);
+		}
+		*/
+	}
+
+	fclose(fr);
+	
+	if (ok) 
+		cout << "Info: visibility solution loaded" << endl;
+	else
+		cout << "Info: loading visibility solution failed" << endl;
+  
+	return true;
+}
+
+
+#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);
+		
+		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);
+		}
+	}
+	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);
+		}
+	}
+  
+	return true;
+}
+#endif
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/ObjConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/ObjConverter.cpp	(revision 3234)
+++ 	(revision )
@@ -1,483 +1,0 @@
-#include "ObjConverter.h"
-#include "SimpleTri.h"
-#include "SimpleVec.h"
-#include "gzstream.h"
-#include <iostream>
-
-
-using namespace std;
-
-//#define USE_TEXTURE
-
-
-static void LoadIndices(char *str, 
-						const VertexArray &vertices, 
-						const VertexArray &normals, 
-						const vector<pair<float, float> > &texcoords,
-						VertexArray &faceVertices,
-						VertexArray &faceNormals,
-						vector<Texcoord> &faceTexcoords
-						)
-{
-	vector<string> triples;
-
-	char *next_token;
-
-	// extract the triples of the form v/t/n v/t/n ...
-	char *pch = strtok_s(str + 1, " ", &next_token);
-
-	while (pch)
-	{
-		string s(pch);
-		//s += "\n",
-		triples.push_back(s);
-		
-		pch = strtok_s(NULL, " ", &next_token);	  
-	}
-
-	vector<int> indices;
-	vector<int> nIndices;
-	vector<int> tIndices;
-
-	char seps[] = " /\t\n";
-
-	for (size_t i = 0; i < triples.size(); ++ i)
-	{
-		static int dummy = 0;
-
-		size_t found;
-		found = triples[i].find_first_of(seps);
-		size_t prevfound = 0;
-		// vertex, normal, texture indices
-		string str = triples[i].substr(prevfound, found);
-
-		int index = (int)strtol(str.c_str(), NULL, 10) - 1;
-
-		int tIndex = index;
-		int nIndex = index;	
-		
-		prevfound = found;
-		found = triples[i].find_first_of(seps, found + 1);  
-
-		if (found != string::npos)
-		{
-			str = triples[i].substr(prevfound, found);
-
-			int idx = (int)strtol(str.c_str(), NULL, 10) - 1;
-			if (idx > 0) tIndex = idx;
-		}
-
-		if ((found + 1) < triples[i].size())
-		{
-			str = triples[i].substr(found + 1);
-
-			int idx = (int)strtol(str.c_str(), NULL, 10) - 1;
-			if (idx > 0) nIndex = idx;
-		}
-
-		// store indices
-		if (index >= 0)
-		{
-			indices.push_back(index);
-			nIndices.push_back(nIndex);
-			tIndices.push_back(tIndex);
-		}
-
-		// new triangle found
-		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]]);
-			faceVertices.push_back(vertices[indices[idx3]]);
-
-
-			if (!normals.empty())
-			{
-				//if (dummy < 3) cout << nIndices[idx1] << " " << nIndices[idx2] << " " << nIndices[idx3] << endl;
-				faceNormals.push_back(normals[nIndices[idx1]]);
-				faceNormals.push_back(normals[nIndices[idx2]]);
-				faceNormals.push_back(normals[nIndices[idx3]]);
-			}
-			else
-			{
-				// no face normals? => create normals
-				const SimpleTri tri(vertices[indices[idx1]],
-					                vertices[indices[idx2]], 
-									vertices[indices[idx3]]);
-				const SimpleVec n = tri.GetNormal();
-
-				faceNormals.push_back(n);
-				faceNormals.push_back(n);
-				faceNormals.push_back(n);
-			}
-
-			++ dummy;
-			if (!texcoords.empty())
-			{
-				faceTexcoords.push_back(texcoords[tIndices[idx1]]);
-				faceTexcoords.push_back(texcoords[tIndices[idx2]]);
-				faceTexcoords.push_back(texcoords[tIndices[idx3]]);
-			}
-		}
-	}
-}
-
-
-ObjConverter::ObjConverter()
-{}
-
-
-ObjConverter::~ObjConverter()
-{
-	for (size_t i = 0; i < mGeometry.size(); ++ i)
-	{
-		delete [] mGeometry[i]->mVertices;
-		delete [] mGeometry[i]->mNormals;
-		delete [] mGeometry[i]->mTexcoords;
-
-		delete mGeometry[i];
-	}
-	
-	mGeometry.clear();
-}
-
-
-void ObjConverter::LoadShape(const VertexArray &faceVertices,
-							 const VertexArray &faceNormals,
-							 const vector<Texcoord> &faceTexcoords)
-{
-	int numElements = (int)faceVertices.size();
-	Geometry *geom = new Geometry();
-
-	// convert the triangles to geometry
-	geom->mVertices = new SimpleVec[numElements];
-	geom->mNormals = new SimpleVec[numElements];
-	geom->mTexcoords = new Texcoord[numElements];
-
-	geom->mVertexCount = numElements;
-	geom->mTexcoordCount = (int)faceTexcoords.size();
-
-	cout << "number of vertices=" << numElements << endl;
-
-	for (int i = 0; i < numElements; ++ i)
-	{
-#if 0
-		// convert to our camera system: change y and z
-		geom->mVertices[i].x = faceVertices[i].x;
-		geom->mVertices[i].y = -faceVertices[i].z;
-		geom->mVertices[i].z = faceVertices[i].y;
-	
-		geom->mNormals[i].x = faceNormals[i].x;
-		geom->mNormals[i].y = -faceNormals[i].z;
-		geom->mNormals[i].z = faceNormals[i].y;
-
-#else
-		geom->mVertices[i].x = faceVertices[i].x;
-		geom->mVertices[i].y = faceVertices[i].y;
-		geom->mVertices[i].z = faceVertices[i].z;
-	
-		geom->mNormals[i].x = faceNormals[i].x;
-		geom->mNormals[i].y = faceNormals[i].y;
-		geom->mNormals[i].z = faceNormals[i].z;
-
-#endif
-
-		if (i < geom->mTexcoordCount)
-		{
-			geom->mTexcoords[i].first = faceTexcoords[i].first;
-			geom->mTexcoords[i].second = faceTexcoords[i].second;
-		}
-	}
-
-	mGeometry.push_back(geom);
-}
-
-
-bool ObjConverter::Convert(const string &filename, const std::string &outputFilename)
-{
-	mNumShapes = 0;
-	
-	for (size_t i = 0; i < mGeometry.size(); ++ i)
-	{
-		delete [] mGeometry[i]->mVertices;
-		delete [] mGeometry[i]->mNormals;
-		delete [] mGeometry[i]->mTexcoords;
-
-		delete mGeometry[i];
-	}
-	
-	mGeometry.clear();
-
-	if (!ReadFile(filename))
-	{
-		cerr << "could not read file" << endl;
-		return false;
-	}
-
-	if (!WriteFile(outputFilename))
-	{
-		cerr << "could not write file" << endl;
-		return false;
-	}
-
-
-	return true;
-}
-
-
-bool ObjConverter::ReadFile(const string &filename) 
-{
-	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;
-
-	vector<int> indices;
-
-	int line = 0;
-	const int len = 10000;
-	char str[len];
-
-	while (fgets(str, len, file) != NULL)
-	{
-		switch (str[0])
-		{
-		case 'v': // vertex or normal
-			{
-				float x, y, z;
-
-				switch (str[1]) 
-				{
-				case 'n' :
-					sscanf(str + 2, "%f %f %f", &x, &y, &z);
-					normals.push_back(SimpleVec(x, y, z));
-					break;
-				case 't':
-					sscanf(str + 2, "%f %f", &x, &y);
-					texcoords.push_back(pair<float, float>(x, y));
-					break;
-				default:
-					sscanf(str + 1, "%f %f %f", &x, &y, &z);
-					//const float scale = 5e-3f;
-					const float scale = 1.0f;
-					vertices.push_back(SimpleVec(x * scale, y * scale, z* scale));
-					//cout <<"v " << x << " " << y << " "<< z << " ";
-				}
-				break;
-			}
-		case 'f': 
-			{
-				//////////
-				//-- indices in the current line
-
-				LoadIndices(str, 
-					        vertices, normals, texcoords, 
-					        faceVertices, faceNormals, faceTexcoords);
-
-				if (0 &&
-					(((line % 1000) == 999) && !faceVertices.empty()))
-				{
-					++ mNumShapes;
-
-					LoadShape(faceVertices, faceNormals, faceTexcoords);
-
-					faceVertices.clear();
-					faceNormals.clear();
-					faceTexcoords.clear();
-				}
-
-				break;
-			}   // end face
-		case 'g': // load a new shape
-			{/*
-				if (!faceVertices.empty())
-				{
-					++ mNumShapes;
-
-					LoadShape(faceVertices, faceNormals, faceTexcoords);
-
-					faceVertices.clear();
-					faceNormals.clear();
-					faceTexcoords.clear();
-				}*/
-			}
-			break;
-		default:
-			// throw away line
-			break;
-		}
-
-		++ line;
-	}
-
-	if (!faceVertices.empty())
-	{
-		++ mNumShapes;
-
-		LoadShape(faceVertices, faceNormals, faceTexcoords);
-
-		faceVertices.clear();
-		faceNormals.clear();
-		faceTexcoords.clear();
-	}
-
-	fclose(file);
-	
-	return true;
-}
-
-
-void ObjConverter::WriteGeometry(ogzstream &str, Geometry *geom)
-{
-	int vertexCount = geom->mVertexCount;
-	str.write(reinterpret_cast<char *>(&vertexCount), sizeof(int));
-  
-	str.write(reinterpret_cast<char *>(geom->mVertices), sizeof(SimpleVec) * vertexCount);
-	str.write(reinterpret_cast<char *>(geom->mNormals), sizeof(SimpleVec) * vertexCount);
-
-	int texCoordCount = geom->mTexcoordCount;
-	str.write(reinterpret_cast<char *>(&texCoordCount), sizeof(int));
-
-	if (texCoordCount)
-		str.write(reinterpret_cast<char *>(geom->mTexcoords), sizeof(float) * texCoordCount * 2);
-	
-
-	///////
-	//-- texture
-
-#ifdef USE_TEXTURE
-	int texId = 0;
-#else
-	int texId = -1;
-#endif
-
-	str.write(reinterpret_cast<char *>(&texId), sizeof(int));
-
-	bool alphaTestEnabled = false;
-	//bool cullFaceEnabled = false;
-	bool cullFaceEnabled = true;
-
-	str.write(reinterpret_cast<char *>(&alphaTestEnabled), sizeof(bool));
-	str.write(reinterpret_cast<char *>(&cullFaceEnabled), sizeof(bool));
-
-	// material
-	bool hasMaterial = true;
-	//bool hasMaterial = false;
-	str.write(reinterpret_cast<char *>(&hasMaterial), sizeof(bool));
-	
-	if (hasMaterial)
-	{
-		SimpleVec ambient, diffuse, spec, emm;
-
-		ambient.x = ambient.y = ambient.z = 0.2f;
-		//diffuse.x = diffuse.y = diffuse.z = 1.0f;
-		diffuse.x = 0.7f; diffuse.y = 0.5f; diffuse.z = 0.2f;
-		spec.x    = spec.y    = spec.z    =  .0f;
-		emm = spec;
-
-		// only write rgb part of the material
-		str.write(reinterpret_cast<char *>(&ambient), sizeof(SimpleVec));
-		str.write(reinterpret_cast<char *>(&diffuse), sizeof(SimpleVec));
-		str.write(reinterpret_cast<char *>(&spec), sizeof(SimpleVec));
-		str.write(reinterpret_cast<char *>(&emm), sizeof(SimpleVec));
-	}
-}
-
-
-bool ObjConverter::WriteFile(const string &filename)
-{
-	ogzstream ofile(filename.c_str());
-
-	if (!ofile.is_open())
-		return false;
-	
-
-	/////////
-	//-- write textures
-
-#ifdef USE_TEXTURE
-	int textureCount = 1;
-#else
-	int textureCount = 0;
-#endif
-	ofile.write(reinterpret_cast<char *>(&textureCount), sizeof(int));
-
-	if (textureCount > 0)
-	{
-		// hack
-		const string texName("wood.jpg");
-
-		int texnameSize = (int)texName.length() + 1;
-		ofile.write(reinterpret_cast<char *>(&texnameSize), sizeof(int));
-
-		ofile.write(texName.c_str(), sizeof(char) * texnameSize);
-
-		int boundS = 1, boundT = 1;
-
-		ofile.write(reinterpret_cast<char *>(&boundS), sizeof(int));
-		ofile.write(reinterpret_cast<char *>(&boundT), sizeof(int));
-	}
-
-
-	///////////
-	//-- write shapes
-
-	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
-
-	vector<Geometry *>::const_iterator it, it_end = mGeometry.end();
-
-	for (it = mGeometry.begin(); it != it_end; ++ it)
-	{
-		WriteGeometry(ofile, *it);
-	}
-
-
-	int entityCount = 1;
-	ofile.write(reinterpret_cast<char *>(&entityCount), sizeof(int));
-
-
-	//////////
-	//-- write single scene entity
-
-	// no transformation
-	bool hasTrafo = false;
-	ofile.write(reinterpret_cast<char *>(&hasTrafo), sizeof(bool));
-
-	// a dummy lod
-	int numLODs = 1;
-	ofile.write(reinterpret_cast<char *>(&numLODs), sizeof(int));
-
-	float dist = 0;
-	ofile.write(reinterpret_cast<char *>(&dist), sizeof(float));
-
-	ofile.write(reinterpret_cast<char *>(&mNumShapes), sizeof(int));
-
-	// all shapes belong to this scene entity
-	for (int i = 0; i < mNumShapes; ++ i)
-	{
-		int shapeId = i;
-		ofile.write(reinterpret_cast<char *>(&shapeId), sizeof(int));
-	}
-
-	return true;
-}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/ObjConverter.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/ObjConverter.h	(revision 3234)
+++ 	(revision )
@@ -1,64 +1,0 @@
-#ifndef _OBJCONVERTER_H
-#define _OBJCONVERTER_H
-
-#include "SimpleVec.h"
-#include <string>
-#include <vector>
-
-/*struct SimpleVec
-{
-	SimpleVec() {}
-	SimpleVec(float _x, float _y, float _z): x(_x), y(_y), z(_z) {}
-
-	float x, y, z;
-};*/
-
-typedef std::vector<SimpleVec> VertexArray;
-typedef std::pair<float, float> Texcoord;
-
-class ogzstream;
-
-/** Converts obj format into objects readable by our format
-*/
-class ObjConverter
-{
-public:
-
-	ObjConverter();
-
-	bool Convert(const std::string &inputFilename, 
-		         const std::string &outputFilename);
-	// const std::string textureFilename) const;
-
-	~ObjConverter();
-
-protected:
-
-	struct Geometry
-	{
-		SimpleVec *mVertices;
-		SimpleVec *mNormals;
-		Texcoord *mTexcoords;
-
-		int mVertexCount;
-		int mTexcoordCount;
-	};
-
-	void LoadShape(const VertexArray &faceVertices,
-		           const VertexArray &faceNormals,
-				   const std::vector<Texcoord> &faceTexcoords);
-
-	void WriteGeometry(ogzstream &str, Geometry *geom);
-
-	bool ReadFile(const std::string &inputFilename);
-	bool WriteFile(const std::string &outputFilename);
-
-
-	std::vector<Geometry *> mGeometry;
-
-	int mNumShapes;
-};
-
-
-
-#endif
