Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 746)
@@ -1813,5 +1813,5 @@
 	if (!vc->IsLeaf()) {	
 	  ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
-	  costFunction.push_back(interior->GetCost());
+	  costFunction.push_back(interior->GetMergeCost());
 	  
 	  ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 718)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 746)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.0) on: ?t 23. III 21:40:08 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: út 11. IV 11:35:23 2006
 # Project:  preprocessor.pro
 # Template: app
@@ -63,45 +63,45 @@
 	$(MAKE) -f $(MAKEFILE).Debug uninstall
 
-Makefile: preprocessor.pro  D:/Qt/4.1.0/mkspecs/win32-msvc.net\qmake.conf D:/Qt/4.1.0/mkspecs/qconfig.pri \
-		D:\Qt\4.1.0\mkspecs\features\qt_config.prf \
-		D:\Qt\4.1.0\mkspecs\features\exclusive_builds.prf \
-		D:\Qt\4.1.0\mkspecs\features\default_pre.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\default_pre.prf \
-		D:\Qt\4.1.0\mkspecs\features\release.prf \
-		D:\Qt\4.1.0\mkspecs\features\debug_and_release.prf \
-		D:\Qt\4.1.0\mkspecs\features\default_post.prf \
-		D:\Qt\4.1.0\mkspecs\features\qt.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\opengl.prf \
-		D:\Qt\4.1.0\mkspecs\features\moc.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\thread.prf \
-		D:\Qt\4.1.0\mkspecs\features\warn_off.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\console.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\rtti.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\exceptions.prf \
-		D:\Qt\4.1.0\mkspecs\features\win32\stl.prf \
-		D:\Qt\4.1.0\mkspecs\features\shared.prf \
-		D:\Qt\4.1.0\mkspecs\features\resources.prf \
-		D:\Qt\4.1.0\mkspecs\features\uic.prf
+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 \
+		C:\Qt\4.1.2\mkspecs\features\default_pre.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\default_pre.prf \
+		C:\Qt\4.1.2\mkspecs\features\release.prf \
+		C:\Qt\4.1.2\mkspecs\features\debug_and_release.prf \
+		C:\Qt\4.1.2\mkspecs\features\default_post.prf \
+		C:\Qt\4.1.2\mkspecs\features\qt.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\opengl.prf \
+		C:\Qt\4.1.2\mkspecs\features\moc.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\thread.prf \
+		C:\Qt\4.1.2\mkspecs\features\warn_off.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\console.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\rtti.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\exceptions.prf \
+		C:\Qt\4.1.2\mkspecs\features\win32\stl.prf \
+		C:\Qt\4.1.2\mkspecs\features\shared.prf \
+		C:\Qt\4.1.2\mkspecs\features\resources.prf \
+		C:\Qt\4.1.2\mkspecs\features\uic.prf
 	$(QMAKE) -win32 -o Makefile preprocessor.pro
-D:/Qt/4.1.0/mkspecs/qconfig.pri:
-D:\Qt\4.1.0\mkspecs\features\qt_config.prf:
-D:\Qt\4.1.0\mkspecs\features\exclusive_builds.prf:
-D:\Qt\4.1.0\mkspecs\features\default_pre.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\default_pre.prf:
-D:\Qt\4.1.0\mkspecs\features\release.prf:
-D:\Qt\4.1.0\mkspecs\features\debug_and_release.prf:
-D:\Qt\4.1.0\mkspecs\features\default_post.prf:
-D:\Qt\4.1.0\mkspecs\features\qt.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\opengl.prf:
-D:\Qt\4.1.0\mkspecs\features\moc.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\thread.prf:
-D:\Qt\4.1.0\mkspecs\features\warn_off.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\console.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\rtti.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\exceptions.prf:
-D:\Qt\4.1.0\mkspecs\features\win32\stl.prf:
-D:\Qt\4.1.0\mkspecs\features\shared.prf:
-D:\Qt\4.1.0\mkspecs\features\resources.prf:
-D:\Qt\4.1.0\mkspecs\features\uic.prf:
+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:
+C:\Qt\4.1.2\mkspecs\features\default_pre.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\default_pre.prf:
+C:\Qt\4.1.2\mkspecs\features\release.prf:
+C:\Qt\4.1.2\mkspecs\features\debug_and_release.prf:
+C:\Qt\4.1.2\mkspecs\features\default_post.prf:
+C:\Qt\4.1.2\mkspecs\features\qt.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\opengl.prf:
+C:\Qt\4.1.2\mkspecs\features\moc.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\thread.prf:
+C:\Qt\4.1.2\mkspecs\features\warn_off.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\console.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\rtti.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\exceptions.prf:
+C:\Qt\4.1.2\mkspecs\features\win32\stl.prf:
+C:\Qt\4.1.2\mkspecs\features\shared.prf:
+C:\Qt\4.1.2\mkspecs\features\resources.prf:
+C:\Qt\4.1.2\mkspecs\features\uic.prf:
 qmake: qmake_all FORCE
 	@$(QMAKE) -win32 -o Makefile preprocessor.pro
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 735)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 746)
@@ -397,7 +397,12 @@
 	void SetMaxFilterSize(const int size);
 
-	/** Deletes interior nodes from the tree which have negative merge cost set (local merge) 
-	*/
-	void DeleteLocalMergeTree(ViewCell *vc) const;
+  int GetMaxFilterSize() {
+	return mMaxFilterSize;
+  }
+
+  /** deletes interior nodes from the tree which have negative merge cost set (local merge) */
+  void
+  DeleteLocalMergeTree(ViewCell *vc
+					   ) const;
   
 	/** Evaluautes histogram for a given number of view cells.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 746)
@@ -1272,5 +1272,5 @@
 					optFloat,
 					"view_cells_filter_width=",
-					"10.0");
+					"200.0");
 
 	RegisterOption("ViewCells.loadFromFile",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 736)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 746)
@@ -327,4 +327,5 @@
 	/** Get costs resulting from each merge step. */
 	void GetCostFunction(vector<float> &costFunction);
+
   
 	/** Returns optimal set of view cells for a given number of view cells.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 712)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 746)
@@ -242,4 +242,5 @@
 		renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager, mKdTree);
 		//		renderer->makeCurrent();
+		
 	}
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 718)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 746)
@@ -559,5 +559,5 @@
 	Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl;
 	// cull viewcells with PVS > median (0.5f)
-	//	mViewCellsManager->SetValidityPercentage(0, 0.5f); 
+	mViewCellsManager->SetValidityPercentage(0, 0.5f); 
 	Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl;
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 693)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 746)
@@ -109,5 +109,20 @@
 	rendererWidget->resize(640, 480);
 	rendererWidget->show();
+
+	if (p->GetRenderer()) {
+
+	  cout<<"CONNECTING"<<endl;
+	  QObject::connect(p->GetRenderer(),
+					   SIGNAL(UpdatePvsErrorItem(int i,
+												 GlRendererBuffer::PvsErrorEntry &)),
+					   rendererWidget->mControlWidget,
+					   SLOT(UpdatePvsErrorItem(int i,
+											   GlRendererBuffer::PvsErrorEntry &)));
+	  cout<<"CONNECTED"<<endl;
+	}
+	
 	pt->start(QThread::LowPriority);
+	
+	
   } else{
 	// just call the mail method -> will be executed in the main thread
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 718)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 746)
@@ -10,10 +10,9 @@
 # filename ../data/vienna/vienna-simple.x3d
 #filename ../data/vienna/vienna-buildings.x3d
-#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d
-#;../data/vienna/vienna-plane.x3d
+#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d
 # filename ../data/vienna/viewcells-25-sel.x3d
-#filename ../data/atlanta/atlanta2.x3d
+filename ../data/atlanta/atlanta2.x3d
 #filename ../data/soda/soda.dat
-filename ../data/soda/soda5.dat
+#filename ../data/soda/soda5.dat
 }
 
@@ -25,7 +24,7 @@
 #	type vss
 	type rss
-	detectEmptyViewSpace true
-	pvsRenderErrorSamples 5000
-#	pvsRenderErrorSamples 1000
+	detectEmptyViewSpace false
+#	pvsRenderErrorSamples 1
+	pvsRenderErrorSamples 1000
 	quitOnFinish true
 	computeVisibility true
@@ -36,5 +35,5 @@
 	samplesPerPass  100000
 	initialSamples 500000
-	vssSamples 2000000
+	vssSamples 1000000
 	vssSamplesPerPass 200000
 	useImportanceSampling true
@@ -78,9 +77,9 @@
 	samplesPerPass 500000
 	initialSamples 500000
-	vssSamples 20000000
+	vssSamples 30000000
 	vssSamplesPerPass 1000000
-	useImportanceSampling true
-
-	directionalSampling true
+	useImportanceSampling false
+
+	directionalSampling false
 	objectBasedSampling false
 
@@ -88,5 +87,5 @@
 		pvs false
 		rssTree false
-		rays true
+		rays false
 		numRays 5000
 	}
@@ -104,6 +103,10 @@
 
 	maxDepth 	40
-	minPvs		1
-	minRays		50
+	minPvs		3
+# before vienna test it was:
+#	minRays	50
+#	splitType heuristic
+
+	minRays		100
 	minSize		0.001
  	maxCostRatio 1.0
@@ -113,7 +116,7 @@
 	maxStaticMemory	100
 
-#	splitType regular
+	splitType regular
 #	splitType heuristic
-	splitType hybrid
+#	splitType hybrid
 	splitUseOnlyDrivingAxis false
 	importanceBasedCost false
@@ -178,10 +181,10 @@
 
 	Filter {
-		maxSize 20
-		width  200.0
+		maxSize 5
+		width  0.05
 	}
 
 	#number of active view cells
-	active 4000
+	active 15000
 	maxStaticMemory	40
 
@@ -255,5 +258,7 @@
 #	filename ../data/soda/soda5-viewcells.xml
 #	filename ../scripts/viewcells_atlanta.xml
-	filename ../data/soda/soda5-viewcells2.xml
+#	filename ../data/soda/soda5-viewcells2.xml
+	filename ../data/atlanta/viewcells_atlanta3.xml
+#	filename ../data/vienna/viewcells_vienna.xml
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 685)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 746)
@@ -161,4 +161,6 @@
   bool mComputeVisibility;
 
+  GlRendererBuffer *GetRenderer() { return renderer;}
+  
 protected:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 713)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 746)
@@ -68,4 +68,5 @@
   int timerId;
   bool mUseFalseColors;
+  bool mUseForcedColors;
 
   HaltonSequence halton;
@@ -117,6 +118,7 @@
 
 
-class GlRendererBuffer : public QGLPixelBuffer, public GlRenderer
-{
+class GlRendererBuffer : public QObject, public QGLPixelBuffer,  public GlRenderer
+{
+Q_OBJECT
 public:
 	GlRendererBuffer(const int w,
@@ -175,4 +177,6 @@
 	float mError;
 	int mPvsSize;
+	Vector3 mPosition;
+	Vector3 mDirection;
   };
   
@@ -185,5 +189,11 @@
 	void SetupProjectionForViewPoint(const Vector3 &viewPoint, 
 									 const Beam &beam, 
+
 									 Intersectable *sourceObject);
+
+public:
+  signals:
+	UpdatePvsErrorItem(int i,
+					   GlRendererBuffer::PvsErrorEntry &);
 };
 
@@ -193,5 +203,14 @@
   Q_OBJECT
 public:
+
+  QListWidget *mPvsErrorWidget;
+
   RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0);
+
+  public slots:
+
+  void FocusNextPvsErrorFrame();
+  void UpdatePvsErrorItem(int i,
+						  GlRendererBuffer::PvsErrorEntry &);
 
   signals:
@@ -202,10 +221,14 @@
   SetVisibilityFilterSize(int);
 
+  SetRenderFilter(bool);
+  SetRenderErrors(bool);
   SetShowViewCells(bool);
+  SetShowRenderCost(bool);
+  SetShowPvsSizes(bool);
   SetTopView(bool);
   SetCutViewCells(bool);
   SetCutScene(bool);
 
-
+  
 };
 
@@ -222,7 +245,17 @@
   bool mCutViewCells;
   bool mCutScene;
-  
+  bool mRenderErrors;
+  bool mRenderFilter;
+  bool mShowRenderCost;
+  bool mShowPvsSizes;
+
   Plane3 mSceneCutPlane;
   float mTopDistance;
+
+  // some statistics
+  int mPvsSize;
+  float mRenderError;
+
+  RendererControlWidget *mControlWidget;
   
   GlRendererWidget(SceneGraph *sceneGraph,
@@ -249,5 +282,8 @@
 
   void keyPressEvent ( QKeyEvent * e ) ;
-  
+
+  void
+  RenderPvs();
+
   float
   RenderErrors();
@@ -265,10 +301,22 @@
 
  public slots:
- void
- SetViewCellGranularity(int number);
-
+
+ void SetRenderErrors(bool b) {
+   mRenderErrors = b;
+   updateGL();
+ }
+
+ void SetRenderFilter(bool b) {
+   mRenderFilter = b;
+   updateGL();
+ }
+
+  
+  void
+  SetViewCellGranularity(int number);
+  
   void
   SetVisibilityFilterSize(int number);
-
+  
   void
   SetSceneCut(int cut);
@@ -281,5 +329,15 @@
 	updateGL();
   }
-  
+
+  void SetShowRenderCost(bool b) {
+	mShowRenderCost = b;
+	updateGL();
+  }
+
+  void SetShowPvsSizes(bool b) {
+	mShowPvsSizes = b;
+	updateGL();
+  }
+
   void SetTopView(bool b) {
 	mTopView = b;
@@ -295,4 +353,5 @@
 	updateGL();
   }
+
 
 };
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 746)
@@ -1044,8 +1044,9 @@
 												const float width) const
 {
-	Vector3 min = viewPoint - width * 0.5f;
-	Vector3 max = viewPoint + width * 0.5;
-
-	return AxisAlignedBox3(min, max);
+  float w = Magnitude(mViewSpaceBox.Size())*width;
+  Vector3 min = viewPoint - w * 0.5f;
+  Vector3 max = viewPoint + w * 0.5f;
+  
+  return AxisAlignedBox3(min, max);
 }
 
@@ -1053,15 +1054,17 @@
 void ViewCellsManager::GetPrVS(const Vector3 &viewPoint, PrVs &prvs)
 {
-	const AxisAlignedBox3 box = GetFilterBBox(viewPoint, mFilterWidth);
-
-	ViewCell *currentViewCell = GetViewCell(viewPoint);
-
+  const AxisAlignedBox3 box = GetFilterBBox(viewPoint, mFilterWidth);
+	
+  ViewCell *currentViewCell = GetViewCell(viewPoint);
+
+  if (currentViewCell) {
 	ViewCellContainer viewCells;
 	ComputeBoxIntersections(box, viewCells);
-
+	
 	ViewCell *root = ConstructLocalMergeTree2(currentViewCell, viewCells);
-
 	prvs.mViewCell = root;
-	//prvs.mPvs = root->GetPvs();
+  } else
+	prvs.mViewCell = NULL;
+  //prvs.mPvs = root->GetPvs();
 }
 
@@ -4519,5 +4522,6 @@
 	Vector3 bsize = mViewSpaceBox.Size();
 	const Vector3 viewPoint(mViewSpaceBox.Center());
-	const Vector3 width = Vector3(mFilterWidth);
+	float w = Magnitude(mViewSpaceBox.Size())*mFilterWidth;
+	const Vector3 width = Vector3(w);
 	
 	PrVs testPrVs;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 713)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 746)
@@ -54,7 +54,7 @@
   mWireFrame = false;
   environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
-  mSnapErrorFrames = false;
-  mSnapPrefix = "";
-
+  mSnapErrorFrames = true;
+  mSnapPrefix = "snap/";
+  mUseForcedColors = false;
 }
 
@@ -162,5 +162,5 @@
   int i = 0;
 
-  if (!mUseFalseColors)
+  if (!mUseFalseColors && !mUseForcedColors)
 	SetupMaterial(mesh->mMaterial);
   
@@ -202,6 +202,65 @@
 	wglGetProcAddress("glGetOcclusionQueryuivNV");
 
-	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
-
+
+
+#if 0
+  GLfloat mat_ambient[]   = {  0.5, 0.5, 0.5, 1.0  };
+  /*  mat_specular and mat_shininess are NOT default values	*/
+  GLfloat mat_diffuse[]   = {  1.0, 1.0, 1.0, 1.0  };
+  GLfloat mat_specular[]  = {  0.3, 0.3, 0.3, 1.0  };
+  GLfloat mat_shininess[] = {  1.0  };
+  
+  GLfloat light_ambient[]  = {  0.2, 0.2, 0.2, 1.0  };
+  GLfloat light_diffuse[]  = {  0.4, 0.4, 0.4, 1.0  };
+  GLfloat light_specular[] = {  0.3, 0.3, 0.3, 1.0  };
+  
+  GLfloat lmodel_ambient[] = {  0.3, 0.3, 0.3, 1.0  };
+  
+  
+  // default Material
+  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
+  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
+  glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
+  glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
+
+  // a light
+  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
+  
+  glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
+  glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
+  glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
+  
+  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+  
+  glEnable(GL_LIGHTING);
+  glEnable(GL_LIGHT0);
+  glEnable(GL_LIGHT1);
+  
+  
+  // set position of the light
+  GLfloat infinite_light[] = {  1.0, 0.8, 1.0, 0.0  };
+  glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
+  
+  // set position of the light2
+  GLfloat infinite_light2[] = {  -0.3, 1.5, 1.0, 0.0  };
+  glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
+  
+  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+  //   glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
+  glEnable(GL_COLOR_MATERIAL);
+  
+  glShadeModel( GL_FLAT );
+  
+  glDepthFunc( GL_LESS );
+  glEnable( GL_DEPTH_TEST );
+#endif
+
+  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
+
+  glEnable( GL_NORMALIZE );
+  
+  glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
 }
 
@@ -213,5 +272,9 @@
   if (mViewCellsManager)
 	vc = mViewCellsManager->GetViewCells().size();
-  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d",
+  int filter = 0;
+  if (mViewCellsManager)
+	filter = mViewCellsManager->GetMaxFilterSize();
+
+  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",
 			mFrame,
 			mViewPoint.x,
@@ -221,7 +284,107 @@
 			mViewDirection.y,
 			mViewDirection.z,
-			vc
+			vc,
+
+			filter,
+			mPvsSize,
+			mRenderError*100.0f
 			);
+  
+  glColor3f(0.0f,0.0f,0.0f);
   renderText(0,20,s);
+  
+  if (mShowRenderCost) {
+	static vector<float> costFunction;
+	static float maxCost = -1;
+	if (costFunction.size()==0) {
+	  ViewCellsTree *tree = mViewCellsManager->GetViewCellsTree();
+	  if (tree) {
+		tree->GetCostFunction(costFunction);
+		maxCost = -1;
+		for (int i=0;  i < costFunction.size(); i++) {
+		  //		  cout<<i<<":"<<costFunction[i]<<" ";
+		  if (costFunction[i] > maxCost)
+			maxCost = costFunction[i];
+		}
+	  }
+	}
+
+	
+	int currentPos = mViewCellsManager->GetViewCells().size();
+	float currentCost=-1;
+
+	if (currentPos < costFunction.size())
+	  currentCost = costFunction[currentPos];
+#if 0	
+	cout<<"costFunction.size()="<<costFunction.size()<<endl;
+	cout<<"CP="<<currentPos<<endl;
+	cout<<"MC="<<maxCost<<endl;
+	cout<<"CC="<<currentCost<<endl;
+#endif
+	if (costFunction.size()) {
+	  glDisable(GL_DEPTH_TEST);
+	  // init ortographic projection
+	  glMatrixMode(GL_PROJECTION);
+	  glPushMatrix();
+	  
+	  glLoadIdentity();
+	  gluOrtho2D(0, 1.0f, 0, 1.0f);
+	  
+	  glTranslatef(0.1f, 0.1f, 0.0f);
+	  glScalef(0.8f, 0.8f, 1.0f);
+	  glMatrixMode(GL_MODELVIEW);
+	  glLoadIdentity();
+	  
+	  glColor3f(1.0f,0,0);
+	  glBegin(GL_LINE_STRIP);
+	  //	  glVertex3f(0,0,0);
+	  
+	  for (int i=0;  i < costFunction.size(); i++) {
+		float x =  i/(float)costFunction.size();
+		float y = costFunction[i]/(maxCost*0.5f);
+		glVertex3f(x,y,0.0f);
+	  }
+	  glEnd();
+	  
+	  glColor3f(1.0f,0,0);
+	  glBegin(GL_LINES);
+	  float x =  currentPos/(float)costFunction.size();
+	  glVertex3f(x,0.0,0.0f);
+	  glVertex3f(x,1.0f,0.0f);
+	  glEnd();
+	  
+	  glColor3f(0.0f,0,0);
+	  // show a grid
+	  glBegin(GL_LINE_LOOP);
+	  glVertex3f(0,0,0.0f);
+	  glVertex3f(1,0,0.0f);
+	  glVertex3f(1,1,0.0f);
+	  glVertex3f(0,1,0.0f);
+	  glEnd();
+
+	  glBegin(GL_LINES);
+	  for (int i=0;  i < 50000 && i < costFunction.size(); i+=10000) {
+		float x =  i/(float)costFunction.size();
+		glVertex3f(x,0.0,0.0f);
+		glVertex3f(x,1.0f,0.0f);
+	  }
+
+	  for (int i=0;  i < maxCost; i+=100) {
+		float y = i/(maxCost*0.5f);
+		glVertex3f(0,y,0.0f);
+		glVertex3f(1,y,0.0f);
+	  }
+
+	  glEnd();
+
+	  
+	  // restore the projection matrix
+	  glMatrixMode(GL_PROJECTION);
+	  glPopMatrix();
+	  glMatrixMode(GL_MODELVIEW);
+	  glEnable(GL_DEPTH_TEST);
+
+	}
+  }
 }
 
@@ -365,5 +528,5 @@
 
 	glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
-
+	
 	// Render PVS
 	std::map<Intersectable *,
@@ -467,4 +630,50 @@
 }
 
+void
+GlRendererWidget::RenderPvs()
+{
+  SetupCamera();
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+  
+  ViewCell *viewcell;
+  //  viewcell = mViewCellsManager->GetViewCell(mViewPoint);
+
+  PrVs prvs;
+  //  mViewCellsManager->SetMaxFilterSize(1);
+  mViewCellsManager->GetPrVS(mViewPoint, prvs);
+  viewcell = prvs.mViewCell;
+  
+  if (viewcell) {
+	ObjectPvs &pvs = viewcell->GetPvs();
+
+	// read back the texture
+	std::map<Intersectable *,
+	  PvsData<Intersectable *>,
+	  LtSample<Intersectable *> >::const_iterator it = pvs.mEntries.begin();
+
+	mPvsSize = pvs.mEntries.size();
+	  
+	for (; it != pvs.mEntries.end(); ++ it) {
+	  Intersectable *object = (*it).first;
+	  float visibility = log10((*it).second.mSumPdf + 1)/5.0f;
+	  glColor3f(visibility, 0.0f, 0.0f);
+	  mUseForcedColors = true;
+	  RenderIntersectable(object);
+	  mUseForcedColors = false;
+	}
+
+	if (mRenderFilter) {
+	  mWireFrame = true;
+	  RenderIntersectable(viewcell);
+	  mWireFrame = false;
+	}
+	mViewCellsManager->DeleteLocalMergeTree(viewcell);
+  } else {
+	ObjectContainer::const_iterator oi = mObjects.begin();
+	for (; oi != mObjects.end(); oi++)
+	  RenderIntersectable(*oi);
+  }
+}
+
 float
 GlRendererWidget::RenderErrors()
@@ -520,5 +729,7 @@
 	  PvsData<Intersectable *>,
 	  LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin();
-	
+
+	mPvsSize = viewcell->GetPvs().mEntries.size();
+
 	for (; it != viewcell->GetPvs().mEntries.end(); ++ it) {
 	  Intersectable *object = (*it).first;
@@ -540,5 +751,4 @@
 		  diff.setPixel(x, y, qRgba(255,128,128,255));
 		  errorPixels++;
-		  
 		}
 	pErrorPixels = ((float)errorPixels)/(im1.height()*im1.width());
@@ -556,5 +766,5 @@
   // now render im1
   if (viewcell) {
-	if (1 || mTopView) {
+	if (0 && mTopView) {
 	  mWireFrame = true;
 	  RenderIntersectable(viewcell);
@@ -608,4 +818,5 @@
 	mViewCellsManager->DeleteLocalMergeTree(viewcell);
 
+  mRenderError = pErrorPixels;
   return pErrorPixels;
 }
@@ -673,4 +884,7 @@
 	  mPvsErrorBuffer[i].mPvsSize = pvsSize;
 
+	  emit UpdatePvsErrorItem(i,
+							  mPvsErrorBuffer[i]);
+	  
 	  cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")";
 	  //	  swapBuffers();
@@ -762,12 +976,16 @@
   
   if (!mRenderViewCells) {
-	RenderErrors();
+	if (mRenderErrors)
+	  RenderErrors();
+	else
+	  RenderPvs();
 	RenderInfo();
   } else {
 	RenderViewCells();
-
+	
 	mWireFrame = true;
 	RenderScene();
 	mWireFrame = false;
+	
 	RenderInfo();
   }
@@ -854,5 +1072,5 @@
   vl->addWidget(slider);
   slider->show();
-  slider->setRange(1, 200);
+  slider->setRange(1, 10000);
   slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
   slider->setValue(200);
@@ -884,4 +1102,14 @@
   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool)));
 
+  cb = new QCheckBox("Show render cost", hbox);
+  hlayout->addWidget(cb);
+  cb->setChecked(false);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRenderCost(bool)));
+
+  cb = new QCheckBox("Show pvs sizes", hbox);
+  hlayout->addWidget(cb);
+  cb->setChecked(false);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPvsSizes(bool)));
+
   vbox->resize(800,100);
 
@@ -892,5 +1120,7 @@
   vl = new QVBoxLayout;
   vbox->setLayout(vl);
-  
+
+
+
   slider = new QSlider(Qt::Horizontal, vbox);
   vbox->layout()->addWidget(slider);
@@ -902,4 +1132,13 @@
   connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int)));
 
+  cb = new QCheckBox("Render errors", vbox);
+  vbox->layout()->addWidget(cb);
+  cb->setChecked(true);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
+
+  cb = new QCheckBox("Render filter", vbox);
+  vbox->layout()->addWidget(cb);
+  cb->setChecked(true);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
 
   cb = new QCheckBox("Cut view cells", vbox);
@@ -922,7 +1161,4 @@
   
   connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
-
-
-
   
   cb = new QCheckBox("Top View", vbox);
@@ -930,7 +1166,50 @@
   cb->setChecked(false);
   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
-  
+
+  vbox = new QGroupBox("PVS Errors", this);
+  layout()->addWidget(vbox);
+
+  vl = new QVBoxLayout;
+  vbox->setLayout(vl);
+
+  mPvsErrorWidget = new QListWidget(vbox);
+  vbox->layout()->addWidget(mPvsErrorWidget);
+  
+  connect(mPvsErrorWidget,
+  		  SIGNAL(doubleClicked(const QModelIndex &)),
+  		  this,
+  		  SLOT(PvsErrorClicked(const QModelIndex &)));
+  
+  QPushButton *button = new QPushButton("Next Error Frame", vbox);
+  vbox->layout()->addWidget(button);
+  connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
+
   setWindowTitle("Preprocessor Control Widget");
   adjustSize();
+}
+
+
+
+void
+RendererControlWidget::FocusNextPvsErrorFrame(void)
+{
+  
+  
+}
+
+void
+RendererControlWidget::UpdatePvsErrorItem(int row,
+										  GlRendererBuffer::PvsErrorEntry &pvsErrorEntry)
+{
+
+  QListWidgetItem *i = mPvsErrorWidget->item(row);
+  QString s;
+  s.sprintf("%5.5f", pvsErrorEntry.mError);
+  if (i) {
+	i->setText(s);
+  } else {
+	new QListWidgetItem(s, mPvsErrorWidget);
+  }
+  mPvsErrorWidget->update();
 }
 
@@ -950,20 +1229,30 @@
   mCutViewCells = false;
   mCutScene = false;
-  
-  RendererControlWidget *cw = new RendererControlWidget(NULL);
-  connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
-  connect(cw, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
-  connect(cw, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
-
-  //connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetMaxFilterSize(int)));
-  //  connect(cw, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
-  //connect(cw, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetViewCellGranularity(int)));
-
-  connect(cw, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
-  connect(cw, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
-  connect(cw, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
-  connect(cw, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
-  
-  cw->show();
+  mRenderErrors = true;
+  mRenderFilter = true;
+  mShowRenderCost = false;
+  mShowPvsSizes = false;
+
+  mPvsSize = 0;
+  mRenderError = 0.0f;
+  mControlWidget = new RendererControlWidget(NULL);
+  
+  connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
+  connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
+  connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
+
+  connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
+
+  connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
+  connect(mControlWidget, SIGNAL(SetShowRenderCost(bool)), this, SLOT(SetShowRenderCost(bool)));
+  connect(mControlWidget, SIGNAL(SetShowPvsSizes(bool)), this, SLOT(SetShowPvsSizes(bool)));
+  connect(mControlWidget, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool)));
+  connect(mControlWidget, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool)));
+  connect(mControlWidget, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool)));
+  connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
+  connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
+
+  
+  mControlWidget->show();
 }
 
@@ -972,6 +1261,6 @@
 {
   if (mViewCellsManager) 
-  	mViewCellsManager->SetMaxFilterSize(number);
-  //  mViewCellsManager->CollectViewCells(number);
+	//  	mViewCellsManager->SetMaxFilterSize(number);
+    mViewCellsManager->CollectViewCells(number);
   updateGL();
 }
@@ -1029,9 +1318,28 @@
   int i;
   ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
+  int maxPvs = -1;
+  for (i=0; i < viewcells.size(); i++) {
+	ViewCell *vc = viewcells[i];
+	int p = vc->GetPvs().GetSize();
+	if (p > maxPvs)
+	  maxPvs = p;
+  }
+
+
   for (i=0; i < viewcells.size(); i++) {
 	ViewCell *vc = viewcells[i];
 	//	Mesh *m = vc->GetMesh();
-	RgbColor c = vc->GetColor();
+
+
+	RgbColor c;
+
+	if (!mShowPvsSizes) 
+	  c = vc->GetColor();
+	else {
+	  float importance = (float)vc->GetPvs().GetSize() / (float)maxPvs;
+	  c = RgbColor(importance, 1.0f - importance, 0.0f);
+	}
 	glColor3f(c.r, c.g, c.b);
+	
 	RenderViewCell(vc);
   }
