Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1259)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1262)
@@ -723,16 +723,17 @@
 
 	//-- the view space bounding box
-	stream << "<ViewSpaceBox" 
-		   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""
-		   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
-
-	if (exportPvs) {
-	//-- export bounding boxes
-	stream << "<BoundingBoxes>" << endl;
-
-	ObjectContainer::const_iterator oit, oit_end = objects.end();
-
-	for (oit = objects.begin(); oit != oit_end; ++ oit)
-	{
+	//stream << "<ViewSpaceBox" 
+	//	   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""
+	//	   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
+
+	if (exportPvs) 
+	{
+		//-- export bounding boxes
+		stream << "<BoundingBoxes>" << endl;
+
+		ObjectContainer::const_iterator oit, oit_end = objects.end();
+
+		for (oit = objects.begin(); oit != oit_end; ++ oit)
+		{
 			MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit);
 			const AxisAlignedBox3 box = mi->GetBox();
@@ -742,11 +743,15 @@
 				   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""
 				   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;
-	}
-
-	stream << "</BoundingBoxes>" << endl;
-	}
+		}
+
+		stream << "</BoundingBoxes>" << endl;
+	}
+
+
+	// the type of hierarchy: this must be known before to build 
+	// the view cells manager
+	stream << "<ViewSpaceHierarchyType name=\"vspBspTree\" />" << endl;
 
 	//-- export the view cells and the pvs
-	stream << "<HierarchyType name=\"vspBspTree\" />" << endl;
 
 	const int numViewCells = mCurrentViewCellsStats.viewCells;
@@ -759,10 +764,12 @@
 
 
-	//-- export the spatial hierarchy
-	
-	// the type of the view cells hierarchy
-	stream << "<Hierarchy>" << endl;
+	//-- export the view space hierarchy
+	
+	stream << "<ViewSpaceHierarchy type=\"bsp\""
+		   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""
+		   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
+
 	mVspBspTree->Export(stream);
-	stream << endl << "</Hierarchy>" << endl;
+	stream << endl << "</ViewSpaceHierarchy>" << endl;
 
 	stream << "</VisibilitySolution>" << endl;
@@ -5007,4 +5014,5 @@
 
 	//-- compression
+
 	if (ViewCellsTreeConstructed() && mCompressViewCells)
 	{
@@ -5469,7 +5477,7 @@
 	//-- export view space bounding box
 	
-	stream << "<ViewSpaceBox" 
-		   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""
-		   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
+	//stream << "<ViewSpaceBox" 
+	//	   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""
+	//	   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
 
 	
@@ -5493,8 +5501,11 @@
 	stream << "</BoundingBoxes>" << endl;
 
+	// the type of the view space hierarchy:
+	// must be known beforehand because necessary for building view cels
+	//stream << "<ViewSpaceHierarchyType name=\"vspTree\" />" << endl;
+
 
 	//-- export the view cells and the pvs
 
-	stream << "<Hierarchy name=\"vspTree\" />" << endl;
 	const int numViewCells = mCurrentViewCellsStats.viewCells;
 
@@ -5506,8 +5517,10 @@
 	//-- export the view space hierarchy
 	
-	// the type of the view space partition
-	stream << "<ViewSpaceHierarchy>" << endl;
+	stream << "<ViewSpaceHierarchy type=\"vsp\""
+		   << " min=\"" << mViewSpaceBox.Min().x << " " << mViewSpaceBox.Min().y << " " << mViewSpaceBox.Min().z << "\""
+		   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
+
 	mVspTree->Export(stream);
-	stream << endl << "</ViewSpacePartitioin>" << endl;
+	stream << endl << "</ViewSpaceHierarchy>" << endl;
 
 	
@@ -5515,8 +5528,18 @@
 	
 	// the type of the view cells hierarchy
-	stream << "<ObjectSpaceHierarchy>" << endl;
-	mOspTree->Export(stream);
-	stream << endl << "</ObjectSpaceHierarchy>" << endl;
-
+	if (mHierarchyManager->GetObjectSpaceSubdivisonType() == 
+		HierarchyManager::KD_BASED_OBJ_SUBDIV)
+	{
+		stream << "<ObjectSpaceHierarchy type=\"osp\">" << endl;
+		mOspTree->Export(stream);
+		stream << endl << "</ObjectSpaceHierarchy>" << endl;
+	}
+	else if (mHierarchyManager->GetObjectSpaceSubdivisonType() == 
+	         HierarchyManager::BV_BASED_OBJ_SUBDIV)
+	{
+		stream << "<ObjectSpaceHierarchy type=\"bvh\">" << endl;
+		mBvHierarchy->Export(stream);
+		stream << endl << "</ObjectSpaceHierarchy>" << endl;
+	}
 
 	stream << "</VisibilitySolution>" << endl;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1259)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1262)
@@ -1081,5 +1081,5 @@
 	case HierarchyManager::BV_BASED_OBJ_SUBDIV:
 		{
-			BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj, NULL);
+			BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj);
 
 			if (!leaf->Mailed())
@@ -1088,5 +1088,5 @@
 				leaf->mCounter = 1;
 
-				++ pvsSize;
+				pvsSize += (int)leaf->mObjects.size();
 			}
 			else
@@ -1266,5 +1266,5 @@
 			{
 				leaf->Mail();
-				++ pvs;
+				pvs += (int)leaf->mObjects.size();
 			}
 			break;
@@ -1311,5 +1311,5 @@
 
 			if (-- leaf->mCounter == 0)
-				++ pvs;
+				pvs += (int)leaf->mObjects.size();
 			break;
 		}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1233)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1262)
@@ -108,24 +108,24 @@
 void ViewCellsParseHandlers::endElement(const XMLCh* const name)
 {
-  StrX lname(name);
-  string element(lname.LocalForm());
-
-  if (element == "ViewCells")
-	  EndViewCells();
-
-  if (element == "BoundingBoxes")
-	  EndBoundingBoxes();
-
-  // inside the view cell description
-  if (mCurrentTask == PARSE_VIEWCELLS)
-  {
-	  if (element == "Interior")
-		  EndViewCellInterior();
-  }
-  else
-  {
-	  if (element == "Interior")
-		  EndBspInterior();
-  }
+	StrX lname(name);
+	string element(lname.LocalForm());
+
+	if (element == "ViewCells")
+		EndViewCells();
+
+	if (element == "BoundingBoxes")
+		EndBoundingBoxes();
+
+	// inside the view cell description
+	if (mCurrentTask == PARSE_VIEWCELLS)
+	{
+		if (element == "Interior")
+			EndViewCellInterior();
+	}
+	else
+	{
+		if (element == "Interior")
+			EndBspInterior();
+	}
 }
 
@@ -150,4 +150,5 @@
 }
 
+
 void ViewCellsParseHandlers::EndViewCellInterior()
 {
@@ -204,5 +205,5 @@
 			const char *ptr = attrValue.LocalForm();
 			
-			//-- the view cells manager is created here
+			// the view cells manager is created here
 			CreateViewCellsManager(ptr);
 		}
@@ -720,5 +721,4 @@
 		mBspTree = new BspTree();
 		mBspTree->mBox = mViewSpaceBox;
-		//mCurrentBspNode = mBspTree->GetRoot();
 
 		mViewCellsManager = new BspViewCellsManager(mBspTree);
@@ -729,5 +729,4 @@
 
 		mVspBspTree = new VspBspTree();
-		//mCurrentBspNode = mVspBspTree->GetRoot();
 		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
 
@@ -746,5 +745,4 @@
 		mVspTree->mBoundingBox = mViewSpaceBox;
 	}
-
 
 	mViewCellsTree = mViewCellsManager->GetViewCellsTree();
