Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 997)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 1000)
@@ -37,6 +37,5 @@
 
 
-	//-- Evaluate results
-	
+	//-- Evaluate results	
 
 	//-- compute histogram from the samples
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 997)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1000)
@@ -470,5 +470,5 @@
 }
 
-
+std::ofstream outfile("try_100.txt");
 void
 GlRendererBuffer::EvalQueryWithOcclusionQueries(
@@ -480,18 +480,42 @@
 	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
 	glDepthMask(GL_FALSE);
+
+
+	// simulate detectemptyviewspace using backface culling
+	/*if (mDetectEmptyViewSpace) 
+	{
+		glEnable(GL_CULL_FACE);
+		cout << "culling" << endl;
+	}
+	else
+	{
+		cout << "not culling" << endl;
+		glDisable(GL_CULL_FACE);
+	}*/
+
+	
+	const int numQ = 500;//(int)mOcclusionQueries.size();
+	
+//outfile << "\n**************" << endl;
+glFinish();
+	//-- now issue queries for all objects
+	for (int j = 0; j < (int)mObjects.size(); ++ j) 
+	{	
+		for (int q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q) 
+		{
+			//glFinish();
+//			outfile << "queries: " << mOcclusionQueries[q] << " ";
+			glBeginOcclusionQueryNV(mOcclusionQueries[q]);
+			
+			RenderIntersectable(mObjects[j + q]);
 		
-	// now issue queries for all objects
-	for (int j = 0; j < mObjects.size(); ++ j) 
-	{
-		for (int q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); ++ q) 
-		{
-			glBeginOcclusionQueryNV(mOcclusionQueries[q]);
-					
-			RenderIntersectable(mObjects[j + q]);
+			glFlush();
 			glEndOcclusionQueryNV();
+			//glFinish();
 		}
-		
+
+//		outfile << endl;
 		// collect results of the queries
-		for (int q = 0; j + q < mObjects.size() && q < mOcclusionQueries.size(); ++ q) 
+		for (int q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q) 
 		{
 			unsigned int pixelCount;
@@ -501,20 +525,16 @@
 			do 
 			{
-				glGetOcclusionQueryuivNV(mOcclusionQueries[q],
-										GL_PIXEL_COUNT_AVAILABLE_NV,
-										&pixelCount);
+				glGetOcclusionQueryuivNV(mOcclusionQueries[q], GL_PIXEL_COUNT_AVAILABLE_NV, &pixelCount);
 					
-				if (0 && !pixelCount) cout << "W";
+				if (pixelCount == 0) cout << "W";
 			} 
 			while (!pixelCount);
 #endif
 
-			glGetOcclusionQueryuivNV(mOcclusionQueries[q],
-									GL_PIXEL_COUNT_NV,
-									&pixelCount);
-
-			// if (pixelCount)
-			// cout<<"q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" ";
-	                
+			glGetOcclusionQueryuivNV(mOcclusionQueries[q], GL_PIXEL_COUNT_NV, &pixelCount);
+
+			if (pixelCount > 0)
+				outfile <<"o="<<j+q<<" q="<<mOcclusionQueries[q]<<" pc="<<pixelCount<<" ";
+			
 			mObjects[j + q]->mCounter += pixelCount;
 		}
@@ -522,7 +542,10 @@
 		j += q;
 	}
-		
+
+glFinish();
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 	glDepthMask(GL_TRUE);
+	
+	glEnable(GL_CULL_FACE);
 }
 
@@ -552,8 +575,9 @@
 	int i, j;
 
-	// reset object visibility
-	for (i=0; i < mObjects.size(); i++) 
+	ObjectContainer::const_iterator it, it_end = mObjects.end();
+
+	for (it = mObjects.begin(); it != it_end; ++ it) 
 	{
-		mObjects[i]->mCounter = 0;
+		(*it)->mCounter = 0;
 	}
 
@@ -567,16 +591,6 @@
 	//else cout << "using item buffer" << endl;
 	
-	glCullFace(GL_FRONT);
-
-	if (mDetectEmptyViewSpace) 
-	{
-		glEnable(GL_CULL_FACE);
-		cout << "culling" << endl;
-	}
-	else
-	{
-		cout << "not culling" << endl;
-		glDisable(GL_CULL_FACE);
-	}
+	//glCullFace(GL_FRONT);
+	glCullFace(GL_BACK);
 
 	for (i = 0; i < 6; ++ i) 
@@ -590,7 +604,5 @@
 		mUseFalseColors = true;
 
-
 		// the actual scene rendering
-
 		RenderScene();
 
@@ -618,15 +630,17 @@
 	sample.Reset();
 
-	for (j = 0; j < mObjects.size(); j++) 
+	for (it = mObjects.begin(); it != it_end; ++ it) 
 	{
-		if (mObjects[j]->mCounter) 
+		Intersectable *obj = *it;
+		if (obj->mCounter) 
 		{
 			++ sample.mVisibleObjects;
-			sample.mVisiblePixels += mObjects[j]->mCounter;
+			sample.mVisiblePixels += obj->mCounter;
 		}
 	}
 
-	cout << "RS=" << sample.mVisibleObjects << " ";
-}
+	outfile << "RS=" << sample.mVisibleObjects << " ";
+}
+
 
 void
@@ -646,9 +660,17 @@
   halton.Reset();
   
-  int i;
-  int numQ = 500;
-
-
-  if (mOcclusionQueries.size() < numQ) 
+  // the number of queries simultanosly allocated
+  const int numQ = 400;
+  //const int numQ = 3;
+#if 1
+  for (int i = (int)mOcclusionQueries.size(); i < numQ; ++ i)
+  {
+	  unsigned int query;
+	  glGenOcclusionQueriesNV(1, &query);
+	  mOcclusionQueries.push_back(query);
+	  //mOcclusionQueries[i] = queries[i];
+  }
+#else
+  if ((int)mOcclusionQueries.size() < numQ)
   {
 	  cout << "allocating occ queries..." << endl;
@@ -657,20 +679,21 @@
 	  
 	  // matt: ?
-	  for (i = 0; i < numQ; ++ i)
+	  for (int i = 0; i < numQ; ++ i)
           queries[i] = 111;
 	
 	  glGenOcclusionQueriesNV(numQ, queries);
-
 	  mOcclusionQueries.resize(numQ);
-	
-	  for (i = 0; i < numQ; ++ i)
-	  {
-		  mOcclusionQueries[i] = queries[i];
-	  }
+	  
     
-	  DEL_PTR(queries);
-  }
-  
-  for (i = 0; i < n; ++ i)
+	   for (int i = 0; i < numQ; ++ i)
+	   {
+		   mOcclusionQueries[i] = queries[i];
+	   }
+
+	   DEL_PTR(queries);
+  }
+#endif
+  
+  for (int i = 0; i < n; ++ i)
   {
 	  EvalRenderCostSample(samples[i]);
