Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 517)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 520)
@@ -9,5 +9,5 @@
 #	filename vienna.x3d
 #	filename ../data/vienna/vienna-simple.x3d
-#	filename ../data/vienna/vienna-buildings.x3d
+	filename ../data/vienna/vienna-buildings.x3d
 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d
 #;../data/vienna/vienna-plane.x3d
@@ -15,5 +15,5 @@
 #	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
-	filename ../data/soda/soda5.dat
+#	filename ../data/soda/soda5.dat
 }
 
@@ -30,5 +30,5 @@
 	samplesPerPass  100000
 	initialSamples 300000
-	vssSamples 500000
+	vssSamples 1000000
 	vssSamplesPerPass 100000
 	useImportanceSampling true
@@ -169,5 +169,5 @@
 
 ViewCells {
-	loadFromFile true
+	loadFromFile false
 	exportToFile false
 	#type kdTree
@@ -246,5 +246,5 @@
 	PostProcess {
 		maxCostRatio 0.005
-		minViewCells 200
+		minViewCells 6000
 		maxPvsSize   50000
 	}
@@ -287,5 +287,5 @@
 	Termination {
 		# parameters used for autopartition
-		minRays 		900
+		minRays 		1500
 		minPolygons 		-1
 		maxDepth		30
@@ -293,7 +293,7 @@
 		minArea 		0.0001
 		#minArea 		0.000
-		maxRayContribution	0.4
-		maxCostRatio		0.93
-		missTolerance		3
+		maxRayContribution	0.05
+		maxCostRatio		0.9
+		missTolerance		2
 		#maxAccRayLength	100
 		
@@ -318,5 +318,5 @@
 	PostProcess {
 		maxCostRatio 0.1
-		minViewCells 100
+		minViewCells 150
 		maxPvsSize   1000
 		useRaysForMerge true
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 517)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 520)
@@ -35,5 +35,5 @@
 {
 	friend class ViewCellsParseHandlers;
-
+	friend class VspBspViewCellsManager;
 public:
 	
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp	(revision 503)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp	(revision 520)
@@ -83,4 +83,5 @@
 }
 
+
 float ViewCell::GetArea() const
 {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h	(revision 503)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h	(revision 520)
@@ -157,4 +157,5 @@
 		if ((int)mLeaves.size() > vcStat.maxLeaves)
 			vcStat.maxLeaves = (int)mLeaves.size();
+		vcStat.leaves += (int)mLeaves.size();
 	}
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 518)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 520)
@@ -249,6 +249,10 @@
 	//-- parse view cells construction method
 	environment->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells);
-
-	
+	char buf[100];
+	if (mLoadViewCells)
+	{
+		environment->GetStringValue("ViewCells.filename", buf);
+		mViewCellsFilename = buf;
+	}
 	if (mUseGlRenderer)
 	  renderer = new GlRendererBuffer(1024, 768, mSceneGraph, mViewCellsManager);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 518)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 520)
@@ -403,10 +403,8 @@
 
   //-- load view cells from file if requested
+  // load now because otherwise bounding box is messed up
   if (mLoadViewCells)
   {
-	  char buff[100];
-	  environment->GetStringValue("ViewCells.filename", buff);
-	  string vcFilename(buff);
-	  mViewCellsManager->LoadViewCells(vcFilename, &mObjects);
+	  mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects);
   }
 
@@ -639,7 +637,5 @@
   //-- render simulation after merge
   cout << "\nevaluating bsp view cells render time after merge ... ";
-  
   mRenderSimulator->RenderScene();
-  
   SimulationStatistics ss;
   mRenderSimulator->GetStatistics(ss);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 518)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 520)
@@ -128,4 +128,6 @@
   bool mLoadViewCells;
 
+  string mViewCellsFilename;
+
 protected:
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 519)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 520)
@@ -100,9 +100,7 @@
 void ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays)
 {
-	Debug << "here2" << endl;
 	// view cells not yet constructed
 	if (!ViewCellsConstructed())
 		return;
-	Debug << "here " << rays.size() << endl;
 
 	VssRayContainer::const_iterator it, it_end = rays.end();
@@ -335,5 +333,5 @@
 	mViewCellsStats.Reset();
 	EvaluateViewCellsStats();
-
+	// has to be recomputed
 	mTotalAreaValid = false;
 }
@@ -361,5 +359,5 @@
 				  termination,
 				  viewcells);
-  Debug << "constribution: " << (int)viewcells.size() << endl;
+  //Debug << "constribution: " << (int)viewcells.size() << endl;
   // copy viewcells memory efficiently
   const bool storeViewcells = false;
@@ -1965,6 +1963,9 @@
 		return 0;
 	}
-	// view cells already finished
-	else if (mViewCellsFinished)
+
+	EvaluateViewCellsStats();
+
+	// view cells already finished post processing step
+	if (mViewCellsFinished)
 		return 0;
 
@@ -1973,5 +1974,5 @@
 
 	Debug << "post processing using " << (int)postProcessRays.size() << " samples" << endl;
-	EvaluateViewCellsStats();
+	
 	Debug << "\nview cell partition after sampling:\n" << mViewCellsStats << endl << endl;
 
@@ -1983,4 +1984,6 @@
 	// collapse sibling leaves that share the same view cell
 	mVspBspTree->CollapseTree();
+
+	ResetViewCells();
 
 	// real meshes are only contructed only at this stage
@@ -2372,4 +2375,6 @@
 	
 	bool success = parser.ParseFile(filename, mVspBspTree, this, objects);
+	mVspBspTree->RepairViewCellsLeafLists();
+	mVspBspTree->mBox = GetViewSpaceBox();
 	ResetViewCells();
 	CreateViewCellMeshes();
