Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2664)
@@ -74,5 +74,5 @@
 QtGlRendererBuffer::MakeCurrent()
 {
-  makeCurrent();
+	makeCurrent();
 }
 
@@ -80,24 +80,33 @@
 QtGlRendererBuffer::DoneCurrent()
 {
-  doneCurrent();
+	doneCurrent();
 }
   
 
-QtGlRendererBuffer::QtGlRendererBuffer(const int w,
-									   const int h,
+QtGlRendererBuffer::QtGlRendererBuffer(int w, int h,
 									   SceneGraph *sceneGraph,
 									   ViewCellsManager *viewcells,
 									   KdTree *tree):
-  QGLPixelBuffer(QSize(w, h)),
-  GlRendererBuffer(sceneGraph, viewcells, tree)
-{
-  mUseVbos = true;
-  MakeCurrent();
-  InitGL();
-  DoneCurrent();
-}
-
-void
-QtGlRendererBuffer::RenderPvs(const ObjectPvs &pvs)
+QGLPixelBuffer(QSize(w, h), QGLFormat(QGL::SampleBuffers)),
+GlRendererBuffer(sceneGraph, viewcells, tree)
+{
+	mUseVbos = true;
+	//mUseVbos = false;
+	
+	MakeCurrent();
+	glViewport(0, 0, w, h);
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+    glOrtho(-1, 1, -1, 1, -99, 99);
+    //glTranslatef(-0.5f, -0.5f, 0.0f);
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+
+	InitGL();
+	DoneCurrent();
+}
+
+
+void QtGlRendererBuffer::RenderPvs(const ObjectPvs &pvs)
 {
 	PreparePvs(pvs);
@@ -112,10 +121,12 @@
 
 // reimplemented here so that we can snap the error windows
-float
-QtGlRendererBuffer::GetPixelError(int &pvsSize)
-{
-
+float QtGlRendererBuffer::GetPixelError(int &pvsSize)
+{
 	MakeCurrent();
-
+	
+/*
+SetupCamera();
+RenderScene();
+*/
 	float pErrorPixels = -1.0f;
 
@@ -127,5 +138,5 @@
 
 	if (viewcell == NULL)
-		return 0.0f;
+		return -1.0f;
 
 	ObjectPvs pvs;
@@ -143,4 +154,5 @@
 
 	SetupCamera();
+
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 	glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
@@ -156,4 +168,7 @@
 	pvsSize = pvs.GetSize();
 	
+	if (pvsSize == 0)
+		return 0.0f;
+
 	RenderPvs(pvs);
 
@@ -178,14 +193,10 @@
 	// reenable other state
 	int wait = 0;
-	
 	while (0 && !query->ResultAvailable()) 
-	{
 		wait ++;
-	}
-
-
+	
 	pixelCount = query->GetQueryResult();
 
-	if ((pixelCount > 0) && (pvsSize > 0))
+	if (pixelCount > 0) 
 	{
 		cout << "vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << endl;
@@ -195,5 +206,6 @@
 
 
-	if (mSnapErrorFrames && (pixelCount > 0)) {
+	if (mSnapErrorFrames && (pixelCount > 0)) 
+	{
 		glReadBuffer(GL_BACK);
 		//glReadBuffer(GL_FRONT);
@@ -226,5 +238,6 @@
 		glColor3f(0,1,0);
 		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+		//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
 		RenderPvs(pvs);
@@ -412,8 +425,8 @@
 	glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
 	glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
+
 #if DYNAMIC_OBJECTS_HACK
 	// handle dynamic objects
 	DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end();
-
 
 	for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit)
@@ -541,5 +554,5 @@
 		if (mUseSpatialFilter && mRenderBoxes) 
 		{
-			for (int i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
+			for (size_t i=0; i < mPvsCache.filteredBoxes.size(); ++ i)
 			{
 				RenderBox(mPvsCache.filteredBoxes[i]);
@@ -559,14 +572,4 @@
 			RenderIntersectable(viewcell);
 			
-			/*glPushMatrix();
-			glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
-			glScalef(5.0f,5.0f,5.0f);
-			glPushAttrib(GL_CURRENT_BIT);
-			glColor3f(1.0f, 0.0f, 0.0f);
-			//	  gluSphere((::GLUquadric *)mSphere,
-			//				1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
-			glPopAttrib();
-			glPopMatrix();
-			*/
 			mWireFrame = false;
 		}
@@ -575,8 +578,12 @@
 	else 
 	{
-		//ObjectContainer::const_iterator oi = mObjects.begin();
-		//for (; oi != mObjects.end(); oi++)
-		//	RenderIntersectable(*oi);
+		//OcclusionQuery *query = mOcclusionQueries[0];
+		//query->BeginQuery();
+		
 		RenderScene();
+
+		//query->EndQuery();
+		//int pixels = query->GetQueryResult();
+		//cout << " pixels: " << pixels;
 	}
 
@@ -611,5 +618,4 @@
 
 	glColor3f(1.0f, 0.0f, 0.0f);
-
 
 	OcclusionQuery *query = mOcclusionQueries[0];
@@ -634,6 +640,6 @@
 
 	int pixelCount = query->GetQueryResult();
-	pErrorPixels = ((float)pixelCount)/(GetWidth()*GetHeight());
-	if (0) cout<<"error pixels="<<pixelCount<<endl;
+	pErrorPixels = ((float)pixelCount) / (GetWidth() * GetHeight());
+	if (0) cout << "error pixels=" << pixelCount << endl;
 
 	mRenderError = pErrorPixels;
@@ -2335,16 +2341,5 @@
 	// set up the pbuffer context
 	mRenderBuffer->makeCurrent();
-	/*mRenderBuffer->InitGL();
-
-	glViewport(0, 0, mRenderBuffer->size().width(), mRenderBuffer->size().height());
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	glOrtho(-1, 1, -1, 1, -99, 99);
-	glTranslatef(-0.5f, -0.5f, 0.0f);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);*/
-
+	
 	// generate a texture that has the same size/format as the pbuffer
 	dynamicTexture = mRenderBuffer->generateDynamicTexture();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2657)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2664)
@@ -54,34 +54,29 @@
 	Q_OBJECT
 public:
-	QtGlRendererBuffer(const int w,
-		const int h,
-		SceneGraph *sceneGraph,
-		ViewCellsManager *viewcells,
-		KdTree *tree);
-
-  ~QtGlRendererBuffer() {}
-
-  virtual void MakeCurrent();
-  virtual void DoneCurrent();
-
-  virtual int GetWidth() const { return width(); }
-  virtual int GetHeight() const { return height(); }
-
-  int ComputePvs() const { return 0; }
-
-  void
-  RenderPvs(const ObjectPvs &pvs);
-
-  float
-  GetPixelError(int &pvsSize);
-  
-  int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
-     
-  
-  
-  
+	QtGlRendererBuffer(int w, int h,
+					   SceneGraph *sceneGraph,
+					   ViewCellsManager *viewcells,
+					   KdTree *tree);
+
+	~QtGlRendererBuffer() {}
+
+	virtual void MakeCurrent();
+	virtual void DoneCurrent();
+
+	virtual int GetWidth() const { return width(); }
+	virtual int GetHeight() const { return height(); }
+
+	int ComputePvs() const { return 0; }
+
+	void RenderPvs(const ObjectPvs &pvs);
+
+	float GetPixelError(int &pvsSize);
+
+	int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
+
 public:
-  signals:
-  void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
+
+signals:
+	void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2615)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2664)
@@ -24,6 +24,6 @@
 
 QtGlViewer::QtGlViewer(QWidget *parent,
-					   QtGlRendererWidget *renderer):
-  QGLWidget(parent), mRenderer(renderer)
+					   QtGlRendererWidget *renderer)
+: QGLWidget(parent), mRenderer(renderer)
 {
 	scale = 1.0f;
@@ -42,4 +42,5 @@
 }
   
+
 QSize QtGlViewer::minimumSizeHint() const
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2664)
@@ -131,5 +131,6 @@
 		                                      mDetectEmptyViewSpace);
 
-	mSnapErrorFrames = false;
+	//mSnapErrorFrames = false;
+	mSnapErrorFrames = true;
 	mSnapPrefix = "snap/";
 	mUseForcedColors = false;
@@ -706,5 +707,4 @@
 		for (q = 0; ((j + q) < (int)mObjects.size()) && (q < numQ); ++ q) 
 		{
-			//glFinish();
 			mOcclusionQueries[q]->BeginQuery();
 			
@@ -712,5 +712,4 @@
 		
 			mOcclusionQueries[q]->EndQuery();
-			//glFinish();
 		}
 		//cout << "q: " << q << endl;
@@ -1417,7 +1416,8 @@
 void GlRendererBuffer::InitGL()
 {
-	MakeCurrent(); 
+	//MakeCurrent(); 
 	GlRenderer::InitGL();
 
+#if 0
 	// initialise dual depth buffer textures
 	glGenTextures(1, &frontDepthMap);
@@ -1442,5 +1442,5 @@
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
 
-#if 0
+
 #ifdef USE_CG
 
@@ -1480,5 +1480,5 @@
 #endif
 #endif
-	DoneCurrent();
+	//DoneCurrent();
 }
 
@@ -1514,5 +1514,5 @@
   SetupProjection(GetWidth(), GetHeight());
 
-  cout<<"Random Pvs STATS, mPvsStatFrames="<<mPvsStatFrames<<endl;
+  cout << "Random Pvs STATS, mPvsStatFrames=" << mPvsStatFrames << endl;
   
   for (int i=0; i < mPvsStatFrames; i++) {
@@ -1537,18 +1537,15 @@
 
 
- 	if (mPvsErrorBuffer[i].mError > 0.0f) {
-	  int pvsSize;
-
-	  float error = GetPixelError(pvsSize);
-
-	  mPvsErrorBuffer[i].mError = error;
-	  mPvsErrorBuffer[i].mPvsSize = pvsSize;
-
-	  //	  emit UpdatePvsErrorItem(i,
-	  //							  mPvsErrorBuffer[i]);
-	  cout<<"("<<i<<" ["<<mViewPoint<<"]["<<mViewDirection<<"] "<<mPvsErrorBuffer[i].mError<<")";
-	  //	  swapBuffers();
-	}
-	
+	if (mPvsErrorBuffer[i].mError > 0.0f) {
+		int pvsSize;
+
+		float error = GetPixelError(pvsSize);
+
+		mPvsErrorBuffer[i].mError = error;
+		mPvsErrorBuffer[i].mPvsSize = pvsSize;
+
+		cout<<"("<<i<<" ["<<mViewPoint<<"]["<<mViewDirection<<"] "<<mPvsErrorBuffer[i].mError<<")";
+	}
+
 	err = mPvsErrorBuffer[i].mError;
 	
@@ -1630,14 +1627,14 @@
 		{
 			// compute the pixel error
-			float error = GetPixelError(pvsSize);
+			const float error = GetPixelError(pvsSize);
 
 			mPvsErrorBuffer[i].mError = error;
 			mPvsErrorBuffer[i].mPvsSize = pvsSize;
 
-			int pixelError = (int)mPvsErrorBuffer[i].mError * GetWidth() * GetHeight();
-
+			const int pixelError = (int)mPvsErrorBuffer[i].mError * GetWidth() * GetHeight();
 			if (0 && (pixelError > 0) && (pvsSize > 0)) 
 			{
-				cout << "!err: " << i << "," << mViewPoint << "," << mViewDirection << " " << mPvsErrorBuffer[i].mError * GetWidth() * GetHeight() << endl;
+				cout << "err: " << i << "," << mViewPoint << "," << mViewDirection << " " 
+					 << mPvsErrorBuffer[i].mError * GetWidth() * GetHeight() << endl;
 			}
 		}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2660)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2664)
@@ -309,4 +309,15 @@
 	if (evalPixelError && (importRandomViewCells || frames))
 	{
+		if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers())
+		{
+			cerr << "this system does not support OpenGL/pbuffers" << endl;
+
+			QMessageBox::information(0, "OpenGL pbuffers", 
+				"This system does not support OpenGL/pbuffers.",
+				QMessageBox::Ok);
+
+			return NULL;
+		}
+
 		QGLFormat f;
 		f.setStencil(true);
@@ -329,9 +340,9 @@
 	
 	if (exportRandomViewCells)
-	  {
+	{
 		cout << "exporting random view cells" << endl;
 		preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile);
 		cout << "finished" << endl;
-	  }
+	}
 
 	if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
@@ -348,9 +359,12 @@
 		if (!rendererWidget) 
 		{
-			if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
-				cout << "damn" << endl;
+			if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers())
+			{
+				cerr << "this system does not support OpenGL/pbuffers" << endl;
+
 				QMessageBox::information(0, "OpenGL pbuffers", 
 					"This system does not support OpenGL/pbuffers.",
 					QMessageBox::Ok);
+
 				return NULL;
 			}
@@ -378,24 +392,15 @@
 		}
 
-
-		/*bool evaluatePixelError;
-		Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError",  evaluatePixelError);
-
-		if (evaluatePixelError)
-		{
-			cout << "evaluating pixel error" << endl;
-			preprocessor->ComputeRenderError();
-		}*/
-
 		qApp->exec();
 	}
-#else // USE_QUT
-
-	//#if USE_THREADS
-	//	pt = new BoostPreprocessorThread(preprocessor);
-	//#else
+#else // USE_QT
+
+	/*#if USE_THREADS
+		pt = new BoostPreprocessorThread(preprocessor);
+	#else
 		// use a dummy thread
 		pt = new DummyPreprocessorThread(preprocessor);
-	//#endif
+	#endif
+	*/
 #endif
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2664)
@@ -168,9 +168,7 @@
   virtual bool ValidViewPoint();
   
-  virtual float
-  GetPixelError(int &pvsSize);
-  
-  virtual void
-  EvalPvsStat();
+  virtual float GetPixelError(int &pvsSize);
+  
+  virtual void EvalPvsStat();
 
   void PreparePvs(const ObjectPvs &pvs);
