Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 2360)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 2502)
@@ -253,5 +253,4 @@
 	/// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
 	bool mExecuteVertexProgramForAllPasses;
-
 	/// if hierarchical culling is currently in use
 	bool mIsHierarchicalCulling;
@@ -259,16 +258,13 @@
 	/// do we use preprocessed visibility
 	bool mViewCellsLoaded;
-
 	/// the view cells manager handling the preprocesor stuff
 	GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
-
-
 	/// Used to assign Ogre meshes to view cell entries.
 	GtpVisibilityPreprocessor::ObjectContainer mObjects;
 
-	GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
+	/// the currently visible view cell
 	GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
 
-	/// If view cells are used.
+	/// If view cells + PVS is used for rendering.
 	bool mUseViewCells;
 
@@ -276,7 +272,5 @@
 	bool mShowViewCells;
 
-	/// if the view cells are filtered
-	bool mUseVisibilityFilter;
-
+	/// if render queue should be flushed occasionally
 	bool mDeleteQueueAfterRendering;
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2455)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2502)
@@ -52,7 +52,5 @@
 mViewCellsLoaded(false),
 mUseViewCells(false),
-mUseVisibilityFilter(false),
 mCurrentViewCell(NULL),
-mElementaryViewCell(NULL),
 mDeleteQueueAfterRendering(true),
 mNormalExecution(false),
@@ -113,8 +111,5 @@
 {
 	CLEAR_CONTAINER(mObjects);
-
 	OGRE_DELETE(mHierarchyInterface);
-	OGRE_DELETE(mCurrentViewCell);
-
 	OGRE_DELETE(mObjReader);
 }
@@ -169,7 +164,4 @@
 	LoadScene(mFilename, mViewCellsFilename);
 	
-	// load view cells: load later ...
-	if (0) mViewCellsLoaded = LoadViewCells(mViewCellsFilename);
-
 	if (mShowTerrain)
 	{	
@@ -292,10 +284,10 @@
 		{
 			mShowTerrain = true;
-			LogManager::getSingleton().logMessage("loading terrain");
+			LogManager::getSingleton().logMessage("scene: loading terrain");
 		}
 		else
 		{
 			mShowTerrain = false;
-			LogManager::getSingleton().logMessage("loading geometry");
+			LogManager::getSingleton().logMessage("scene: loading geometry");
 		}
 	}
@@ -564,5 +556,5 @@
 {
 	GtpVisibilityPreprocessor::ObjectPvsIterator pit = 
-			mCurrentViewCell->GetPvs().GetIterator();
+		mCurrentViewCell->GetPvs().GetIterator();
 
 	while (pit.HasMoreEntries())
@@ -587,5 +579,6 @@
 //-----------------------------------------------------------------------
 void OcclusionCullingSceneManager::ShowViewCellsGeometry()
-{/*
+{
+#if TODO
 	// show only current view cell
 	if (!mShowViewCells)
@@ -607,5 +600,6 @@
 				(*mit).second->_updateRenderQueue(getRenderQueue());
 		}	
-	}*/
+	}
+#endif
 }
 //-----------------------------------------------------------------------
@@ -697,5 +691,5 @@
 	{
 		// show current view cell geometry
-		if (mCurrentViewCell)// && mCurrentViewCell->GetMesh())
+		if (mCurrentViewCell)
 		{
 			//const bool showSingleViewCell = true;
@@ -882,5 +876,4 @@
 		mVisible.clear();
 		mBoxes.clear();
-
 		// clear render queue before depth pass
 		getRenderQueue()->clear();
@@ -1122,31 +1115,27 @@
 	}
 	if (key == "UseViewCells")
-	{ 	
-		if (!mViewCellsLoaded)
-		{
+	{
+		bool useViewCells = *static_cast<const bool *>(val);
+
+		if (useViewCells && !mViewCellsLoaded)
+		{		
 			// try to load view cells
 			mViewCellsLoaded = LoadViewCells(mViewCellsFilename);	
-		}
-
-		if (!mViewCellsLoaded)
-			return false;
 		
+			if (!mViewCellsLoaded)
+				// something went wrong => bail out
+				return false;
+		}
+
 		// only use this option if view cells are available
-		mUseViewCells = *static_cast<const bool *>(val);
-
-		// reset view cell
-		OGRE_DELETE(mCurrentViewCell);
-			
-		if (mUseViewCells)
-		{
-			mCurrentViewCell = mViewCellsManager->GenerateViewCell();
-		}
-		
-		// view cell corresponding to leaf in the view cell hierarchy
-		mElementaryViewCell = NULL;
-
-		// all objects are set to invisible per default
-		SetObjectsVisible(!mUseViewCells);
-
+		mUseViewCells = useViewCells;
+
+		// reset current view cell
+		mCurrentViewCell = NULL;
+
+		// if we don't use the view cells, all objects are set to invisible per default
+		//SetObjectsVisible(!mUseViewCells);
+
+		// note: this sets the objects invisible which are not in the pvs ...
 		MovableObjectIterator movit = getMovableObjectIterator("Entity");
 		while (movit.hasMoreElements())
@@ -1181,17 +1170,7 @@
 		return true;
 	}
-	if (key == "UseVisibilityFilter")
-	{
-		mUseVisibilityFilter = *static_cast<const bool *>(val);
-
-		// set null => recomputation of the pvs
-        mElementaryViewCell = NULL;
-
-		return true;
-	}
 	if (key == "UseVisibilityQueries")
 	{
 		mUseVisibilityQueries = *static_cast<const bool *>(val);
-
 		return true;
 	}
@@ -1199,5 +1178,4 @@
 	{
 		mUseFromPointQueries = *static_cast<const bool *>(val);
-
 		return true;
 	}
@@ -1205,5 +1183,4 @@
 	{
 		mQueryMode = *static_cast<const int *>(val);
-
 		return true;
 	}
@@ -1689,11 +1666,6 @@
 {
 	GtpVisibilityPreprocessor::ObjectContainer::iterator it, it_end = mObjects.end();
-
 	for (it = mObjects.begin(); it != it_end; ++ it)
-	{
-		GtpVisibilityPreprocessor::Intersectable *entry = *it;
-
-		SetObjectVisible(entry, visible);
-	}
+		SetObjectVisible(*it, visible);
 }
 //-----------------------------------------------------------------------
@@ -1717,15 +1689,13 @@
 	mViewCellsManager = 
 		GtpVisibilityPreprocessor::ViewCellsManager::
-			LoadViewCells(filename, mObjects, false, &bconverter);
+			LoadViewCells(filename, mObjects, finalizeViewCells, &bconverter);
 	
 	LogManager::getSingleton().logMessage("******** view cells loaded *********");
 
 	// objects are set to invisible initially
-	SetObjectsVisible(false);
+	//SetObjectsVisible(false);
 
 	if (finalizeViewCells)
-	{
 		CreateViewCellsGeometry();
-	}
 
 	return (mViewCellsManager != NULL);
@@ -1733,11 +1703,10 @@
 //-------------------------------------------------------------------------
 void OcclusionCullingSceneManager::ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, 
-													const bool load)
+													const bool loadObjects)
 {	
-	// NOTE: should not encounter NULL view cell, 
 	// rather apply view cell representing unbounded space then
 	if (!vc) 
 	{	
-		LogManager::getSingleton().logMessage("error: should not come here");
+		LogManager::getSingleton().logMessage("no view cell or outside of view space, setting everything to invisible");
 		// question: if no view cell, set everything visible?
 		SetObjectsVisible(false);
@@ -1746,5 +1715,5 @@
 		
 	////////////
-	//-- set PVS of view cell to visible
+	//-- set view cell PVS to visible
 
 	GtpVisibilityPreprocessor::ObjectPvsIterator pit = vc->GetPvs().GetIterator();
@@ -1753,9 +1722,7 @@
 	{		
 		GtpVisibilityPreprocessor::Intersectable *obj = pit.Next();
-
 		// no associated geometry found
 		if (!obj) continue;
-	
-		SetObjectVisible(obj, load);
+		SetObjectVisible(obj, loadObjects);
 	}
 }
@@ -1769,52 +1736,19 @@
 		OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition());
 
-	GtpVisibilityPreprocessor::ViewCell *newElementary = 
+	GtpVisibilityPreprocessor::ViewCell *viewCell = 
 		mViewCellsManager->GetViewCell(viewPoint);
 
-	// elementary view cell did not change => don't change pvs
-	if (mElementaryViewCell == newElementary)
+	// view cell did not change => don't change pvs
+	if (mCurrentViewCell == viewCell)
 		return;
 
-	mElementaryViewCell = newElementary;
-	
 
 	//////////////
-	//-- unload old pvs
+	//-- unload old pvs and load new pvs
 
 	ApplyViewCellPvs(mCurrentViewCell, false);
 
-	// the new view cell
-	GtpVisibilityPreprocessor::ViewCell *viewCell;
-		
-	if (mUseVisibilityFilter)
-	{	
-		////////////
-		//-- compute new filtered cell
-
-		GtpVisibilityPreprocessor::PrVs prvs;
-		mViewCellsManager->GetPrVS(viewPoint, prvs, 5);
-		viewCell = prvs.mViewCell;
-	}
-	else
-	{
-		viewCell = newElementary;
-	}
-
-	///////////////
-	//-- load new pvs
-
-	ApplyViewCellPvs(viewCell, true);
-
-	if (viewCell)
-	{
-		// store current view cell
-		mCurrentViewCell->SetPvs(viewCell->GetPvs());
-		mCurrentViewCell->SetMesh(viewCell->GetMesh());
-		mCurrentViewCell->SetId(viewCell->GetId());
-
-		// delete merge tree of filtered view cell
-		if (mUseVisibilityFilter)
-			mViewCellsManager->DeleteLocalMergeTree(viewCell);
-	}
+	mCurrentViewCell = viewCell;
+	ApplyViewCellPvs(mCurrentViewCell, true);
 }
 //-------------------------------------------------------------------------
@@ -2089,5 +2023,5 @@
 												bool includeOverlays)
 {
-	if (mNormalExecution)
+	if (0 && mNormalExecution)
 	{
 		TerrainSceneManager::_renderScene(camera, vp, includeOverlays);
@@ -2318,6 +2252,6 @@
 		std::stringstream d; 
 		d << "Query mode: " << queryModes 
-		  << " visible nodes: " << (int)visibleNodes.size() 
-		  << " visible geometry: " << (int)visibleGeometry.size();
+		  << ", visible nodes: " << (int)visibleNodes.size() 
+		  << ", visible geometry: " << (int)visibleGeometry.size();
 
 		LogManager::getSingleton().logMessage(d.str());
@@ -2545,5 +2479,5 @@
 													   bool onlyShadowCasters)										 
 {
-	if (mNormalExecution || (!mUseVisibilityQueries == 0))
+	if (mNormalExecution || !mUseVisibilityQueries)
 	{
 		TerrainSceneManager::_findVisibleObjects(cam, onlyShadowCasters);
@@ -2567,9 +2501,10 @@
 	int queryModes = 0;
 
-	if (mQueryMode != 0)
+	if (mQueryMode != EXACT_QUERIES)
 	{
 		queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY;
 
-		if (mQueryMode == 2)
+		// approximate visibility not for exact queries
+		if (mQueryMode == APPROXIMATE_QUERIES)
 			approximateVisibility = true;
 	}
@@ -2611,5 +2546,5 @@
 	}
 		
-	if (0)
+	if (1)
 	{
 		std::stringstream d; 
