Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 375)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 378)
@@ -793,6 +793,8 @@
 	static bool sStoreSplitPolys;
 
-	/// threshold where view cells are merged
+	//-- thresholds used for view cells are merging
 	static int sMinPvsDif;
+	static int sMinPvs;
+	static int sMaxPvs;
 
 private:
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 376)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 378)
@@ -1165,7 +1165,17 @@
 		 "bspTree");
 
-  RegisterOption("ViewCells.minPvsDif",
+  RegisterOption("ViewCells.PostProcessing.minPvsDif",
+		 optInt,
+		 "-view_cells_min_pvs_dif",
+		 "10");
+  
+  RegisterOption("ViewCells.PostProcessing.maxPvs",
+		 optInt,
+		 "-view_cells_max_pvs",
+		 "300");
+
+  RegisterOption("ViewCells.PostProcessing.minPvs",
 		 optString,
-		 "-view_cells_min_pvs_dif",
+		 "-view_cells_min_pvs",
 		 "10");
 
@@ -1190,5 +1200,5 @@
 	  "100000");
 
-  RegisterOption("BspTree.PostProcessing.samples",
+  RegisterOption("ViewCells.PostProcessing.samples",
 	  optInt,
 	  "-bsp_postprocessing_samples=",
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 375)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 378)
@@ -24,4 +24,6 @@
 int BspTree::sTermMaxRays = -1;
 int BspTree::sMinPvsDif = 10;
+int BspTree::sMinPvs = 10;
+int BspTree::sMaxPvs = 500;
 
 float BspTree::sCt_div_ci = 1.0f;
@@ -349,4 +351,6 @@
 	app << setprecision(4);
 
+	app << "#N_OVERALLPVS ( objects in PVS )\n" << pvs << endl;
+
 	app << "#N_PMAXPVS ( largest PVS )\n" << maxPvs << endl;
 
@@ -1482,5 +1486,8 @@
 	Vector3::sDistToleranceSqrt = Vector3::sDistTolerance * Vector3::sDistTolerance;
 
-	environment->GetIntValue("ViewCells.minPvsDif", sMinPvsDif);
+	// post processing stuff
+	environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", sMinPvsDif);
+	environment->GetIntValue("ViewCells.PostProcessing.minPvs", sMinPvs);
+	environment->GetIntValue("ViewCells.PostProcessing.maxPvs", sMaxPvs);
 
     Debug << "BSP max depth: " << sTermMaxDepth << endl;
@@ -1814,15 +1821,16 @@
 		return false;
 
-	/*Debug << "merge (" << sMinPvsDif << ")" << endl;
-	Debug << "size f: " << fvc->GetPvs().GetSize() << ", "
-		  << "size b: " << bvc->GetPvs().GetSize() << endl;
-	
-	Debug << "diff f: " << fvc->GetPvs().Diff(bvc->GetPvs()) << ", "
-		  << "diff b: " << bvc->GetPvs().Diff(fvc->GetPvs()) << endl;*/
-
-    if ((fvc->GetPvs().Diff(bvc->GetPvs()) < sMinPvsDif) &&
-	    (bvc->GetPvs().Diff(fvc->GetPvs()) < sMinPvsDif))
-		return true;
-
+	int fdiff = fvc->GetPvs().Diff(bvc->GetPvs());
+
+	if (fvc->GetPvs().GetSize() + fdiff < sMaxPvs)
+	{
+		if ((fvc->GetPvs().GetSize() < sMinPvs) ||	
+			(bvc->GetPvs().GetSize() < sMinPvs) ||
+			((fdiff < sMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < sMinPvsDif)))
+		{
+			return true;
+		}
+	}
+	
 	return false;
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 373)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 378)
@@ -267,4 +267,7 @@
     for (; vi != face->mVertexIndices.end(); vi++)
       stream<<*vi<<" ";
+	if (mWireframe) // final line to finish polygon
+		stream << (*face->mVertexIndices.begin()) << " ";
+
     stream<<"-1"<<endl;
   }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 375)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 378)
@@ -14,5 +14,5 @@
   environment->GetIntValue("Sampling.totalSamples", mTotalSamples);
   environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples);
-  environment->GetIntValue("BspTree.PostProcessing.samples", mPostProcessSamples);
+  environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples);
   mKdPvsDepth = 100;
   mStats.open("stats.log");
@@ -531,8 +531,15 @@
 		cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
   
-	//-- post processing of bsp view cells
 	if (mBspTree)
 	{
-		int vcSize = 0;
+		//-- render simulation
+		cout << "\nevaluating render time before merge ... ";
+		Real rt = SimulateRendering();
+		
+		cout << "avg render time: " << rt * 1e-3 << endl;
+		Debug << "avg render time: " << rt * 1e-3 << endl;
+
+		//-- post processing of bsp view cells
+        int vcSize = 0;
 		int pvsSize = 0;
 
@@ -553,6 +560,4 @@
 			 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl;
 
-		cout << "evaluating render time heuristics ... ";
-
 		//-- recount pvs
 		mBspTree->EvaluateViewCellsStats(stat);
@@ -560,7 +565,10 @@
 		Debug << "after post processing:\n" << stat << endl;
 
-		Real rt = SimulateRendering();
-		cout << "finished" << endl;
-
+		//-- render simulation
+		cout << "\nevaluating render time after merge ... ";
+			
+		rt = SimulateRendering();
+
+		cout << "render time: " << rt * 1e-3 << endl;
 		Debug << "render time: " << rt * 1e-3 << endl;
 	}
@@ -917,5 +925,4 @@
 
 
-
 Real SamplingPreprocessor::RenderPvs(ViewCell &viewCell, 
 									 const float objRenderTime) const
@@ -959,6 +966,8 @@
 	renderTime /= totalArea;
 
+	Debug << "render time without overhead: " << renderTime * 1e-3 << endl;
+	
 	renderTime += (float)viewCells.size() * vcOverhead;
-	
+
 	return renderTime;
 }
