Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env	(revision 648)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env	(revision 649)
@@ -177,5 +177,5 @@
 	Construction {
 		samples 0
-		samplesPerPass 500000
+		samplesPerPass 50000
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 648)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 649)
@@ -50,6 +50,4 @@
 	return (float)pvs;
 }
-
-
 
 
@@ -1413,4 +1411,8 @@
 
 
+void ViewCellsTree::ExportStats()
+{
+
+}
 
 void ViewCellsTree::GetPvs(ViewCell *vc, ObjectPvs &pvs) const
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 610)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 649)
@@ -353,5 +353,5 @@
 
 
-	virtual void CreateMergeHierarchy() {};
+	virtual int ConstructSpatialMergeTree() { return 0;};
 	
 	virtual bool EqualToSpatialNode(ViewCell *viewCell) const { return false;}
@@ -529,5 +529,5 @@
 	bool ExportViewCells(const string filename);
 
-	void CreateMergeHierarchy();
+	int ConstructSpatialMergeTree();
 
 
@@ -815,5 +815,6 @@
 	void PrepareLoadedViewCells();
 
-	void CreateMergeHierarchy();
+	int ConstructSpatialMergeTree();
+
 	/// the view space partition BSP tree.
 	VspBspTree *mVspBspTree;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 648)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 649)
@@ -1182,7 +1182,9 @@
 	backData.mNode = interior->GetBack();
 	
+	interior->mTimeStamp = leaf->mTimeStamp;
 	frontData.mNode->mTimeStamp = mTimeStamp;
 	backData.mNode->mTimeStamp = mTimeStamp ++;
 
+	Debug << "time stamp: " << mTimeStamp << endl;
 	//DEL_PTR(leaf);
 	return interior;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 613)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 649)
@@ -108,5 +108,5 @@
 	int Type() const;
 
-  void SetParent(ViewCellInterior *parent);
+	void SetParent(ViewCellInterior *parent);
 
 	/** Adds a passing ray to the passing ray container.
@@ -357,4 +357,7 @@
 	bool Export(ofstream &stream);
 
+	/** Export statistics of this view cell tree.
+	*/
+	void ExportStats();
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 643)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 649)
@@ -1032,5 +1032,6 @@
 
 	// recast rest of the rays
-	ComputeSampleContributions(savedRays, true, false);
+	if (SAMPLE_AFTER_SUBDIVISION)
+		ComputeSampleContributions(savedRays, true, false);
 
 
@@ -1143,23 +1144,30 @@
 	int merged;
 	
+	cout << "starting post processing using " << mPostProcessSamples << " samples ... ";
+	long startTime = GetTime();
+	
+	VssRayContainer postProcessRays;
+	GetRaySets(rays, mPostProcessSamples, postProcessRays);
+
 	if (mMergeViewCells)
 	{
-		cout << "starting post processing using " << mPostProcessSamples << " samples ... ";
-		long startTime = GetTime();
-	
-		VssRayContainer postProcessRays;
-		GetRaySets(rays, mPostProcessSamples, postProcessRays);
-
+		Debug << "constructing visibility based merge tree" << endl;
 		merged = mViewCellsTree->ConstructMergeTree(rays, objects);
-
-		//-- stats and visualizations
-		cout << "finished" << endl;
-		cout << "merged " << merged << " view cells in "
-			 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl;
-
-		Debug << "Postprocessing: Merged " << merged << " view cells in "
-			<< TimeDiff(startTime, GetTime()) *1e-3 << " secs"
-			<< "using " << (int)rays.size() << " samples" << endl << endl;
-	}
+	}
+	else
+	{
+		Debug << "constructing spatial merge tree" << endl;
+		// create spatial merge hierarchy
+		merged = ConstructSpatialMergeTree();
+	}
+
+	//-- stats and visualizations
+	cout << "finished" << endl;
+	cout << "merged " << merged << " view cells in "
+		 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl;
+
+	Debug << "Postprocessing: Merged " << merged << " view cells in "
+		<< TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl << endl;
+	
 
     // reset view cells and stats
@@ -1674,9 +1682,44 @@
 
 
-void BspViewCellsManager::CreateMergeHierarchy()
+int BspViewCellsManager::ConstructSpatialMergeTree()
 {
 	TraversalQueue tQueue;
 
 	tQueue.push(TraversalData(mBspTree->GetRoot(), NULL));
+
+	int merged = 0;
+
+	int numViewCells = (int)mViewCells.size();
+
+	float var = 0;
+	float dev = 0;
+	int totalPvs = 0;
+	float totalRenderCost = 0;
+	float avgRenderCost = 0;
+	float expCost = 0;
+
+	//-- compute statistics values of initial view cells
+	EvaluateRenderStatistics(totalRenderCost,
+						     expCost,
+							 dev,
+							 var,
+							 totalPvs,
+							 avgRenderCost);
+
+	Debug/*mStats*/ << "#Pass\n" << 0 << endl
+		   << "#Merged\n" << merged << endl 
+		   << "#ViewCells\n" << numViewCells << endl 
+		   << "#RenderCostIncrease\n" << 0 << endl
+		   << "#TotalRenderCost\n" << totalRenderCost << endl
+		   << "#CurrentPvs\n" << 0 << endl
+		   << "#ExpectedCost\n" << expCost << endl
+		   << "#AvgRenderCost\n" << avgRenderCost << endl
+		   << "#Deviation\n" << dev << endl
+		   << "#TotalPvs\n" << totalPvs << endl
+		   << "#PvsSizeDecrease\n0" << endl
+		   << "#Volume\n0" << endl
+		   //<< "#Siblings\n" << mergeStats.siblings << endl
+		   << endl;
+	
 
 	while (!tQueue.empty())
@@ -1689,9 +1732,11 @@
 			ViewCell *viewCell = dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell();
 			viewCell->SetMergeCost((float)tData.mNode->mTimeStamp);
+
+			Debug << "leaf time stamp: " << tData.mNode->mTimeStamp << endl;
 
 			if (tData.mParentViewCell)
 			{
 				tData.mParentViewCell->SetupChildLink(viewCell);
-				// probagate up pvs
+				// propagate up pvs: could be redone as propagepvs, which propagates pvs up and down
 				mViewCellsTree->PropagateUpPvs(viewCell);
 			}
@@ -1701,4 +1746,27 @@
 			BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode);
 			ViewCellInterior *viewCellInterior = new ViewCellInterior();
+
+			++ merged;
+			-- numViewCells;
+
+			avgRenderCost = totalPvs / numViewCells;
+
+			Debug//mStats 
+				<< "#Pass\n" << 0 << endl
+				<< "#Merged\n" << merged << endl 
+				<< "#ViewCells\n" << numViewCells << endl 
+                << "#RenderCostIncrease\n" << 0 << endl
+				<< "#TotalRenderCost\n" << totalRenderCost << endl
+				<< "#CurrentPvs\n" << 0 << endl
+                << "#ExpectedCost\n" << 0 << endl
+				<< "#AvgRenderCost\n" << avgRenderCost << endl
+				<< "#Deviation\n" << dev << endl
+				<< "#TotalPvs\n" << totalPvs << endl
+				<< "#PvsSizeDecrease\n" << 0 << endl
+				<< "#Volume\n" << 0 << endl
+				<< endl;
+
+			Debug << "interior time stamp: " << tData.mNode->mTimeStamp << endl;
+
 			viewCellInterior->SetMergeCost((float)tData.mNode->mTimeStamp);
 
@@ -1711,4 +1779,6 @@
 		}
 	}
+
+	return merged;
 }
 
@@ -2838,9 +2908,10 @@
 
 
-void VspBspViewCellsManager::CreateMergeHierarchy()
+int VspBspViewCellsManager::ConstructSpatialMergeTree()
 {
 	TraversalQueue tQueue;
-
 	tQueue.push(TraversalData(mVspBspTree->GetRoot(), NULL));
+
+	int merged = 0;
 
 	while (!tQueue.empty())
@@ -2864,5 +2935,6 @@
 			BspInterior *interior = dynamic_cast<BspInterior *>(tData.mNode);
 			ViewCellInterior *viewCellInterior = new ViewCellInterior();
-			
+			++ merged;
+
 			tQueue.push(TraversalData(interior->GetBack(), viewCellInterior));
 			tQueue.push(TraversalData(interior->GetFront(), viewCellInterior));
@@ -2872,4 +2944,5 @@
 		}
 	}
+	return merged;
 }
 
