Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 2069)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 2097)
@@ -180,16 +180,17 @@
 {
 	list<SceneNode *> sceneNodeList;
-			
+
 	// find intersecting scene nodes to get candidates for intersection
     // note: this function has to be provided by scene manager
+
 #if ENLARGE_NODE_BBOX
 	// make search radius larger
-	AxisAlignedBox mybox = EnlargeBox(box);
-	mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
+	AxisAlignedBox largebox = EnlargeBox(box);
+	mSceneMgr->findNodesIn(largebox, sceneNodeList, NULL);
 
 	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
 
 	GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = 
-		OgreTypeConverter::ConvertFromOgre(mybox);
+		OgreTypeConverter::ConvertFromOgre(largebox);
 #else
 
@@ -201,5 +202,5 @@
 		OgreTypeConverter::ConvertFromOgre(box);
 #endif
-	
+
 	// loop through the intersected scene nodes
 	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
@@ -233,4 +234,5 @@
 	}
 }
+
 #if USE_KD_PVS
 //-------------------------------------------------------------------------
@@ -255,4 +257,5 @@
 		EngineIntersectable *entry = 
 			new EngineIntersectable(entryObjects);
+
 		entry->SetId((*iit).first);
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 2066)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 2097)
@@ -364,6 +364,8 @@
 	else if (strKey == "UseViewCells")
 	{ 
+			Ogre::LogManager::getSingleton().logMessage("here44");
 		if (mViewCellsLoaded)
 		{
+				Ogre::LogManager::getSingleton().logMessage("here99");
 			mUseViewCells = *static_cast<const bool *>(pValue);
 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2067)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2097)
@@ -136,5 +136,5 @@
 													const String& typeName)
 {
-    // Clear out any existing world resources (if not default)
+	// Clear out any existing world resources (if not default)
     if (ResourceGroupManager::getSingleton().getWorldResourceGroupName() != 
         ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
@@ -150,11 +150,12 @@
     loadConfig(stream);
 
-	// apply parameters for file loading
-
-	// loas the scene
+	//////////////
+	// file loading
+
+	// load the scene
 	LoadScene(mFilename);
-
+	
 	// load view cells
-	mViewCellsLoaded = LoadViewCells(mViewCellsFilename);
+	//mViewCellsLoaded = LoadViewCells(mViewCellsFilename);
 
 	if (mShowTerrain)
@@ -170,5 +171,5 @@
 		maxAxis = std::max(maxAxis, max_z);
 		//resize(AxisAlignedBox( 0, 0, 0, maxAxis, maxAxis, maxAxis));
-		resize( AxisAlignedBox( 0, 0, 0, max_x, max_y, max_z ) );
+		resize(AxisAlignedBox( 0, 0, 0, max_x, max_y, max_z ));
 
 		setupTerrainMaterial();
@@ -177,4 +178,5 @@
  }
 #endif
+
 //-------------------------------------------------------------------------
 void OcclusionCullingSceneManager::loadConfig(DataStreamPtr& stream)
@@ -211,5 +213,5 @@
 		{
 			mShowTerrain = true;
-			LogManager::getSingleton().logMessage("creating terrain");
+			LogManager::getSingleton().logMessage("loading terrain");
 		}
 	}
@@ -221,10 +223,8 @@
 		if (!val.empty())
 		{
-			mViewCellsFilename = val.c_str();
-			d << "view cells file name: " << mViewCellsFilename;
-			LogManager::getSingleton().logMessage(d.str());
-		}
-	}
-	
+			mViewCellsFilename = val;
+		}
+	}
+
 	val = config.getSetting("OnlineCullingAlgorithm");
 		
@@ -262,5 +262,5 @@
 	}
 
-	/////////////////////////////////////////
+	/////////////
 	// terrain options
 
@@ -268,16 +268,16 @@
 		return;
 
-	val = config.getSetting( "DetailTile" );
-	if ( !val.empty() )
+	val = config.getSetting("DetailTile");
+	if (!val.empty())
 		setDetailTextureRepeat(atoi(val.c_str()));
 
-	val = config.getSetting( "MaxMipMapLevel" );
-	if ( !val.empty() )
-		setMaxGeoMipMapLevel(atoi( val.c_str() ));
-
-
-	val = config.getSetting( "PageSize" );
-	if ( !val.empty() )
-		setPageSize(atoi( val.c_str() ));
+	val = config.getSetting("MaxMipMapLevel");
+	if (!val.empty())
+		setMaxGeoMipMapLevel(atoi(val.c_str()));
+
+
+	val = config.getSetting("PageSize");
+	if (!val.empty())
+		setPageSize(atoi(val.c_str()));
 	else
 		OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSize'",
@@ -285,7 +285,7 @@
 
 
-	val = config.getSetting( "TileSize" );
-	if ( !val.empty() )
-		setTileSize(atoi( val.c_str() ));
+	val = config.getSetting("TileSize");
+	if (!val.empty())
+		setTileSize(atoi(val.c_str()));
 	else
 		OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'TileSize'",
@@ -472,11 +472,10 @@
 					for (eit = entries->begin(); eit != eit_end; ++ eit)
 					{
-						//OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*eit);
+					
 						Entity *ent = *eit;
 						Any newAny = ent->getUserAny();
 
 						int flt = any_cast<int>(newAny);
-						//std::stringstream d; d << "any: " << flt << " ";
-						//Ogre::LogManager::getSingleton().logMessage(d.str());
+					
 						if (any_cast<int>(newAny) == 0)
 						{
@@ -485,5 +484,4 @@
 						}
 
-						//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
 					}
 				}
@@ -883,32 +881,39 @@
 	}
 	if (key == "UseViewCells")
-	{ 
+	{ 	
+		if (!mViewCellsLoaded)
+		{
+			// try ro loaded view cells
+			mViewCellsLoaded = LoadViewCells(mViewCellsFilename);	
+		}
+
+		if (!mViewCellsLoaded)
+			return false;
+		
 		// only use this option if view cells are available
-		if (mViewCellsLoaded)
-		{
-			mUseViewCells = *static_cast<const bool *>(val);
-
-			// reset view cell
-			OGRE_DELETE(mCurrentViewCell);
+
+		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;
-
-			// if we decide use view cells
-			// all objects are set to invisible per default
-			SetObjectsVisible(!mUseViewCells);
-
-			MovableObjectIterator movit = getMovableObjectIterator("Entity");
-			while (movit.hasMoreElements())
-			{
-				Entity *ent = static_cast<Entity *>(movit.getNext());
-				ent->setVisible(!mUseViewCells);
-			}
-		}
-
+		if (mUseViewCells)
+		{
+			mCurrentViewCell = mViewCellsManager->GenerateViewCell();
+		}
+		
+		// view cell corresponding to leaf in the view cell hierarchy
+		mElementaryViewCell = NULL;
+
+		// with view cells all objects are set to invisible per default
+		SetObjectsVisible(!mUseViewCells);
+
+		MovableObjectIterator movit = getMovableObjectIterator("Entity");
+		while (movit.hasMoreElements())
+		{
+			Entity *ent = static_cast<Entity *>(movit.getNext());
+			ent->setVisible(!mUseViewCells);
+		}
+		
 		return true;
 	}
@@ -1422,7 +1427,9 @@
 bool OcclusionCullingSceneManager::LoadViewCells(const String &filename)
 {
+	// no filename specified
 	if (filename == "")
 		return false;
 
+	// view cells already loaded
 	if (mViewCellsLoaded) 
 		return true;
@@ -1432,5 +1439,5 @@
 
 	// load the view cells assigning the found objects to the pvss
-	const bool finalizeViewCells = true;
+	const bool finalizeViewCells = false;
 
 	mViewCellsManager = GtpVisibilityPreprocessor::
@@ -1439,4 +1446,6 @@
 										true, 
 										&bconverter);
+	
+	Ogre::LogManager::getSingleton().logMessage("*******************");
 
 	// objects are set to invisible initially
@@ -1453,9 +1462,11 @@
 void OcclusionCullingSceneManager::ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, 
 													const bool load)
-{	// NOTE: should not encounter NULL view cell, 
+{	
+	// NOTE: should not encounter NULL view cell, 
 	// rather apply view cell representing unbounded space then
 	if (!vc) 
 	{	
-		// if no there is no view cell, set everything visible
+		LogManager::getSingleton().logMessage("error: should not come here");
+		// question: if no view cell, set everything visible?
 		//SetObjectsVisible(true);
 		SetObjectsVisible(false);
@@ -1467,4 +1478,7 @@
 	////////////
 	//-- set PVS of view cell to visible
+
+	std::stringstream d; d << "appying new view cell pvs: " << vc->GetPvs().GetSize();
+	LogManager::getSingleton().logMessage(d.str());
 
 	while (pit.HasMoreEntries())
@@ -1482,14 +1496,10 @@
 					OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
 					omi->GetEntity()->setVisible(load);
-					//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
-				}
+				}				
 				break;
 			case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
 				{
-					//GtpVisibilityPreprocessor::EngineIntersectable *oi = 
-					//	static_cast<GtpVisibilityPreprocessor::EngineIntersectable *>(entry);
 					EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
 
-					//GtpVisibilityPreprocessor::ObjectContainer *entries = oi->GetItem();
 					EntityContainer *entries = oi->GetItem();
 
@@ -1498,9 +1508,6 @@
 					for (eit = entries->begin(); eit != eit_end; ++ eit)
 					{
-						//OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(*eit);
-						//omi->GetEntity()->setVisible(load);
 						Entity *ent = *eit;
 						ent->setVisible(load);					
-						//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
 					}
 				}
@@ -1520,8 +1527,11 @@
 		OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition());
 
+	//std::stringstream d; d << "vp: " << viewPoint;
+	//LogManager::getSingleton().logMessage(d.str());
+
 	GtpVisibilityPreprocessor::ViewCell *newElementary = 
 		mViewCellsManager->GetViewCell(viewPoint);
 
-	// elementary view cell did not change => apply same pvs
+	// elementary view cell did not change => don't change pvs
 	if (mElementaryViewCell == newElementary)
 		return;
@@ -1557,7 +1567,7 @@
 	ApplyViewCellPvs(viewCell, true);
 
-	// store pvs
 	if (viewCell)
 	{
+		// store current view cell
 		mCurrentViewCell->SetPvs(viewCell->GetPvs());
 		mCurrentViewCell->SetMesh(viewCell->GetMesh());
@@ -1691,5 +1701,5 @@
 		return false;
 	}
-
+/*
 	for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
 	{
@@ -1709,5 +1719,5 @@
 		result = true;
 	}
-	
+*/	result=true;
 	return result;
 }
@@ -1771,5 +1781,6 @@
 		const String& instanceName)
 {
-	OcclusionCullingSceneManager* tsm = new OcclusionCullingSceneManager(instanceName, visManager);
+	OcclusionCullingSceneManager* tsm = 
+		new OcclusionCullingSceneManager(instanceName, visManager);
 	
 	// Create & register default sources (one per manager)
