Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 670)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 676)
@@ -798,4 +798,6 @@
 	bool mBreathFirstSplits;
 
+	bool mEmptyViewCellsMergeAllowed;
+
 private:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 666)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 676)
@@ -481,5 +481,5 @@
 	bool mEvaluateViewCells;
 
-	bool mShowVisualization;
+	bool mShowVisualization;	
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 675)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 676)
@@ -121,4 +121,6 @@
 	environment->GetBoolValue("VspBspTree.useBreathFirstSplits", mBreathFirstSplits);
 
+	environment->GetBoolValue("ViewCells.PostProcess.emptyViewCellsMergeAllowed", mEmptyViewCellsMergeAllowed);
+	
 	char subdivisionStatsLog[100];
 	environment->GetStringValue("VspBspTree.subdivisionStats", subdivisionStatsLog);
@@ -184,4 +186,5 @@
 	mSplitCandidates = new vector<SortableEntry>;
 
+	Debug << "here3" << endl;
 	Debug << endl;
 }
@@ -1011,5 +1014,5 @@
 									   splitPlane,
 									   mBox,
-									   0.0000001f);
+									   0.000000001f);
 									   //mEpsilon);
 		
@@ -1023,7 +1026,16 @@
 			frontData.mProbability = frontData.mGeometry->GetVolume();
 			backData.mProbability = tData.mProbability - frontData.mProbability;
+
+			if (frontData.mProbability < -0.00001)
+				Debug << "here2 error: " << frontData.mProbability << endl;
+			if (backData.mProbability < -0.00001)
+				Debug << "here2 error: " << backData.mProbability << endl;
+
 			// clamp because of precision issues
-			if (frontData.mProbability < 0)	frontData.mProbability = 0;
-			if (backData.mProbability < 0) backData.mProbability = 0;
+			if (0)
+			{
+				if (frontData.mProbability < 0)	frontData.mProbability = 0;
+				if (backData.mProbability < 0) backData.mProbability = 0;
+			}
 		}
 	}
@@ -1692,5 +1704,5 @@
 								  candidatePlane,
 								  mBox,
-								  0.0000001f);
+								  0.000000001f);
 								  //mEpsilon);
 
@@ -1700,7 +1712,17 @@
 		pBack = pOverall - pFront;
 
+		if ((pFront < 0.001) || (pBack < 0.001))
+		{
+			Debug << "vol f " << pFront << " b " << pBack << " p " << pOverall << endl;
+			Debug << "real vol f " << pFront << " b " << geomBack.GetVolume() << " p " << pOverall << endl;
+			Debug << "polys f" << (int)geomFront.mPolys.size() << " b " << (int)geomFront.mPolys.size() << " data " << (int)data.mGeometry->mPolys.size() << endl;
+		}
+
 		// clamp because of possible precision issues
-		if (pFront < 0)	pFront = 0;
-		if (pBack < 0) pBack = 0;
+		if (0)
+		{
+			if (pFront < 0)	pFront = 0;
+			if (pBack < 0) pBack = 0;
+		}
 	}
 	else
@@ -1785,6 +1807,6 @@
 								  candidatePlane,
 								  mBox,
-
-								  mEpsilon);
+								  0.0000001f);
+								  //mEpsilon);
 
 	pOverall = data.mProbability;
@@ -1796,6 +1818,18 @@
 		
 		// clamp because of possible precision issues
-		if (pFront < 0)	pFront = 0;
-		if (pBack < 0) pBack = 0;
+		if (1)
+		{
+			if (pFront <= 0)
+			{
+				//Debug << "error f: " << pFront << endl;
+				return 999;
+			}
+
+			if (pBack <= 0) 
+			{
+				//Debug << "error b: " << pBack << endl;
+				return 999;
+			}
+		}
 	}
 	else
@@ -3335,5 +3369,13 @@
 			{
 				MergeCandidate mc(leaf->GetViewCell(), (*nit)->GetViewCell());
-				candidates.push_back(mc);
+
+				// dont't merge view cells if they are empty and not front and back leaf of the same parent
+				// in the tree?
+				if (mEmptyViewCellsMergeAllowed ||
+					(!leaf->GetViewCell()->GetPvs().Empty() && ! (*nit)->GetViewCell()->GetPvs().Empty()) ||
+                    leaf->IsSibling(*nit))
+				{
+					candidates.push_back(mc);
+				}
 
 				++ numCandidates;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 675)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 676)
@@ -1276,5 +1276,10 @@
 	RegisterOption("ViewCells.exportToFile",
 					optBool,
-					"view_cells_export_to_file",
+					"view_cells_export_to_file=",
+					"false");
+
+	RegisterOption("ViewCells.PostProcess.emptyViewCellsMergeAllowed",
+					optBool,
+					"view_cells_post_process_empty_view_cells_merge_allowed="
 					"false");
 
@@ -1565,5 +1570,5 @@
 	RegisterOption("Preprocessor.samplesFilename",
 					optString,
-					"-preprocessor_samples_filename=",
+					"preprocessor_samples_filename=",
 					"rays.out");
 
@@ -1717,5 +1722,5 @@
 	RegisterOption("VspKdTree.Termination.missTolerance",
 			optInt,
-			"-vsp_kd_term_miss_tolerance=",
+			"vsp_kd_term_miss_tolerance=",
 			"4");
 
@@ -1997,7 +2002,18 @@
 			"0.1");
 
-	RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0");
-	RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0");
-	RegisterOption("VspBspTree.Factor.pvs", optFloat, "-vsp_bsp_factor_pvs=", "1.0");
+	RegisterOption("VspBspTree.Factor.leastRaySplits", 
+					optFloat, 
+					"vsp_bsp_factor_least_ray_splits=", 
+					"1.0");
+
+	RegisterOption("VspBspTree.Factor.balancedRays", 
+					optFloat, 
+					"vsp_bsp_factor_balanced_rays=", 
+					"1.0");
+
+	RegisterOption("VspBspTree.Factor.pvs", 
+					optFloat, 
+					"vsp_bsp_factor_pvs=", 
+					"1.0");
 	
 	RegisterOption("VspBspTree.Construction.renderCostWeight",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 675)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 676)
@@ -980,5 +980,6 @@
 		viewCell->mLeaf = leaf;
 
-		float probability = max(0.0f, tData.mProbability);
+		//float probability = max(0.0f, tData.mProbability);
+		float probability = tData.mProbability;
 
 		if (mUseAreaForPvs)
@@ -2983,5 +2984,5 @@
 		/// don't use epsilon here to get exact split planes
 		const int cf = 
-			mPolys[i]->ClassifyPlane(splitPlane, Limits::Small);
+			mPolys[i]->ClassifyPlane(splitPlane, epsilon);
 			
 		switch (cf)
