Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp	(revision 867)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.cpp	(revision 901)
@@ -155,5 +155,7 @@
 mSavePrecomputedFps(false),
 mUseBufferedInputMouse(false),
-mVizScale(25)
+mVizScale(25),
+mUseViewCells(false),
+mUseVisibilityFilter(false)
 {
 	//mInputDevice = PlatformManager::getSingleton().createInputReader();
@@ -206,5 +208,5 @@
 	}
 
-	// larger magnification for terrain
+	// note: larger magnification for terrain to show single objects
 	if (TestCullingTerrainApplication::msShowHillyTerrain)
 		mVizScale = 25;
@@ -237,5 +239,7 @@
 		Ogre::LogManager::getSingleton().logMessage("found entity");
 	
-	
+	mSceneMgr->setOption("UseViewCells", &mUseViewCells);
+	mSceneMgr->setOption("UseVisibilityFilter", &mUseVisibilityFilter);
+
 	// reset statistics
 	mWalkthroughStats.Reset();
@@ -1118,4 +1122,16 @@
 }
 //-----------------------------------------------------------------------
+void TerrainFrameListener::toggleUseViewCells()
+{
+	mUseViewCells = !mUseViewCells;
+	mSceneMgr->setOption("UseViewCells", &mUseViewCells);
+}
+//-----------------------------------------------------------------------
+void TerrainFrameListener::toggleUseVisibilityFilter()
+{
+	mUseVisibilityFilter = !mUseVisibilityFilter;
+	mSceneMgr->setOption("UseVisibilityFilter", &mUseVisibilityFilter);
+}
+//-----------------------------------------------------------------------
 void TerrainFrameListener::toggleUseDepthPass()
 {
@@ -1336,4 +1352,10 @@
 		switchMouseMode();
 		break;
+	case KC_V:
+		toggleUseViewCells();
+		break;
+	case KC_Q:
+		toggleUseVisibilityFilter();
+		break;
 	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
 	//KEY_PRESSED(KC_F4, 0.3, loadFrames());
@@ -1525,4 +1547,5 @@
 void TerrainFrameListener::nextSceneDetailLevel()
 {
+#if OGRE_103
 	mSceneDetailIndex = (mSceneDetailIndex + 1) % 3;
 	switch (mSceneDetailIndex) 
@@ -1538,4 +1561,5 @@
 			break;
 	}
+#endif
 }
 //-----------------------------------------------------------------------
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp	(revision 866)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.cpp	(revision 901)
@@ -5,5 +5,5 @@
 #include <../CEGUIRenderer/include/OgreCEGUITexture.h>
 #include <OgreMemoryMacros.h>
-
+#include <OgreIteratorWrappers.h>
 #include <Ogre.h>
 #include <direct.h> // for getcwd
@@ -12,4 +12,5 @@
 #include "TestCullingTerrainApplication.h"
 #include "TerrainFrameListener.h"
+//#include "OgreVisibilityOctreeSceneManager.h"
 
 #include "IVReader.h"
@@ -18,6 +19,7 @@
 #include <windows.h>
 
-
+const static bool USE_STATIC_GEOMETRY = false;
 bool TestCullingTerrainApplication::msShowHillyTerrain = false;
+//bool TestCullingTerrainApplication::msShowHillyTerrain = true;
 
 /******************************************************/
@@ -52,4 +54,5 @@
 		mAnimationState->setEnabled(true);
 	}
+
 	mTimeElapsed = Math::RangeRandom(1, 5);
 }
@@ -155,5 +158,7 @@
 
 TestCullingTerrainApplication::TestCullingTerrainApplication():
-mTerrainContentGenerator(NULL), mRayQueryExecutor(NULL)
+mTerrainContentGenerator(NULL), 
+mRayQueryExecutor(NULL),
+mIVReader(NULL)
 {
 }
@@ -188,18 +193,10 @@
 	*	because then the camera is displayed correctly in the visualization
 	*/
-	if (msShowHillyTerrain)
-	{
-		mCamNode = mSceneMgr->getRootSceneNode()->
+	mCamNode = mSceneMgr->getRootSceneNode()->
 		createChildSceneNode("CamNode1", Vector3(707, 5000, 528));
-	}
-	else
-	{
-		mCamNode = mSceneMgr->getRootSceneNode()->
-			createChildSceneNode("CamNode1", Vector3(0, -100, -200));
-	}
-
+	
 	mCamNode->setOrientation(Quaternion(-0.3486, 0.0122, 0.9365, 0.0329));
 	mCamNode->attachObject(mCamera);
-
+	
 	//-- create visualization camera
 	mVizCamera = mSceneMgr->createCamera("VizCam");
@@ -246,12 +243,16 @@
 	// use the function to get the path
 	getcwd(currentPath, _MAX_PATH);
+	
+
+	// $$matt TODO; use relatrive path
 	std::stringstream d;
 	d << "current path: " << currentPath;
-//E:\ogre_versions\ogre-win32-v1-0-3p1\ogrenew\Samples\Common\bin\Release
 	Ogre::LogManager::getSingleton().logMessage(d.str());
-	//String path = "E:/svn/gametools/trunk/VUT/Ogre/resources/";
+
 	String path = "E:/svn/gametools/OGRE/trunk/resources/";
 	
-	SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
+
+/*	SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
+		
 	SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2");
 	SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3");
@@ -260,9 +261,7 @@
 	SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node6");
 	SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node7");
-	SceneNode *node8 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node8");
-	SceneNode *node9 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node9");
-
-
-	node1->translate(Vector3(-500, 0, 750));
+
+
+
 	node2->translate(Vector3(-400, 0, 750));
 	node3->scale(Vector3(100, 100 ,100));
@@ -281,12 +280,27 @@
 	node7->translate(Vector3(100, 0, 0));
 	
-	node8->translate(Vector3(-300, -300, 0));
+	*/
 
 	Log *log = LogManager::getSingleton().createLog("IVLog.log");
 	mIVReader->setLog(log);
-#if 1
+
+
+
+#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 (mIVReader->loadFile(fileName.c_str()))
+	if (0 && mIVReader->loadFile(fileName.c_str()))
 	{
 		mIVReader->buildTree(mSceneMgr, node1);
@@ -294,61 +308,115 @@
 	}
 
-	/*if (mIVReader->loadFile("media\\anhk.wrl"))
+	if (0 && mIVReader->loadFile("media\\anhk.wrl"))
 	{
 		mIVReader->buildTree(mSceneMgr, node3);
 	}
-	if (mIVReader->loadFile("media\\ant.wrl"))
+	if (0 && mIVReader->loadFile("media\\ant.wrl"))
 	{
 		mIVReader->buildTree(mSceneMgr, node4);
 	}
-	if (mIVReader->loadFile("media\\zepplin0.wrl"))
+	if (0 && mIVReader->loadFile("media\\zepplin0.wrl"))
 	{
 		mIVReader->buildTree(mSceneMgr, node5);
 	}
-	if (mIVReader->loadFile("media\\warbird.wrl"))
+	if (0 && mIVReader->loadFile("media\\warbird.wrl"))
 	{
 		mIVReader->buildTree(mSceneMgr, node6);
 	}
-	if (mIVReader->loadFile("media\\z_wing.wrl"))
+	if (0 && mIVReader->loadFile("media\\z_wing.wrl"))
 	{
 		mIVReader->buildTree(mSceneMgr, node7);
-	}*/
-#else
-	
+	}
+
+#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));
+	
+	//viennaNode->translate(Vector3(-300, -300, 0));
+
 	String fileName = path + "media\\city1500_flat_1.iv";
-	
-	if (mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node8);
-	}
+
+	if (0 && mIVReader->loadFile(fileName.c_str()))
+	{
+		wallsNode = viennaNode->createChildSceneNode("Walls");
+		mIVReader->buildTree(mSceneMgr, wallsNode);
+	}
+
 
 	fileName = path + "media\\roofs_1500.iv";
-	if (mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node8);
-	}
-
+	if (1 && mIVReader->loadFile(fileName.c_str()))
+	{
+		roofsNode = viennaNode->createChildSceneNode("Roofs");
+		mIVReader->buildTree(mSceneMgr, roofsNode);	
+	}
+    
 	fileName = path + "media\\CityRoads60.iv";
-	if (mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node8);
+	if (0 && mIVReader->loadFile(fileName.c_str()))
+	{
+		roadsNode = viennaNode->createChildSceneNode("Roads");
+		mIVReader->buildTree(mSceneMgr, roadsNode);	
 	}
 
 	fileName = path + "media\\CityPlane60.iv";
-    if (mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node8);
-	}
-	
-	fileName = path + "media\\test.iv";
-	if (mIVReader->loadFile(fileName.c_str()))
-	{
-		mIVReader->buildTree(mSceneMgr, node9);
-	}
+    if (0 && mIVReader->loadFile(fileName.c_str()))
+	{
+		planeNode = viennaNode->createChildSceneNode("Plane");
+		mIVReader->buildTree(mSceneMgr, planeNode);		
+	}
+	
 #endif
+
 	mIVReader->collapse();
-}
-
-//-----------------------------------------------------------------------
+
+	//-- bake into static geometry
+	if (USE_STATIC_GEOMETRY)
+	{
+		BakeSceneIntoStaticGeometry("staticVienna", "Vienna");
+	}
+}
+//--------------------------------------------------------
+void TestCullingTerrainApplication::BakeSceneIntoStaticGeometry(const String &staticGeomName, 
+																const String &nodeName)
+{
+#if OGRE_103
+	// note: different static geom for roofs, roads, ..., becazse they have same material
+	StaticGeometry *staticGeom = mSceneMgr->createStaticGeometry(staticGeomName);
+
+	// note: looping over entities here. why does scene node not work?
+	SceneManager::EntityIterator it = mSceneMgr->getEntityIterator();
+	while (it.hasMoreElements())
+	{
+		Entity *ent = it.getNext();
+		ent->setVisible(false);
+		staticGeom->addEntity(ent, ent->getParentSceneNode()->getPosition());
+	}
+
+	staticGeom->setRegionDimensions(Vector3(100,100,100));
+	staticGeom->build();
+
+	// cleanup node
+	//wallsNode->detachAllObjects();
+	
+	//roofsNode->detachAllObjects();
+//roadsNode->detachAllObjects();
+//	planeNode->detachAllObjects();
+	
+	//viennaNode->removeChild("Walls");
+	mSceneMgr->destroySceneNode(nodeName);
+#endif
+}
+//--------------------------------------------------------
 void TestCullingTerrainApplication::createScene()
 {
@@ -400,13 +468,16 @@
 	setupGui();
 
-	/* // occluder plane to test visibility
-	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");
-	pPlaneEnt->setCastShadows(true);
-	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);	*/
+	// occluder plane to test visibility
+	if (0)
+	{
+		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");
+		pPlaneEnt->setCastShadows(true);
+		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
+	}
 
 	// Warning: In GL since we can't go higher than the window res
@@ -439,4 +510,13 @@
 		if (0) generateScene(100, 2); // create ninjas
 	}
+
+	// HACK: load the view cells from the disc
+	//(dynamic_cast<VisibilityOctreeSceneManager *>(mSceneMgr))->LoadViewCells("");
+
+	//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());
 }
 //-----------------------------------------------------------------------
@@ -498,6 +578,11 @@
 void TestCullingTerrainApplication::setupGui()
 {
+#if OGRE103
 	 mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, 
 		 false, 3000, ST_EXTERIOR_CLOSE);
+#else
+	  mGUIRenderer = new CEGUI::OgreCEGUIRenderer(mWindow, Ogre::RENDER_QUEUE_OVERLAY, 
+		 false, 3000, mSceneMgr);
+#endif
      mGUISystem = new CEGUI::System(mGUIRenderer);
 
@@ -521,4 +606,5 @@
 void TestCullingTerrainApplication::chooseSceneManager()
 {
+#ifdef OGRE_103
 	if (msShowHillyTerrain)
 	{
@@ -530,4 +616,17 @@
 		mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
 	}
+#else
+	if (msShowHillyTerrain)
+	{
+		//mSceneMgr = mRoot->createSceneManager("VisibilityTerrainSceneManager");
+		mSceneMgr = mRoot->createSceneManager("TerrainSceneManager");
+	}
+	else
+	{	
+		mSceneMgr = mRoot->createSceneManager("VisibilityOctreeSceneManager");
+		//mSceneMgr = mRoot->createSceneManager("OctreeSceneManager");
+	}
+
+#endif
 }
 //-----------------------------------------------------------------------
@@ -587,5 +686,5 @@
 
 /**********************************************************************/
-/*            VisualizationRenderTargetListener implementation        */
+/*           VisualizationRenderTargetListener implementation         */
 /**********************************************************************/
 
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h	(revision 867)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h	(revision 901)
@@ -213,4 +213,10 @@
 	*/
 	void toggleShowOctree();
+	/** Toggles between view cells / no view cells.
+	*/
+	void toggleUseViewCells();
+
+	void toggleUseVisibilityFilter();
+
 	/** Toggles whether we use the initial depth pass.
 	*/
@@ -422,5 +428,8 @@
 
 	bool mUseBufferedInputMouse;
-	Matrix4 rotMatrix;
+	
+	bool mUseViewCells;
+
+	bool mUseVisibilityFilter;
 };
 
Index: /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h	(revision 866)
+++ /GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TestCullingTerrainApplication.h	(revision 901)
@@ -142,4 +142,7 @@
 	virtual void createRenderTargetListener();
 
+	void BakeSceneIntoStaticGeometry(const String &staticGeomName,
+									 const String &nodeName);
+
 	std::vector<EntityState *> mEntityStates;
 
@@ -171,5 +174,6 @@
 
 	IVReader *mIVReader;
-
+	
+	StaticGeometry *mStaticGeometry;
 private:
 	void chooseSceneManager(void);
