Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg	(revision 1261)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/scripts/terrainCulling.cfg	(revision 1264)
@@ -1,15 +1,44 @@
+######################################################################
+
+#
+#  Settings for vienna scene
+#
+
+#
+# The scene geometry
+#
+
+
 #Scene=../../../../../resources/media/house_test1.iv
-#Scene=../../../../../resources/media/city1500_flat_1.iv;../../../../../resources/media/roofs_1500.iv;../../../../../resources/media/CityRoads60.iv
-Scene=terrain
+Scene=../../../../../resources/media/city1500_flat_1.iv;../../../../../resources/media/roofs_1500.iv;../../../../../resources/media/CityRoads60.iv
+#Scene=../../../../../resources/media/city1.iv;../../../../../resources/media/roofs_1500.iv;../../../../../resources/media/CityRoads60.iv
 
 # current view point
-#ViewX=830
-#ViewY=300
-#ViewZ=-540
+ViewX=830
+ViewY=300
+ViewZ=-540
 
-ViewX=707
-ViewY=5000
-ViewZ=528
+#
+# The visibility environment: load the view cells from there
+#
 
-#VisibilityEnvironment=D:/svn/gametools/GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env
+VisibilityEnvironment=D:/svn/gametools/GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env
 #VisibilityEnvironment=../../../../../../../GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env
+
+
+
+######################################################################
+
+#
+#  Settings for terrain scene
+#
+
+#Scene=terrain
+
+#
+# current view point
+#
+
+#ViewX=707
+#ViewY=5000
+#ViewZ=528
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1251)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1264)
@@ -40,5 +40,4 @@
 mIsDepthPassPhase(false),
 mUseItemBuffer(false),
-//mUseItemBuffer(true),
 mIsItemBufferPhase(false),
 mCurrentEntityId(1),
@@ -46,5 +45,4 @@
 mSkipTransparents(false),
 mRenderTransparentsForItemBuffer(true),
-//mExecuteVertexProgramForAllPasses(true),
 mExecuteVertexProgramForAllPasses(false),
 mIsHierarchicalCulling(false),
@@ -56,4 +54,6 @@
 mDeleteQueueAfterRendering(true)
 {
+	Ogre::LogManager::getSingleton().logMessage("creating occlusion culling scene manager");
+
 	mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem);
 	
@@ -321,5 +321,5 @@
 	
 	
-	// -- delete lists stored for visualization
+	// lists only used for visualization
 	mVisible.clear();
 	mBoxes.clear();
@@ -331,5 +331,4 @@
 	{
 		OctreeSceneManager::_renderVisibleObjects();
-
 		return;
 	}
@@ -457,5 +456,5 @@
 		OGRE_DELETE(mRenderQueue); // HACK: should rather only be cleared ...
 
-	if (0) WriteLog(); // write out stats
+	if (1) WriteLog(); // write out stats
 }
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1258)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1264)
@@ -685,6 +685,5 @@
 		else //-- the hierarchical culling algorithm
 		{
-			// this is also called in TerrainSceneManager: really
-			// necessary?
+			// this is also called in TerrainSceneManager: really necessary?
 			//mDestRenderSystem -> setLightingEnabled(false);
 
@@ -697,4 +696,5 @@
 
 			//-- hierarchical culling
+
 			// the objects of different layers (e.g., background, scene, 
 			// overlay) must be identified and rendered one after another
@@ -781,6 +781,5 @@
 }
 
-//void KdTreeSceneManager::_renderNodes(const KdRenderableList& nodelist, Camera * cam, 
-//	bool onlyShadowCasters, int leavePassesInQueue)
+
 void KdTreeSceneManager::_renderNode(KdTree::NodePtr node, Camera * cam, 
 									 bool onlyShadowCasters, int leavePassesInQueue)
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 1165)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp	(revision 1264)
@@ -24,9 +24,6 @@
 */
 
-//#include <OgreVisibilityTerrainSceneManager.h>
 #include <OgreOcclusionCullingSceneManager.h>
 #include <OgreKdTreeSceneManager.h>
-
-//#include <OgreHeightmapTerrainPageSource.h>
 #include <OgreRoot.h>
 #include <OgreLogManager.h>
@@ -40,5 +37,5 @@
 namespace Ogre {
 
-//VisibilityTerrainSceneManagerFactory *visibilityTerrainPlugin;
+
 OcclusionCullingSceneManagerFactory *occlusionCullingPlugin;
 KdTreeSceneManagerFactory *kdTreeFactory;
@@ -52,12 +49,11 @@
 
 	// Create new scene manager
-	//visibilityTerrainPlugin = new VisibilityTerrainSceneManagerFactory(visManager);
 	occlusionCullingPlugin = new OcclusionCullingSceneManagerFactory(visManager);
 	kdTreeFactory = new KdTreeSceneManagerFactory(visManager);
+
 	// Construct listener manager singleton
 	new TerrainPageSourceListenerManager();
 
 	// Register
-	//Root::getSingleton().addSceneManagerFactory(visibilityTerrainPlugin);
 	Root::getSingleton().addSceneManagerFactory(occlusionCullingPlugin);
 	Root::getSingleton().addSceneManagerFactory(kdTreeFactory);
@@ -66,7 +62,7 @@
 extern "C" void __declspec(dllexport) dllShutdownPlugin()
 {
-	//Root::getSingleton().removeSceneManagerFactory(visibilityTerrainPlugin);
 	Root::getSingleton().removeSceneManagerFactory(occlusionCullingPlugin);
 	Root::getSingleton().removeSceneManagerFactory(kdTreeFactory);
+
 	// destroy listener manager
 	delete TerrainPageSourceListenerManager::getSingletonPtr();
@@ -77,6 +73,4 @@
 	//delete heightmapTerrainPageSource;
 	// BUG: crashes on delete!!!! FIX this 
-
-	//delete visibilityTerrainPlugin;
 	delete occlusionCullingPlugin;
 	delete kdTreeFactory;
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp	(revision 897)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreSceneContentGenerator.cpp	(revision 1264)
@@ -65,7 +65,4 @@
 		createChildSceneNode(String(name) + "Node", position);
 
-	//std::stringstream d; d << "new node: " << name << "Node";
-	//Ogre::LogManager::getSingleton().logMessage(d.str());
-
 	//ent->setCastShadows(false);
 	node->attachObject(ent);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1261)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1264)
@@ -36,5 +36,5 @@
 				OutputFile="$(OutDir)/Preprocessor.exe"
 				LinkIncremental="2"
-				AdditionalLibraryDirectories="..\src\GL;..\lib\debug;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib"
+				AdditionalLibraryDirectories="..\include;..\src\GL;&quot;..\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib"
 				GenerateDebugInformation="TRUE"
 				ProgramDatabaseFile="$(OutDir)/TestPreprocessor.pdb"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1259)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1264)
@@ -37,4 +37,5 @@
 class HierarchyManager;
 class BvHierarchy;
+class ViewCellsTree;
 
 struct AxisAlignedPlane;
@@ -79,5 +80,5 @@
 	/** Default constructor.
 	*/
-	ViewCellsManager();
+	ViewCellsManager(ViewCellsTree *viewCellsTree);
 
 	virtual ~ViewCellsManager();
@@ -90,6 +91,7 @@
 	/** Constructs view cell container with a given number of samples.
 	*/
-	virtual int ConstructSubdivision(const ObjectContainer &objects, 
-						  const VssRayContainer &rays) = 0;
+	virtual int ConstructSubdivision(
+		const ObjectContainer &objects, 
+		const VssRayContainer &rays) = 0;
 
 	/** Computes sample contributions of the rays to the view cells PVS.
@@ -696,5 +698,5 @@
 		used to construct the bsp tree.
 	*/
-	BspViewCellsManager(BspTree *tree);
+	BspViewCellsManager(ViewCellsTree *viewCellsTree, BspTree *tree);
 
 	~BspViewCellsManager();
@@ -779,5 +781,5 @@
 public:
 
-	KdViewCellsManager(KdTree *tree);
+	KdViewCellsManager(ViewCellsTree *viewCellsTree, KdTree *tree);
 
 	int ConstructSubdivision(const ObjectContainer &objects, 
@@ -844,5 +846,5 @@
 public:
 
-	VspBspViewCellsManager(VspBspTree *tree);
+	VspBspViewCellsManager(ViewCellsTree *viewCellsTree, VspBspTree *tree);
 	~VspBspViewCellsManager();
 
@@ -972,5 +974,5 @@
 public:
 
-	VspOspViewCellsManager(VspTree *tree, OspTree *ospTree);
+	VspOspViewCellsManager(ViewCellsTree *viewCellsTree, VspTree *tree, OspTree *ospTree);
 	~VspOspViewCellsManager();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.vcproj	(revision 1252)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.vcproj	(revision 1264)
@@ -20,5 +20,5 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;..\..\..\..\..\..\NonGTP\Zlib\include;&quot;$(CG_INC_PATH)&quot;"
+				AdditionalIncludeDirectories="&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\..\src;&quot;$(CG_INC_PATH)&quot;;..\..\..\..\..\..\..\NonGTP\Zlib\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;QTGLRENDERER_EXPORTS"
 				MinimalRebuild="TRUE"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1251)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1264)
@@ -16,4 +16,6 @@
 #include "OspTree.h"
 #include "ObjParser.h"
+#include "BvHierarchy.h"
+
 #ifdef GTP_INTERNAL
 #include "ArchModeler2MLRT.hxx"
@@ -122,4 +124,7 @@
 mBspTree(NULL),
 mVspBspTree(NULL),
+mVspTree(NULL),
+mOspTree(NULL),
+mBvHierarchy(NULL),
 mViewCellsManager(NULL),
 mRenderSimulator(NULL),
@@ -394,4 +399,5 @@
 	{	
 		Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
+		cout << "loading view cells from " << buf << endl;
 		mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true);
 	}
@@ -399,4 +405,5 @@
 	{
 		//-- parse type of view cell container
+
 		Environment::GetSingleton()->GetStringValue("ViewCells.type", buf);		
 	    mViewCellsManager = CreateViewCellsManager(buf);
@@ -437,7 +444,9 @@
 ViewCellsManager *Preprocessor::CreateViewCellsManager(const char *name)
 {
+	ViewCellsTree *vcTree = new ViewCellsTree;
+
 	if (strcmp(name, "kdTree") == 0)
 	{
-		mViewCellsManager = new KdViewCellsManager(mKdTree);
+		mViewCellsManager = new KdViewCellsManager(vcTree, mKdTree);
 	}
 	else if (strcmp(name, "bspTree") == 0)
@@ -446,5 +455,5 @@
 
 		mBspTree = new BspTree();
-		mViewCellsManager = new BspViewCellsManager(mBspTree);
+		mViewCellsManager = new BspViewCellsManager(vcTree, mBspTree);
 	}
 	else if (strcmp(name, "vspBspTree") == 0)
@@ -453,15 +462,15 @@
 
 		mVspBspTree = new VspBspTree();
-		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
+		mViewCellsManager = new VspBspViewCellsManager(vcTree, mVspBspTree);
 	}
 	else if (strcmp(name, "vspOspTree") == 0)
 	{
 		mVspTree = new VspTree();
-		mOspTree = new OspTree();
+		//mOspTree = new OspTree();
 		
 		// HACK for testing if per kd evaluation works!!
 		mOspTree = new OspTree(*mKdTree);
 
-		mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree);
+		mViewCellsManager = new VspOspViewCellsManager(vcTree, mVspTree, mOspTree);
 	}
 	else if (strcmp(name, "sceneDependent") == 0)
@@ -471,5 +480,5 @@
 		//TODO
 		mBspTree = new BspTree();
-		mViewCellsManager = new BspViewCellsManager(mBspTree);
+		mViewCellsManager = new BspViewCellsManager(vcTree, mBspTree);
 	}
 	else
@@ -479,4 +488,5 @@
 	}
 
+	//vcTree->SetViewCellsManager(mViewCellsManager);
 	return mViewCellsManager;
 }
@@ -841,5 +851,5 @@
 	float pforg[3];
 	float pfdir[3];
-	double pfnorm[3];
+	//double pfnorm[3];
 
 	pforg[0] = viewPoint[0]; pforg[1] = viewPoint[1]; pforg[2] = viewPoint[2];
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.cpp	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.cpp	(revision 1264)
@@ -80,8 +80,7 @@
 {
 	// Try to open the file
-    //fSource = XMLPlatformUtils::openFile(fileName, manager);
-	// todo: delete xmlstring
 	char *myFileName = XMLString::transcode(fileName);
-	//mStream.open(myFileName, ios::binary);
+	//fSource = XMLPlatformUtils::openFile(fileName, manager);
+
 	mStream.open(myFileName);
 
@@ -95,5 +94,4 @@
 {
     // Try to open the file
-	//mStream.open(fileName, ios::binary);
 	mStream.open(fileName);
 }
@@ -143,8 +141,8 @@
     //unsigned int result = XMLPlatformUtils::readFileBuffer(fSource, maxToRead, toFill, fMemoryManager);
 	mStream.read((char *)toFill, maxToRead);
-	
+	//cout << "\n\n tofill: " << toFill << endl << endl;
+
 	unsigned int result = mStream.gcount();
 	mCurrentPos = mStream.tellg();
-	//GtpVisibilityPreprocessor::Debug << "stream: " << maxToRead << " " << toFill << " " << result << endl;
 
 	return result;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1251)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1264)
@@ -488,5 +488,5 @@
 
 			  Vector3 size = mViewSpaceBox->Size();
-			  tbox.SetMax(0, mViewSpaceBox->Max(0) + size[0] * 0.5);
+			  tbox.SetMax(0, mViewSpaceBox->Max(0) + size[0] * 0.5f);
 			  tbox.SetMin(0, mViewSpaceBox->Min(0) + size[0]);
 			  *mViewSpaceBox = tbox;
@@ -514,5 +514,5 @@
   mSceneGraph->CollectObjects(&mObjects);
 
-  //-- load view cells from file if requested
+  //-- load view cells from file or reconstruct them
   if (!mLoadViewCells)
   {
@@ -525,11 +525,12 @@
 	  mViewCellsManager->PrintStatistics(Debug);
   }
-  else
+#if 1 // test successful view cells loading by exporting them again
+  else 
   {	 
 	  VssRayContainer dummies;
 	  mViewCellsManager->Visualize(mObjects, dummies);
-	  mViewCellsManager->ExportViewCells("test.xml", mViewCellsManager->GetExportPvs(), mObjects);
-  }
-
+	  mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects);
+  }
+#endif
   VssTree *vssTree = NULL;
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1251)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1264)
@@ -26,4 +26,5 @@
 class VspTree;
 class OspTree;
+class BvHierarchy;
 class Intersectable;
 
@@ -182,5 +183,6 @@
   BspTree *mBspTree;
 
-
+  BvHierarchy *mBvHierarchy;
+  
   /// list of all loaded occluders
   ObjectContainer mOccluders;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1263)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1264)
@@ -45,5 +45,5 @@
 
 
-ViewCellsManager::ViewCellsManager():
+ViewCellsManager::ViewCellsManager(ViewCellsTree *viewCellsTree):
 mRenderer(NULL),
 mInitialSamples(0),
@@ -58,10 +58,12 @@
 mMaxPvsRatio(1.0),
 mViewCellPvsIsUpdated(false),
-mPreprocessor(NULL)
+mPreprocessor(NULL),
+mViewCellsTree(viewCellsTree)
 {
 	mViewSpaceBox.Initialize();
 	ParseEnvironment();
 
-	mViewCellsTree = new ViewCellsTree(this);
+	mViewCellsTree->SetViewCellsManager(this);
+	//mViewCellsTree = new ViewCellsTree(this);
 }
 
@@ -226,5 +228,5 @@
 {
 	// HACK: if view cells tree does not 
-	// take care of view cells, we have to do it
+	// handle view cells, we have to do it here
 	// question: rather create view cells resource manager?
 	if (!ViewCellsTreeConstructed())
@@ -232,6 +234,5 @@
 		CLEAR_CONTAINER(mViewCells);
 	}
-
-	DEL_PTR(mViewCellsTree);
+	//DEL_PTR(mViewCellsTree);
 }
 
@@ -412,5 +413,5 @@
 	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
-	
+
 	// construct view cells
 	ConstructSubdivision(preprocessor->mObjects, initialSamples);
@@ -526,8 +527,6 @@
 	cout << "starting post processing and visualization" << endl;
 
-
 	// store view cells for postprocessing
 	const bool storeViewCells = true;
-
 
 	if (SAMPLE_AFTER_SUBDIVISION)
@@ -713,5 +712,5 @@
 
 	cout << "exporting view cells to xml ... ";
-	
+
 	OUT_STREAM stream(filename.c_str());
 
@@ -722,12 +721,8 @@
 	stream << "<VisibilitySolution>" << endl;
 
-	//-- 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;
 
@@ -748,8 +743,5 @@
 	}
 
-
-	// 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
 
@@ -767,5 +759,5 @@
 	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;
+		   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\">" << endl;
 
 	mVspBspTree->Export(stream);
@@ -773,5 +765,4 @@
 
 	stream << "</VisibilitySolution>" << endl;
-
 
 	stream.close();
@@ -2548,6 +2539,6 @@
 
 
-BspViewCellsManager::BspViewCellsManager(BspTree *bspTree):
-ViewCellsManager(), mBspTree(bspTree)
+BspViewCellsManager::BspViewCellsManager(ViewCellsTree *vcTree, BspTree *bspTree):
+ViewCellsManager(vcTree), mBspTree(bspTree)
 {
 	Environment::GetSingleton()->GetIntValue("BspTree.Construction.samples", mInitialSamples);
@@ -2691,4 +2682,5 @@
 
 	//-- merge view cells
+
 	cout << "starting post processing using " << mPostProcessSamples << " samples ... ";
 	long startTime = GetTime();
@@ -3276,6 +3268,6 @@
 
 
-KdViewCellsManager::KdViewCellsManager(KdTree *kdTree):
-ViewCellsManager(), mKdTree(kdTree), mKdPvsDepth(100)
+KdViewCellsManager::KdViewCellsManager(ViewCellsTree *vcTree, KdTree *kdTree):
+ViewCellsManager(vcTree), mKdTree(kdTree), mKdPvsDepth(100)
 {
 }
@@ -3578,6 +3570,6 @@
 
 
-VspBspViewCellsManager::VspBspViewCellsManager(VspBspTree *vspBspTree):
-ViewCellsManager(), mVspBspTree(vspBspTree)
+VspBspViewCellsManager::VspBspViewCellsManager(ViewCellsTree *vcTree, VspBspTree *vspBspTree):
+ViewCellsManager(vcTree), mVspBspTree(vspBspTree)
 {
 	Environment::GetSingleton()->GetIntValue("VspBspTree.Construction.samples", mInitialSamples);
@@ -3609,5 +3601,6 @@
 	}
 	else 
-	{	// we can use the view cells tree hierarchy to get the right set
+	{	
+		// we can use the view cells tree hierarchy to get the right set
 		mViewCellsTree->CollectBestViewCellSet(mViewCells, mNumActiveViewCells);
 	}
@@ -4810,6 +4803,6 @@
 
 
-VspOspViewCellsManager::VspOspViewCellsManager(VspTree *vspTree, OspTree *ospTree):
-ViewCellsManager(), mVspTree(vspTree), mOspTree(ospTree)
+VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, VspTree *vspTree, OspTree *ospTree):
+ViewCellsManager(vcTree), mVspTree(vspTree), mOspTree(ospTree)
 {
 	mHierarchyManager = new HierarchyManager(*vspTree, *ospTree);
@@ -5474,11 +5467,5 @@
 	stream << "<VisibilitySolution>" << endl;
 
-	//-- 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;
-
-	
+
 	//-- export bounding boxes
 
@@ -5499,8 +5486,4 @@
 
 	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;
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1233)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1264)
@@ -361,4 +361,26 @@
 #endif
 {
+	ReadEnvironment();
+	MergeCandidate::sRenderCostWeight = mRenderCostWeight;
+}
+
+
+ViewCellsTree::ViewCellsTree():
+mRoot(NULL),
+mUseAreaForPvs(false),
+mViewCellsManager(NULL),
+#if 0
+mViewCellsStorage(PVS_IN_INTERIORS)
+#else
+mViewCellsStorage(PVS_IN_LEAVES)
+#endif
+{
+	ReadEnvironment();
+	MergeCandidate::sRenderCostWeight = mRenderCostWeight;
+}
+
+
+void ViewCellsTree::ReadEnvironment()
+{
 	Environment::GetSingleton()->GetBoolValue("ViewCells.Visualization.exportMergedViewCells", mExportMergedViewCells);
 	Environment::GetSingleton()->GetFloatValue("ViewCells.maxStaticMemory", mMaxMemory);
@@ -379,6 +401,4 @@
 	Debug << "refining view cells: " << mRefineViewCells << endl;
 	Debug << "=========== end view cell tree options ===============\n";
-
-	MergeCandidate::sRenderCostWeight = mRenderCostWeight;
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/gzstream.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/gzstream.h	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/gzstream.h	(revision 1264)
@@ -77,5 +77,5 @@
         // ASSERT: both input & output capabilities will not be used together
     }
-    int is_open() { return opened; }
+    int is_open() const { return opened; }
     gzstreambuf* open( const char* name, int open_mode);
     gzstreambuf* close();
@@ -99,5 +99,5 @@
   void close();
   gzstreambuf* rdbuf() { return &buf; }
-  int is_open() { return buf.is_open(); }
+  int is_open() const { return buf.is_open(); }
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.h	(revision 975)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.h	(revision 1264)
@@ -106,4 +106,5 @@
 
 	unsigned int mCurrentPos;
+
 private :
     // -----------------------------------------------------------------------
@@ -130,5 +131,5 @@
 inline bool GzBinFileInputStream::getIsOpen() const
 {
-    return (fSource != 0);
+	return (mStream.is_open());//(fSource != 0);
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 1263)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 1264)
@@ -23,5 +23,5 @@
 class ViewCellsManager;
 class ViewCellLeaf;
-//class Environment;
+
 
 
@@ -391,4 +391,5 @@
 
 public:
+	ViewCellsTree();
 	/** View cells tree constructor taking a view cell mnanager as parameter
 	*/
@@ -511,6 +512,12 @@
 	int CountKdPvs(const ViewCellLeaf *vc) const;
 
+	void SetViewCellsManager(ViewCellsManager *vcm)
+	{
+		mViewCellsManager = vcm;
+	}
+
 protected:
 
+	void ReadEnvironment();
 
 	/////////////////////////////////////////////////////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1248)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1264)
@@ -212,9 +212,8 @@
 	}
 
-
 	// create a preprocessor thread (note: capsulates calls to boost fuctions!)
+	BoostPreprocessorThread pt(preprocessor);
 
 	//PreprocessorThread *pt = PreprocessorThreadFactory::Create(preprocessor);
-	BoostPreprocessorThread pt(preprocessor);
 
 	bool guiSupported = false;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1263)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1264)
@@ -99,5 +99,5 @@
   int mCurrentState;
   
-  enum {PARSE_OPTIONS, PARSE_VIEWCELLS, PARSE_VSP, PARSE_OSP};
+  enum {PARSE_OPTIONS, PARSE_VIEWCELLS, PARSE_VIEWSPACE_HIERARCHY, PARSE_OBJECTSPACE_HIERARCHY};
 
   /// view space / object space hierarchy types
@@ -125,5 +125,6 @@
   void StartVspElement(string element, AttributeList& attributes);
 
-  void StartViewSpaceBox(AttributeList&  attributes);
+  void StartViewSpaceHierarchy(AttributeList& attributes);
+  void StartObjectSpaceHierarchy(AttributeList& attributes);
 
   void StartBoundingBox(AttributeList& attributes);
@@ -140,4 +141,11 @@
   void StartOspLeaf(AttributeList& attributes);
   void StartOspInterior(AttributeList& attributes);
+
+  void CreateObjectSpaceHierarchy();
+  void CreateViewSpaceHierarchy();
+
+  void StartBvhLeaf(AttributeList& attributes);
+  void StartBvhInterior(AttributeList& attributes);
+  void StartBvhElement(string element, AttributeList& attributes);
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1259)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1264)
@@ -270,7 +270,10 @@
 	mOspTree->mOspStats.Stop();
 
-	float rc = mOspTree->EvalRenderCost(sampleRays);
-
-	Debug << "here47 My render cost evalulation: " << rc << endl;
+	//////////////////////////
+	// matt: only for debugging purpose
+
+	const float rc = mOspTree->EvalRenderCost(sampleRays);
+
+	Debug << "My render cost evalulation: " << rc << endl;
 
 #if 0
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1263)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1264)
@@ -111,10 +111,10 @@
 	string element(lname.LocalForm());
 
+	if (element == "BoundingBoxes")
+		EndBoundingBoxes();
+
 	if (element == "ViewCells")
 		EndViewCells();
 
-	if (element == "BoundingBoxes")
-		EndBoundingBoxes();
-
 	// inside the view cell description
 	if (mCurrentState == PARSE_VIEWCELLS)
@@ -128,4 +128,8 @@
 			EndBspInterior();
 	}
+
+	// finished, create view cells manager
+	if (element == "VisibilitySolution")
+		CreateViewCellsManager();
 }
 
@@ -135,5 +139,5 @@
 	// go one up in the tree
 	if (mCurrentBspNode->GetParent())
-	{	Debug << "]";
+	{	cout << "]";
 		mCurrentBspNode = mCurrentBspNode->GetParent();
 	}
@@ -145,5 +149,5 @@
 	// go one up in the tree
 	if (mCurrentVspNode->GetParent())
-	{	Debug << "]";
+	{	cout << "]";
 		mCurrentVspNode = mCurrentVspNode->GetParent();
 	}
@@ -155,5 +159,5 @@
 	// go one up in the tree
 	if (mCurrentViewCell->GetParent())
-	{	Debug << "]";
+	{	cout << "]";
 		mCurrentViewCell = mCurrentViewCell->GetParent();
 	}
@@ -217,5 +221,5 @@
 	if (element == "Interior") 
 	{
-		Debug << "[";
+		cout << "[";
 		StartBspInterior(attributes);
 	}
@@ -223,5 +227,5 @@
 	if (element == "Leaf") 
 	{
-		Debug << "l";
+		cout << "l";
 		StartBspLeaf(attributes);
 	}
@@ -234,5 +238,5 @@
 	if (element == "Interior") 
 	{
-		Debug << "[";
+		cout << "[";
 		StartVspInterior(attributes);
 	}
@@ -240,5 +244,5 @@
 	if (element == "Leaf") 
 	{
-		Debug << "l";
+		cout << "l";
 		StartVspLeaf(attributes);
 	}
@@ -251,5 +255,5 @@
 	if (element == "Interior") 
 	{
-		Debug << "[";
+		cout << "[";
 		StartOspInterior(attributes);
 	}
@@ -257,23 +261,40 @@
 	if (element == "Leaf") 
 	{
-		Debug << "l";
+		cout << "l";
 		StartOspLeaf(attributes);
 	}
 }
+
+
+void ViewCellsParseHandlers::StartBvhElement(string element,
+											 AttributeList& attributes)
+{
+	if (element == "Interior") 
+	{
+		cout << "[";
+		StartBvhInterior(attributes);
+	}
+
+	if (element == "Leaf") 
+	{
+		cout << "l";
+		StartBvhLeaf(attributes);
+	}
+}
+
 
 void ViewCellsParseHandlers::StartViewSpaceHierarchyElement(const std::string &element,
 															AttributeList& attributes)
 {
-	if (!mViewCellsManager)
-		return;
-
-	//-- use cell type according to the chosen view cell manager
-	switch (mViewCellsManager->GetType())
-	{
-		case ViewCellsManager::BSP:
-		case ViewCellsManager::VSP_BSP:
+	//if (!mViewCellsManager)return;
+
+	//-- use cell type according to the chosen method
+
+	switch (mViewSpaceHierarchyType)
+	{
+		case BSP:
 			StartBspElement(element, attributes);
 			break;
-		case ViewCellsManager::VSP_OSP:
+		case VSP:
 			StartVspElement(element, attributes);
 			break;
@@ -288,12 +309,15 @@
 															  AttributeList& attributes)
 {
-	if (!mViewCellsManager)
-		return;
-
-	//-- use cell type according to the chosen view cell manager
-	switch (mViewCellsManager->GetType())
-	{
-		case ViewCellsManager::VSP_OSP:
+	//if (!mViewCellsManager)return;
+
+	//-- use cell type according to the chosen method
+
+	switch (mObjectSpaceHierarchyType)
+	{
+		case OSP:
 			StartOspElement(element, attributes);
+			break;
+		case BVH:
+			StartBvhElement(element, attributes);
 			break;
 		default:
@@ -331,5 +355,9 @@
 	{
 		cout << "parsing view cells" << endl;
+		
 		mCurrentState = PARSE_VIEWCELLS;
+
+		// create new view cells hierarchy
+		mViewCellsTree = new ViewCellsTree();
 	}
 
@@ -343,8 +371,8 @@
 	// decides about the view cell hierarchy
 	if (element == "ViewSpaceHierarchy")
-	{
-		//StartViewSpaceHierarchy(attributes);
-		cout << "parsing view space partition" << endl;
-		mCurrentState = PARSE_VSP;
+	{		
+		cout << "parsing view space hierarchy" << endl;
+		mCurrentState = PARSE_VIEWSPACE_HIERARCHY;
+		StartViewSpaceHierarchy(attributes);
 	}
 
@@ -352,16 +380,9 @@
 	if (element == "ObjectSpaceHierarchy")
 	{
-		//StartObjectSpaceHierarchy(attributes);
-		cout << "parsing object space partition" << endl;
-		mCurrentState = PARSE_OSP;
-	}
-	
-	// decides the used view cell hierarchy
-	if (element == "ViewSpaceBox")
-	{
-		Debug << "v";
-		StartViewSpaceBox(attributes);
-	}
-
+		cout << "parsing object space hierarchy" << endl;
+		mCurrentState = PARSE_OBJECTSPACE_HIERARCHY;
+		StartObjectSpaceHierarchy(attributes);
+	}
+	
 	// decides the used view cell hierarchy
 	if (element == "BoundingBox")
@@ -371,11 +392,11 @@
 	}
 
-	// parse view space partition
+	// parse view space hierarchy
 	switch (mCurrentState)
 	{
-	case PARSE_VSP:
+	case PARSE_VIEWSPACE_HIERARCHY:
 		StartViewSpaceHierarchyElement(element, attributes);
 		break;
-	case PARSE_OSP:
+	case PARSE_OBJECTSPACE_HIERARCHY:
 		StartObjectSpaceHierarchyElement(element, attributes);
 		break;
@@ -484,5 +505,5 @@
 
 
-void ViewCellsParseHandlers::StartViewSpaceBox(AttributeList& attributes)
+void ViewCellsParseHandlers::StartViewSpaceHierarchy(AttributeList& attributes)
 {
 	int len = attributes.getLength();
@@ -496,5 +517,19 @@
 		const char *ptr = attrValue.LocalForm();
 
-		if (attrName == "min") 
+		// hierarchy type
+		if (attrName == "type")
+		{
+			if (strcmp(ptr, "bsp") == 0)
+			{
+				cout << "view space hierarchy: Bsp" << endl;
+				mViewSpaceHierarchyType = BSP;
+			}
+			else if (strcmp(ptr, "vsp") == 0)
+			{
+				Debug << "view space hierarchy: Vsp" << endl;
+				mViewSpaceHierarchyType = VSP;
+			}
+		}
+		else if (attrName == "min") // the view space extent
 		{
 			sscanf(ptr, "%f %f %f",
@@ -510,14 +545,14 @@
 	mViewSpaceBox = AxisAlignedBox3(bmin, bmax);
 
-	Debug << "\nview space box: " << mViewSpaceBox << endl;
-}
-
-
-void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes)
+	// create the hierarchy based on this information
+	CreateViewSpaceHierarchy();
+}
+
+
+void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes)
 {
 	int len = attributes.getLength();
 
 	Vector3 bmin, bmax;
-	int id;
 
 	for (int i = 0; i < len; ++ i) 
@@ -527,4 +562,36 @@
 		const char *ptr = attrValue.LocalForm();
 
+		// hierarchy type
+		if (attrName == "type")
+		{
+			if (strcmp(ptr, "bsp") == 0)
+			{
+				Debug << "view space hierarchy: Bsp" << endl;
+				mViewSpaceHierarchyType = BSP;
+			}
+			else if (strcmp(ptr, "vsp") == 0)
+			{
+				Debug << "view space hierarchy: Vsp" << endl;
+				mViewSpaceHierarchyType = VSP;
+			}
+		}
+	}
+}
+
+
+
+void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes)
+{
+	int len = attributes.getLength();
+
+	Vector3 bmin, bmax;
+	int id;
+
+	for (int i = 0; i < len; ++ i) 
+	{
+		string attrName(StrX(attributes.getName(i)).LocalForm());
+		StrX attrValue(attributes.getValue(i));
+		const char *ptr = attrValue.LocalForm();
+
 
 		if (attrName == "id")
@@ -532,14 +599,11 @@
 			sscanf(ptr, "%d", &id);
 		}
-
 		if (attrName == "min") 
 		{
-			sscanf(ptr, "%f %f %f",
-				   &bmin.x, &bmin.y, &bmin.z);
+			sscanf(ptr, "%f %f %f", &bmin.x, &bmin.y, &bmin.z);
 		}
 		else if (attrName == "max") 
 		{
-			sscanf(ptr, "%f %f %f",
-				   &bmax.x, &bmax.y, &bmax.z);
+			sscanf(ptr, "%f %f %f", &bmax.x, &bmax.y, &bmax.z);
 		}
 	}
@@ -547,6 +611,5 @@
 	AxisAlignedBox3 box(bmin, bmax);
 	mIBoundingBoxes.push_back(IndexedBoundingBox(id, box));
-
-	//Debug << "bbox: " << box << endl;
+	//cout << "bbox: " << box << endl;
 }
 
@@ -563,15 +626,9 @@
 	else
 	{
-		if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
-		{
-			mBspTree->mRoot = leaf;
-		}
-		else if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
-		{
-			mVspBspTree->mRoot = leaf;
-		}
+		mVspBspTree->mRoot = leaf;
 	}
 
 	//-- find associated view cell
+
 	int viewCellId;
 	
@@ -593,5 +650,5 @@
 
 	
-	if (viewCellId >= 0) // valid view cell
+	if (viewCellId >= 0) // valid view cell found
 	{
 		// TODO: get view cell with specified id
@@ -617,5 +674,5 @@
 	{
 		// add to invalid view space
-		if (mViewCellsManager->GetType() == ViewCellsManager::VSP_BSP)
+		if (mViewSpaceHierarchyType== ViewCellsManager::VSP_BSP)
 		{
 			leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
@@ -656,12 +713,5 @@
 	else
 	{
-		if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
-		{
-			mBspTree->mRoot = interior;
-		}
-		else
-		{
-			mVspBspTree->mRoot = interior;
-		}
+		mVspBspTree->mRoot = interior;
 	}
 
@@ -712,45 +762,61 @@
 
 
+void ViewCellsParseHandlers::CreateViewSpaceHierarchy()
+{
+	if (mViewSpaceHierarchyType == BSP)
+	{
+		cout << "hierarchy type: Bsp" << endl;
+
+		mVspBspTree = new VspBspTree();
+
+		// set view space box
+		mVspBspTree->mBox = mViewSpaceBox;
+	}
+	else if (mViewSpaceHierarchyType == VSP) 
+	{
+		cout << "hierarchy type: Vsp" << endl;
+
+		mVspTree = new VspTree();
+		// set view space box
+		mVspTree->mBoundingBox = mViewSpaceBox;
+	}
+	
+	cout << "\nview space box: " << mViewSpaceBox << endl;
+}
+
+
+void ViewCellsParseHandlers::CreateObjectSpaceHierarchy()
+{
+	if (mViewSpaceHierarchyType == OSP)
+	{
+		Debug << "object hierarchy type: Osp" << endl;
+
+		mOspTree = new OspTree();
+	}
+	else if (mViewSpaceHierarchyType == VSP) 
+	{
+		Debug << "object hierarchy type: Vsp" << endl;
+
+		mVspTree = new VspTree();
+	}
+}
+
 
 void ViewCellsParseHandlers::CreateViewCellsManager(/*const char *name*/)
 {
-	/*if (strcmp(name, "bsp") == 0)
-	{
-		Debug << "view cell type: Bsp" << endl;
-
-		mBspTree = new BspTree();
-		mBspTree->mBox = mViewSpaceBox;
-
-		mViewCellsManager = new BspViewCellsManager(mBspTree);
-	}*/
 	if (mViewSpaceHierarchyType == BSP) // 
 	{
-		Debug << "view cell type: VspBsp" << endl;
-
-		mVspBspTree = new VspBspTree();
-		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree);
-
-		mVspBspTree->mBox = mViewSpaceBox;
-		mVspBspTree->mRoot = mBspRoot;
+		Debug << "creating view cells manager: VspBsp" << endl;
+
+		//mVspBspTree = new VspBspTree();
+		mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree);
 	}
 	else if (mViewSpaceHierarchyType == VSP) 
 	{
-		Debug << "view cell type: Vsp" << endl;
-
-		mVspTree = new VspTree();
-
-		if (mObjectSpaceHierarchyType == OSP) 
-			mOspTree = new OspTree();
-		else
-			mBvHierarchy = new BvHierarchy();
+		Debug << "vcreating view cells manager: VsOspp" << endl;
 
 		// hack
-		mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree);
-
-		mVspTree->mBoundingBox = mViewSpaceBox;
-	}
-
-	mViewCellsTree = mViewCellsManager->GetViewCellsTree();
-	mViewCellsTree->mRoot = mViewCellRoot;
+		mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mVspTree, mOspTree);
+	}
 
 	mViewCellsManager->SetViewSpaceBox(mViewSpaceBox);
@@ -934,4 +1000,57 @@
 }
 
+
+void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes)
+{
+	KdLeaf * leaf = 
+		new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL);
+
+	if (mCurrentKdNode) // replace front or (if not NULL) back child
+	{
+		dynamic_cast<KdInterior *>(mCurrentKdNode)->ReplaceChildLink(NULL, leaf);
+	}
+	else
+	{
+		mOspTree->mRoot = leaf;
+	}
+}
+
+
+void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes)
+{
+	AxisAlignedPlane plane;
+	int len = attributes.getLength();
+
+	for (int i = 0; i < len; ++ i) 
+	{
+		string attrName(StrX(attributes.getName(i)).LocalForm());
+		StrX attrValue(attributes.getValue(i));
+		const char *ptr = attrValue.LocalForm();
+
+		if (attrName == "plane") 
+		{
+			sscanf(ptr, "%d %f",
+				   &plane.mAxis, &plane.mPosition);
+		}
+	}
+
+	KdInterior* interior = new KdInterior(NULL);
+	
+	interior->mAxis = plane.mAxis;
+	interior->mPosition = plane.mPosition;
+
+	if (mCurrentKdNode) // replace NULL child of parent with current node
+	{
+		KdInterior *parent = dynamic_cast<KdInterior *>(mCurrentKdNode);
+		parent->ReplaceChildLink(NULL, interior);
+		interior->mParent = parent;
+	}
+	else
+	{
+		mOspTree->mRoot = interior;
+	}
+
+	mCurrentKdNode = interior;
+}
 
 
@@ -1019,6 +1138,7 @@
     //    StdInInputSource src;
     try
-      {
+	{
 	const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
+
 #if USE_GZLIB
 	XMLCh *myFilePath = XMLString::transcode(filename.c_str());
@@ -1026,5 +1146,4 @@
 	GzFileInputSource isource(myFilePath);
 	parser->parse(isource);
-
 #else
 	parser->parse(filename.c_str());
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp	(revision 1259)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp	(revision 1264)
@@ -1080,6 +1080,4 @@
 	float nPosition[3];
 	float nCostRatio[3];
-	float nProbFront[3];
-	float nProbBack[3];
 
 	// create bounding box of node geometry
@@ -2533,5 +2531,4 @@
 	ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
 
-	//Debug << "here53 " << touchedViewCells.size() << endl;
 	for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
 	{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1264)
@@ -51,5 +51,5 @@
 	Vector3 origin, direction; 
 
-    const int i = (int)RandomValue(0, (int)mPreprocessor.mObjects.size() - 1);
+    const int i = (int)RandomValue(0, (Real)((int)mPreprocessor.mObjects.size() - 1));
 
 	Intersectable *object = mPreprocessor.mObjects[i];
Index: GTP/trunk/Lib/Vis/GtpVisibility.sln
===================================================================
--- GTP/trunk/Lib/Vis/GtpVisibility.sln	(revision 1251)
+++ GTP/trunk/Lib/Vis/GtpVisibility.sln	(revision 1264)
@@ -10,10 +10,11 @@
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IVReader", "OnlineCullingCHC\IVReader\src\IVReader.vcproj", "{7319E499-473D-4CE5-9983-725D6E68A55D}"
 	ProjectSection(ProjectDependencies) = postProject
+		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436} = {80DECC17-BDDD-4412-8CF8-F7C1C17A7436}
 	EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Plugin_VisibilitySceneManager", "OnlineCullingCHC\OGRE\src\Plugin_VisibilitySceneManager.vcproj", "{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}"
 	ProjectSection(ProjectDependencies) = postProject
+		{101A7691-74F3-48B4-96A3-CF35578F5900} = {101A7691-74F3-48B4-96A3-CF35578F5900}
 		{EABCE292-D598-4600-A1C9-2591E7D62FDA} = {EABCE292-D598-4600-A1C9-2591E7D62FDA}
-		{101A7691-74F3-48B4-96A3-CF35578F5900} = {101A7691-74F3-48B4-96A3-CF35578F5900}
 	EndProjectSection
 EndProject
@@ -30,5 +31,5 @@
 	ProjectSection(ProjectDependencies) = postProject
 		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436} = {80DECC17-BDDD-4412-8CF8-F7C1C17A7436}
-		{7319E499-473D-4CE5-9983-725D6E68A55D} = {7319E499-473D-4CE5-9983-725D6E68A55D}
+		{101A7691-74F3-48B4-96A3-CF35578F5900} = {101A7691-74F3-48B4-96A3-CF35578F5900}
 	EndProjectSection
 EndProject
@@ -36,5 +37,4 @@
 	ProjectSection(ProjectDependencies) = postProject
 		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436} = {80DECC17-BDDD-4412-8CF8-F7C1C17A7436}
-		{7319E499-473D-4CE5-9983-725D6E68A55D} = {7319E499-473D-4CE5-9983-725D6E68A55D}
 	EndProjectSection
 EndProject
