Index: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp	(revision 901)
+++ GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp	(revision 924)
@@ -81,4 +81,7 @@
 	
 std::ofstream video_out("video.lst");
+
+// if we are recording a demo
+static const bool DEMO_HACK = false;
 
 //-----------------------------------------------------------------------
@@ -111,4 +114,5 @@
 #else
 mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::FRUSTUM_CULLING),
+//mCurrentAlgorithm(GtpVisibility::VisibilityEnvironment::STOP_AND_WAIT_CULLING),
 #endif
 mNodeVizMode(NODEVIZ_NONE),
@@ -194,17 +198,17 @@
 	mMyStatsFpsInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/MyFpsInfo");
 	mMyStatsFpsInfo->setCaption(str);
+	
 	//mMyStatsAlgorithmInfo->setTop(top);
-
-	//mMyStatsOverlay->show();
-
-	if (1)
-	{
-		initVisStatsOverlay(); // visibility stats overlay
-		initHelpOverlay();     // help overlay
-		initQueryOverlay();    // visibility query stats overlay
-	
-		// show stats overlays
+	
+	initVisStatsOverlay(); // visibility stats overlay
+	initHelpOverlay();     // help overlay
+	initQueryOverlay();    // visibility query stats overlay
+	
+	// show stats overlays
+	if (!DEMO_HACK)
 		showStats(true);
-	}
+	else
+		mMyStatsOverlay->show();
+
 
 	// note: larger magnification for terrain to show single objects
@@ -216,7 +220,6 @@
 	// the scale factor for the visualized bounding boxes
 	mSceneMgr->setOption("NodeVizScale", &mVizScale);
-	
-
-	// set culling algorithm type
+		
+	//-- set culling algorithm type
 	setAlgorithm(mCurrentAlgorithm);
 
@@ -236,7 +239,9 @@
 	mTimeFrameEnded = mTimeFrameStarted = mTimer->getMilliseconds();
 	
-	if (0 && (mSceneMgr->getSceneNode("robot Entity1Node")->getAttachedObject(0)->getMovableType() == "Entity"))
+	if (0 && (mSceneMgr->getSceneNode("robot Entity1Node")->
+		getAttachedObject(0)->getMovableType() == "Entity"))
 		Ogre::LogManager::getSingleton().logMessage("found entity");
-	
+
+	// init view cell parameters
 	mSceneMgr->setOption("UseViewCells", &mUseViewCells);
 	mSceneMgr->setOption("UseVisibilityFilter", &mUseVisibilityFilter);
@@ -244,4 +249,5 @@
 	// reset statistics
 	mWalkthroughStats.Reset();
+
 }
 //-----------------------------------------------------------------------
@@ -508,8 +514,4 @@
 												bool useItemBuffer)
 {
-	// TODO: change this (does not work with other scene manager plugins)
-	VisibilityTerrainSceneManager *sm = 
-		dynamic_cast<VisibilityTerrainSceneManager *>(mSceneMgr);
-
 	int itemBufferMode = useItemBuffer ? mItemBufferMode : 0;
 	
@@ -518,11 +520,22 @@
 	queryModes |= GtpVisibility::QueryManager::GEOMETRY_VISIBILITY;
 	queryModes |= GtpVisibility::QueryManager::NODE_VISIBILITY;
-	
-	mQueryManager = new OcclusionQueriesQueryManager(sm->GetHierarchyInterface(),
+
+	// no visibility manager available => no visibility scene manager, return
+	GtpVisibility::VisibilityManager *visManager;
+	
+	if (!mSceneMgr->getOption("VisibilityManager", visManager))
+		return;
+
+	GtpVisibility::HierarchyInterface *hierarchyInterface;
+	if (!mSceneMgr->getOption("HierarchyInterface", hierarchyInterface))
+		return;
+
+	mQueryManager = new OcclusionQueriesQueryManager(hierarchyInterface,
 			mWindow->getViewport(0), queryModes, itemBufferMode);
 
 	//mQueryManager = new PlatformQueryManager(sm->GetHierarchyInterface(),	mWindow->getViewport(0), false);
-	
-	sm->GetVisibilityManager()->SetQueryManager(mQueryManager);
+
+
+	visManager->SetQueryManager(mQueryManager);
 
 	GtpVisibility::NodeInfoContainer visibleNodes;
@@ -553,4 +566,7 @@
 	float averageNodeVis = 0, averageGeometryVis = 0, averagePatchVis = 0;
 	int geomSize = 0, nodesSize = 0, patchSize = 0;
+
+	///////////////////////////////////////////////////////////////////////////
+	//-- apply queries on geometry level
 
 	GtpVisibility::MeshInfoContainer::iterator geomIt, geomIt_end = visibleGeometry.end();
@@ -574,4 +590,10 @@
 	}
 
+
+
+	///////////////////////////////////////////////////////////////////////////
+	//-- apply queries on node level
+
+
 	GtpVisibility::NodeInfoContainer::iterator nodesIt, nodesIt_end = visibleNodes.end();
 
@@ -592,4 +614,9 @@
 	}
 
+
+	///////////////////////////////////////////////////////////////////////////
+	//-- apply queries on patch level
+
+
 	GtpVisibility::PatchInfoContainer::iterator patchIt, patchIt_end = visiblePatches.end();
 
@@ -609,4 +636,7 @@
 		}	
 	}
+
+	///////////////////////////////////////////////////////////////
+	//-- update visibility queries stats
 
 	if (nodesSize)
@@ -617,5 +647,5 @@
 		averagePatchVis /= (float)patchSize;
 
-	//-- update visibility queries stats
+
     try 
 	{
@@ -955,4 +985,6 @@
 	mAlgorithmInfo->setCaption(": " + msAlgorithmCaptions[mCurrentAlgorithm]);
 	mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
+	std::stringstream d; d << "algorithm: " << msAlgorithmCaptions[mCurrentAlgorithm];
+	if (1) Ogre::LogManager::getSingleton().logMessage(d.str());
 }
 //-----------------------------------------------------------------------
@@ -1029,8 +1061,11 @@
 		}
 
-		/*std::stringstream d;
-		d << "fps: " << StringConverter::toString(currentFps) << ", "
-		  << "avg fps: " << StringConverter::toString(avgFps);
-		LogManager::getSingleton().logMessage(d.str());*/
+		if (0)
+		{
+			std::stringstream d;
+			d << "fps: " << StringConverter::toString(currentFps) << ", "
+			  << "avg fps: " << StringConverter::toString(avgFps);
+			LogManager::getSingleton().logMessage(d.str());
+		}
 
 		//guiAvg->setCaption(avgFps + StringConverter::toString(stats.avgFPS));
Index: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp	(revision 901)
+++ GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp	(revision 924)
@@ -12,5 +12,5 @@
 #include "TestCullingTerrainApplication.h"
 #include "TerrainFrameListener.h"
-//#include "OgreVisibilityOctreeSceneManager.h"
+//#include "OgreOcclusionCullingSceneManager.h"
 
 #include "IVReader.h"
@@ -21,5 +21,6 @@
 const static bool USE_STATIC_GEOMETRY = false;
 bool TestCullingTerrainApplication::msShowHillyTerrain = false;
-//bool TestCullingTerrainApplication::msShowHillyTerrain = true;
+
+
 
 /******************************************************/
@@ -163,4 +164,34 @@
 {
 }
+//-------------------------------------------------------------------------
+void TestCullingTerrainApplication::loadConfig(const String& filename)
+{
+	// TODO matt
+	// Set up the options
+	ConfigFile config;
+	String val;
+
+	config.load(filename);
+
+	std::stringstream d; d << "reading config from: " << filename;
+	LogManager::getSingleton().logMessage(d.str());
+
+	val = config.getSetting("Scene");
+
+    if (!val.empty())
+	{
+		 mFilename = val.c_str();
+
+		 std::stringstream d; d << "filename: " << mFilename;
+		 LogManager::getSingleton().logMessage(d.str());
+	}
+
+/*	val = config.getSetting("ViewCells");
+
+	if (!val.empty())
+	{
+		 mViewCellsFilename = val.c_str();
+	}*/
+}
 //-----------------------------------------------------------------------
 TestCullingTerrainApplication::~TestCullingTerrainApplication()
@@ -235,147 +266,29 @@
 }
 //-----------------------------------------------------------------------
-void TestCullingTerrainApplication::LoadWorldGeometry()
+bool TestCullingTerrainApplication::LoadSceneIV(const String &filename, 
+												SceneNode *root, 
+												const int index)
 {
 	mIVReader = new IVReader();
 
-	// _MAX_PATH is the maximum length allowed for a path
-	char currentPath[_MAX_PATH];
-	// use the function to get the path
-	getcwd(currentPath, _MAX_PATH);
-	
-
-	// $$matt TODO; use relatrive path
-	std::stringstream d;
-	d << "current path: " << currentPath;
-	Ogre::LogManager::getSingleton().logMessage(d.str());
-
-	String path = "E:/svn/gametools/OGRE/trunk/resources/";
-	
-
-/*	SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
-		
-	SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2");
-	SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3");
-	SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node4");
-	SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node5");
-	SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node6");
-	SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node7");
-
-
-
-	node2->translate(Vector3(-400, 0, 750));
-	node3->scale(Vector3(100, 100 ,100));
-	node3->pitch(Radian(3 * Math::HALF_PI));
-	node4->translate(Vector3(-100, 0, 0));
-	node5->translate(Vector3(0, 300, 0));
-	
-	node6->scale(Vector3(100, 100 ,100));
-	node6->pitch(Radian(3 * Math::HALF_PI));
-	node6->roll(Radian(Math::HALF_PI));
-	node6->translate(Vector3(0, -100, 0));
-
-	node7->scale(Vector3(100, 100 ,100)); 
-	node7->pitch(Radian(3 * Math::HALF_PI));
-	node7->roll(Radian(Math::HALF_PI));
-	node7->translate(Vector3(100, 0, 0));
-	
-	*/
-
-	Log *log = LogManager::getSingleton().createLog("IVLog.log");
-	mIVReader->setLog(log);
-
-
-
-#if 0
-	//String fileName = path + "media\\simple_geom.wrl";
-	String fileName = path + "media\\city.wrl";
-    //String fileName = path + "media\\house_test1.iv";
-	mCamNode->setPosition(Vector3(-6, 0.5, 10));
-	//mCamNode->setPosition(Vector3(412, 7.4, -667));
-	mCamNode->setOrientation(Quaternion(-0.95, 0, 0.3, 0));
-
-	if (0 && mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node1);
-	}
-	
-	String fileName = path + "media\\house_test1.iv";
-
-	if (0 && mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node1);
-		mIVReader->buildTree(mSceneMgr, node2);
-	}
-
-	if (0 && mIVReader->loadFile("media\\anhk.wrl"))
-	{
-		mIVReader->buildTree(mSceneMgr, node3);
-	}
-	if (0 && mIVReader->loadFile("media\\ant.wrl"))
-	{
-		mIVReader->buildTree(mSceneMgr, node4);
-	}
-	if (0 && mIVReader->loadFile("media\\zepplin0.wrl"))
-	{
-		mIVReader->buildTree(mSceneMgr, node5);
-	}
-	if (0 && mIVReader->loadFile("media\\warbird.wrl"))
-	{
-		mIVReader->buildTree(mSceneMgr, node6);
-	}
-	if (0 && mIVReader->loadFile("media\\z_wing.wrl"))
-	{
-		mIVReader->buildTree(mSceneMgr, node7);
-	}
-
-#endif
-	
-#if 1
-	//-- load vienna model
-
-	SceneNode *roofsNode = NULL;
-	SceneNode *viennaNode = NULL;
-	SceneNode *roadsNode = NULL;
-	SceneNode *planeNode = NULL;
-	SceneNode *wallsNode = NULL;
-
-	viennaNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Vienna");
-
-	mCamNode->setPosition(Vector3(830, 300, -540));
-	mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+	if (1)
+	{
+		std::string logFilename = "IVLog" + index;
+		logFilename += ".log";
+
+		Log *log = LogManager::getSingleton().createLog(logFilename);
+		mIVReader->setLog(log);
+	}
 	
 	//viennaNode->translate(Vector3(-300, -300, 0));
 
-	String fileName = path + "media\\city1500_flat_1.iv";
-
-	if (0 && mIVReader->loadFile(fileName.c_str()))
-	{
-		wallsNode = viennaNode->createChildSceneNode("Walls");
-		mIVReader->buildTree(mSceneMgr, wallsNode);
-	}
-
-
-	fileName = path + "media\\roofs_1500.iv";
-	if (1 && mIVReader->loadFile(fileName.c_str()))
-	{
-		roofsNode = viennaNode->createChildSceneNode("Roofs");
-		mIVReader->buildTree(mSceneMgr, roofsNode);	
-	}
-    
-	fileName = path + "media\\CityRoads60.iv";
-	if (0 && mIVReader->loadFile(fileName.c_str()))
-	{
-		roadsNode = viennaNode->createChildSceneNode("Roads");
-		mIVReader->buildTree(mSceneMgr, roadsNode);	
-	}
-
-	fileName = path + "media\\CityPlane60.iv";
-    if (0 && mIVReader->loadFile(fileName.c_str()))
-	{
-		planeNode = viennaNode->createChildSceneNode("Plane");
-		mIVReader->buildTree(mSceneMgr, planeNode);		
-	}
-	
-#endif
+	if (mIVReader->loadFile(filename.c_str()))
+	{
+		SceneNode *node = root->createChildSceneNode("IVSceneNode" + index);
+
+		mIVReader->buildTree(mSceneMgr, node);
+		//OGRE_DELETE(mIVReader);
+		return true;
+	}
 
 	mIVReader->collapse();
@@ -386,4 +299,8 @@
 		BakeSceneIntoStaticGeometry("staticVienna", "Vienna");
 	}
+	
+	OGRE_DELETE(mIVReader);
+
+	return false;
 }
 //--------------------------------------------------------
@@ -411,6 +328,6 @@
 	
 	//roofsNode->detachAllObjects();
-//roadsNode->detachAllObjects();
-//	planeNode->detachAllObjects();
+	//roadsNode->detachAllObjects();
+	//	planeNode->detachAllObjects();
 	
 	//viennaNode->removeChild("Walls");
@@ -421,6 +338,15 @@
 void TestCullingTerrainApplication::createScene()
 {
-	if (!msShowHillyTerrain)
-		LoadWorldGeometry();
+	//-- load scene
+
+	//GtpVisibility::VisibilityManager *mVisManager;
+	//if (!mSceneMgr->getOption("VisibilityManager", mVisManager))	return;
+	//const std::string filename = visEnv->getSceneFilename();
+	loadConfig("test.cfg");
+	LoadScene(mFilename);
+
+
+
+	/////////////////////////////////////
 
 	// Set ambient light
@@ -471,8 +397,12 @@
 	if (0)
 	{
-		Plane plane; plane.normal = Vector3::UNIT_Y;	plane.d = -60;
+		Plane plane; 
+		plane.normal = Vector3::UNIT_Y;	
+		plane.d = -60;
+
 		MeshManager::getSingleton().createPlane("Myplane",
 			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
 			5000,5000,100,100,true,1,5,5,Vector3::UNIT_Z);
+
 		Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
 		pPlaneEnt->setMaterialName("Examples/Rockwall");
@@ -511,12 +441,14 @@
 	}
 
-	// HACK: load the view cells from the disc
-	//(dynamic_cast<VisibilityOctreeSceneManager *>(mSceneMgr))->LoadViewCells("");
-
+
+
+	//-- HACK: load the view cells from the disc
+	
 	//std::string filename = "vienna_simple-21-04-avs2-viewCells.xml";
 	//std::string filename = "vienna_simple-21-04-kdcasm-viewCells.xml";
 	std::string filename = "vienna_simple-21-04-avs-viewCells.xml";
 
-	mSceneMgr->setOption("LoadViewCells", filename.c_str());
+	//-- the actual loading happens here
+	if (0) mSceneMgr->setOption("LoadViewCells", filename.c_str());
 }
 //-----------------------------------------------------------------------
@@ -620,10 +552,12 @@
 	{
 		//mSceneMgr = mRoot->createSceneManager("VisibilityTerrainSceneManager");
-		mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
+		//mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
+		mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
 	}
 	else
-	{	
-		mSceneMgr = mRoot->createSceneManager("VisibilityOctreeSceneManager");
+	{	//mSceneMgr = mRoot->createSceneManager("VisibilityTerrainSceneManager");
+    	//mSceneMgr = mRoot->createSceneManager("VisibilityOctreeSceneManager");
 		//mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
+		mSceneMgr = mRoot->createSceneManager("OcclusionCullingSceneManager");
 	}
 
@@ -666,5 +600,6 @@
 				mCamNode->getPosition().z);
 	
-			/*std::stringstream d;
+			/*
+			std::stringstream d;
 			d << "World: " << it->movable->getWorldBoundingBox().getCenter().y <<
 			", Object: " << it->movable->getBoundingBox().getCenter().y <<
@@ -683,4 +618,88 @@
 }
 
+//-----------------------------------------------------------------------
+// splits strings containing multiple file names
+static int SplitFilenames(const std::string str, std::vector<std::string> &filenames)
+{
+	int pos = 0;
+
+	while(1) 
+	{
+		int npos = (int)str.find(';', pos);
+		
+		if (npos < 0 || npos - pos < 1)
+			break;
+		filenames.push_back(std::string(str, pos, npos - pos));
+		pos = npos + 1;
+	}
+	
+	filenames.push_back(std::string(str, pos, str.size() - pos));
+	return (int)filenames.size();
+}
+
+//-----------------------------------------------------------------------
+bool TestCullingTerrainApplication::LoadScene(const std::string filename)
+{
+	using namespace std;
+	// use leaf nodes of the original spatial hierarchy as occludees
+	vector<string> filenames;
+	int files = SplitFilenames(filename, filenames);
+	
+	std::stringstream d;
+	d << "number of input files: " << files << "\n";
+	LogManager::getSingleton().logMessage(d.str());
+
+	bool result = false;
+	vector<string>::const_iterator fit, fit_end = filenames.end();
+	int i = 0;
+	// root for different files
+	for (fit = filenames.begin(); fit != fit_end; ++ fit, ++ i)
+	{
+		const string fn = *fit;
+
+		if (strstr(fn.c_str(), ".iv") || strstr(fn.c_str(), ".wrl"))
+		{
+			// hack: set postion manually for vienna
+			mCamNode->setPosition(Vector3(830, 300, -540));
+			mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
+
+			// load iv files
+			LoadSceneIV(fn, mSceneMgr->getRootSceneNode(), i);			
+		}
+		else if (strstr(filename.c_str(), ".collada"))
+		{
+			// load collada files
+		}
+		else if (filename == "terrain")
+		{
+			// terrain hack
+			msShowHillyTerrain = true;
+			LogManager::getSingleton().logMessage("loading terrain");
+		}
+	
+		result = true;
+	}
+	
+
+	/*
+	if (result) 
+	{
+		int intersectables, faces;
+
+	  std::stringstream d;
+	  d << filename << " parsed successfully.\n"
+		<< "#NUM_OBJECTS (Total numner of objects)\n" << intersectables << "\n"
+		<< "#NUM_FACES (Total numner of faces)\n" << faces << "\n";
+	}
+	*/
+	
+	return result;
+}
+//-----------------------------------------------------------------------
+bool TestCullingTerrainApplication::LoadViewCells(const std::string filename)
+{
+
+	return true;
+}
 
 
Index: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h
===================================================================
--- GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h	(revision 915)
+++ GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h	(revision 924)
@@ -124,8 +124,15 @@
 	bool Clamp2FloorPlane();
 
-	/** Loads world geometry.
+	/** Loads iv geometry.
 	*/
-	void LoadWorldGeometry();
+	bool LoadSceneIV(const String &filename, SceneNode *root, const int index);
 
+	bool LoadScene(const std::string filename);
+
+	bool LoadViewCells(const std::string filename);
+
+	/** Loads configuration from disc.
+	*/
+	void loadConfig(const String& filename);
 	// if hilly terrain should be loaded
 	static bool msShowHillyTerrain;
@@ -176,4 +183,8 @@
 	
 	StaticGeometry *mStaticGeometry;
+
+	String mFilename;
+	//String mViewCellsFilename;
+
 private:
 	void chooseSceneManager(void);
