Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 880)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 884)
@@ -424,4 +424,11 @@
 				);
 
+  void
+  ApplySpatialFilter(
+					 KdTree *kdTree,
+					 const float spatialFilterSize,
+					 ObjectPvs &pvs
+					 );
+	
 	/** Returns bounding box of a view cell.
 	*/
@@ -447,4 +454,8 @@
 	static ViewCellsManager *LoadViewCells(const string filename, ObjectContainer *objects);
 
+  float GetFilterWidth() {
+	return Magnitude(mViewSpaceBox.Size())*mFilterWidth;
+  }
+  
 protected:
     void
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 884)
@@ -686,6 +686,6 @@
 	rssSamples += (int)vssRays.size();
 
-	cout<<"Generated "<<castRays<<" rays, progress "<<totalSamples/((float) mRssSamples +
-																	mInitialSamples)<<"%\n";
+	cout<<"Generated "<<castRays<<" rays, progress "<<100.0f*totalSamples/((float) mRssSamples +
+																		   mInitialSamples)<<"%\n";
 	
 	
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 878)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 884)
@@ -9,6 +9,6 @@
 #	filename vienna.x3d
 # filename ../data/vienna/vienna-simple.x3d
-#filename ../data/vienna/vienna-buildings.x3d
-filename ../data/vienna/city1500_flat_1.x3d
+filename ../data/vienna/vienna-buildings.x3d
+#filename ../data/vienna/city1500_flat_1.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
@@ -53,7 +53,7 @@
 	samplesPerPass  100000
 	initialSamples 500000
-	vssSamples 1000000
-	vssSamplesPerPass 200000
-	useImportanceSampling false
+	vssSamples 5000000
+	vssSamplesPerPass 500000
+	useImportanceSampling true
 	loadInitialSamples  false
 	storeInitialSamples false
@@ -95,7 +95,7 @@
 	samplesPerPass 500000
 	initialSamples 1000000
-	vssSamples 2000000
+	vssSamples 5000000
 	vssSamplesPerPass 1000000
-	useImportanceSampling false
+	useImportanceSampling true
 
 	directionalSampling false
@@ -203,5 +203,5 @@
 	Filter {
 		maxSize 5
-		width  0.05
+		width  0.02
 	}
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 865)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 884)
@@ -259,6 +259,9 @@
   SetTopDistance(int);
   SetVisibilityFilterSize(int);
+  SetSpatialFilterSize(int);
 
   SetRenderFilter(bool);
+  SetUseFilter(bool);
+  SetUseSpatialFilter(bool);
   SetRenderErrors(bool);
   SetShowViewCells(bool);
@@ -286,7 +289,11 @@
   bool mRenderErrors;
   bool mRenderFilter;
+  bool mUseFilter;
+  bool mUseSpatialFilter;
   bool mShowRenderCost;
+  
   bool mShowPvsSizes;
-
+  float mSpatialFilterSize;
+  
   Plane3 mSceneCutPlane;
   float mTopDistance;
@@ -351,4 +358,14 @@
  }
 
+  void SetUseFilter(bool b) {
+   mUseFilter = b;
+   updateGL();
+ }
+
+  void SetUseSpatialFilter(bool b) {
+	mUseSpatialFilter = b;
+	updateGL();
+  }
+
   
   void
@@ -357,4 +374,7 @@
   void
   SetVisibilityFilterSize(int number);
+
+  void
+  SetSpatialFilterSize(int number);
   
   void
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 882)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 884)
@@ -4844,4 +4844,56 @@
 }
 
+void
+ViewCellsManager::ApplySpatialFilter(
+									 KdTree *kdTree,
+									 const float spatialFilterSize,
+									 ObjectPvs &pvs
+									 )
+{
+
+  // now compute a new Pvs by including also objects intersecting the extended boxes of
+  // visible objects
+
+  Intersectable::NewMail();
+  
+  std::map<Intersectable *,
+	PvsData<Intersectable *>,
+	LtSample<Intersectable *> >::const_iterator oi;
+  
+  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) {
+	Intersectable *object = (*oi).first;
+	object->Mail();
+  }
+
+  ObjectPvs nPvs;
+  int nPvsSize=0;
+  // now go through the pvs again
+  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) {
+	Intersectable *object = (*oi).first;
+
+	//	Vector3 center = object->GetBox().Center();
+	//	AxisAlignedBox3 box(center - Vector3(spatialFilterSize/2),
+	//						center + Vector3(spatialFilterSize/2));
+
+	AxisAlignedBox3 box = object->GetBox();
+	box.Enlarge(Vector3(spatialFilterSize/2));
+
+	ObjectContainer objects;
+
+	// $$ warning collect objects takes only unmailed ones!
+	kdTree->CollectObjects(box,
+						   objects);
+	//	cout<<"collected objects="<<objects.size()<<endl;
+	ObjectContainer::const_iterator noi = objects.begin();
+	for (; noi != objects.end(); ++noi) {
+	  Intersectable *o = *noi;
+	  // $$ JB warning: pdfs are not correct at this point!
+	  nPvs.AddSample(o, Limits::Small);
+	  nPvsSize++;
+	}
+  }
+  //  cout<<"nPvs size = "<<nPvsSize<<endl;
+  pvs.Merge(nPvs);
+}
 
 void
@@ -4881,46 +4933,5 @@
   }
   
-  // now compute a new Pvs by including also objects intersecting the extended boxes of
-  // visible objects
-
-  Intersectable::NewMail();
-  
-  std::map<Intersectable *,
-	PvsData<Intersectable *>,
-	LtSample<Intersectable *> >::const_iterator oi;
-  
-  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) {
-	Intersectable *object = (*oi).first;
-	object->Mail();
-  }
-
-  ObjectPvs nPvs;
-  // now go through the pvs again
-  for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++oi) {
-	Intersectable *object = (*oi).first;
-
-	//	Vector3 center = object->GetBox().Center();
-	//	AxisAlignedBox3 box(center - Vector3(spatialFilterSize/2),
-	//						center + Vector3(spatialFilterSize/2));
-
-	AxisAlignedBox3 box = object->GetBox();
-	box.Enlarge(Vector3(spatialFilterSize/2));
-
-	ObjectContainer objects;
-
-	// $$ warning collect objects takes only unmailed ones!
-	kdTree->CollectObjects(box,
-						   objects);
-	//	cout<<"collected objects="<<objects.size()<<endl;
-	ObjectContainer::const_iterator noi = objects.begin();
-	for (; noi != objects.end(); ++noi) {
-	  Intersectable *o = *noi;
-	  if (!o->Mailed())
-		// $$ JB warning: pdfs are not correct at this point!
-		nPvs.AddSample(o, Limits::Small);
-	}
-  }
-
-  pvs.Merge(nPvs);
+  ApplySpatialFilter(kdTree, spatialFilterSize, pvs);
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 878)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 884)
@@ -44,5 +44,4 @@
 #endif
 
-bool useFilter = false;
 
 GlRenderer::GlRenderer(SceneGraph *sceneGraph,
@@ -848,6 +847,6 @@
   PrVs prvs;
   
-  if (!useFilter) {
-	viewcell = mViewCellsManager->GetViewCell(mViewPoint);
+  if (!mUseFilter) {
+	viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
   } else {
 	//  mViewCellsManager->SetMaxFilterSize(1);
@@ -857,6 +856,16 @@
   
   if (viewcell) {
-	ObjectPvs &pvs = viewcell->GetPvs();
-
+	// copy the pvs so that it can be filtered...
+	ObjectPvs pvs = viewcell->GetPvs();
+
+	if (mUseSpatialFilter) {
+	  mViewCellsManager->ApplySpatialFilter(mKdTree,
+											mSpatialFilterSize*
+											Magnitude(mViewCellsManager->GetViewSpaceBox().Size()),
+											//											mViewCellsManager->GetFilterWidth()/2,
+											pvs);
+	}
+	
+	
 	// read back the texture
 	std::map<Intersectable *,
@@ -881,5 +890,5 @@
 	}
 	
-	if (useFilter)
+	if (mUseFilter)
 	  mViewCellsManager->DeleteLocalMergeTree(viewcell);
   } else {
@@ -924,15 +933,4 @@
   ViewCell *viewcell;
 
-  PrVs prvs;
-  //  mViewCellsManager->SetMaxFilterSize(1);
-
-
-  if (!useFilter)
-	viewcell = mViewCellsManager->GetViewCell(mViewPoint);
-  else {
-	mViewCellsManager->GetPrVS(mViewPoint, prvs);
-	viewcell = prvs.mViewCell;
-  }
-  
   QImage im1, im2;
   QImage diff;
@@ -942,17 +940,5 @@
 	im1 = grabFrameBuffer(true);
 	
-	SetupCamera();
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-	
-	std::map<Intersectable *,
-	  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;
-	  RenderIntersectable(object);
-	}
+	RenderPvs();
 
 	// read back the texture
@@ -978,5 +964,5 @@
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   mUseFalseColors = false;
-	
+  
   oi = mObjects.begin();
   for (; oi != mObjects.end(); oi++)
@@ -1033,7 +1019,4 @@
 
   glDisable(GL_CLIP_PLANE0);
-
-  if (useFilter && viewcell)
-	mViewCellsManager->DeleteLocalMergeTree(viewcell);
   
   mRenderError = pErrorPixels;
@@ -1317,4 +1300,17 @@
 
 
+  label = new QLabel("Spatial Filter size");
+  vbox->layout()->addWidget(label);
+  
+  slider = new QSlider(Qt::Horizontal, vbox);
+  vbox->layout()->addWidget(slider);
+  slider->show();
+  slider->setRange(1, 100);
+  slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+  slider->setValue(10);
+  
+  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSpatialFilterSize(int)));
+
+
 
   QWidget *hbox = new QWidget(vbox);
@@ -1363,8 +1359,19 @@
   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderErrors(bool)));
 
+  cb = new QCheckBox("Use filter", vbox);
+  vbox->layout()->addWidget(cb);
+  cb->setChecked(true);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseFilter(bool)));
+
+  cb = new QCheckBox("Use spatial filter", vbox);
+  vbox->layout()->addWidget(cb);
+  cb->setChecked(true);
+  connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetUseSpatialFilter(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);
@@ -1457,7 +1464,9 @@
   mRenderErrors = false;
   mRenderFilter = true;
+  mUseFilter = true;
+  mUseSpatialFilter = true;
   mShowRenderCost = false;
   mShowPvsSizes = false;
-
+  mSpatialFilterSize = 0.01;
   mPvsSize = 0;
   mRenderError = 0.0f;
@@ -1469,4 +1478,5 @@
 
   connect(mControlWidget, SIGNAL(SetVisibilityFilterSize(int)), this, SLOT(SetVisibilityFilterSize(int)));
+  connect(mControlWidget, SIGNAL(SetSpatialFilterSize(int)), this, SLOT(SetSpatialFilterSize(int)));
 
   connect(mControlWidget, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool)));
@@ -1478,4 +1488,7 @@
   connect(mControlWidget, SIGNAL(SetRenderErrors(bool)), this, SLOT(SetRenderErrors(bool)));
   connect(mControlWidget, SIGNAL(SetRenderFilter(bool)), this, SLOT(SetRenderFilter(bool)));
+  connect(mControlWidget, SIGNAL(SetUseFilter(bool)), this, SLOT(SetUseFilter(bool)));
+  connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
+		  this, SLOT(SetUseSpatialFilter(bool)));
 
   
@@ -1489,4 +1502,5 @@
 	//  	mViewCellsManager->SetMaxFilterSize(number);
     mViewCellsManager->CollectViewCells(number);
+
   updateGL();
 }
@@ -1497,4 +1511,11 @@
   if (mViewCellsManager) 
   	mViewCellsManager->SetMaxFilterSize(number);
+  updateGL();
+}
+
+void
+GlRendererWidget::SetSpatialFilterSize(int number)
+{
+  mSpatialFilterSize = 1e-3*number;
   updateGL();
 }
