Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3276)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Geometry.cpp	(revision 3282)
@@ -40,5 +40,5 @@
 	if (delData)
 	{
-		DEL_ARRAY_PTR(mVertices);
+		//DEL_ARRAY_PTR(mVertices);
 		DEL_ARRAY_PTR(mNormals);
 		DEL_ARRAY_PTR(mTexCoords);
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3269)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhLoader.cpp	(revision 3282)
@@ -140,6 +140,5 @@
 	Bvh *bvh = new Bvh(staticEntities, dynamicEntities, maxDepthForTestingChildren);
 
-	BvhConstructor bvhConstructor(bvh->mGeometry, 
-		                          0,
+	BvhConstructor bvhConstructor(bvh->mGeometry, 0,
 								  (int)bvh->mStaticGeometrySize - 1);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3281)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/VisibilitySolutionLoader.cpp	(revision 3282)
@@ -2,4 +2,5 @@
 #include "ViewCellsTree.h"
 #include "Bvh.h"
+#include "SceneEntity.h"
 #include <stack>
 
@@ -120,5 +121,5 @@
 	nodes.push_back(n);
 
-	if (!n->IsVirtualLeaf())
+	if (!n->IsLeaf() && !n->IsVirtualLeaf())
 	{
 		BvhInterior *interior = static_cast<BvhInterior *>(n);
@@ -157,15 +158,26 @@
 	ofstream outstream("test.log");
 
+	BvhNode *f = ((BvhInterior *)bvh->GetStaticRoot())->GetFront();
+	BvhNode *b = ((BvhInterior *)bvh->GetStaticRoot())->GetBack();
+
+	outstream << "front: " << f->GetFirstEntity() << " " << f->GetLastEntity() << endl;
+	outstream << "back: " << b->GetFirstEntity() << " " << b->GetLastEntity() << endl;
+
 	for (size_t i = 0; i < nodes.size(); ++ i)
 	{
-		if (nodes[i]->GetId() >= nodes.size())
-			cout << "id " << nodes[i]->GetId() << endl;
-
-		outstream << "id " << nodes[i]->GetId() << endl;
-	}
-		
-	cout << "nodes: " << nodes.size() << endl;
-
-
+		BvhNode *n = nodes[i];
+		//if (nodes[i]->GetId() >= nodes.size()) cout << "id " << nodes[i]->GetId() << endl;
+		if (n->IsVirtualLeaf())
+		{
+			int geometrySize;
+			AxisAlignedBox3 box;
+			SceneEntity **ent = bvh->GetGeometry(n, geometrySize);
+			box = SceneEntity::ComputeBoundingBox(ent, geometrySize);
+
+			outstream << n->GetFirstEntity() << " " << n->GetLastEntity() << " " << n->GetBox() << " " << box << endl;
+			
+		}
+	}
+		
 	outstream.close();
 	
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 3274)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.h	(revision 3282)
@@ -88,4 +88,10 @@
 	*/
 	inline float GetDistance() const;
+	/** Returns id of the first scene entity in the node.
+	*/
+	inline int GetFirstEntity() const;
+	/** Returns id of the last scene entity in the node.
+	*/
+	inline int GetLastEntity() const;
 
 
@@ -505,5 +511,5 @@
 	void RenderBoundsForViz(BvhNode *node, RenderState *state, bool useTightBounds);
 
-
+	
 protected:
 
@@ -527,4 +533,5 @@
 	*/
 	void Init();
+
 
 	/////////////
@@ -844,4 +851,16 @@
 
 
+inline int BvhNode::GetFirstEntity() const
+{
+	return mFirst;
+}
+
+
+inline int BvhNode::GetLastEntity() const
+{
+	return mLast;
+}
+
+
 inline BvhNode *BvhInterior::GetBack()
 {
@@ -856,4 +875,8 @@
 
 
+
+//////////////////////////////
+
+	
 inline int Bvh::GetNumNodes() const
 {
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3279)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3282)
@@ -603,5 +603,5 @@
 	//LoadModel("sibenik.dem", dynamicObjects);
 
-	if (1) LoadPompeiiFloor();
+	if (0) LoadPompeiiFloor();
 
 #if 0
@@ -672,6 +672,6 @@
 
 
-	//ObjExporter().Export(model_path + "mypompeii.obj", bvh);
-	//BvhExporter().Export(model_path + "mypompeii.bv", bvh);
+	//ObjExporter().Export(model_path + "mytest.obj", bvh);
+	//BvhExporter().Export(model_path + "mytest.bv", bvh);
 
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhExporter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhExporter.cpp	(revision 3279)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/src/BvhExporter.cpp	(revision 3282)
@@ -59,7 +59,7 @@
 		BvhInterior *interior = static_cast<BvhInterior *>(node);
 
-		ConstructTriangleRangeMap(bvh, interior->GetFront(), first, m);
+		ConstructTriangleRangeMap(bvh, interior->GetBack(), first, m);
 		int newFirst = m + 1;
-		ConstructTriangleRangeMap(bvh, interior->GetBack(), newFirst, last);
+		ConstructTriangleRangeMap(bvh, interior->GetFront(), newFirst, last);
 
 		mTriangleRangeMap[node] = pair<int, int>(first, last);
@@ -69,6 +69,6 @@
 		//first = currentIdx;
 		last = first + bvh->CountTriangles(node) - 1;
+		//cout << "x " << node->GetFirstEntity() << " " << node->GetLastEntity() << " " << first << " " << last << endl;
 		//currentIdx = last;
-
 		mTriangleRangeMap[node] = pair<int, int>(first, last);
 	}
@@ -109,11 +109,9 @@
 		 BvhNode *node = *it;
 
-		 int f = mTriangleRangeMap[node].first;
-		 int l = mTriangleRangeMap[node].second;
+		 const int f = mTriangleRangeMap[node].first;
+		 const int l = mTriangleRangeMap[node].second;
 
 		 for (int i = f; i <= l; ++ i)
-		 {
 			 triangles.push_back(i);
-		 }
 	 }
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3281)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/default.env	(revision 3282)
@@ -9,12 +9,12 @@
 #filename=vienna_full_hp
 #bvhname=vienna_full_hp
-filename=tryvienna
-bvhname=tryvienna
+filename=tryvienna2
+bvhname=tryvienna2
 #filename=mypompeii
 #bvhname=mypompeii
 #filename=pompeii/pompeii_full
 #filename=pompeii/pompeii_part
-filename=city
-bvhname=city
+#filename=city
+#bvhname=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 3277)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.h	(revision 3282)
@@ -110,5 +110,4 @@
 	bool LoadSolution(const std::string &filename);
 
-
 	BvhNode *LoadNode(FILE *fr, int depth);
 
Index: GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3277)
+++ GTP/trunk/App/Demos/Vis/FriendlyCulling/VisibilitySolutionConverter/VisibilitySolutionConverter.cpp	(revision 3282)
@@ -230,6 +230,6 @@
 	mGeometry.clear();
 
+	if (!LoadSolutionTest(bvhInputFilename))
 	//if (!LoadSolution(bvhInputFilename))
-	if (!LoadSolution(bvhInputFilename))
 	{
 		cerr << "could not read solution file" << endl;
@@ -648,5 +648,4 @@
 BvhNode *VisibilitySolutionConverter::LoadNode(FILE *fr, int depth)
 {
-	//cout<<"here4"<<endl;
 	++ mNumNodes;
 	
