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());
+	
 }
 //-----------------------------------------------------------------------
