Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2544)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2547)
@@ -1690,17 +1690,7 @@
 	//-- load the view cells assigning the found objects to the pvss
 
-	if (!strstr(filename.c_str(), ".bn"))
-	{
-		LogManager::getSingleton().logMessage("*** loading xml view cells ***");
-
-		mViewCellsManager = GtpVisibilityPreprocessor::ViewCellsManager::
-			LoadViewCells(filename, mObjects, finalizeViewCells, &bconverter);
-	}
-	else
-	{
-		LogManager::getSingleton().logMessage("*** loading binary view cells ***");
-		mViewCellsManager =
-			LoadViewCellsBinary(filename, mObjects, finalizeViewCells, &bconverter);
-	}
+	mViewCellsManager = GtpVisibilityPreprocessor::ViewCellsManager::
+		LoadViewCells(filename, mObjects, finalizeViewCells, &bconverter);
+	
 
 	if (mViewCellsManager)
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2543)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2547)
@@ -715,6 +715,7 @@
 	*/
 	virtual void ExportStats(const string &mergeStats);
-
-	friend ViewCellsManager *LoadViewCellsBinary(const string &filename, 
+	/** Loads view cells in binary mode.
+	*/
+	static ViewCellsManager *LoadViewCellsBinary(const string &filename, 
 												 ObjectContainer &pvsObjects,
 												 bool finalizeViewCells,
@@ -722,5 +723,6 @@
 	/** This helper function loads the bounding boxes for a binary solution.
 	*/
-	static void LoadIndexedBoundingBoxesBinary(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes);
+	static void LoadIndexedBoundingBoxesBinary(IN_STREAM &stream, 
+		                                       IndexedBoundingBoxContainer &iboxes);
 
 
@@ -1270,8 +1272,10 @@
 	/** Fast view cell loader in binary mode.
 	*/
-	friend ViewCellsManager *LoadViewCellsBinary(const string &filename, 
-												 ObjectContainer &pvsObjects,
-												 bool finalizeViewCells,
-												 BoundingBoxConverter *bconverter);
+	friend ViewCellsManager *ViewCellsManager::
+		LoadViewCellsBinary(const std::string &filename, 
+		                    ObjectContainer &pvsObjects,
+							bool finalizeViewCells,
+							BoundingBoxConverter *bconverter);
+
 
 	/** Print statistics about the view cells compression.
@@ -1282,8 +1286,8 @@
 	////////////////////
 
-	/// if we should compress the objects after view cell evaluation: this makes
-	/// only sense for testing purpose
+	/// if we the objects are compressed after evaluation 
+	/// this makes only sense for testing purpose
 	bool mCompressObjects;
-	/// pointer to the hierarchy manager responsible for view space / object space subdivision.
+	/// hierarchy manager managing view space / object subdivision.
 	HierarchyManager *mHierarchyManager;
 };
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2544)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2547)
@@ -550,4 +550,7 @@
 	*/ 
 	VspTree();
+	/** Constructor just setting the bounds of the tree.
+	*/ 
+	VspTree(const AxisAlignedBox3 &bbox);
 	/** Default destructor.
 	*/
@@ -706,5 +709,7 @@
 		}
 	};
-
+	/** Parse the environment settings.
+	*/
+	void ParseEnvironment();
 	/** faster evaluation of split plane cost for kd axis aligned cells.
 	*/
@@ -754,5 +759,4 @@
 	*/
 	void EvaluateLeafStats(const VspTraversalData &data);
-
 	/** Subdivides node using a best split priority queue.
 	    @param tQueue the best split priority queue
@@ -804,5 +808,6 @@
 	*/
 	float EvalPvsCost(const RayInfoContainer &rays) const;
-
+	/** Helper function for split cost evaluation.
+	*/
 	int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate,
 						   const SplitData &sData) const;
@@ -1084,10 +1089,5 @@
 
 #endif
-
-
-	friend ViewCellsManager *LoadViewCellsBinary(const std::string &filename, 
-									             ObjectContainer &pvsObjects,
-												 bool finalizeViewCells,
-												 BoundingBoxConverter *bconverter);
+	
 
 protected:
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2544)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2547)
@@ -1021,16 +1021,30 @@
 	if (!Debug.is_open()) Debug.open("debug.log");
 
-	// give just an empty container as parameter:
-	// this loading function is used in the engine, thus it
-	// does not need to load the entities the preprocessor works on
-	ObjectContainer preprocessorObjects;
-
-	return LoadViewCells(filename, 
-						 pvsObjects,
-						 preprocessorObjects,
-						 finalizeViewCells,
-						 bconverter);
-}
-
+
+	if (strstr(filename.c_str(), ".bn"))
+	{
+		Debug << "binary view cells format detected" << endl;
+
+		return LoadViewCellsBinary(filename, 
+			                       pvsObjects,
+								   finalizeViewCells,
+								   bconverter);
+	}
+	else
+	{
+		Debug << "xml view cells format detected" << endl;
+
+		// give just an empty container as parameter:
+		// this loading function is used in the engine, thus it
+		// does not need to load the entities the preprocessor works on
+		ObjectContainer preprocessorObjects;
+
+		return LoadViewCells(filename, 
+			                 pvsObjects,
+							 preprocessorObjects,
+							 finalizeViewCells,
+							 bconverter);
+	}
+}
 
 void ViewCellsManager::LoadIndexedBoundingBoxesBinary(IN_STREAM &stream, IndexedBoundingBoxContainer &iboxes)
@@ -7110,12 +7124,9 @@
 
 
-
-ViewCellsManager *LoadViewCellsBinary(const string &filename, 
-									  ObjectContainer &pvsObjects,
-									  bool finalizeViewCells,
-									  BoundingBoxConverter *bconverter)												 
-{
-	if (!Debug.is_open()) Debug.open("debug.log");
-
+ViewCellsManager *ViewCellsManager::LoadViewCellsBinary(const string &filename, 
+														ObjectContainer &pvsObjects,
+														bool finalizeViewCells,
+														BoundingBoxConverter *bconverter)												 
+{
 	IN_STREAM stream(filename.c_str());
 
@@ -7142,7 +7153,4 @@
 	}
 
-	// sort objects by id
-	//sort(pvsObjects.begin(), pvsObjects.end(), ilt);
-
 
 	ObjectContainer pvsLookup;
@@ -7188,7 +7196,5 @@
 
 	Debug << "loading the view space partition tree" << endl;
-	VspTree *vspTree = new VspTree();
-
-	vspTree->mBoundingBox = viewSpaceBox;
+	VspTree *vspTree = new VspTree(viewSpaceBox);
 
 	if (!vspTree->ImportBinary(stream))
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2546)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2547)
@@ -387,18 +387,37 @@
 mOutOfBoundsCell(NULL),
 mStoreRays(false),
-//mStoreRays(true),
 mTimeStamp(1),
 mHierarchyManager(NULL)
 {
 	mLocalSubdivisionCandidates = new vector<SortableEntry>;
-
-	bool randomize = false;
-	Environment::GetSingleton()->GetBoolValue("VspTree.Construction.randomize", randomize);
-	if (randomize)
-		Randomize(); // initialise random generator for heuristics
+	ParseEnvironment();
+}
+
+
+VspTree::VspTree(const AxisAlignedBox3 &bbox):
+mRoot(NULL),
+mOutOfBoundsCell(NULL),
+mStoreRays(false),
+mTimeStamp(1),
+mHierarchyManager(NULL),
+mBoundingBox(bbox)
+{
+	mLocalSubdivisionCandidates = new vector<SortableEntry>;
+	ParseEnvironment();
+}
+
+
+
+void VspTree::ParseEnvironment()
+{
+	// initialise random generator for heuristics
+	bool randomize;
+    Environment::GetSingleton()->GetBoolValue("VspTree.Construction.randomize", randomize);
+	if (randomize) Randomize(); 
 
 	char subdivisionStatsLog[100];
 	Environment::GetSingleton()->GetStringValue("VspTree.subdivisionStats", subdivisionStatsLog);
 	mSubdivisionStats.open(subdivisionStatsLog);
+
 
 	/////////////
@@ -410,5 +429,5 @@
 	Environment::GetSingleton()->GetFloatValue("VspTree.Termination.minProbability", mTermMinProbability);
 	Environment::GetSingleton()->GetFloatValue("VspTree.Termination.maxRayContribution", mTermMaxRayContribution);
-	
+
 	Environment::GetSingleton()->GetIntValue("VspTree.Termination.missTolerance", mTermMissTolerance);
 	Environment::GetSingleton()->GetIntValue("VspTree.Termination.maxViewCells", mMaxViewCells);
@@ -432,5 +451,5 @@
 
 	Environment::GetSingleton()->GetFloatValue("VspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight);
-	
+
 	// if only the driving axis is used for axis aligned split
 	Environment::GetSingleton()->GetBoolValue("VspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis);
@@ -439,9 +458,10 @@
 
 	//mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(VspViewCell));
-	//mMemoryConst = 50;//(float)(sizeof(VspViewCell));
 	//mMemoryConst = (float)(sizeof(VspLeaf) + sizeof(ObjectPvs));
-
-	mMemoryConst = 16;//(float)sizeof(ObjectPvs);
-	
+	//mMemoryConst = (float)sizeof(ObjectPvs);
+
+	// hack
+	mMemoryConst = 16;
+
 
 	//////////////
@@ -450,5 +470,5 @@
 	Debug << "******* VSP options ********" << endl;
 
-    Debug << "max depth: " << mTermMaxDepth << endl;
+	Debug << "max depth: " << mTermMaxDepth << endl;
 	Debug << "min PVS: " << mTermMinPvs << endl;
 	Debug << "min probabiliy: " << mTermMinProbability << endl;
@@ -458,6 +478,6 @@
 	Debug << "miss tolerance: " << mTermMissTolerance << endl;
 	Debug << "max view cells: " << mMaxViewCells << endl;
+
 	Debug << "randomize: " << randomize << endl;
-
 	Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl;
 	Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl;
