Index: trunk/VUT/GtpVisibility/include/QueryManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/QueryManager.h	(revision 130)
+++ trunk/VUT/GtpVisibility/include/QueryManager.h	(revision 143)
@@ -41,5 +41,5 @@
 	If NULL no visible meshes are not evaluated.
 
-	@param relativeVisibility If true the visibility member for
+	@param projectedPixels If true the visibility member for
 	NodeInfo and MeshInfo represent relative visibility; i.e. the number of visible
 	pixels divided by the the number of projected pixels.
@@ -51,5 +51,5 @@
 			    InfoContainer<NodeInfo> *visibleNodes,
 			    InfoContainer<MeshInfo> *visibleGeometry,
-			    bool relativeVisibility = false
+			    bool projectedPixels = false
 			    ) = 0;
     
@@ -62,5 +62,5 @@
 			       InfoContainer<NodeInfo> *visibleNodes,
 			       InfoContainer<MeshInfo> *visibleGeometry,
-			       bool relativeVisibility = false
+			       bool projectedPixels = false
 			       ) = 0;
     
Index: trunk/VUT/GtpVisibility/include/VisibilityInfo.h
===================================================================
--- trunk/VUT/GtpVisibility/include/VisibilityInfo.h	(revision 141)
+++ trunk/VUT/GtpVisibility/include/VisibilityInfo.h	(revision 143)
@@ -14,11 +14,18 @@
 {
 public:
-    NodeInfo(HierarchyNode *node,const float v): mNode(node), mVisibility(v) {}
+    NodeInfo(HierarchyNode *node, const int projectedPixels, const int visiblePixels): 
+	mNode(node)//, mProjectedPixels(projectedPixels), mVisiblePixels(visiblePixels) 
+	{}
 
-	float GetVisibility() const {return mVisibility;}
-	void SetVisibility(float vis) { mVisibility = vis;}
-	bool operator<(const NodeInfo& rhs) const {return mNode < rhs.mNode;}
-	//bool operator>(const NodeInfo& rhs) const {return mNode > rhs.mNode;}
-	//bool operator==(const NodeInfo& rhs) const {return mNode == rhs.mNode;}
+	int GetVisiblePixels() const {return mVisiblePixels;}
+	int GetProjectedPixels() const {return mProjectedPixels;}
+
+	void SetVisiblePixels(int vis) {mVisiblePixels = vis;}
+	void SetProjectedPixels(int vis) {mProjectedPixels = vis;}
+
+	void SetNode(HierarchyNode *node) {mNode = node;}
+	HierarchyNode *GetNode() const {return mNode;}
+
+	//bool operator<(const NodeInfo& rhs) const {return mNode < rhs.mNode;}
 
 protected:
@@ -26,8 +33,7 @@
     /** pointer to the scene node */
     HierarchyNode *mNode;
-    /** node visibility can either be a number of visible pixels or relative
-	number of visible pixels (if the hardware queries will provide the
-	total number of ratsterized pixels */
-    float mVisibility;
+    
+    int mVisiblePixels;
+	int mProjectedPixels;
 };
   
@@ -37,8 +43,16 @@
 {
 public:
-	MeshInfo(Mesh *mesh, const float v): mMesh(mesh), mVisibility(v) {}
+	MeshInfo(Mesh *mesh,  const int projectedPixels, const int visiblePixels): 
+	mMesh(mesh), mProjectedPixels(projectedPixels), mVisiblePixels(visiblePixels) 
+	{}
 
-	float GetVisibility() const {return mVisibility;}
-	void SetVisibility(float vis) { mVisibility = vis;}
+	int GetVisiblePixels() const {return mVisiblePixels;}
+	int GetProjectedPixels() const {return mProjectedPixels;}
+
+	void SetVisiblePixels(float vis) { mVisiblePixels = vis;}
+	void SetProjectedPixels(float vis) { mProjectedPixels = vis;}
+
+	Mesh *GetMesh() const {return mMesh;}
+	void SetMesh(Mesh *mesh) {mMesh = mesh;}
 
 	bool operator<(const MeshInfo& rhs) const {return mMesh < rhs.mMesh;}
@@ -51,14 +65,12 @@
 	*/
     Mesh *mMesh;
-    /** Node visibility can either be a number of visible pixels or relative
-	number of visible pixels (if the hardware queries will provide the
-	total number of ratsterized pixels.
-	*/
-    float mVisibility;
+  
+    int mVisiblePixels;
+	int mProjectedPixels;
 };
   
 //TODO: this define shall be replaced by template typedef
-//#define InfoContainer std::vector
-#define InfoContainer std::set
+#define InfoContainer std::vector
+//#define InfoContainer std::set
 };
 
Index: trunk/VUT/GtpVisibility/include/DummyQueryManager.h
===================================================================
--- trunk/VUT/GtpVisibility/include/DummyQueryManager.h	(revision 65)
+++ trunk/VUT/GtpVisibility/include/DummyQueryManager.h	(revision 143)
@@ -25,5 +25,5 @@
 			    InfoContainer<NodeInfo> *visibleNodes,
 			    InfoContainer<MeshInfo> *visibleGeometry,
-			    bool relativeVisibility = false
+			    bool projectedPixels = false
 			    );
     
@@ -35,5 +35,5 @@
 			       InfoContainer<NodeInfo> *visibleNodes,
 			       InfoContainer<MeshInfo> *visibleGeometry,
-			       bool relativeVisibility = false
+			       bool projectedPixels = false
 			       );
     
Index: trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp
===================================================================
--- trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp	(revision 141)
+++ trunk/VUT/GtpVisibility/src/DummyQueryManager.cpp	(revision 143)
@@ -11,8 +11,8 @@
 					     InfoContainer<NodeInfo> *visibleNodes,
 					     InfoContainer<MeshInfo> *visibleGeometry,
-					     bool relativeVisibility
+					     bool projectedPixels
 					     )
   {
-	  visibleNodes->insert(NodeInfo(mHierarchyInterface->GetSceneRoot(), 1.0f));
+	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetSceneRoot(), 0, 0));
     
 //      HierarchyInterface::MeshIterator *mi =
@@ -30,8 +30,8 @@
 						InfoContainer<NodeInfo> *visibleNodes,
 						InfoContainer<MeshInfo> *visibleGeometry,
-						bool relativeVisibility
+						bool projectedPixels
 						)
   {
-	  visibleNodes->insert(NodeInfo(mHierarchyInterface->GetSceneRoot(), 1.0f));
+	  visibleNodes->push_back(NodeInfo(mHierarchyInterface->GetSceneRoot(), 0, 0));
     
 //      HierarchyInterface::MeshIterator *mi =
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 141)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 143)
@@ -353,5 +353,5 @@
 }
 //-----------------------------------------------------------------------
-void TerrainFrameListener::ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility)
+void TerrainFrameListener::ApplyVisibilityQuery(bool fromPoint, bool projectedPixels)
 {
 	InfoContainer<GtpVisibility::NodeInfo> visibleNodes;
@@ -362,10 +362,10 @@
 		mVisibilityManager->GetQueryManager()->
 			ComputeFromPointVisibility(mCamNode->getPosition(), &visibleNodes, 
-									   &visibleGeometry, relativeVisibility);
+									   &visibleGeometry, projectedPixels);
 	}
 	else
 	{
 		mVisibilityManager->GetQueryManager()->ComputeCameraVisibility(*mCamera,
-			    &visibleNodes, &visibleGeometry, relativeVisibility);
+			    &visibleNodes, &visibleGeometry, projectedPixels);
 	}
 
@@ -377,7 +377,7 @@
 	for (geomIt = visibleGeometry.begin(); geomIt != geomIt_end; ++geomIt)
 	{
-		averageGeometryVis += (*geomIt).GetVisibility();
-
-		std::stringstream d; d << "Geometry visibility: " << (*geomIt).GetVisibility();
+		averageGeometryVis += (*geomIt).GetVisiblePixels();
+
+		std::stringstream d; d << "Geometry visibility: " << (*geomIt).GetVisiblePixels();
 		LogManager::getSingleton().logMessage(d.str());
 	}
@@ -387,7 +387,7 @@
 	for (nodesIt = visibleNodes.begin(); nodesIt != nodesIt_end; ++nodesIt)
 	{
-		averageNodeVis += (*nodesIt).GetVisibility();
-
-		std::stringstream d; d << "Node visibility: " << (*nodesIt).GetVisibility();
+		averageNodeVis += (*nodesIt).GetVisiblePixels();
+
+		std::stringstream d; d << "Node visibility: " << (*nodesIt).GetVisiblePixels();
 		LogManager::getSingleton().logMessage(d.str());
 	}
@@ -405,5 +405,5 @@
 		//-- visibility queries stats
 		int idx = fromPoint ?  1 : 0;
-		idx += relativeVisibility ? 2 : 0;
+		idx += projectedPixels ? 2 : 0;
 
 		sprintf(str, ": %s", queryTypeCaptions[idx].c_str()); 
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 139)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.h	(revision 143)
@@ -117,8 +117,8 @@
 		and their visibility information.
 		@param fromnPoint if query should be from point or from camera
-		@param relativeVisibility if query should return number of visible pixels or the ratio
+		@param projectedPixels if query should return number of visible pixels or the ratio
 		visible pixels / projected pixels.
 	*/
-	void ApplyVisibilityQuery(bool fromPoint, bool relativeVisibility);
+	void ApplyVisibilityQuery(bool fromPoint, bool projectedPixels);
 
 	void toggleShowQueryStats();
Index: trunk/VUT/Ogre/include/OgrePlatformQueryManager.h
===================================================================
--- trunk/VUT/Ogre/include/OgrePlatformQueryManager.h	(revision 140)
+++ trunk/VUT/Ogre/include/OgrePlatformQueryManager.h	(revision 143)
@@ -31,5 +31,5 @@
 	If NULL no visible meshes are not evaluated.
 
-	@param relativeVisibility If true the visibility member for
+	@param projectedPixels If true the visibility member for
 	NodeInfo and MeshInfo represent relative visibility; i.e. the number of visible
 	pixels divided by the the number of projected pixels.
@@ -41,5 +41,5 @@
 			    InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			    bool relativeVisibility = false
+			    bool projectedPixels = false
 			    );
     
@@ -52,5 +52,5 @@
 			       InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			       InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			       bool relativeVisibility = false
+			       bool projectedPixels = false
 			       );
     
Index: trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp
===================================================================
--- trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 141)
+++ trunk/VUT/Ogre/src/OgrePlatformQueryManager.cpp	(revision 143)
@@ -23,5 +23,5 @@
 			    InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			    InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			    bool relativeVisibility)
+			    bool projectedPixels)
 {
 	// we need access to the scene manager and the rendersystem
@@ -68,5 +68,5 @@
 	*/
 	// for relative visibility we need 2 rendering passes
-	int n = relativeVisibility ? 2 : 1;
+	int n = projectedPixels ? 2 : 1;
 	
 	for (int i=0; i<n; ++i)
@@ -118,15 +118,13 @@
 		(*visQueryIt)->GetQueryResult(visiblePixels, true);
 	
-		float vis = (float)visiblePixels;
-		bool isVisible = visiblePixels > 0;
-
-		if (relativeVisibility)
+		int visiblePixels = visiblePixels;
+		int projectedPixels = 0;
+
+		if (projectedPixels)
 		{
 			(*projQueryIt)->GetQueryResult(visiblePixels, true);
 	
-			if (visiblePixels > 0)
-			{				
-				vis /= (float) visiblePixels;
-			}
+			mProjectedPixels = visiblePixels;
+		
 			++projQueryIt;
 		}
@@ -136,18 +134,7 @@
 		// nodes with visibilty 0 in queue: 
 		// happens if node is intersected by near plane
-		if (isVisible)
-		{
-			insertNode = visibleNodes->insert(GtpVisibility::NodeInfo(*nodeIt, vis));
-
-			if (!insertNode.second) // element already in list
-			{
-				//LogManager::getSingleton().logMessage("element already in list");
-                (*insertNode.first).SetVisibility((*insertNode.first).GetVisibility() + vis);
-
-				if (relativeVisibility) // relative visibility between zero and one
-				{
-					(*insertNode.first).SetVisibility((*insertNode.first).GetVisibility() * 0.5);
-				}
-			}
+		if (visiblePixels > 0)
+		{
+			visibleNodes->push_back(GtpVisibility::NodeInfo(*nodeIt, visiblePixels, projectedPixels));
 		}
 	}
@@ -160,16 +147,13 @@
 		(*visQueryIt)->GetQueryResult(visiblePixels, true);
 		
-
-		float vis = (float)visiblePixels;
-		bool isVisible = visiblePixels > 0;
-		
-		if (relativeVisibility)
+		int visiblePixels = visiblePixels;
+		int projectedPixels = 0;
+
+		if (projectedPixels)
 		{
 			(*projQueryIt)->GetQueryResult(visiblePixels, true);
 
-			if (visiblePixels)
-			{
-				vis /= (float) visiblePixels;
-			}
+			mProjectedPixels = visiblePixels;
+
 			++projQueryIt;
 		}
@@ -181,18 +165,18 @@
 		if (isVisible)
 		{			 
-			insertGeom = visibleGeometry->insert(GtpVisibility::MeshInfo(*geometryIt, vis));
-			if (!insertGeom.second) // element already in list
-			{
-				//LogManager::getSingleton().logMessage("element already in list");
-                (*insertGeom.first).SetVisibility((*insertGeom.first).GetVisibility() + vis);
-
-				if (relativeVisibility) // relative visibility between zero and one
-				{
-					(*insertGeom.first).SetVisibility((*insertGeom.first).GetVisibility() * 0.5);
-				}
-			}
-		}
-	}
-
+			visibleGeometry->push_back(GtpVisibility::MeshInfo(*geometryIt,visiblePixels, projectedPixels));
+		}
+	}
+
+}
+//-----------------------------------------------------------------------
+inline bool nodeinfo_eq(const GtpVisibility::NodeInfo &info1, const GtpVisibility::NodeInfo &info2) 
+{ 
+	return info1.GetNode() == info2.GetNode(); 
+}
+//-----------------------------------------------------------------------
+inline bool meshinfo_eq(const GtpVisibility::MeshInfo &info1, const GtpVisibility::MeshInfo &info2) 
+{ 
+	return info1.GetMesh() == info2.GetMesh(); 
 }
 //-----------------------------------------------------------------------
@@ -200,5 +184,5 @@
 			       InfoContainer<GtpVisibility::NodeInfo> *visibleNodes,
 			       InfoContainer<GtpVisibility::MeshInfo> *visibleGeometry,
-			       bool relativeVisibility)
+			       bool projectedPixels)
 {
 	SceneManager *sm = dynamic_cast<PlatformHierarchyInterface *>(mHierarchyInterface)->GetSceneManager();
@@ -237,6 +221,6 @@
 		LogManager::getSingleton().logMessage(d.str());
 
-		ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, relativeVisibility);
-			   
+		ComputeCameraVisibility(*cam, visibleNodes, visibleGeometry, projectedPixels);
+		
 		//mViewport->getTarget()->update(); for(int j=0; j<10000000; j++)	printf("HAAHHAHAHAHAH");
 
@@ -248,7 +232,64 @@
 	}
 	
-
 	// reset camera
 	mViewport->setCamera(savedCam);
+
+	// --- single out duplicates
+
+	// before duplicates can be deleted we have to add up visibility
+
+	// --- visible nodes
+	sort(visibleNodes->begin(), visibleNodes->end());
+	InfoContainer<GtpVisibility::NodeInfo>::iterator visibleNodesIt,
+		visibleNodesIt_end = visibleNodes->end();
+	
+	GtpVisibility::NodeInfo *nodeInfo = NULL;
+
+	for (visibleNodesIt = visibleNodes->begin(); visibleNodesIt != visibleNodesIt_end; 
+		++visibleNodesIt);
+	{
+		if (!nodeInfo || (nodeInfo->GetNode() != (*visibleNodesIt).GetNode()))
+		{
+			nodeInfo = &(*visibleNodesIt);
+		}
+		else
+		{
+			// add visibility
+			nodeInfo->SetVisibility(nodeInfo->GetVisiblePixels() + 
+				(*visibleNodesIt).GetVisiblePixels());
+		}
+
+	}
+	
+	// now delete duplicates
+	visibleNodes->erase( std::unique(visibleNodes->begin(), 
+		visibleNodes->end(), nodeinfo_eq), visibleNodes->end());
+
+	// --- visible geometry
+	sort(visibleGeometry->begin(), visibleGeometry->end());
+	InfoContainer<GtpVisibility::MeshInfo>::iterator visibleGeomIt,
+		visibleGeomIt_end = visibleGeometry->end();
+
+	GtpVisibility::MeshInfo *geomInfo = NULL;
+
+	for (visibleGeomIt = visibleGeometry->begin(); visibleGeomIt != visibleGeomIt_end; 
+		++visibleGeomIt);
+	{
+		if (!geomInfo || (geomInfo->GetMesh() != (*visibleGeomIt).GetMesh()))
+		{
+			geomInfo = &(*visibleGeomIt);
+		}
+		else // info points to equal mesh
+		{
+			// add visibility
+			geomInfo->SetVisibility(geomInfo->GetVisiblePixels() + 
+				(*visibleGeomIt).GetVisiblePixels());
+		}
+	}
+
+	// now delete duplicates
+	visibleGeometry->erase(std::unique(visibleGeometry->begin(), 
+		visibleGeometry->end(), meshinfo_eq), visibleGeometry->end());
+	
 }
 //-----------------------------------------------------------------------
