Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2619)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2620)
@@ -21,5 +21,5 @@
 #define USE_CG 1
 
-#define TEST_PVS_RENDERING 1
+#define TEST_PVS_RENDERING 0
 
 #if USE_CG
@@ -91,4 +91,5 @@
   GlRendererBuffer(sceneGraph, viewcells, tree)
 {
+  mUseVbos = true;
   MakeCurrent();
   InitGL();
@@ -96,4 +97,32 @@
 }
 
+void
+QtGlRendererBuffer::RenderPvs(const ObjectPvs &pvs)
+{
+#if TEST_PVS_RENDERING 
+
+  // Render PVS
+  ObjectPvsIterator it = pvs.GetIterator();
+  
+  Intersectable::NewMail();
+  mCurrentFrame++;
+  while (it.HasMoreEntries()) 
+	{
+	  RenderIntersectable(it.Next());
+	}
+
+#else
+  
+  PreparePvs(pvs);
+
+  int offset = (int)mObjects.size() * 3;
+  char *arrayPtr = mUseVbos ? NULL : (char *)mData;
+
+  glVertexPointer(3, GL_FLOAT, 0, (char *)arrayPtr);
+  glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
+  glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
+  
+#endif
+}
 
 // reimplemented here so that we can snap the error windows
@@ -133,18 +162,10 @@
 	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 
 
-	
-	// Render PVS
-	ObjectPvsIterator it = pvs.GetIterator();
 
 	pvsSize = pvs.GetSize();
 	cout<<pvsSize<<endl;
-
-	Intersectable::NewMail();
-	mCurrentFrame++;
-	while (it.HasMoreEntries()) 
-	  {
-		RenderIntersectable(it.Next());
-	  }
-
+	
+	RenderPvs(pvs);
+	
 	//glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@@ -212,14 +233,5 @@
 	  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 	  
-	  // Render PVS
-	  Intersectable::NewMail();
-	  mCurrentFrame++;
-	  
-	  
-	  ObjectPvsIterator it = pvs.GetIterator();
-	  for (; it.HasMoreEntries(); ) 
-		{
-		  RenderIntersectable(it.Next());
-		}
+	  RenderPvs(pvs);
 
 	  mUseForcedColors = false;
@@ -464,47 +476,4 @@
 
 
-void QtGlRendererWidget::_UpdatePvsIndices(KdNode *node, int &indexBufferSize)
-{
-	if (node->Mailed())
-		return;
-
-	node->Mail();
-
-	// if (mObjects.size() * 3 < indexBufferSize) cerr << "problem: " << mObjects.size() * 3 << " < " << indexBufferSize << endl;
-	if (!node->IsLeaf()) 
-	{
-		KdInterior *kdInterior = static_cast<KdInterior *>(node);
-
-		_UpdatePvsIndices(kdInterior->mBack, indexBufferSize);
-		_UpdatePvsIndices(kdInterior->mFront, indexBufferSize);
-	} 
-	else 
-	{
-		KdLeaf *leaf = static_cast<KdLeaf *>(node);
-
-		leaf->mIndexBufferStart = indexBufferSize;
-
-		for (size_t i = 0; i < leaf->mObjects.size(); ++ i)
-		{
-			TriangleIntersectable *obj = 
-				static_cast<TriangleIntersectable *>(leaf->mObjects[i]);
-
-			if (obj->mRenderedFrame != mCurrentFrame)
-			{
-				obj->mRenderedFrame = mCurrentFrame;
-
-				mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
-				mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
-				mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
-
-				indexBufferSize += 3;
-			}
-		}
-
-		leaf->mIndexBufferSize = indexBufferSize - leaf->mIndexBufferStart;
-	}
-
-	//cout << "id: " << indexBufferSize << endl;
-}
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2615)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2620)
@@ -66,5 +66,8 @@
 
   int ComputePvs() const { return 0; }
-  
+
+  void
+  RenderPvs(const ObjectPvs &pvs);
+
   float
   GetPixelError(int &pvsSize);
@@ -216,5 +219,4 @@
 	float mTransferFunction;
 
-	unsigned int mIndexBufferSize;
 
 	Vector3 mDummyViewPoint;
@@ -543,5 +545,5 @@
 	void _RenderColoredPvs();
 
-	void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
+  //	void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
 
 	float ComputeRenderCost(ViewCell *vc);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2619)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2620)
@@ -26,5 +26,5 @@
 
 // if 1 = SAFE RENDERING OF PVS primitives without VBOs for Pvs error estimation
-#define EVAL_ERROR 1
+#define EVAL_ERROR 0
 
 namespace GtpVisibilityPreprocessor {
@@ -449,4 +449,6 @@
 }
 
+
+
 void
 GlRenderer::_RenderScene()
@@ -516,5 +518,5 @@
 	for (; oi != mObjects.end(); oi++) {
 
-		if ((*oi)->Type() == Intersectable::TRIANGLE_INTERSECTABLE) {
+	  if ((*oi)->Type() == Intersectable::TRIANGLE_INTERSECTABLE) {
 			TriangleIntersectable *object = (TriangleIntersectable *)*oi;
 			Triangle3 *t = &(object->GetItem());
@@ -525,6 +527,5 @@
 			glVertex3f(t->mVertices[1].x, t->mVertices[1].y, t->mVertices[1].z);
 			glVertex3f(t->mVertices[2].x, t->mVertices[2].y, t->mVertices[2].z);
-
-		}
+	  }
 	}
 
@@ -834,5 +835,5 @@
 GlRenderer::RenderKdNode(KdNode *node)
 {
-	if (node->IsLeaf()) 
+  if (node->IsLeaf()) 
 	{
 #if !EVAL_ERROR
@@ -843,4 +844,5 @@
 		  {
 			RenderIntersectable(leaf->mObjects[i]);
+			
 		  }
 #endif
@@ -1577,5 +1579,5 @@
 		  // compute the pixel error
 		  float error = GetPixelError(pvsSize);
-
+		  
 		  mPvsErrorBuffer[i].mError = error;
 		  mPvsErrorBuffer[i].mPvsSize = pvsSize;
@@ -1685,6 +1687,6 @@
 void GlRenderer::EnableDrawArrays()
 {
-	glEnableClientState(GL_VERTEX_ARRAY);
-	glEnableClientState(GL_NORMAL_ARRAY);
+  glEnableClientState(GL_VERTEX_ARRAY);
+  glEnableClientState(GL_NORMAL_ARRAY);
 }
 
@@ -1771,4 +1773,77 @@
 #endif
 
+
+
+void GlRenderer::PreparePvs(const ObjectPvs &pvs)
+{
+	int indexBufferSize = 0;
+	
+	KdNode::NewMail();
+	//Intersectable::NewMail();
+
+	
+	ObjectPvsIterator it = pvs.GetIterator();
+
+	while (it.HasMoreEntries()) 
+	{
+		Intersectable *obj = it.Next();
+		switch (obj->Type())
+		{
+		case Intersectable::KD_INTERSECTABLE:
+			{
+				KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
+				_UpdatePvsIndices(node, indexBufferSize);
+			}
+			break;
+			
+		}
+	}
+
+	mIndexBufferSize = indexBufferSize;
+}
+
+void GlRenderer::_UpdatePvsIndices(KdNode *node, int &indexBufferSize)
+{
+	if (node->Mailed())
+		return;
+
+	node->Mail();
+
+	// if (mObjects.size() * 3 < indexBufferSize) cerr << "problem: " << mObjects.size() * 3 << " < " << indexBufferSize << endl;
+	if (!node->IsLeaf()) 
+	{
+		KdInterior *kdInterior = static_cast<KdInterior *>(node);
+
+		_UpdatePvsIndices(kdInterior->mBack, indexBufferSize);
+		_UpdatePvsIndices(kdInterior->mFront, indexBufferSize);
+	} 
+	else 
+	{
+		KdLeaf *leaf = static_cast<KdLeaf *>(node);
+
+		leaf->mIndexBufferStart = indexBufferSize;
+
+		for (size_t i = 0; i < leaf->mObjects.size(); ++ i)
+		{
+			TriangleIntersectable *obj = 
+				static_cast<TriangleIntersectable *>(leaf->mObjects[i]);
+
+			if (obj->mRenderedFrame != mCurrentFrame)
+			{
+				obj->mRenderedFrame = mCurrentFrame;
+
+				mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
+				mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
+				mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
+
+				indexBufferSize += 3;
+			}
+		}
+
+		leaf->mIndexBufferSize = indexBufferSize - leaf->mIndexBufferStart;
+	}
+
+	//cout << "id: " << indexBufferSize << endl;
+}
 
 void GlRenderer::CreateVertexArrays(SceneGraphLeaf *leaf)
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2617)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2620)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: ne 20. I 00:39:42 2008
+# Generated by qmake (2.00a) (Qt 4.1.2) on: po 21. I 14:57:24 2008
 # Project:  preprocessor.pro
 # Template: app
@@ -63,5 +63,5 @@
 	$(MAKE) -f $(MAKEFILE).Debug uninstall
 
-Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc2005\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \
+Makefile: preprocessor.pro  C:/Qt/4.1.2/mkspecs/win32-msvc.net\qmake.conf C:/Qt/4.1.2/mkspecs/qconfig.pri \
 		C:\Qt\4.1.2\mkspecs\features\qt_config.prf \
 		C:\Qt\4.1.2\mkspecs\features\exclusive_builds.prf \
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2615)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2620)
@@ -174,4 +174,8 @@
   EvalPvsStat();
 
+  void PreparePvs(const ObjectPvs &pvs);
+  void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
+
+	
   virtual void EvalPvsStat(const SimpleRayContainer &viewPoints);
 
@@ -211,4 +215,6 @@
 
 	PvsRenderStatistics mPvsStat;
+
+  	unsigned int mIndexBufferSize;
 
 	int mPvsStatFrames;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_vienna
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_vienna	(revision 2607)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_vienna	(revision 2620)
@@ -5,5 +5,5 @@
 #COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace- -total_samples=500000000"
 
-COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace+ -samples_per_evaluation=5000000 -samples_per_pass=1000000 -total_samples=1000000000 -view_cells_use_kd_pvs+"
+COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -preprocessor_detect_empty_viewspace+ -samples_per_evaluation=5000000 -samples_per_pass=1000000 -total_samples=12000000 -view_cells_use_kd_pvs+ -preprocessor_ray_cast_method=0"
 
 
@@ -13,5 +13,5 @@
 
 
-PREFIX=../work/plots/osp-vienna-SG08
+PREFIX=../work/plots/osp-vienna-SG08-gr
 
 
@@ -19,14 +19,14 @@
 ######################
 
-# # $COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
-# # -preprocessor_visibility_file=$PREFIX-reference.xml \
-# # -view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \
-# # -preprocessor_histogram_file=$PREFIX-r-reference.hlog
-
-# $COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
-#  -rss_distributions=direction -view_cells_filter_max_size=1 \
-#  -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \
-#  -preprocessor_stats=$PREFIX-reference-global.log \
-#  -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog
+$COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+-preprocessor_visibility_file=$PREFIX-reference.xml \
+-view_cells_filter_max_size=1 -preprocessor_stats=$PREFIX-r-reference.log \
+-preprocessor_histogram_file=$PREFIX-r-reference.hlog
+
+$COMMAND -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+ -rss_distributions=direction -view_cells_filter_max_size=1 \
+ -preprocessor_visibility_file=$PREFIX-r-reference-global.xml \
+ -preprocessor_stats=$PREFIX-reference-global.log \
+ -preprocessor_histogram_file=$PREFIX-r-reference-global.hlog
 
 # $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
@@ -286,14 +286,15 @@
 # -preprocessor_stats=$PREFIX-combined-m8-1.log 
 
-$COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
--mutation_silhouette_prob=0.5 \
--mutation_reverse_samples_distance=1.0 \
--mutation_radius_origin=1.0 \
--mutation_radius_termination=0.2 \
--mutation_use_unsucc_count_importance+ \
--mutation_use_pass_importance- \
--mutation_buffer_size=2000000 \
--rss_distributions=mutation+object_direction+spatial \
--preprocessor_stats=$PREFIX-combined-m8-2.log 
+# USE THIS ONE!!!!!!
+# $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+# -mutation_silhouette_prob=0.5 \
+# -mutation_reverse_samples_distance=1.0 \
+# -mutation_radius_origin=1.0 \
+# -mutation_radius_termination=0.2 \
+# -mutation_use_unsucc_count_importance+ \
+# -mutation_use_pass_importance- \
+# -mutation_buffer_size=2000000 \
+# -rss_distributions=mutation+object_direction+spatial \
+# -preprocessor_stats=$PREFIX-combined-m8-2.log 
 
 # $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
@@ -308,12 +309,12 @@
 # -preprocessor_stats=$PREFIX-combined-m8-3.log 
 
-$COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
--mutation_silhouette_prob=0.5 \
--mutation_reverse_samples_distance=1.0 \
--mutation_radius_origin=0.5 \
--mutation_radius_termination=0.2 \
--mutation_use_unsucc_count_importance- \
--mutation_use_pass_importance+ \
--mutation_buffer_size=2000000 \
--rss_distributions=mutation+object_direction+spatial \
--preprocessor_stats=$PREFIX-combined-m8-4.log 
+# $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+# -mutation_silhouette_prob=0.5 \
+# -mutation_reverse_samples_distance=1.0 \
+# -mutation_radius_origin=0.5 \
+# -mutation_radius_termination=0.2 \
+# -mutation_use_unsucc_count_importance- \
+# -mutation_use_pass_importance+ \
+# -mutation_buffer_size=2000000 \
+# -rss_distributions=mutation+object_direction+spatial \
+# -preprocessor_stats=$PREFIX-combined-m8-4.log 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_pixel
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_pixel	(revision 2619)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SG08/run_test_pixel	(revision 2620)
@@ -4,6 +4,6 @@
 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+"
 #COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -samples_per_pass=500000 -samples_per_evaluation=10000000 -total_samples=500000000 -preprocessor_pvs_rendererror_samples=10000 -preprocessor_evaluatePixelError+"
-COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_pass=500000 -samples_per_evaluation=100000 -total_samples=500000000 -preprocessor_pvs_rendererror_samples=100 -preprocessor_evaluatePixelError+ -preprocessor_detect_empty_viewspace+ -kd_pvs_area=1e-5 -view_cells_use_kd_pvs+ -af_use_kd_pvs+"
-
+COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish+ -preprocessor_use_gl_renderer- -preprocessor_evaluate_filter- -samples_per_pass=1000000 -samples_per_evaluation=10000000 -total_samples=250000000 -preprocessor_pvs_rendererror_samples=1000 -preprocessor_evaluatePixelError+ -preprocessor_detect_empty_viewspace+ -kd_pvs_area=1e-5 -view_cells_use_kd_pvs+ -af_use_kd_pvs+"
+ 
 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d"
 #VIEWCELLS=../data/vienna/vienna-viewcells-5000.xml
