Index: trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h	(revision 375)
@@ -122,5 +122,5 @@
 	/** Counts the number of different intersectables associated with the polygons.
 	*/
-	static int CountIntersectables(const PolygonContainer &polys);
+	static int ParentObjectsSize(const PolygonContainer &polys);
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 373)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 375)
@@ -68,12 +68,10 @@
   // number of initial polygons
   int polys;
-  /// number of view cells different to the view cell representing unbounded space.
-  int viewCells;
-  /// size of the VPS
-  int pvs;
   /// samples contributing to pvs
   int contributingSamples;
    /// sample contributions to pvs
   int sampleContributions;
+  /// largest pvs
+  int largestPvs;
 
   // Constructor
@@ -97,6 +95,5 @@
 	  polys = 0;
 	  accumDepth = 0;
-	  viewCells = 0;
-	  pvs = 0;
+	 	
 	  contributingSamples = 0;
 	  sampleContributions = 0;
@@ -107,4 +104,61 @@
 
   friend ostream &operator<<(ostream &s, const BspTreeStatistics &stat) {
+    stat.Print(s);
+    return s;
+  }
+  
+};
+
+class BspViewCellsStatistics
+{
+public:
+  
+  /// number of view cells
+  int viewCells;
+
+  /// size of the PVS
+  int pvs;
+  
+  /// largest PVS of all view cells
+  int maxPvs;
+
+  /// smallest PVS of all view cells
+  int minPvs;
+
+  /// view cells with empty PVS
+  int emptyPvs;
+
+  /// number of bsp leaves covering the view space
+  int bspLeaves;
+
+  /// largest number of leaves covered by one view cell
+  int maxBspLeaves;
+
+  
+  // Constructor
+  BspViewCellsStatistics() 
+  {
+	  Reset();
+  }
+
+  double AvgBspLeaves() const {return (double)bspLeaves / (double)viewCells;};
+  double AvgPvs() const {return (double)pvs / (double)viewCells;};
+  
+  
+  void Reset() 
+  {
+	  viewCells = 0;
+	  pvs = 0;
+	  maxPvs = 0;
+	  minPvs = 999999;
+	  emptyPvs = 0;
+	  bspLeaves = 0;
+	  maxBspLeaves = 0;
+  }
+
+  void
+  Print(ostream &app) const;
+
+  friend ostream &operator<<(ostream &s, const BspViewCellsStatistics &stat) {
     stat.Print(s);
     return s;
@@ -422,7 +476,7 @@
 	bool MergeViewCells(BspLeaf *front, BspLeaf *back) const;
 
-	/** Traverses tree and counts PVS size of all view cells
-	*/
-	int CountViewCellPvs() const;
+	/** Traverses tree and counts all view cells as well as their PVS size.
+	*/
+	void EvaluateViewCellsStats(BspViewCellsStatistics &stat) const;
 
 protected:
@@ -667,6 +721,4 @@
 	BspNode *mRoot;
 
-	/// Pointer to the root cell of the viewspace
-	// ViewCell *mRootCell;
 		
 	BspTreeStatistics mStat;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 374)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 375)
@@ -343,4 +343,27 @@
 }
 
+void BspViewCellsStatistics::Print(ostream &app) const
+{
+	app << "===== BspViewCells statistics ===============\n";
+
+	app << setprecision(4);
+
+	app << "#N_PMAXPVS ( largest PVS )\n" << maxPvs << endl;
+
+	app << "#N_PMINPVS ( smallest PVS )\n" << minPvs << endl;
+
+	app << "#N_PAVGPVS ( average PVS )\n" << AvgPvs() << endl;
+
+	app << "#N_PEMPTYPVS ( view cells with PVS smaller 2 )\n" << emptyPvs << endl;
+
+	app << "#N_VIEWCELLS ( number of view cells)\n" << viewCells << endl;
+
+	app << "#N_AVGBSPLEAVES (average number of BSP leaves per view cell )\n" << AvgBspLeaves() << endl;
+
+	app << "#N_MAXBSPLEAVES ( maximal number of BSP leaves per view cell )\n" << maxBspLeaves << endl;
+	
+	app << "===== END OF BspViewCells statistics ==========\n";
+}
+
 void BspTreeStatistics::Print(ostream &app) const
 {
@@ -368,5 +391,5 @@
 	app << "#N_INPUT_POLYGONS (number of input polygons )\n" <<	polys << endl;
 
-	app << "#N_PVS: " << pvs << endl;
+	//app << "#N_PVS: " << pvs << endl;
 
 	app << "#N_ROUTPUT_INPUT_POLYGONS ( ratio polygons after subdivision / input polygons )\n" <<
@@ -375,4 +398,5 @@
 	app << "===== END OF BspTree statistics ==========\n";
 }
+
 
 BspTree::~BspTree()
@@ -1044,5 +1068,5 @@
 		((int)rays.size() > sTermMaxRaysForAxisAligned) &&
 		((sTermMaxObjectsForAxisAligned < 0) || 
-		  (Polygon3::CountIntersectables(polys) > sTermMaxObjectsForAxisAligned)))
+		  (Polygon3::ParentObjectsSize(polys) > sTermMaxObjectsForAxisAligned)))
 	{
 		Plane3 plane;
@@ -1529,7 +1553,9 @@
 	if (data.mDepth >= sTermMaxDepth)
 		++ mStat.maxDepthNodes;
+	
 	// store maximal and minimal depth
 	if (data.mDepth > mStat.maxDepth)
 		mStat.maxDepth = data.mDepth;
+
 	if (data.mDepth < mStat.minDepth)
 		mStat.minDepth = data.mDepth;
@@ -1537,10 +1563,4 @@
 	// accumulate depth to compute average
 	mStat.accumDepth += data.mDepth;
-
-	if (leaf->mViewCell != mRootCell)
-	{	
-		++ mStat.viewCells;
-		mStat.pvs += leaf->mViewCell->GetPvs().GetSize();
-	}
 	
 #ifdef _DEBUG
@@ -1695,7 +1715,8 @@
 }
 
-int BspTree::CountViewCellPvs() const
-{
-	int count = 0;
+void BspTree::EvaluateViewCellsStats(BspViewCellsStatistics &stat) const
+{
+	stat.Reset();
+
 	stack<BspNode *> nodeStack;
 	nodeStack.push(mRoot);
@@ -1713,10 +1734,28 @@
 		if (node->IsLeaf()) 
 		{
-			ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell;
+			++ stat.bspLeaves;
+
+			BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->mViewCell;
 
 			if (!viewCell->Mailed()) 
 			{
 				viewCell->Mail();
-				count += viewCell->GetPvs().GetSize();
+				
+				++ stat.viewCells;
+				int pvsSize = viewCell->GetPvs().GetSize();
+
+                stat.pvs += pvsSize;
+
+				if (pvsSize < 2)
+					++ stat.emptyPvs;
+
+				if (pvsSize > stat.maxPvs)
+					stat.maxPvs = pvsSize;
+
+				if (pvsSize < stat.minPvs)
+					stat.minPvs = pvsSize;
+
+				if ((int)viewCell->mBspLeaves.size() > stat.maxBspLeaves)
+					stat.maxBspLeaves = (int)viewCell->mBspLeaves.size();		
 			}
 		}
@@ -1729,5 +1768,4 @@
 		}
 	}
-	return count;
 }
 
@@ -2308,5 +2346,6 @@
 		Ray *ray = (*rit)->mRay;
 		
-		for (iit = ray->bspIntersections.begin(); iit != ray->bspIntersections.end(); ++ iit)
+		for (iit = ray->bspIntersections.begin(); 
+			 iit != ray->bspIntersections.end(); ++ iit)
 		{
 			BspViewCell *vc = (*iit).mLeaf->mViewCell;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp	(revision 375)
@@ -414,5 +414,5 @@
 }
 
-int Polygon3::CountIntersectables(const PolygonContainer &polys)
+int Polygon3::ParentObjectsSize(const PolygonContainer &polys)
 {
 	int count = 0;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 374)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 375)
@@ -514,5 +514,5 @@
 				 << "k   #SampleContributions=" << passSampleContributions << " (" 
 				 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS="
-				 << pvsSize/(float)objects.size() << endl 
+				 << pvsSize /(float)objects.size() << endl 
 				 << "avg ray contrib=" << avgRayContrib << endl
 				 << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl;
@@ -531,11 +531,19 @@
 		cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
   
+	//-- post processing of bsp view cells
 	if (mBspTree)
 	{
+		int vcSize = 0;
+		int pvsSize = 0;
+
+		BspViewCellsStatistics stat;
+		
+		Debug << "overall scene size: " << objects.size() << endl;
+		mBspTree->EvaluateViewCellsStats(stat);
+		
+		Debug << "original view cell partition:\n" << stat << endl;
+		
 		cout << "starting post processing using " << mSampleRays.size() << " samples ... ";
-
-		Debug << "original pvs size: " << mBspTree->CountViewCellPvs() << endl;
-
-		// merge or subdivide view cells
+		
 		long startTime = GetTime();
 		int merged = PostprocessViewCells(mSampleRays);
@@ -545,9 +553,11 @@
 			 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl;
 
+		cout << "evaluating render time heuristics ... ";
+
 		//-- recount pvs
-		Debug << "merged pvs size: " << mBspTree->CountViewCellPvs() << endl;
-
-
-		cout << "evaluating render time heuristics ... ";
+		mBspTree->EvaluateViewCellsStats(stat);
+		
+		Debug << "after post processing:\n" << stat << endl;
+
 		Real rt = SimulateRendering();
 		cout << "finished" << endl;
@@ -591,7 +601,9 @@
 
 		// export the bsp splits
+		cout << "exporting splits ... ";
 		if (exportSplits)
 	  		ExportSplits(objects);
-		
+		cout << "finished" << endl;
+
 		ExportBspPvs(objects);
 	}
@@ -686,4 +698,5 @@
 {
 	int merged = 0;
+
 	RayContainer::const_iterator rit, rit_end = rays.end();
 	vector<Ray::BspIntersection>::const_iterator iit;
@@ -708,4 +721,5 @@
 			{			
 				mBspTree->MergeViewCells(leaf, previousLeaf);
+
 				++ merged;
 			}
@@ -723,6 +737,4 @@
 	if (exporter) 
 	{	
-		cout << "exporting splits ... ";
-
 		Material m; 
 		m.mDiffuseColor = RgbColor(1, 0, 0);
@@ -769,6 +781,4 @@
 
 		delete exporter;
-
-		cout << "finished" << endl;
 	}
 }
@@ -787,15 +797,18 @@
 	const int raysOut = min((int)mSampleRays.size(), 20000);
 
-	// check whether we can add the current ray to the output rays
-	for (int k = 0; k < raysOut; ++ k) 
+	ViewCell::NewMail();
+
+	for (int i = 0; i < bspLeaves.size(); ++ i)
 	{
-		Ray *ray = mSampleRays[k];
-
-		for (int j = 0; j < (int)ray->bspIntersections.size(); ++ j)
-		{
-			BspLeaf *leaf = ray->bspIntersections[j].mLeaf;
-
-			for (int i = 0; i < (int)bspLeaves.size(); ++ i)
+		cout << "creating output for view cell " << i << " ... ";
+		// check whether we can add the current ray to the output rays
+		for (int k = 0; k < raysOut; ++ k) 
+		{
+			Ray *ray = mSampleRays[k];
+
+			for	(int j = 0; j < (int)ray->bspIntersections.size(); ++ j)
 			{
+				BspLeaf *leaf = ray->bspIntersections[j].mLeaf;
+
 				if (bspLeaves[i]->GetViewCell() == leaf->GetViewCell()) 
 				{
@@ -804,10 +817,5 @@
 			}
 		}
-	}
-
-	ViewCell::NewMail();
-
-	for (int i = 0; i < bspLeaves.size(); ++ i)
-	{
+
 		Intersectable::NewMail();
 
@@ -883,8 +891,10 @@
 		}
 		DEL_PTR(exporter);
+		cout << "finished" << endl;
 	}
 
 	if (1) // export view cells and leaves
 	{
+		cout << "exporting view cells and leaves ... ";
 		Exporter *exporter = Exporter::GetExporter("viewCells.x3d");
 		if (exporter)
@@ -901,4 +911,5 @@
 			delete exporter;
 		}
+		cout << "finished" << endl;
 	}
 
