Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 411)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 414)
@@ -24,6 +24,7 @@
 
 Preprocessor {
-#	type sampling
-	type vss
+	type sampling
+#	type exact
+#	type vss
 }
 
@@ -78,6 +79,6 @@
 		minPvsDif 100
 		minPvs 10
-		maxPvs 300
-		samples 0
+		maxPvs 150
+		samples 100000
 	}
 
@@ -94,5 +95,5 @@
 	#	input fromViewCells
 	#	input fromSceneGeometry
-		samples 200000
+		samples 100000
 		sideTolerance 0.005
 	}
@@ -132,5 +133,5 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 1024
+	splitPlaneStrategy 12
 	
 	maxPolyCandidates 50
@@ -166,5 +167,5 @@
 		exportSplits true
 		# how much samples should be used in visualization
-		samples 1000
+		samples 20000
 	}
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 413)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 414)
@@ -241,5 +241,5 @@
 					 AxisAlignedBox3 *forcedBoundingBox)
 {
-	stat.Start();
+	mStat.Start();
   
 	maxMemory = maxStaticMemory;
@@ -254,5 +254,5 @@
 
 	
-	stat.nodes = 1;
+	mStat.nodes = 1;
   	
 	bbox.Initialize();
@@ -276,8 +276,8 @@
 	cout<<"Dirr Bbox = "<<dirBBox<<endl;
 
-	stat.rays = leaf->rays.size();
+	mStat.rays = leaf->rays.size();
 	leaf->UpdatePvsSize();
 	
-	stat.initialPvsSize = leaf->GetPvsSize();
+	mStat.initialPvsSize = leaf->GetPvsSize();
 	
 	// Subdivide();
@@ -291,7 +291,7 @@
 	}
   
-	stat.Stop();
-
-	stat.Print(cout);
+	mStat.Stop();
+
+	mStat.Print(cout);
 	cout<<"#Total memory=" << GetMemUsage() << endl;
 }
@@ -899,6 +899,6 @@
 	
 	// update stats
-	stat.rayRefs -= (int)leaf->rays.size();
-	stat.rayRefs += raysBack + raysFront;
+	mStat.rayRefs -= (int)leaf->rays.size();
+	mStat.rayRefs += raysBack + raysFront;
 
 	delete leaf;
@@ -1066,5 +1066,5 @@
 							while (tail >= i && leaf->rays[tail].mRay->ScheduledForRemoval()) 
 							{
-								++ stat.removedRayRefs;
+								++ mStat.removedRayRefs;
 								leaf->rays[tail].mRay->Unref();
 								leaf->rays.pop_back();
@@ -1076,5 +1076,5 @@
 								break;
 	      
-							++ stat.removedRayRefs;
+							++ mStat.removedRayRefs;
 	      
 							leaf->rays[i].mRay->Unref();
@@ -1092,5 +1092,5 @@
 					if (leaf->rays[i].mRay == ray) 
 					{
-						++ stat.removedRayRefs;
+						++ mStat.removedRayRefs;
 						ray->Unref();
 						leaf->rays[i] = leaf->rays[leaf->rays.size() - 1];
@@ -1296,6 +1296,6 @@
 #endif
 
-	stat.nodes -= collapsedNodes - 1;
-	stat.rayRefs -= totalRayCount - rayCount;
+	mStat.nodes -= collapsedNodes - 1;
+	mStat.rayRefs -= totalRayCount - rayCount;
   
 #if DEBUG_COLLAPSE
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h	(revision 411)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h	(revision 414)
@@ -3,4 +3,5 @@
 
 #include "common.h"
+#include "Statistics.h"
 
 class BspTree;
@@ -9,4 +10,33 @@
 class KdLeaf;
 
+class SimulationStatistics: public StatisticsBase
+{
+public:
+	/// view cell with the biggest "cost"
+	float maxCost;
+	/// view cell with the minimal "cost"
+    float minCost;
+	/// average render time
+	float avgRenderTime;
+	/// average render time with the overhead when crossing view cells
+	float avgRtWithoutOverhead;
+  
+	void Reset() 
+	{
+		maxCost = 0;
+		minCost = 999999;
+		avgRenderTime = 0;
+		avgRtWithoutOverhead = 0;
+	}
+
+	void Print(ostream &app) const;
+
+	friend ostream &operator<<(ostream &s, const SimulationStatistics &stat) 
+	{
+		stat.Print(s);
+		return s;
+	}  
+};
+
 /** Simulated rendering using a simple render heuristics. Used to evaluate the 
 	quality of the view cell partition.
@@ -14,4 +44,5 @@
 class RenderSimulator
 {
+
 public:
 	RenderSimulator();
@@ -25,4 +56,6 @@
 	/// move speed of player
 	float mMoveSpeed;
+
+	SimulationStatistics mStat;
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 412)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 414)
@@ -6,4 +6,5 @@
 #include "Polygon3.h"
 #include <stack>
+#include "Statistics.h"
 
 class ViewCell;
@@ -71,123 +72,121 @@
 typedef vector<BoundedRay *> BoundedRayContainer;
 
-class BspTreeStatistics
+class BspTreeStatistics: public StatisticsBase
 {
 public:
-  // total number of nodes
-  int nodes;
-  // number of splits
-  int splits;
-  // totals number of rays
-  int rays;
-  // maximal reached depth
-  int maxDepth;
-  // minimal depth
-  int minDepth;
-  // max depth nodes
-  int maxDepthNodes;
-  // max number of rays per node
-  int maxObjectRefs;
-   // accumulated depth (used to compute average)
-  int accumDepth;
-  // number of initial polygons
-  int polys;
-  /// samples contributing to pvs
-  int contributingSamples;
-   /// sample contributions to pvs
-  int sampleContributions;
-  /// largest pvs
-  int largestPvs;
-
-  // Constructor
-  BspTreeStatistics() 
-  {
-	  Reset();
-  }
-
-  int Nodes() const {return nodes;}
-  int Interior() const { return nodes / 2; }
-  int Leaves() const { return (nodes / 2) + 1; }
-  // TODO: computation wrong
-  double AvgDepth() const { return accumDepth / (double)Leaves();}; 
+	// total number of nodes
+	int nodes;
+	// number of splits
+	int splits;
+	// totals number of rays
+	int rays;
+	// maximal reached depth
+	int maxDepth;
+	// minimal depth
+	int minDepth;
+	// max depth nodes
+	int maxDepthNodes;
+	// max number of rays per node
+	int maxObjectRefs;
+	// accumulated depth (used to compute average)
+	int accumDepth;
+	// number of initial polygons
+	int polys;
+	/// samples contributing to pvs
+	int contributingSamples;
+	/// sample contributions to pvs
+	int sampleContributions;
+	/// largest pvs
+	int largestPvs;
+
+	// Constructor
+	BspTreeStatistics() 
+	{
+		Reset();
+	}
+
+	int Nodes() const {return nodes;}
+	int Interior() const { return nodes / 2; }
+	int Leaves() const { return (nodes / 2) + 1; }
+	
+	// TODO: computation wrong
+	double AvgDepth() const { return accumDepth / (double)Leaves();}; 
   
-  void Reset() 
-  {
-	  nodes = 0;
-	  splits = 0;
-      maxDepthNodes = 0;
-	  maxDepth = 0;
-	  minDepth = 99999;
-	  polys = 0;
-	  accumDepth = 0;
-	 	
-	  contributingSamples = 0;
-	  sampleContributions = 0;
-  }
-
-  void
-  Print(ostream &app) const;
-
-  friend ostream &operator<<(ostream &s, const BspTreeStatistics &stat) {
-    stat.Print(s);
-    return s;
-  }
-  
+	void Reset() 
+	{
+		nodes = 0;
+		splits = 0;
+		maxDepthNodes = 0;
+		maxDepth = 0;
+		minDepth = 99999;
+		polys = 0;
+		accumDepth = 0;
+        
+		contributingSamples = 0;
+		sampleContributions = 0;
+	}
+
+	void Print(ostream &app) const;
+
+	friend ostream &operator<<(ostream &s, const BspTreeStatistics &stat) 
+	{
+		stat.Print(s);
+		return s;
+	} 
 };
 
-class BspViewCellsStatistics
+class BspViewCellsStatistics: public StatisticsBase
 {
 public:
+
+	/// number of view cells
+	int viewCells;
+
+	/// size of the PVS
+	int pvs;
   
-  /// 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;};
   
-  /// 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;
-  }
-  
+	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;
+	}  
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 411)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 414)
@@ -1336,5 +1336,5 @@
 
 
-  RegisterOption("VspKdTree.Construction.Samples",
+  RegisterOption("VspKdTree.Construction.samples",
 		 optInt,
 		 "-vsp_construction_samples=",
@@ -1343,5 +1343,5 @@
   RegisterOption("VspKdTree.Termination.maxDepth", 
 		optInt, 
-		"vsp_depth=", "30");
+		"vsp_term_maxdepth=", "30");
 
   RegisterOption("VspKdTree.Termination.minPvs", 
@@ -1352,15 +1352,20 @@
   RegisterOption("VspKdTree.Termination.minRays", 
 	  optInt, 
-	  "vsp_minrays=", 
+	  "vsp_term_minrays=", 
 	  "10");
 
-  RegisterOption("VspKdTree.maxCostRatio", 
+  RegisterOption("VspKdTree.Termination.minSize", 
 	  optFloat, 
-	  "vsp_maxcost=", 
+	  "vsp_term_minsize=", 
+	  "0.001");
+
+  RegisterOption("VspKdTree.Termination.maxCostRatio", 
+	  optFloat, 
+	  "vsp_term_maxcost=", 
 	  "0.95");
 
-  RegisterOption("VspKdTree.maxRayContribution", 
+  RegisterOption("VspKdTree.Termination.maxRayContribution", 
 	  optFloat, 
-	  "vsp_max_ray_contrib=", 
+	  "vsp_term_max_ray_contrib=", 
 	  "0.5");
 
@@ -1383,9 +1388,4 @@
 	  "endpoints=", 
 	  "10000");
-
-  RegisterOption("VspKdTree.minSize", 
-	  optFloat, 
-	  "minsize=", 
-	  "0.001");
 
   RegisterOption("VspKdTree.maxTotalMemory", 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 411)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 414)
@@ -285,8 +285,6 @@
 			
 		if (!ray->intersections.empty())
-		{	
-            contribution += mViewCell->GetPvs().AddSample(ray->intersections[0].mObject);
-		}
-
+			contribution += mViewCell->GetPvs().AddSample(ray->intersections[0].mObject);
+		
 		if (ray->sourceObject.mObject)
 			contribution += mViewCell->GetPvs().AddSample(ray->sourceObject.mObject);
@@ -297,4 +295,5 @@
 			++ contributingSamples;
 		}
+		
 		if (BspTree::sStoreLeavesWithRays)
 			// warning: intersections not ordered
@@ -320,34 +319,11 @@
 }
 
-void BspViewCellsStatistics::Print(ostream &app) const
-{
-	app << "===== BspViewCells statistics ===============\n";
+void BspTreeStatistics::Print(ostream &app) const
+{
+	app << "===== BspTree statistics ===============\n";
 
 	app << setprecision(4);
 
-	app << "#N_OVERALLPVS ( objects in PVS )\n" << pvs << endl;
-
-	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
-{
-	app << "===== BspTree statistics ===============\n";
-
-	app << setprecision(4);
+	app << "#N_CTIME  ( Construction time [s] )\n" << Time() << " \n";
 
 	app << "#N_NODES ( Number of nodes )\n" << nodes << "\n";
@@ -586,5 +562,5 @@
 void BspTree::Construct(const RayContainer &sampleRays)
 {
-	mStat.nodes = 1;
+    mStat.nodes = 1;
 	mBox.Initialize(); 	// initialise BSP tree bounding box
 	
@@ -673,5 +649,5 @@
 	tStack.push(tData);
 
-	long startTime = GetTime();
+	mStat.Start();
 	cout << "**** Contructing bsp tree ****\n";
 
@@ -685,6 +661,5 @@
 	}
 
-	cout << "**** Finished tree construction ****\n";
-	Debug << "BSP tree contruction time: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
+	mStat.Stop();
 }
 
@@ -898,4 +873,5 @@
 	backData.mNode = interior->mBack;
 	
+	//DEL_PTR(leaf);
 	return interior;
 }
@@ -1941,9 +1917,9 @@
 				
 				++ stat.viewCells;
-				int pvsSize = viewCell->GetPvs().GetSize();
+				const int pvsSize = viewCell->GetPvs().GetSize();
 
                 stat.pvs += pvsSize;
 
-				if (pvsSize < 2)
+				if (pvsSize < 1)
 					++ stat.emptyPvs;
 
@@ -2555,2 +2531,29 @@
 	return planePoly;
 }
+
+void BspViewCellsStatistics::Print(ostream &app) const
+{
+	app << "===== BspViewCells statistics ===============\n";
+
+	app << setprecision(4);
+
+	//app << "#N_CTIME  ( Construction time [s] )\n" << Time() << " \n";
+
+	app << "#N_OVERALLPVS ( objects in PVS )\n" << pvs << endl;
+
+	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";
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp	(revision 410)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp	(revision 414)
@@ -3,4 +3,23 @@
 #include "ViewCellBsp.h"
 #include "ViewCell.h"
+
+void SimulationStatistics::Print(ostream &app) const
+{
+	app << "===== Simulation statistics ===============\n";
+
+	app << setprecision(4);
+
+	app << "#N_CTIME  ( Simulation time [s] )\n" << Time() << " \n";
+
+	app << "#MAX_COST ( maximal cost of a view cell )\n" << maxCost << "\n";
+
+	app << "#MIN_COST ( minimal cost of a view cell )\n" << minCost << "\n";
+
+	app << "#AVG_RENDER_TIME ( average render time )\n" << avgRenderTime << "\n";
+
+	app << "#AVG_RENDER_TIME_NO_OVERHEAD ( average render time without overhead )\n" << avgRtWithoutOverhead << "\n";
+	
+	app << "===== END OF Simulation statistics ==========\n";
+}
 
 RenderSimulator::RenderSimulator()
@@ -26,12 +45,13 @@
 Real BspViewCellRenderSimulator::SimulateRendering()
 {
+	mStat.Reset();
+	mStat.Start();
+
 	Real renderTime = 0;
-
+	
 	// overhead for loading the PVS of the view cells
 	float loadPvsOverhead = 0;
-
 	// probability that view point lies in a view cell
 	float pInVcTotal = 0;
-
 	// total probability that a view cell border is crossed
 	float pCrossVcTotal = 0;
@@ -57,9 +77,17 @@
 				
 		// compute render time of PVS times probability that view point is in view cell
-		renderTime += pInVc * RenderPvs(*(*it), mObjRenderCost);
+		float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
 		
+		renderTime += vcCost;
+
+		if (vcCost > mStat.maxCost)
+			mStat.maxCost = vcCost;
+		else if (vcCost < mStat.minCost)
+			mStat.minCost = vcCost;
+
 		// probability that a view cell border is crossed
 		float pCrossVc = area;
 
+		// crossing the border of a view cell is also depending on the move speed
 		loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
 
@@ -72,6 +100,9 @@
 	loadPvsOverhead /= pCrossVcTotal;
 
-	//Debug << "render time without overhead: " << renderTime * 1e-3 << endl;
-	
+	mStat.avgRtWithoutOverhead = renderTime;
+	mStat.avgRenderTime = renderTime + loadPvsOverhead;
+	
+	mStat.Stop();
+
 	return renderTime + loadPvsOverhead;
 }
@@ -98,4 +129,6 @@
 {
 	//mKdTree->CollectLeavesPvs();
+	mStat.Reset();
+	mStat.Start();
 
 	// total render time
@@ -132,5 +165,12 @@
 		const float pCrossVc = box.SurfaceArea();
 
-		renderTime += pInVc * RenderPvs(*it, mObjRenderCost);
+		float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
+		renderTime += vcCost;
+
+		if (vcCost > mStat.maxCost)
+			mStat.maxCost = vcCost;
+		else if (vcCost < mStat.minCost)
+			mStat.minCost = vcCost;
+
 		loadPvsOverhead += pCrossVc * mVcOverhead * mMoveSpeed;
 
@@ -139,7 +179,16 @@
 	}
 
+	Debug << "RT: " << renderTime << endl;
+	Debug << "pvsOverhead: " << loadPvsOverhead << endl;
+
+
 	renderTime /= pInVcTotal;
 	loadPvsOverhead /= pCrossVcTotal;
 
+    mStat.avgRtWithoutOverhead = renderTime;
+	mStat.avgRenderTime = renderTime + loadPvsOverhead;
+	
+	mStat.Stop();
+
 	return renderTime + loadPvsOverhead;
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 413)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 414)
@@ -371,5 +371,5 @@
 	virtual void Print(ostream &s) const 
 	{
-		s << endl << "L: r = " << rays.size() << endl;
+		s << endl << "L: r = " << (int)rays.size() << endl;
 	};
   
@@ -620,5 +620,5 @@
 	
 	/////////////////////////////
-	VspKdStatistics mstat;
+	VspKdStatistics mStat;
 	
 	VspKdTree();
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 412)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 414)
@@ -15,6 +15,5 @@
   environment->GetIntValue("Sampling.totalSamples", mTotalSamples);
   environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples);
-  environment->GetIntValue("VspTree.Construction.samples", mVspConstructionSamples);
-
+  environment->GetIntValue("VspKdTree.Construction.samples", mVspConstructionSamples);
   environment->GetIntValue("ViewCells.PostProcessing.samples", mPostProcessSamples);
   environment->GetIntValue("BspTree.Visualization.samples", mVisualizationSamples);
@@ -389,4 +388,5 @@
 
   int pvsOut = Min((int)objects.size(), 10);
+  int pvsSize = 0;
 
   RayContainer rays[10];
@@ -509,13 +509,9 @@
     
 		mPass++;
-
-		int pvsSize = 0;
         
-		if (ViewCell::sHierarchy == ViewCell::BSP) {
-			for (i=0; i < mViewCells.size(); i++) {
-				ViewCell *vc = mViewCells[i];
-				pvsSize += vc->GetPvs().GetSize();
-			}
-		} else 	{
+		if (ViewCell::sHierarchy == ViewCell::KD)
+		{
+			pvsSize = 0;
+
 			for (i=0; i < objects.size(); i++) {
 				Intersectable *object = objects[i];
@@ -523,5 +519,9 @@
 			}
 		}
-
+		else
+		{
+			Debug << "contr: " << passSampleContributions << " pvs: " << pvsSize << " objects: " << objects.size() << endl;
+			pvsSize += passSampleContributions;
+		}
 		float avgRayContrib = (passContributingSamples > 0) ? 
 			passSampleContributions/(float)passContributingSamples : 0;
@@ -531,5 +531,5 @@
 				 << "k   #SampleContributions=" << passSampleContributions << " (" 
 				 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS="
-				 << pvsSize /(float)objects.size() << endl 
+				 << (float)pvsSize /(float)objects.size() << endl 
 				 << "avg ray contrib=" << avgRayContrib << endl
 				 << "reverse samples [%]" << reverseSamples/(float)passSamples*100.0f << endl;
@@ -552,8 +552,8 @@
 		//-- render simulation
 		cout << "\nevaluating bsp view cells render time before merge ... ";
-		Real rt = GetRenderSimulator()->SimulateRendering();
-		
-		cout << "avg render time: " << rt * 1e-3 << endl;
-		Debug << "avg render time: " << rt * 1e-3 << endl;
+		GetRenderSimulator()->SimulateRendering();
+		
+		cout << "avg render time: " << 	GetRenderSimulator()->mStat << endl;
+		Debug << "avg render time: " << GetRenderSimulator()->mStat << endl;
 
 		//-- post processing of bsp view cells
@@ -574,5 +574,5 @@
 			if (exporter)
 			{
-				exporter->ExportBspLeaves(*mBspTree, stat.maxPvs);
+				exporter->ExportBspLeaves(*mBspTree, 350/*stat.maxPvs*/);
 				//exporter->ExportBspViewCellPartition(*mBspTree, 0);
 				delete exporter;
@@ -598,8 +598,8 @@
 		cout << "\nevaluating render time after merge ... ";
 			
-		rt = GetRenderSimulator()->SimulateRendering();
-
-		cout << "render time: " << rt * 1e-3 << endl;
-		Debug << "render time: " << rt * 1e-3 << endl;
+		GetRenderSimulator()->SimulateRendering();
+
+		cout << "render time: " << GetRenderSimulator()->mStat << endl;
+		Debug << "render time: " << GetRenderSimulator()->mStat << endl;
 
 		if (1) // export view cells
@@ -609,5 +609,5 @@
 			if (exporter)
 			{
-				exporter->ExportBspViewCellPartition(*mBspTree, stat.maxPvs);
+				exporter->ExportBspViewCellPartition(*mBspTree, 350/*stat.maxPvs*/);
 				//exporter->ExportBspViewCellPartition(*mBspTree, 0);
 				delete exporter;
@@ -813,5 +813,5 @@
 	int limit = min((int)mSampleRays.size(), mPostProcessSamples);
 
-	for (int i = 0; i < limit; ++i)
+	for (int i = 0; i < limit; ++ i)
 	{  
 		Ray *ray = mSampleRays[i];
@@ -819,5 +819,5 @@
 		// traverse leaves stored in the rays and compare and merge consecutive
 		// leaves (i.e., the neighbors in the tree)
-		if (ray->bspIntersections.empty())
+		if (ray->bspIntersections.size() < 2)
 			continue;
 
@@ -827,5 +827,5 @@
 		++ iit;
 		
-		for (; iit != (*rit)->bspIntersections.end(); ++ iit)
+		for (; iit != ray->bspIntersections.end(); ++ iit)
 		{
 			BspLeaf *leaf = (*iit).mLeaf;
@@ -837,4 +837,5 @@
 				++ merged;
 			}
+		
 			previousLeaf = leaf;
 		}
@@ -882,5 +883,5 @@
 
 		// export scene geometry
-		if (0)
+		if (1)
 		{
 			Material m;//= RandomMaterial();
