Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp	(revision 3243)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.cpp	(revision 3244)
@@ -24,4 +24,5 @@
 	while (!node->IsLeaf()) 
 	{
+		//cout << "pt: " << point[node->mAxis] << " " << node->mPosition << endl;
 		if (point[node->mAxis] < node->mPosition)
 			node = node->mBack;
@@ -29,4 +30,6 @@
 			node = node->mFront;
 	}
+
+	//cout << "vc: " << node->mViewCell->GetBox() << " pvs " << node->mViewCell->mPvs.Size() << endl;
 
 	return node->mViewCell;
@@ -36,5 +39,5 @@
 bool ViewCellsTree::LoadFromFile(const std::string &filename)
 {
-	cout << "Info: Loading view cells from file '" + filename + "'";
+	cout << "Loading view cells from file '" + filename + "'";
 
 	FILE *fr = fopen(filename.c_str(), "rb");
@@ -48,5 +51,5 @@
 	bool result = _LoadFromFile(fr);
 
-	cout << "Info: done. " << endl;
+	cout << "finished loading view cells. " << endl;
 	fclose(fr);
 
@@ -58,5 +61,5 @@
 {
 	int buffer[256]; 
-	fread(buffer, sizeof(int), 3, fr);
+	fread(buffer, sizeof(int), 2, fr);
 
 	if (buffer[0] != MAGIC) 
@@ -75,7 +78,22 @@
 	fread(&mBox, sizeof(AxisAlignedBox3), 1, fr);
 
+	Vector3 v1(mBox.Min().x, -mBox.Min().z, mBox.Min().y);
+	Vector3 v2(mBox.Max().x, -mBox.Max().z, mBox.Max().y);
+	
+	Vector3 newMin = v1;
+	Vector3 newMax = v2;
+
+	Minimize(newMin, v2);
+	Maximize(newMax, v1);
+
+	mBox.SetMin(newMin);
+	mBox.SetMax(newMax);
+
 	stack<ViewCellsTreeNode **> nodeStack;
+	nodeStack.push(&mRoot);
 
-	nodeStack.push(&mRoot);
+	cout << "view cells bounds " << mBox << endl;
+
+	int numViewCells = 0;
 
 	while (!nodeStack.empty()) 
@@ -85,9 +103,25 @@
 		node = new ViewCellsTreeNode();
 
-		fread(&node->mAxis, sizeof(int), 1, fr);
+		++ numViewCells;
+
+		int axis;
+		fread(&axis, sizeof(int), 1, fr);
+
+		// exchange y and z axis like we have to do for the scene
+		if (axis == 2) axis = 1;
+		else if (axis == 1) axis = 2;
+
+		node->mAxis = axis;
+
+		if (node->mAxis > 2 || node->mAxis < -1) cout << "a " << node->mAxis << " ";
 
 		if (!node->IsLeaf())
 		{
-			fread(&node->mPosition, sizeof(float), 1, fr);
+			float pos;
+			fread(&pos, sizeof(float), 1, fr);
+
+			if (axis == 1) pos = -pos;
+			node->mPosition = pos;
+			
 			nodeStack.push(&node->mFront);
 			nodeStack.push(&node->mBack);
@@ -95,4 +129,5 @@
 	}
 
+	cout << "loaded " << numViewCells << " view cells" << endl;
 	return true;
 }
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3102)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderTraverser.cpp	(revision 3244)
@@ -55,4 +55,5 @@
 mRenderDynamicObjects(true)
 {
+	mStats.Reset();
 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3242)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3244)
@@ -72,5 +72,5 @@
 	if (!stream.is_open()) return NULL;
 
-	cout << "loading bvh" << endl;
+	cout << "\n*******************\nloading bvh ..." << endl;
 
 	Bvh *bvh = new Bvh(staticEntities, dynamicEntities, maxDepthForTestingChildren);
@@ -82,5 +82,5 @@
 	bvh->mNumNodes = 3;
 
-	cout << "*******************\nbox: " << root->mBox << " area: " << root->mArea << endl;
+	cout << "static bvh bb: " << root->mBox << endl;
 
 	tQueue.push(root);
@@ -111,4 +111,7 @@
 	}
 
+	cout << "... finished loading " << bvh->mNumNodes - 2 << " static bvh nodes" << endl;
+
+
 	///////////
 	//-- create dynamic part of the hierarchy
@@ -121,6 +124,5 @@
 	bvh->PostProcess();
 
-	cout << "... finished loading " << bvh->mNumNodes << " nodes" << endl;
-	cout << "scene box: " << bvh->mBox << endl;
+	cout << "bvh bb: " << bvh->mBox << endl;
 
 	return bvh;
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3243)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3244)
@@ -20,5 +20,5 @@
 	FILE *fr = fopen(filename.c_str(), "rb");
   
-	cout << "Info: Loading visibility solution from file '" + filename + "'" << endl;
+	cout << "Loading visibility solution from file '" + filename + "'" << endl;
   
 	if (fr == NULL) 
@@ -34,22 +34,44 @@
 	fread(&totalTime, sizeof(float), 1, fr);
 
+	cout << "loading view cells" << endl;
+
 	ViewCellsTree *viewCellsTree = new ViewCellsTree();
 
 	bool ok = viewCellsTree->_LoadFromFile(fr);
+
+	cout << "finished loading view cells" << endl;
+
   
 	if (ok) 
 	{
-		// skip bvh loading
+		// skip loading of bvh nodes
 		int buffer[6]; 
 		fread(buffer, sizeof(int), 6, fr);
 
-		const size_t numNodes = buffer[5];
-		
+		const int numNodes = buffer[5];
+		const int numTriangleIds = buffer[2];
+
+		// skip triangle ids
+		cout << "skipping " << numTriangleIds << " triangle ids" << endl;
+
+		int tid;
+		for (int i = 0; i < numTriangleIds; ++ i) 
+			fread(&tid, sizeof(int), 1, fr);
+	
+		cout << "skipping " << numNodes << " bvh nodes" << endl;
+
 		for (int i = 0; i < numNodes; ++ i)
 			fread(buffer, sizeof(int), 4, fr);
 
+
+		cout << "allocating view cells" << endl;
+
 		AllocateLeafViewCells(viewCellsTree);
 		
+		cout << "loading pvss" << endl;
+
 		ok = LoadPvs(fr, bvh);
+
+		cout << "finished loading pvss" << endl;
 	}
 
@@ -57,7 +79,7 @@
 
 	if (ok) 
-		cerr << "Info: visibility solution loaded" << endl;
+		cout << "Visibility solution loaded" << endl;
 	else
-		cerr << "Info: loading visibility solution failed." << endl;
+		cerr << "Error: loading visibility solution failed." << endl;
 
 	return viewCellsTree;
@@ -99,7 +121,7 @@
 	fread(&number, sizeof(int), 1, fw);
 
-	if (number == 0) 
-	{
-		cerr << "Info: Warning empty PVSs in visibility solution" << endl;
+	if (!number) 
+	{
+		cerr << "Warning: empty PVSs in visibility solution" << endl;
 		return true;
 	}
@@ -107,5 +129,5 @@
 	if (number != mViewCells.size()) 
 	{
-		cerr << "Info: Number of view cells does not match when loading PVSs!" << endl;
+		cerr << "Warning: Number of view cells (" << number << ", " << (int)mViewCells.size() << ") does not match when loading PVSs!" << endl;
 		return false;
 	}
@@ -160,5 +182,5 @@
 		if (node->IsLeaf()) 
 		{
-			if (node->mViewCell == NULL) 
+			if (!node->mViewCell) 
 			{
 				node->mViewCell = new ViewCell();
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3236)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp	(revision 3244)
@@ -1161,8 +1161,9 @@
 	mBox = mRoot->GetBox();
 
-	// compute and print stats
+	// compute and print stats for whole (static + dynamic) bvh
 	ComputeBvhStats(mRoot, mBvhStats);
 	PrintBvhStats(mBvhStats);
 
+	// also output dynamic stats
 	if (mDynamicGeometrySize)
 	{
@@ -1475,5 +1476,5 @@
 	l->mArea = l->mBox.SurfaceArea();
 	
-	cout << "updating dynamic branch " << l->mFirst << " " << l->mLast << endl;
+	cout << "creating dynamic bvh branch"  << endl;
 
 	if (mDynamicGeometrySize)
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3243)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3244)
@@ -139,4 +139,6 @@
 bool makeSnapShot = false;
 
+ViewCellsTree *viewCellsTree = NULL;
+
 
 /// the technique used for rendering
@@ -267,4 +269,5 @@
 int maxBatchSize = 50;
 int trianglesPerVirtualLeaf = INITIAL_TRIANGLES_PER_VIRTUAL_LEAVES;
+
 
 //////////////
@@ -349,4 +352,6 @@
 SceneQuery *GetOrCreateSceneQuery();
 
+void RenderPvs();
+
 
 // new view projection matrix of the camera
@@ -619,5 +624,5 @@
 	VisibilitySolutionLoader visLoader;
 
-	ViewCellsTree *viewCellsTree = visLoader.Load(vis_filename, bvh);
+	viewCellsTree = visLoader.Load(vis_filename, bvh);
 
 
@@ -1249,5 +1254,7 @@
 	{
 		// actually render the scene geometry using the specified algorithm
-		traverser->RenderScene();
+		//traverser->RenderScene();
+
+		RenderPvs();
 	}
 
@@ -1256,5 +1263,5 @@
 	//-- do the rest of the rendering
 	
-	// reset depth pass and render visible objects
+	// return from depth pass and render visible objects
 	if ((renderMethod == RENDER_DEPTH_PASS) ||
 		(renderMethod == RENDER_DEPTH_PASS_DEFERRED))
@@ -2035,4 +2042,5 @@
 	DEL_PTR(walkThroughPlayer);
 	DEL_PTR(statsWriter);
+	DEL_PTR(viewCellsTree);
 
 	ResourceManager::DelSingleton();
@@ -2508,2 +2516,14 @@
 	return sampleCount;
 }
+
+
+void RenderPvs()
+{
+	ViewCell *vc = viewCellsTree->GetViewCell(camera->GetPosition());
+
+	for (int i = 0; i < vc->mPvs.Size(); ++ i)
+	{
+		SceneEntity *ent = vc->mPvs.GetEntry(i);
+		ent->Render(&renderState);
+	}
+}
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h	(revision 3243)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ViewCellsTree.h	(revision 3244)
@@ -25,4 +25,5 @@
 	void SetBox(const AxisAlignedBox3 &box) { mBox = box; }
 
+	AxisAlignedBox3 GetBox() const { return mBox; }
 
 	// the pvs associated with the viewcell
@@ -42,8 +43,11 @@
 	ViewCellsTreeNode(): mAxis(-1), mViewCell(NULL) {}
 
-	bool IsLeaf() { return mViewCell != NULL; }
+	bool IsLeaf() { return mAxis == -1; }
 
 
 	///////////////////////
+
+	/// split mAxis 
+	int mAxis;
 
 	union 
@@ -58,7 +62,4 @@
 	ViewCellsTreeNode *mBack;
 	ViewCellsTreeNode *mFront;
-
-	/// split mAxis 
-	int mAxis;
 };
 
