Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/egsr_test_script
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/egsr_test_script	(revision 675)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/egsr_test_script	(revision 711)
@@ -2,6 +2,7 @@
 PROGRAM=../bin/release/Preprocessor.exe
 
-SCENE=soda5
-#SCENE=soda
+#SCENE=$1
+SCENE=soda
+#SCENE=soda5
 #SCENE=atlanta
 #SCENE=vienna
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 710)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 711)
@@ -1055,7 +1055,14 @@
 	// subdivide further
 
+	// store maximal and minimal depth
+	if (tData.mDepth > mBspStats.maxDepth)
+	{
+		Debug << "max depth increases to " << tData.mDepth << " at " << mBspStats.Leaves() << " leaves" << endl;
+		mBspStats.maxDepth = tData.mDepth;
+	}
+
 	mBspStats.nodes += 2;
 
-	
+    
 	BspInterior *interior = new BspInterior(splitPlane);
 
@@ -1064,4 +1071,5 @@
 #endif
 
+
 	//-- create front and back leaf
 
@@ -1087,4 +1095,5 @@
 	interior->mTimeStamp = mTimeStamp ++;
 	
+
 	//DEL_PTR(leaf);
 	return interior;
@@ -1142,5 +1151,5 @@
 	// creates a sorted split candidates array
 	if (mSplitCandidates->capacity() > 500000 &&
-		requestedSize < (int)(mSplitCandidates->capacity()  / 10) )
+		requestedSize < (int)(mSplitCandidates->capacity() / 10) )
 	{
     	delete mSplitCandidates;
@@ -1851,5 +1860,5 @@
 		pBack = pOverall - pFront;
 		
-		// clamp because of possible precision issues
+		// precision issues possible for unbalanced split => don't take this split!
 		if (1 && 
 			(!splitSuccessFull || (pFront <= 0) || (pBack <= 0) || 
@@ -1857,5 +1866,5 @@
 		{
 			Debug << "error f: " << pFront << " b: " << pBack << endl;
-			return 999;
+			return 99999.9f;
 		}
 	}
@@ -2167,18 +2176,21 @@
 	BspLeaf *leaf = dynamic_cast<BspLeaf *>(data.mNode);
 
-	// store maximal and minimal depth
-	if (data.mDepth > mBspStats.maxDepth)
-		mBspStats.maxDepth = data.mDepth;
 
 	if (data.mPvs > mBspStats.maxPvs)
+	{
 		mBspStats.maxPvs = data.mPvs;
-	
+	}
+
 	mBspStats.pvs += data.mPvs;
 
 	if (data.mDepth < mBspStats.minDepth)
+	{
 		mBspStats.minDepth = data.mDepth;
+	}
 	
 	if (data.mDepth >= mTermMaxDepth)
+	{
 		++ mBspStats.maxDepthNodes;
+	}
 
 	// accumulate rays to compute rays /  leaf
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 710)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 711)
@@ -467,4 +467,5 @@
 }
 
+
 BspViewCell *BspTree::GetOrCreateOutOfBoundsCell()
 {
@@ -1706,24 +1707,34 @@
 
 		// construct child geometry with regard to the candidate split plane
-		BspNodeGeometry frontCell;
-		BspNodeGeometry backCell;
-
-		cell.SplitGeometry(frontCell, 
-						   backCell, 
-						   candidatePlane,
-						   mBox,
-						   mEpsilon);
+		BspNodeGeometry geomFront;
+		BspNodeGeometry geomBack;
+
+		const bool splitSuccessFull = 
+			cell.SplitGeometry(geomFront, 
+							   geomBack, 
+							   candidatePlane,
+							   mBox,
+							   mEpsilon);
 
 		if (mUseAreaForPvs)
 		{
-			pFront = frontCell.GetArea();
-			pBack = backCell.GetArea();
+			pFront = geomFront.GetArea();
+			pBack = geomBack.GetArea();
 		}
 		else
 		{
-			pFront = frontCell.GetVolume();
+			pFront = geomFront.GetVolume();
 			pBack = pOverall - pFront;
 		}
 		
+		
+		// give penalty to unbalanced split
+		if (1 && 
+			(!splitSuccessFull || (pFront <= 0) || (pBack <= 0) || 
+			!geomFront.Valid() || !geomBack.Valid()))
+		{
+			Debug << "error f: " << pFront << " b: " << pBack << endl;
+			return 99999.9f;
+		}
 
 		pOverall = probability;
@@ -1793,15 +1804,9 @@
 		val += mBalancedRaysFactor * fabs(sumBalancedRays) /  raysSize;
 
-	const float denom = pOverall * (float)pvs * 2.0f + Limits::Small;
+	const float denom = pOverall * (float)pvs + Limits::Small;
 
 	if (mSplitPlaneStrategy & PVS)
 	{
 		val += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / denom;
-
-		// give penalty to unbalanced split
-		if (0)
-		if (((pFront * 0.2 + Limits::Small) > pBack) || 
-			(pFront < (pBack * 0.2 + Limits::Small)))
-			val += 0.5;
 	}
 
@@ -1975,6 +1980,6 @@
 }
 
-int
-BspTree::_CastRay(Ray &ray)
+
+int BspTree::_CastRay(Ray &ray)
 {
 	int hits = 0;
@@ -3085,19 +3090,20 @@
 									const float epsilon) const
 {	
-#if 0
-	// trivial cases
-	const int cf = Side(splitPlane, epsilon);
-
-	if (cf == -1)
-	{
-		back = *this;
-		return false;
-	}
-	else if (cf == 1)
-	{
-		front = *this;
-		return false;
-	}
-#endif
+	//-- trivial cases
+	if (0)
+	{
+		const int cf = Side(splitPlane, epsilon);
+
+		if (cf == -1)
+		{
+			back = *this;
+			return false;
+		}
+		else if (cf == 1)
+		{
+			front = *this;
+			return false;
+		}
+	}
 
 	// get cross section of new polygon
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 710)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 711)
@@ -16,5 +16,5 @@
 #include "RssPreprocessor.h"
 
-#define SAMPLE_AFTER_SUBDIVISION 0
+#define SAMPLE_AFTER_SUBDIVISION 1
 #define TEST_EMPTY_VIEW_CELLS 0
 
