Index: GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp
===================================================================
--- GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp	(revision 1285)
+++ GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp	(revision 1296)
@@ -113,4 +113,7 @@
 mTopCamFollow(true),
 mShowTree(SHOWTREE_OFF),
+// view cells
+mUseViewCells(false),
+mUseVisibilityFilter(false),
 //counters
 mSeqNum(0),
@@ -164,4 +167,7 @@
 	mCamNode = sm->getSceneNode("PlayerCamNode");
 
+	sm->getOption("UseViewCells", &mUseViewCells);
+	sm->getOption("UseVisibilityFilter", &mUseVisibilityFilter);
+
 	mRaySceneQuery = mSceneMgr->createRayQuery(Ray(mCamNode->getPosition(), Vector3::NEGATIVE_UNIT_Y));
 
@@ -248,5 +254,5 @@
 
 	String ext = "KdTree/";
-	String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC, sEV;
+	String sMD, sKT, sKI, sHL, sBM, sRM, sFM, sTC, sEV, sVC, sVF;
 
 	int maxd;
@@ -319,4 +325,28 @@
 	else
 		sTC = ": Free";
+
+	if (mSceneMgr->getOption("UseViewCells", &mUseViewCells))
+	{
+		if (mUseViewCells)
+			sVC = ": on";
+		else
+			sVC = ": off";
+	}
+	else
+	{
+		sVC = NA;
+	}
+
+	if (mSceneMgr->getOption("UseVisibilityFilter", &mUseVisibilityFilter))
+	{
+		if (mUseVisibilityFilter)
+			sVF = ": on";
+		else
+			sVF = ": off";
+	}
+	else
+	{
+		sVF = NA;
+	}
 
 	initOverlayElement(&mRenderMethodInfo, ext, "RenderMethod", top, sRM); top += vert_space;
@@ -329,4 +359,6 @@
 	initOverlayElement(&mMovementInfo, ext, "Movement", top, sFM); top += vert_space;
 	initOverlayElement(&mTopCamInfo, ext, "TopCam", top, sTC); top += vert_space;
+	initOverlayElement(&mViewCellsInfo, ext, "ViewCells", top, sVC); top += vert_space;
+	initOverlayElement(&mViewFilterInfo, ext, "ViewFilter", top, sVF); top += vert_space;
 
 	OverlayElement *visPanel = OverlayManager::getSingleton().
@@ -350,4 +382,36 @@
 			mKdTreeOverlay->hide();
 		}
+	}
+}
+
+void KdTreeAppListener::toggleUseViewCells()
+{
+	mUseViewCells = !mUseViewCells;
+	if (mSceneMgr->setOption("UseViewCells", &mUseViewCells))
+	{
+		if (mUseViewCells)
+			mViewCellsInfo->setCaption(": on");
+		else
+			mViewCellsInfo->setCaption(": off");
+	}
+	else
+	{
+		mViewCellsInfo->setCaption(NA);
+	}
+}
+
+void KdTreeAppListener::toggleUseVisibilityFilter()
+{
+	mUseVisibilityFilter = !mUseVisibilityFilter;
+	if (mSceneMgr->setOption("UseVisibilityFilter", &mUseVisibilityFilter))
+	{
+		if (mUseVisibilityFilter)
+			mViewFilterInfo->setCaption(": on");
+		else
+			mViewFilterInfo->setCaption(": off");
+	}
+	else
+	{
+		mViewFilterInfo->setCaption(NA);
 	}
 }
@@ -442,4 +506,6 @@
 			else
 				mEnhancedVisInfo->setCaption(": Simple");
+
+			mOptions.mEnhancedVisibility = mode;
 		}
 	}
@@ -458,5 +524,8 @@
 		bm = (bm + 1) % KdTree::KDBM_SIZE;
 		if (mSceneMgr->setOption("BuildMethod", &bm))
+		{
 			mBuildMethodInfo->setCaption(": " + BUILDMETHODCAPTION[bm]);
+			mOptions.mBuildMethod = bm;
+		}
 	}
 	else
@@ -474,5 +543,8 @@
 		rm = (rm + 1) % KdTree::KDRM_SIZE;
 		if (mSceneMgr->setOption("RenderMethod", &rm))
+		{
 			mRenderMethodInfo->setCaption(": " + RENDERMETHODCAPTION[rm]);
+			mOptions.mRenderMethod = rm;
+		}
 	}
 	else
@@ -553,4 +625,42 @@
 	}
 
+	if (mInputDevice->isKeyDown(KC_F8) && mTimeUntilNextToggle <= 0)
+	{
+		// fill scene only once (for now), stop if anchor node exists
+		try
+		{
+			SceneNode *entnode = mSceneMgr->getSceneNode("AnchorNode");
+		}
+		catch (Exception)
+		{
+			// read interesting params from config file
+			ConfigFile terrainconf;
+			std::stringstream s;
+			Real x,y,z;
+			
+			terrainconf.load("terrain.cfg");
+
+			s << terrainconf.getSetting("PageWorldX");
+			s >> x;
+			s.clear();
+
+			s << terrainconf.getSetting("MaxHeight");
+			s >> y;
+			s.clear();
+
+			s << terrainconf.getSetting("PageWorldZ");
+			s >> z;
+			s.clear();
+
+			mOptions.myApp->createTerrainScene(x, y * 0.3, z);
+
+			// rebuild tree
+			mSceneMgr->setOption("RebuildKdTree", 0);
+		}
+
+		mTimeUntilNextToggle = 0.5;
+	}
+
+
 	if (mInputDevice->isKeyDown(KC_F9) && mTimeUntilNextToggle <= 0)
 	{
@@ -571,7 +681,13 @@
 	}
 
-	if (mInputDevice->isKeyDown(KC_V) && mTimeUntilNextToggle <= 0)
-	{
-		toggleEnhancedVisibility();
+	if (mInputDevice->isKeyDown(KC_C) && mTimeUntilNextToggle <= 0)
+	{
+		toggleUseViewCells();
+		mTimeUntilNextToggle = 0.5;
+	}
+
+	if (mInputDevice->isKeyDown(KC_X) && mTimeUntilNextToggle <= 0)
+	{
+		toggleUseVisibilityFilter();
 		mTimeUntilNextToggle = 0.5;
 	}
@@ -982,5 +1098,5 @@
 	if (!mFreeMove)
 	{
-		if (mOptions.mSceneFiles == TERRAIN_SCENE)
+		if (mOptions.mSceneType == ST_TERRAIN)
 		{
 			static Vector3 pos;
@@ -1155,5 +1271,8 @@
 			{
 				saveLog();
-				return false;
+				if (mOptions.mBurnIn)
+					togglePlayback();
+				else
+					return false;
 			}
 		}
@@ -1344,4 +1463,5 @@
 		mDemoStats.mEllapsedTime = 0.0f;
 		mDemoStats.mTotalEllapsedTime = 0.0f;
+		mDemoFPS.clear();
 	}
 	// stop playback
@@ -1597,10 +1717,21 @@
 		if (mOptions.mSceneManager == SM_KDT || mOptions.mSceneManager == SM_KTE)
 		{
-			logwrite << ds << RENDERMETHOD[mOptions.mRenderMethod] << ds << mOptions.mMaxDepth << ds 
-				<< mOptions.mKT << ds << mOptions.mKI;
+			// info about enhanced visibility if internal rendering
+			String senhvis;
+			if (mOptions.mRenderMethod == KdTree::KDRM_INTERNAL)
+			{
+				if (mOptions.mEnhancedVisibility)
+					senhvis = "E" + ds;
+				else
+					senhvis = "S" + ds;
+			}
+
+			logwrite << ds << RENDERMETHOD[mOptions.mRenderMethod] << ds << senhvis << 
+				mOptions.mMaxDepth << ds << mOptions.mKT << ds << mOptions.mKI << ds << 
+				BUILDMETHOD[mOptions.mBuildMethod];
 		}
 		else if (mOptions.mSceneManager == SM_OCM && mOptions.mRenderMethod != KdTree::KDRM_INTERNAL)
 		{
-			logwrite << ds << RENDERMETHOD[(mOptions.mRenderMethod+3)%3];
+			logwrite << ds << RENDERMETHOD[CONV_OCM_TO_KDT_ALG(mOptions.mRenderMethod)];
 		}
 		logwrite << "\"" << fs;
