Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 685)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 713)
@@ -301,8 +301,8 @@
 
 float
-GlRendererBuffer::GetPixelError()
+GlRendererBuffer::GetPixelError(int &pvsSize)
 {
   float pErrorPixels = -1.0f;
-
+  
   glReadBuffer(GL_BACK);
   
@@ -351,6 +351,13 @@
 	
 
-  ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
-	
+  ViewCell *viewcell = NULL;
+  
+  PrVs prvs;
+  //  mViewCellsManager->SetMaxFilterSize(1);
+  mViewCellsManager->GetPrVS(mViewPoint, prvs);
+  viewcell = prvs.mViewCell;
+  
+  //  ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
+  pvsSize = 0;
   if (viewcell) {
 	SetupCamera();
@@ -363,4 +370,6 @@
 	  PvsData<Intersectable *>,
 	  LtSample<Intersectable *> >::const_iterator it = viewcell->GetPvs().mEntries.begin();
+
+	pvsSize = viewcell->GetPvs().mEntries.size();
 	
 	for (; it != viewcell->GetPvs().mEntries.end(); ++ it) {
@@ -436,4 +445,7 @@
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
   }
+
+  if (viewcell)
+	mViewCellsManager->DeleteLocalMergeTree(viewcell);
   
   return pErrorPixels;
@@ -487,5 +499,11 @@
 	RenderIntersectable(*oi);
 
-  ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
+  ViewCell *viewcell;
+  //  viewcell = mViewCellsManager->GetViewCell(mViewPoint);
+
+  PrVs prvs;
+  //  mViewCellsManager->SetMaxFilterSize(1);
+  mViewCellsManager->GetPrVS(mViewPoint, prvs);
+  viewcell = prvs.mViewCell;
   
   QImage im1, im2;
@@ -587,4 +605,7 @@
   glDisable(GL_CLIP_PLANE0);
 
+  if (viewcell)
+	mViewCellsManager->DeleteLocalMergeTree(viewcell);
+
   return pErrorPixels;
 }
@@ -615,5 +636,5 @@
 {
   for (int i=0; i < mPvsStatFrames; i++) {
-	mPvsErrorBuffer[i] = 1.0f;
+	mPvsErrorBuffer[i].mError = 1.0f;
   }
 }
@@ -646,11 +667,15 @@
 	}
 #endif
-	if (mPvsErrorBuffer[i] > 0.0f) {
-	  mPvsErrorBuffer[i] = GetPixelError();
-	  cout<<"("<<i<<","<<mPvsErrorBuffer[i]<<")";
+	if (mPvsErrorBuffer[i].mError > 0.0f) {
+	  int pvsSize;
+	  float error = GetPixelError(pvsSize);
+	  mPvsErrorBuffer[i].mError = error;
+	  mPvsErrorBuffer[i].mPvsSize = pvsSize;
+
+	  cout<<"("<<i<<","<<mPvsErrorBuffer[i].mError<<")";
 	  //	  swapBuffers();
 	}
 	
-	err = mPvsErrorBuffer[i];
+	err = mPvsErrorBuffer[i].mError;
 	
 	if (err >= 0.0f) {
@@ -658,4 +683,6 @@
 		mPvsStat.maxError = err;
 	  mPvsStat.sumError += err;
+	  mPvsStat.sumPvsSize += mPvsErrorBuffer[i].mPvsSize;
+	  
 	  if (err == 0.0f)
 		mPvsStat.errorFreeFrames++;
@@ -820,13 +847,28 @@
   vl = new QVBoxLayout;
   vbox->setLayout(vl);
-  
+
+  QLabel *label = new QLabel("Granularity");
+  vbox->layout()->addWidget(label);
+
   QSlider *slider = new QSlider(Qt::Horizontal, vbox);
   vl->addWidget(slider);
   slider->show();
-  slider->setRange(1, 5000);
+  slider->setRange(1, 200);
   slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
-  slider->setValue(500);
+  slider->setValue(200);
 
   connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
+
+  label = new QLabel("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(3);
+  
+  connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetVisibilityFilterSize(int)));
 
 
@@ -881,4 +923,7 @@
   connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int)));
 
+
+
+  
   cb = new QCheckBox("Top View", vbox);
   vbox->layout()->addWidget(cb);
@@ -886,5 +931,5 @@
   connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool)));
   
-
+  setWindowTitle("Preprocessor Control Widget");
   adjustSize();
 }
@@ -910,4 +955,9 @@
   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)));
@@ -921,5 +971,15 @@
 GlRendererWidget::SetViewCellGranularity(int number)
 {
-  mViewCellsManager->CollectViewCells(number);
+  if (mViewCellsManager) 
+  	mViewCellsManager->SetMaxFilterSize(number);
+  //  mViewCellsManager->CollectViewCells(number);
+  updateGL();
+}
+
+void
+GlRendererWidget::SetVisibilityFilterSize(int number)
+{
+  if (mViewCellsManager) 
+  	mViewCellsManager->SetMaxFilterSize(number);
   updateGL();
 }
