Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 133)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 135)
@@ -16,11 +16,18 @@
 
 
-String mCurrentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] = 
-{
-    "View Frustum Culling", 
+String currentAlgorithmCaptions[GtpVisibility::VisibilityEnvironment::NUM_CULLING_MANAGERS] = 
+{
+	"View Frustum Culling", 
 	"Stop and Wait Culling", 
 	"Coherent Hierarchical Culling"
 };
 
+String queryTypeCaptions[4] = 
+{
+	"from camera, visible pixels", 
+	"from viewpoint, visible pixels", 
+	"from camera, relative visibility",
+	"from viewpoint, relative visibility"
+};
 
 //-----------------------------------------------------------------------
@@ -73,9 +80,10 @@
 mVisualizeCulledNodes(false),
 mSunLight(sunLight),
-mShiftPressed(false)
+mShiftPressed(false),
+mShowQueryStats(false)
 {
 	//mInputDevice = PlatformManager::getSingleton().createInputReader();
-	
 	//mInputDevice->initialise(win, true, true);
+
 	mEventProcessor = new EventProcessor();
 	
@@ -94,5 +102,5 @@
 	mHelpOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/HelpOverlay"); 
 	mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
-
+	mQueryOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/QueryOverlay"); 
 
 	//-- visibility culling stats overlay
@@ -112,5 +120,5 @@
 	mQueriesIssuedInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/QueriesIssuedInfo");
 	
-	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mAlgorithmInfo->setCaption(": " + currentAlgorithmCaptions[mCurrentAlgorithm]);
 	mThresholdInfo->setCaption(": 0");
 	mFrustumCulledNodesInfo->setCaption(": 0");
@@ -124,4 +132,12 @@
 	mQueriesIssuedInfo->setCaption(": 0");
 
+
+	//-- visibility query stats overlay
+	mQueryTypeInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/QueryTypeInfo");
+	mQueryVisibleNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisibleNodesInfo");
+    mQueryVisibleGeometryInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/VisibleGeometryInfo");
+	mQueryNodeVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/NodeVisibilityInfo");
+	mQueryGeometryVisibilityInfo = OverlayManager::getSingleton().getOverlayElement("Example/Visibility/Query/GeometryVisibilityInfo");
+
 	// show stats overlays
 	showStats(true);
@@ -145,5 +161,5 @@
 	mSceneMgr->setOption("ShowVisualization", &mShowVisualization);
 
-	// TODO: change this
+	// TODO: change this (does not work with other scene manager plugins)
 	mVisibilityManager = dynamic_cast<VisibilityTerrainSceneManager *>(mSceneMgr)->
 		GetVisibilityManager();
@@ -155,6 +171,4 @@
 TerrainFrameListener::~TerrainFrameListener()
 {
-	//PlatformManager::getSingleton().destroyInputReader(mInputDevice);
-    
 	delete mRayQueryExecutor;
 	delete mEventProcessor;
@@ -182,5 +196,5 @@
 		 // Get results, create a node/entity on the position
 		 mCurrentObject = mTerrainContentGenerator->GenerateSceneObject(
-			 mouseRay.getOrigin(), Vector3::ZERO, "robot", false);
+			 mouseRay.getOrigin(), Vector3::ZERO, "robot");
 		
          mLMouseDown = true; 
@@ -341,4 +355,7 @@
 	if (fromPoint)
 	{
+		Vector3 point;
+		mVisibilityManager->GetQueryManager()->
+		ComputeFromPointVisibility(point, &visibleNodes, &visibleGeometry, relativeVisibility);
 	}
 	else
@@ -348,15 +365,60 @@
 	}
 
+	float averageNodeVis = 0;
+	float averageGeometryVis = 0;
+
 	for (int i=0; i < visibleGeometry.size(); ++i)
 	{
-		std::stringstream d; d << "Geometry visibility: " << visibleGeometry[i].GetVisibiliy();
+		averageGeometryVis += visibleGeometry[i].GetVisibility();
+
+		std::stringstream d; d << "Geometry visibility: " << visibleGeometry[i].GetVisibility();
 		LogManager::getSingleton().logMessage(d.str());
 	}
 	for (int i=0; i < visibleNodes.size(); ++i)
 	{
-		std::stringstream d; d << "Node visibility: " << visibleNodes[i].GetVisibiliy();
+		averageNodeVis += visibleNodes[i].GetVisibility();
+
+		std::stringstream d; d << "Node visibility: " << visibleNodes[i].GetVisibility();
 		LogManager::getSingleton().logMessage(d.str());
 	}
 
+	averageNodeVis /= (float)visibleNodes.size();
+	averageGeometryVis /= (float)visibleGeometry.size();
+
+	char str[100];
+
+	//-- update visibility queries stats
+    try 
+	{
+		//-- visibility queries stats
+		int idx = fromPoint ?  1 : 0;
+		idx += relativeVisibility ? 2 : 0;
+
+		sprintf(str, ": %s", queryTypeCaptions[idx].c_str()); 
+		mQueryTypeInfo->setCaption(str);
+
+		sprintf(str, ": %d", (int)visibleNodes.size()); 
+		mQueryVisibleNodesInfo->setCaption(str);
+	
+		sprintf(str,": %d", (int)visibleGeometry.size()); 
+		mQueryVisibleGeometryInfo->setCaption(str);
+		
+		sprintf(str,": %3.3f", averageNodeVis); 
+		mQueryNodeVisibilityInfo->setCaption(str);
+
+		sprintf(str,": %3.3f", averageGeometryVis); 
+		mQueryGeometryVisibilityInfo->setCaption(str);
+	}
+	catch (...)
+	{
+		// ignore
+	}
+
+	// show the results
+	if (!mShowQueryStats)
+	{
+		mQueryOverlay->show();
+		mShowQueryStats = true;
+	}
 }
 //-----------------------------------------------------------------------
@@ -399,5 +461,5 @@
 
 	it_end = mFrameInfo.end();
-	for(it = mFrameInfo.begin(); it < it_end; ++it)
+	for (it = mFrameInfo.begin(); it < it_end; ++it)
 	{
 		ofstr << StringConverter::toString((*it).position) << " " 
@@ -422,6 +484,6 @@
 		ifstr.getline(line, 256);
 		sscanf(line, "%f %f %f %f %f %f %f %f", &info.position.x, &info.position.y, &info.position.z,
-				&info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z,
-				&info.timeElapsed);
+			   &info.orientation.w, &info.orientation.x, &info.orientation.y, &info.orientation.z,
+			   &info.timeElapsed);
 		
 		mFrameInfo.push_back(info);
@@ -447,5 +509,5 @@
 		//-- write out stats for recorded walkthrough
 		std::stringstream d;
-		d << "Algorithm: " << mCurrentAlgorithmCaptions[mCurrentAlgorithm] << "\n"
+		d << "Algorithm: " << currentAlgorithmCaptions[mCurrentAlgorithm] << "\n"
 		  << "avg. FPS: " << mWindow->getAverageFPS() << "\n"
 		  << "best FPS: " << mWindow->getBestFPS() << "\n"
@@ -532,5 +594,5 @@
 void TerrainFrameListener::setAlgorithm(int algorithm)
 {
-	mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]);
+	mAlgorithmInfo->setCaption(": " + currentAlgorithmCaptions[mCurrentAlgorithm]);
 	mSceneMgr->setOption("Algorithm", &mCurrentAlgorithm);
 }
@@ -548,5 +610,6 @@
 
 	// update stats when necessary
-    try {
+    try 
+	{
 		OverlayElement* guiAvg = OverlayManager::getSingleton().getOverlayElement("Core/AverageFps");
 		OverlayElement* guiCurr = OverlayManager::getSingleton().getOverlayElement("Core/CurrFps");
@@ -591,7 +654,7 @@
 		mObjectsInfo->setCaption(str);
 	}
-	catch(...)
-	{
-            // ignore
+	catch (...)
+	{
+		// ignore
 	}
 }
@@ -787,5 +850,5 @@
 
 	case KC_LSHIFT:
-		mShiftPressed = !mShiftPressed;
+		mShiftPressed = true;
 		break;
 	//KEY_PRESSED(KC_F3, 0.3, writeFrames());
@@ -798,6 +861,6 @@
     {
         // Print camera details
-        mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + " " + 
-            "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
+        mWindow->setDebugText("P: " + StringConverter::toString(mCamera->getDerivedPosition()) + 
+			" " + "O: " + StringConverter::toString(mCamera->getDerivedOrientation()));
     }
 
@@ -809,4 +872,9 @@
 void TerrainFrameListener::keyReleased(KeyEvent* e)
 {
+	if (e->getKey() == KC_LSHIFT)
+	{
+		mShiftPressed = false;
+	}
+	
 	CEGUI::System::getSingleton().injectKeyUp(e->getKey());
 	e->consume();
@@ -867,19 +935,17 @@
 bool TerrainFrameListener::processUnbufferedKeyInput(const FrameEvent& evt)
 {
-	/*if (mInputDevice->isKeyDown(KC_ESCAPE))
-    {            
-        return false;
-    }*/
-
+	bool cursorPressed = false;
+	
 	/* Move camera forward by keypress. */
     if (mInputDevice->isKeyDown(KC_UP))
 	{
 		mTranslateVector.z = -mMoveScale;
-	}
-
+		cursorPressed = true;
+	}
     /* Move camera backward by keypress. */
     if (mInputDevice->isKeyDown(KC_DOWN))
     {
 		mTranslateVector.z = mMoveScale;
+		cursorPressed = true;
     }
 
@@ -887,4 +953,5 @@
     {
         mCamNode->yaw(-mRotScale);
+		cursorPressed = true;
     }
 	
@@ -892,4 +959,5 @@
     {
         mCamNode->yaw(mRotScale);
+		cursorPressed = true;
     }
 	// visualization camera
@@ -903,4 +971,10 @@
 	}
 
+	// show the results
+	if (cursorPressed && mShowQueryStats)
+	{
+		mQueryOverlay->hide();
+		mShowQueryStats = false;
+	}
 
     // Return true to continue rendering
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 133)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.cpp	(revision 135)
@@ -162,6 +162,6 @@
 	if (!mTerrainContentGenerator->LoadObjects("objects.out"))
 	{
-		// height is restricted to 50, so no objects appear on peaks 
-		// => there is much occlusion
+		// to provide much occlusion,
+		// height is restricted to 50, so no objects appear on peaks
 		mTerrainContentGenerator->SetMaxPos(Vector3(3000.0f, 50.0f, 3000.0f));
 		mTerrainContentGenerator->SetOffset(0);
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 133)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 135)
@@ -121,4 +121,6 @@
 	*/
 	void ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility);
+
+	void toggleShowQueryStats();
 
 protected:
@@ -156,4 +158,11 @@
 	OverlayElement *mObjectsInfo;
 	OverlayElement *mQueriesIssuedInfo;
+
+	OverlayElement *mQueryTypeInfo;
+	OverlayElement *mQueryVisibleNodesInfo;
+    OverlayElement *mQueryVisibleGeometryInfo;
+	OverlayElement *mQueryVisiblityInfo;
+	OverlayElement *mQueryNodeVisibilityInfo;
+	OverlayElement *mQueryGeometryVisibilityInfo;
 
 	RayQueryExecutor *mRayQueryExecutor;
@@ -173,5 +182,5 @@
 	bool mShutdownRequested;
 	bool mDisplayCameraDetails;
-
+	
 	Real mVizCameraHeight;
 
@@ -208,4 +217,5 @@
 	Overlay* mHelpOverlay;
 	Overlay* mCullStatsOverlay;
+	Overlay* mQueryOverlay;
 
 	Light *mSunLight;
@@ -214,4 +224,6 @@
 	
 	bool mShiftPressed;
+	bool mShowQueryStats;
+
 	//bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
 };
