Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1608)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1613)
@@ -13,4 +13,5 @@
 #include "RssTree.h"
 #include "Trackball.h"
+#include "QtPreprocessorThread.h"
 
 
@@ -1253,7 +1254,9 @@
 	if (mShowRays) {
 	  RssPreprocessor *p = (RssPreprocessor *)mViewCellsManager->GetPreprocessor();
-	  VssRayContainer rays;
-	  p->mRssTree->CollectRays(rays, 10000);
-	  RenderRays(rays);
+	  if (p->mRssTree) {
+		VssRayContainer rays;
+		p->mRssTree->CollectRays(rays, 10000);
+		RenderRays(rays);
+	  }
 	}
 
@@ -1365,4 +1368,5 @@
   GlRendererWidget(sceneGraph, viewcells, tree), QGLWidget(parent, shareWidget, f)
 {
+  mPreprocessorThread = NULL;
   mTopView = false;
   mRenderViewCells = false;
@@ -1396,4 +1400,8 @@
   
   connect(mControlWidget, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int)));
+  connect(mControlWidget, SIGNAL(UpdateAllPvs()), this, SLOT(UpdateAllPvs()));
+  connect(mControlWidget, SIGNAL(ComputeVisibility()), this, SLOT(ComputeVisibility()));
+  connect(mControlWidget, SIGNAL(StopComputation()), this, SLOT(StopComputation()));
+
   connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
   connect(mControlWidget, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int)));
@@ -1424,4 +1432,27 @@
   resize(1000, 500);
   mControlWidget->show();
+}
+
+void
+QtGlRendererWidget::UpdateAllPvs()
+{
+  // $$ does not work so far:(
+  mViewCellsManager->UpdatePvsForEvaluation();
+  //	mViewCellsManager->FinalizeViewCells(false);
+}
+
+void
+QtGlRendererWidget::ComputeVisibility()
+{
+  cerr<<"Compute Visibility called!\n"<<endl;
+  if (!mPreprocessorThread->isRunning())
+	mPreprocessorThread->RunThread();
+}
+
+void
+QtGlRendererWidget::StopComputation()
+{
+  cerr<<"stop computation called!\n"<<endl;
+  mViewCellsManager->GetPreprocessor()->mStopComputation = true;
 }
 
@@ -1763,5 +1794,5 @@
   QLabel *label = new QLabel("Granularity");
   vbox->layout()->addWidget(label);
-
+  
   QSlider *slider = new QSlider(Qt::Horizontal, vbox);
   vl->addWidget(slider);
@@ -1771,6 +1802,14 @@
   slider->setValue(200);
 
+  
   connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int)));
 
+  {
+	QPushButton *button = new QPushButton("Update all PVSs", vbox);
+	vbox->layout()->addWidget(button);
+	connect(button, SIGNAL(clicked()), SLOT(UpdateAllPvs()));
+  }
+  
+  
   label = new QLabel("Filter size");
   vbox->layout()->addWidget(label);
@@ -1910,25 +1949,45 @@
   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);
+  QPushButton *button = new QPushButton("Compute Visibility", vbox);
   vbox->layout()->addWidget(button);
-  connect(button, SIGNAL(clicked(void)), SLOT(FocusNextPvsErrorFrame(void)));
-
+  connect(button, SIGNAL(clicked()), SLOT(ComputeVisibility()));
+
+  button = new QPushButton("Stop Computation", vbox);
+  vbox->layout()->addWidget(button);
+  connect(button, SIGNAL(clicked()), SLOT(StopComputation()));
+
+
+  if (0) {
+	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();
 }
+
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1579)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1613)
@@ -1715,4 +1715,9 @@
 					"true");
 
+	RegisterOption("Preprocessor.delayVisibilityComputation",
+				   optBool,
+				   "preprocessor_delay_computation=",
+				   "true");
+
 	RegisterOption("Preprocessor.pvsRenderErrorSamples",
 				   optInt,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1608)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1613)
@@ -134,5 +134,6 @@
 mPass(0),
 mSceneGraph(NULL),
-mRayCaster(NULL)
+mRayCaster(NULL),
+mStopComputation(false)
 {
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
@@ -141,4 +142,7 @@
 	renderer = NULL;
   
+	Environment::GetSingleton()->GetBoolValue("Preprocessor.delayVisibilityComputation",
+											  mDelayVisibilityComputation);
+	
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlDebugger", mUseGlDebugger);
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.loadMeshes", mLoadMeshes);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h	(revision 1594)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.h	(revision 1613)
@@ -13,6 +13,7 @@
 #include "GlRenderer.h"
 #include "Beam.h"
-
+#include "QtPreprocessorThread.h"
 class QWidget;
+//class QtPreprocessorThread;
 
 namespace GtpVisibilityPreprocessor {
@@ -143,5 +144,8 @@
 
   signals:
-  
+
+  void ComputeVisibility();
+  void StopComputation();
+  void UpdateAllPvs();
   void SetViewCellGranularity(int);
   void SetSceneCut(int);
@@ -202,4 +206,6 @@
   
   QtRendererControlWidget *mControlWidget;
+
+  QtPreprocessorThread *mPreprocessorThread;
   
   QtGlRendererWidget(SceneGraph *sceneGraph,
@@ -211,4 +217,7 @@
   QtGlRendererWidget() {};
 
+  void SetThread(QtPreprocessorThread *t) {
+	mPreprocessorThread = t;
+  }
   void
   RenderRenderCost();
@@ -263,4 +272,8 @@
 
  public slots:
+
+ void UpdateAllPvs();
+  void ComputeVisibility();
+  void StopComputation();
 
  void SetRenderErrors(bool b) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1585)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1613)
@@ -627,16 +627,11 @@
 	  
 	  // now evaluate the ratios for the next pass
-#define TIMES 1
-
-#if TIMES
-	  ratios[0] = sqr(contributions[0]/times[0]);
-	  ratios[1] = sqr(contributions[1]/times[1]);
-	  ratios[2] = sqr(contributions[2]/times[2]);
-#else
-	  ratios[0] = sqr(contributions[0]/nrays[0]);
-	  ratios[1] = sqr(contributions[1]/nrays[1]);
-	  ratios[2] = sqr(contributions[2]/nrays[2]);
-#endif
-	  NormalizeRatios(ratios);
+#define TIME_WEIGHT 0.5f
+
+	  ratios[0] = sqr(contributions[0]/(TIME_WEIGHT*times[0] + (1 - TIME_WEIGHT)*nrays[0]));
+	  ratios[1] = sqr(contributions[1]/(TIME_WEIGHT*times[1] + (1 - TIME_WEIGHT)*nrays[1]));
+	  ratios[2] = sqr(contributions[2]/(TIME_WEIGHT*times[2] + (1 - TIME_WEIGHT)*nrays[2]));
+
+					  NormalizeRatios(ratios);
 
 	  cout<<"New ratios: "<<ratios[0]<<" "<<ratios[1]<<" "<<ratios[2]<<endl;
@@ -772,9 +767,11 @@
 	if (totalSamples >= mRssSamples + mInitialSamples)
 	  break;
-
+	
 	
 	rssPass++;
 	mPass++;
 	mRssTree->SetPass(mPass);
+
+	
   }
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1608)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1613)
@@ -7,5 +7,4 @@
 
 #filename ../data/arena/export.obj
-
 # filename ../data/City4M/City4M.obj
 # filename ../data/CityModel/CityModel.obj
@@ -15,11 +14,11 @@
 # 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;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
-
-# ../data/vienna/vienna-plane.x3d;
+#filename ../data/vienna/city1500_flat_1.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
+filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
+
+#;../data/vienna/vienna-plane.x3d;
 # filename ../data/vienna/viewcells-25-sel.x3d
 #filename ../data/atlanta/atlanta2.x3d
-filename ../data/soda/soda.dat
+# filename ../data/soda/soda.dat
 #filename ../data/test1/test2.x3d
 #filename ../data/soda/soda5.dat
@@ -35,4 +34,5 @@
 
 Preprocessor {
+	delayVisibilityComputation false
 	# stored sample rays
 	samplesFilename rays.out
@@ -79,6 +79,6 @@
 	samplesPerPass 1000
 	initialSamples 1000000
-	vssSamples 10000000
-	vssSamplesPerPass 1000000
+	vssSamples 20000000
+	vssSamplesPerPass 500000
 	useImportanceSampling true
 
@@ -148,7 +148,7 @@
 		minCost 4
 		maxDepth 30
-		maxCostRatio 1.0
+		maxCostRatio 1.1
 		ct_div_ci 0.5
-		maxNodes 300000
+		maxNodes 500000
 #500000	
 	}
@@ -192,6 +192,6 @@
 	#type vspKdTree
 	#type bspTree
-	type vspBspTree
-	#type vspOspTree
+	#type vspBspTree
+	type vspOspTree
 	#type sceneDependent
 	
@@ -260,5 +260,5 @@
 #	filename ../data/soda/soda5-viewcells.xml
 #	filename ../scripts/viewcells_atlanta.xml
-	filename ../data/soda/soda-viewcells-5000.xml
+#	filename ../data/soda/soda-viewcells-5000.xml
 #	filename ../data/test1/test-viewcells.xml
 
@@ -280,5 +280,5 @@
 #	filename ../data/vienna/vienna_simple-21-04-avs2-viewCells.xml
 #	filename ../data/vienna/vienna-viewcells-5000.xml
-#	filename ../data/vienna/vienna-viewcells-1000.xml.zip
+	filename ../data/vienna/vienna-viewcells-1000.xml.zip
 #	filename ../data/vienna/vsposp-seq-viewCells.xml.gz
 
@@ -383,5 +383,4 @@
 	}
 
-
 	# random polygon       = 1
 	# axis aligned         = 2
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1564)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1613)
@@ -202,5 +202,8 @@
 
 	int mPass;
-
+  
+  bool mDelayVisibilityComputation;
+  bool mStopComputation;
+  
 protected:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1608)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1613)
@@ -30,6 +30,6 @@
 
 // $$JB HACK
-#define USE_KD_PVS 0
-#define KD_PVS_AREA 1e-4f
+#define USE_KD_PVS 1
+#define KD_PVS_AREA 1e-3f
 
 namespace GtpVisibilityPreprocessor {
@@ -230,4 +230,5 @@
 	}
 }
+
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1608)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1613)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: út 10. X 22:38:46 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: st 11. X 21:13:40 2006
 # Project:  preprocessor.pro
 # Template: app
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1594)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1613)
@@ -98,6 +98,6 @@
 public:
   
-	static int sMailId;
-	static int sReservedMailboxes;
+  static int sMailId;
+  static int sReservedMailboxes;
   int mMailbox;
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1595)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1613)
@@ -197,5 +197,6 @@
 #if USE_THREADS
 		pt->InitThread();
-		pt->RunThread();
+		if (!preprocessor->mDelayVisibilityComputation)
+		  pt->RunThread();
 #endif
 		
@@ -217,5 +218,6 @@
 												  preprocessor->mViewCellsManager,
 												  preprocessor->mKdTree);
-		  
+
+		  ((QtGlRendererWidget *)rendererWidget)->SetThread((QtPreprocessorThread *)pt);
 		  rendererWidget->Show();
 		  guiSupported = true; 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h	(revision 1457)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h	(revision 1613)
@@ -10,5 +10,5 @@
 class Preprocessor;
 
-class QtPreprocessorThread : public PreprocessorThread, QThread
+class QtPreprocessorThread : public PreprocessorThread, public QThread
 {
 public:
