Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env	(revision 664)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env	(revision 666)
@@ -13,7 +13,7 @@
 #;../data/vienna/vienna-plane.x3d
 #	filename ../data/vienna/viewcells-25-sel.x3d
-	filename ../data/atlanta/atlanta2.x3d
+#	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
-#	filename ../data/soda/soda5.dat
+	filename ../data/soda/soda5.dat
 }
 
@@ -177,6 +177,6 @@
 	# samples used for view cell construction
 	Construction {
-		samples 0
-		samplesPerPass 50000
+		samples 1000000
+		samplesPerPass 200000
 	}
 
@@ -192,5 +192,4 @@
 	#type bspTree
 	type vspBspTree
-	
 	#type sceneDependent
 	
@@ -204,7 +203,8 @@
 	processOnlyValidViewCells false
 
-	stats viewCellStats.log
+	#stats viewCellStats.log
 
 	samplingType directional
+	#samplingType box
 
 	PostProcess {
@@ -219,6 +219,5 @@
 		refine false
 		compress false
-		merge true
-		statsPrefix ../scripts/viewCells
+		merge false
 	}
 
@@ -231,5 +230,5 @@
 		colorCode Random
 		exportRays false
-		exportGeometry true
+		exportGeometry false
 		exportMergedViewCells false
 		useClipPlane true
@@ -237,9 +236,11 @@
 	}
 
-	evaluateViewCells true
+	showVisualization false	
+	evaluateViewCells false
 	
 	Evaluation {
-		samplesPerPass 200000
-		samples 2000000
+		samplesPerPass 800000
+		samples 1000000
+		statsPrefix ../scripts/viewCells
 	}
 
@@ -301,5 +302,5 @@
 VspBspTree {
 	Construction {
-		samples 300000
+		samples 800000
 		epsilon 0.0005
 		randomize false
@@ -317,7 +318,8 @@
 	
 	# maximal candidates for split planes
-	maxPolyCandidates 100
+	maxPolyCandidates 150
 
 	usePolygonSplitIfAvailable false
+
 	# maximal tested rays for split cost heuristics
 	maxTests 10000
@@ -325,8 +327,6 @@
 	maxTotalMemory	50
 	maxStaticMemory	50
-	
-	simulateOctree false
-	
-	subdivisionStats ../subDivisionStats.log
+
+	subdivisionStats ../subdivisionStats.log
 
 	# factors for evaluating split plane costs
@@ -350,5 +350,5 @@
 		minGlobalCostRatio      0.0000001
 #		minGlobalCostRatio      0.0001
-		maxViewCells		40000
+		maxViewCells		20000
 	
 
@@ -362,9 +362,12 @@
 	}
 	
-	useSplitCostQueue	false
-
+	useSplitCostQueue true
 	useCostHeuristics true
+
 	splitUseOnlyDrivingAxis false
+	simulateOctree false
+	useRandomAxis false
 	usePolygonSplitIfAvailable false
+	useBreathFirstSplits false
 
 	Visualization {
@@ -376,5 +379,5 @@
 BspTree {
 	Construction {
-		samples 50000
+		samples 300000
 		epsilon 0.005
 	}
@@ -439,10 +442,10 @@
 		# parameters used for autopartition
 		minRays -1
-		minPolygons 1
+		minPolygons 0
 		maxDepth 30
 		minPvs -1
 		minProbability 0.00001
 		maxRayContribution 9999
-		maxViewCells	10000
+		maxViewCells 20000
 
 		# used for pvs criterium
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 664)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 666)
@@ -799,11 +799,4 @@
 private:
 
-
-	static const float sLeastRaySplitsTable[5];
-	/** Evaluates split plane classification with respect to the plane's 
-		contribution for balanced rays.
-	*/
-	static const float sBalancedRaysTable[5];
-
 	/// Generates unique ids for PVS criterium
 	static void GenerateUniqueIdsForPvs();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 664)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 666)
@@ -1866,9 +1866,10 @@
 
 		vc->GetPvs().mEntries.clear();
-
+		
 		if (!vc->IsLeaf())
 		{
 			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
+
 			for (it = interior->mChildren.begin(); it != it_end; ++ it)
 			{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 656)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 666)
@@ -1013,4 +1013,5 @@
 };
 
+
 struct BspIntersection 
 {
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 664)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 666)
@@ -480,4 +480,6 @@
 
 	bool mEvaluateViewCells;
+
+	bool mShowVisualization;
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 665)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 666)
@@ -23,13 +23,4 @@
 //-- static members
 
-/** Evaluates split plane classification with respect to the plane's
-	contribution for a minimum number of ray splits.
-*/
-const float VspBspTree::sLeastRaySplitsTable[] = {0, 0, 1, 1, 0};
-/** Evaluates split plane classification with respect to the plane's
-	contribution for  balanced rays.
-*/
-const float VspBspTree::sBalancedRaysTable[] = {1, -1, 0, 0, 0};
-
 
 int VspBspTree::sFrontId = 0;
@@ -87,4 +78,5 @@
 	environment->GetIntValue("VspBspTree.Termination.missTolerance", mTermMissTolerance);
 	environment->GetIntValue("VspBspTree.Termination.maxViewCells", mMaxViewCells);
+
 	//-- max cost ratio for early tree termination
 	environment->GetFloatValue("VspBspTree.Termination.maxCostRatio", mTermMaxCostRatio);
@@ -96,5 +88,4 @@
 
 	//-- factors for bsp tree split plane heuristics
-	environment->GetFloatValue("VspBspTree.Factor.balancedRays", mBalancedRaysFactor);
 	environment->GetFloatValue("VspBspTree.Factor.pvs", mPvsFactor);
 	environment->GetFloatValue("VspBspTree.Termination.ct_div_ci", mCtDivCi);
@@ -124,16 +115,13 @@
 	environment->GetBoolValue("VspBspTree.usePolygonSplitIfAvailable", mUsePolygonSplitIfAvailable);
 
-	mSubdivisionStats.open("subdivisionStats.log");
-
 	environment->GetBoolValue("VspBspTree.useCostHeuristics", mUseCostHeuristics);
 	environment->GetBoolValue("VspBspTree.useSplitCostQueue", mUseSplitCostQueue);
 	environment->GetBoolValue("VspBspTree.simulateOctree", mSimulateOctree);
 	environment->GetBoolValue("VspBspTree.useRandomAxis", mUseRandomAxis);
-	environment->GetBoolValue("VspBspTree.breathFirstSplits", mBreathFirstSplits);
+	environment->GetBoolValue("VspBspTree.useBreathFirstSplits", mBreathFirstSplits);
 
 	char subdivisionStatsLog[100];
-	environment->GetStringValue("BspTree.subdivisionStats", subdivisionStatsLog);
+	environment->GetStringValue("VspBspTree.subdivisionStats", subdivisionStatsLog);
 	mSubdivisionStats.open(subdivisionStatsLog);
-
 
 	//-- debug output
@@ -603,6 +591,6 @@
 
 	long startTime = GetTime();	
-	int nLeaves = 0;
-	int nViewCells = 0;
+	int nLeaves = 500;
+	int nViewCells = 500;
 
 	// used for intermediate time measurements and progress
@@ -841,5 +829,5 @@
 
 	if (!LocalTerminationCriteriaMet(tData) && !GlobalTerminationCriteriaMet(tData))
-	{
+	{	
 		PolygonContainer coincident;
 
@@ -852,5 +840,5 @@
 				
 		newNode = SubdivideNode(splitPlane, tData, tFrontData, tBackData, coincident);
-		
+	
 		const int splitAxis = splitCandidate.mSplitAxis;
 		const int maxCostMisses = splitCandidate.mMaxCostMisses;
@@ -867,4 +855,5 @@
 		tBackData.mMaxCostMisses = maxCostMisses;
 			
+		
 		if (1)
 		{
@@ -887,4 +876,5 @@
 		}
 
+	
 		//-- push the new split candidates on the stack
 		VspBspSplitCandidate frontCandidate;
@@ -896,5 +886,5 @@
 		tQueue.push(frontCandidate);
 		tQueue.push(backCandidate);
-
+	
 		// delete old leaf node
 		DEL_PTR(tData.mNode);
@@ -962,11 +952,9 @@
 	VspBspTraversalData backData;
 
-	int splitAxis = 0;
-
 	BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode);
 
 	// compute locally best split plane
 	bool success = SelectPlane(splitData.mSplitPlane, leaf, tData, 
-							   frontData, backData, splitAxis);
+							   frontData, backData, splitData.mSplitAxis);
 
 	// TODO: reuse
@@ -2989,4 +2977,6 @@
 
 	float t;
+	const float thresh = 1 ? 1e-6f : 0.0f;
+
 	while (1)
 	{
@@ -2997,26 +2987,27 @@
 			Plane3 splitPlane = in->GetPlane();
 			
-			const int entSide = splitPlane.Side(entp);
-			const int extSide = splitPlane.Side(extp);
+			const int entSide = splitPlane.Side(entp, thresh);
+			const int extSide = splitPlane.Side(extp, thresh);
 
 			if (entSide < 0) 
 			{
-			  node = in->GetBack();
-			  // plane does not split ray => no far child
-			  if (extSide <= 0) 
-				continue;
-			  
-			  farChild = in->GetFront(); // plane splits ray
+				node = in->GetBack();
+				
+				// plane does not split ray => no far child
+				if (extSide <= 0) 
+					continue;
+  
+				farChild = in->GetFront(); // plane splits ray
 			} 
 			else if (entSide > 0)
 			{
-			  node = in->GetFront();
-
-			  if (extSide >= 0) // plane does not split ray => no far child
-				continue;
+				node = in->GetFront();
+
+				if (extSide >= 0) // plane does not split ray => no far child
+					continue;
 
 				farChild = in->GetBack(); // plane splits ray
 			}
-			else // ray end point on plane
+			else // one of the ray end points on the plane
 			{	// NOTE: what to do if ray is coincident with plane?
 				if (extSide < 0)
@@ -3038,6 +3029,9 @@
 			// reached leaf => intersection with view cell
 			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
-
-			ViewCell *viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
+			ViewCell *viewCell;
+			
+			viewCell = mViewCellsTree->GetActiveViewCell(leaf->GetViewCell());
+			//viewCell = leaf->GetViewCell();
+
 			if (!viewCell->Mailed())
 			{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 664)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 666)
@@ -1209,8 +1209,8 @@
 			"box");
 
-	RegisterOption("ViewCells.stats",
+	RegisterOption("ViewCells.mergeStats",
 					optString,
-					"view_cells_stats=",
-					"viewCellsStats.log");
+					"view_cells_merge_stats=",
+					"mergeStats.log");
 
 	RegisterOption("ViewCells.Evaluation.statsPrefix",
@@ -1358,5 +1358,5 @@
 	RegisterOption("ViewCells.PostProcess.merge", 
 		optBool,
-		"view_cells_post_merge=", 
+		"view_cells_post_process_merge=",
 		"true");
 
@@ -1376,4 +1376,9 @@
 		"false");
 	
+	RegisterOption("ViewCells.showVisualization",
+		optBool, 
+		"view_cells_show_visualization=", 
+		"false");
+
 	RegisterOption("ViewCells.Visualization.clipPlaneAxis",
 		optInt, 
@@ -1417,5 +1422,5 @@
 	RegisterOption("BspTree.subdivisionStats",
 					optString,
-					"vsp_bsp_subdivision_stats=",
+					"bsp_subdivision_stats=",
 					"bspSubdivisionStats.log");
 
@@ -1907,20 +1912,20 @@
 	RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
 		optFloat,
-		"-vsp_bsp_term_axis_aligned_max_cost_ratio=",
+		"vsp_bsp_term_axis_aligned_max_cost_ratio=",
 		"1.5");
 
 	RegisterOption("VspBspTree.useCostHeuristics",
 		optBool,
-		"-vsp_bsp_use_cost_heuristics=",
+		"vsp_bsp_use_cost_heuristics=",
 		"false");
 
 	RegisterOption("VspBspTree.Termination.maxViewCells",
 		optInt,
-		"-vsp_bsp_term_max_view_cells=",
+		"vsp_bsp_term_max_view_cells=",
 		"1000");
 
 	RegisterOption("VspBspTree.Termination.maxCostRatio",
 		optFloat,
-		"-vsp_bsp_term_max_cost_ratio=",
+		"vsp_bsp_term_max_cost_ratio=",
 		"1.5");
 
@@ -2002,5 +2007,5 @@
 		"false");
 
-	RegisterOption("VspBspTree.breathFirstSplits",
+	RegisterOption("VspBspTree.useBreathFirstSplits",
 		optBool,
 		"-vsp_bsp_breath_first_splits=",
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 660)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 666)
@@ -2087,4 +2087,6 @@
 	BspNode *farChild = NULL;
 
+	const float thresh = 1 ? 1e-6f : 0.0f;
+
 	while (1) 
 	{
@@ -2095,6 +2097,6 @@
 			Plane3 splitPlane = in->GetPlane();
 			
-			const int entSide = splitPlane.Side(entp);
-			const int extSide = splitPlane.Side(extp);
+			const int entSide = splitPlane.Side(entp, thresh);
+			const int extSide = splitPlane.Side(extp, thresh);
 
 			if (entSide < 0) 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 664)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 666)
@@ -66,5 +66,6 @@
 	environment->GetBoolValue("ViewCells.PostProcess.merge", mMergeViewCells);
 	environment->GetBoolValue("ViewCells.evaluateViewCells", mEvaluateViewCells);
-
+	environment->GetBoolValue("ViewCells.showVisualization", mShowVisualization);
+	
 	char buf[100];
 	environment->GetStringValue("ViewCells.samplingType", buf);
@@ -75,9 +76,9 @@
 	else if (strcmp(buf, "directional") == 0)
 		mSamplingType = Preprocessor::DIRECTION_BASED_DISTRIBUTION;
-
-#if 0
-	environment->GetStringValue("ViewCells.stats", buf);
-	mViewCellsStats.open(buf);
-#endif
+	else 
+	{
+		Debug << "error! wrong sampling type" << endl;
+		exit(0);
+	}
 
 	environment->GetStringValue("ViewCells.Visualization.colorCode", buf);
@@ -116,4 +117,5 @@
 	Debug << "evaluate view cells: " << mEvaluateViewCells << endl;
 	Debug << "sampling type: " << mSamplingType << endl;
+	Debug << "show visualization: " << mShowVisualization << endl;
 
 	Debug << endl;
@@ -208,4 +210,5 @@
 
 	// rays can be passed or deleted
+	if (0) // remove!!
 	disposeRays(initialSamples, outRays);
 	
@@ -236,5 +239,6 @@
 	const int n = mConstructionSamples; //+initialSamples;
 
-	bool dirSamples = mSamplingType;
+	// should we use directional samples?
+	bool dirSamples = mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION;
 
 	while (numSamples < n)
@@ -243,13 +247,13 @@
 		VssRayContainer constructionSamples;
 
-		const int samplingType = 
-			dirSamples ? 
+		const int samplingType = mSamplingType;
+/*			dirSamples ? 
 						Preprocessor::DIRECTION_BASED_DISTRIBUTION :
 				 		Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION;
-
+*/
 		if (0)
-		dirSamples = !dirSamples; // toggle sampling method
+			dirSamples = !dirSamples; // toggle sampling method
 		numSamples += CastPassSamples(mSamplesPerPass, 
-									  mSamplingType,
+									  samplingType,
 									  constructionSamples);
 
@@ -294,5 +298,5 @@
 
 
-	// store viewCells for postprocessing
+	// store view cells for postprocessing
 	const bool storeViewCells = true;
 
@@ -306,26 +310,44 @@
 
 	//-- visualization
-	VssRayContainer visualizationSamples;
-
-	//-- construction rays => we use uniform samples for this
-	CastPassSamples(mVisualizationSamples,
-				    Preprocessor::DIRECTION_BASED_DISTRIBUTION, 
-					visualizationSamples);
-
-	if (SAMPLE_AFTER_SUBDIVISION)
-		ComputeSampleContributions(visualizationSamples, true, storeViewCells);
-
-	// different visualizations
-	Visualize(preprocessor->mObjects, visualizationSamples);
-
-	disposeRays(visualizationSamples, outRays);
+	if (mShowVisualization)
+	{
+		VssRayContainer visualizationSamples;
+
+		//-- construction rays => we use uniform samples for this
+		CastPassSamples(mVisualizationSamples,
+					    Preprocessor::DIRECTION_BASED_DISTRIBUTION, 
+						visualizationSamples);
+
+		if (SAMPLE_AFTER_SUBDIVISION)
+			ComputeSampleContributions(visualizationSamples, true, storeViewCells);
+
+		// different visualizations
+		Visualize(preprocessor->mObjects, visualizationSamples);
+
+		disposeRays(visualizationSamples, outRays);
+	}
 
 	if (mEvaluateViewCells)
 	{
-		Debug << "Evaluatating view cells!!!" << endl;
-        EvalViewCellPartition(preprocessor);
-	}
-	else
-		Debug << "No evaluation!!" << endl;
+		EvalViewCellPartition(preprocessor);
+	}
+	
+	ViewCellContainer leaves;
+	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
+	mViewCellsTree->ResetPvs();
+	VssRayContainer dummyRays;
+	CastPassSamples(mInitialSamples, mSamplingType, dummyRays);
+	
+	//ComputeSampleContributions(initialSamples, true, false);
+	ComputeSampleContributions(dummyRays, true, false);
+
+	ViewCellContainer::const_iterator it, it_end = leaves.end();
+
+	for (it = leaves.begin(); it != it_end; ++ it)
+	{
+		mViewCellsTree->PropagatePvs(*it);
+	}
+
+	mViewCellsTree->ExportStats("dummy.log");
 
 	return numSamples;
@@ -352,9 +374,6 @@
 
 	//VssRayContainer outRays;
-
-	int dirSamples = mSamplingType;
-
-	if (0)
-		mViewCellsTree->ResetPvs();
+	// should directional sampling be used?
+	bool dirSamples = mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION;
 
 	cout << "Evaluating view cell partition" << endl;
@@ -363,13 +382,31 @@
 	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
 
+	bool startFromZero = true;
+
+	// reset pvs and start over from zero
+	if (startFromZero)
+	{
+		mViewCellsTree->ResetPvs();
+	}
+	else // statistics without addidtional samples
+	{
+		cout << "compute new statistics ... ";
+		sprintf(s, "-%09d-eval.log", castSamples);
+		string fName = string(statsPrefix) + string(s);
+
+		mViewCellsTree->ExportStats(fName);
+		cout << "finished" << endl;
+	}
+	
+
 	while (castSamples < numSamples)
 	{
 		VssRayContainer evaluationSamples;
 
-		const int samplingType = 
-			dirSamples ? 
+		const int samplingType = mSamplingType;
+		/*	dirSamples ? 
 						Preprocessor::DIRECTION_BASED_DISTRIBUTION :
 				 		Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION;
-
+		*/
 		//-- construction rays => we use uniform samples for this
 		CastPassSamples(samplesPerPass, samplingType, evaluationSamples);
@@ -987,5 +1024,6 @@
 			// if ray not outside of view space
 			float contribution;
-			if (viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject,
+			if (ray.mTerminationObject &&
+				viewcell->GetPvs().GetSampleContribution(ray.mTerminationObject,
 														 ray.mPdf,
 														 contribution))
@@ -994,4 +1032,12 @@
 				ray.mRelativePvsContribution += contribution;
 			}
+			if (ray.mOriginObject && 
+				viewcell->GetPvs().GetSampleContribution(ray.mOriginObject,
+														 ray.mPdf,
+														 contribution))
+			{
+				++ ray.mPvsContribution;
+				ray.mRelativePvsContribution += contribution;
+			}
 		}
 	}
@@ -1007,5 +1053,8 @@
 			{
 				// if ray not outside of view space
-				viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf);
+				 if (ray.mTerminationObject)
+					 viewcell->GetPvs().AddSample(ray.mTerminationObject, ray.mPdf);
+				 if (ray.mOriginObject)
+					 viewcell->GetPvs().AddSample(ray.mOriginObject, ray.mPdf);
 			}
 		}
@@ -1291,6 +1340,10 @@
 
 	// export statistics after merge
-	if (0)
-		mViewCellsTree->ExportStats("mergeStats.log");
+	if (1)
+	{
+		char mstats[100];
+		environment->GetStringValue("ViewCells.mergeStats", mstats);
+		mViewCellsTree->ExportStats(mstats);
+	}
 
 	//-- stats and visualizations
@@ -2102,4 +2155,5 @@
 }
 
+
 ViewCell *KdViewCellsManager::GenerateViewCell(Mesh *mesh) const
 {
@@ -2608,6 +2662,9 @@
 	mMaxPvsSize = (int)(mMaxPvsRatio * (float)objects.size());
 
+	//TODO: remove
+	if(0)
 	mVspBspTree->Construct(constructionRays, &mViewSpaceBox);
-
+	else
+mVspBspTree->Construct(rays, &mViewSpaceBox);
 	// collapse invalid regions
 	cout << "collapsing invalid tree regions ... ";
@@ -2667,6 +2724,10 @@
 	}
 
-	if (0)
-		mViewCellsTree->ExportStats("mergeStats.log");
+	if (1)
+	{
+		char mstats[100];
+		environment->GetStringValue("ViewCells.mergeStats", mstats);
+		mViewCellsTree->ExportStats(mstats);
+	}
 
 	//-- stats and visualizations
