Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 370)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionQueriesQueryManager.cpp	(revision 645)
@@ -225,5 +225,5 @@
 	}
 }
-//------j-----------------------------------------------------------------
+//------------------------------------------------------------------------
 void  OcclusionQueriesQueryManager::CollectNodeVisibility(
 						GtpVisibility::QueryList::iterator &visQueryIt, 
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env	(revision 644)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/default.env	(revision 645)
@@ -289,5 +289,5 @@
 	Construction {
 		samples 500000
-		epsilon 0.005
+		epsilon 0.00005
 		randomize false
 		renderCostWeight 1.0
@@ -331,5 +331,5 @@
 		missTolerance		6
 		
-		maxViewCells		10000
+		maxViewCells		50000
 		
 		# used for pvs criterium
@@ -354,5 +354,5 @@
 BspTree {
 	Construction {
-		samples 500000
+		samples 50000
 		epsilon 0.005
 	}
@@ -420,5 +420,5 @@
 		minProbability 0.001
 		maxRayContribution 9999
-		maxViewCells	2048
+		maxViewCells	1000
 
 		# used for pvs criterium
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 644)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 645)
@@ -963,6 +963,4 @@
 							   new BoundedRayContainer(), 0, 0, new BspNodeGeometry());
 
-	int pvsData = tData.mPvs;
-	float cData = (float)tData.mPvs * tData.mProbability;
 
 	// create new interior node and two leaf nodes
@@ -973,9 +971,21 @@
 	if (1)
 	{
+		int pvsData = tData.mPvs;
+		float cData = (float)pvsData * tData.mProbability;
+
 		float cFront = (float)tFrontData.mPvs * tFrontData.mProbability;
 		float cBack = (float)tBackData.mPvs * tBackData.mProbability;
 		
-		float costDecr = 
-			(cFront + cBack - cData) / mBox.GetVolume();
+		Debug << "front pvs: " << tFrontData.mPvs << " p: " << tFrontData.mProbability << endl;
+		Debug << "back pvs: " << tBackData.mPvs << " p: " << tBackData.mProbability << endl;
+		Debug << "pvs: " << pvsData << " p: " << tData.mProbability << endl;
+
+		Debug << "data: " << cData << " front: " << cFront << " back: " << cBack << endl;
+		Debug << "cost ratio: " << (cFront + cBack) / cData << endl;
+
+		if ((cFront + cBack) / cData > 1)
+			Debug << "ERROR!!" << endl;
+
+		float costDecr = (cFront + cBack - cData) / mBox.GetVolume();
 
 		
@@ -1017,4 +1027,5 @@
 }
 
+
 void BspTree::ExtractViewCells(BspTraversalData &frontData,
 							   BspTraversalData &backData, 
@@ -1044,4 +1055,5 @@
 	}
 }
+
 
 BspInterior *BspTree::SubdivideNode(BspTraversalData &tData,
@@ -1091,5 +1103,6 @@
 									   interior->mPlane,
 									   mBox,
-									   mEpsilon);
+									   0.000000000001);
+									   //mEpsilon);
 	
 		
@@ -1103,4 +1116,11 @@
 			frontData.mProbability = frontData.mGeometry->GetVolume();
 			backData.mProbability = tData.mProbability - frontData.mProbability;
+
+			Debug << "************" << endl;
+			Debug << "plane: " << interior->mPlane << endl;
+			Debug << "box: " << mBox << endl;
+			Debug << "all: " << tData.mProbability << " f: " << frontData.mProbability << " b: " << backData.mProbability << endl;
+			Debug << "real back: " << backData.mGeometry->GetVolume() << endl;
+			Debug << "data geom: " << tData.mGeometry->mPolys.size() << " f: " << frontData.mGeometry->mPolys.size() << " b: " << backData.mGeometry->mPolys.size() << endl;
 		}
 	}
@@ -1443,4 +1463,6 @@
 		const float candidateCost = 
 			SplitPlaneCost(poly->GetSupportingPlane(), data);
+
+		Debug << "supporting plane: " << poly->GetSupportingPlane() << endl;
 
 		if (candidateCost < lowestCost)
@@ -1982,5 +2004,5 @@
 			if (!leaf->mViewCell->Mailed())
 			{
-			  //				ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf));
+				//ray.bspIntersections.push_back(Ray::BspIntersection(maxt, leaf));
 				leaf->mViewCell->Mail();
 				++ hits;
@@ -2061,8 +2083,11 @@
 			else // ray and plane are coincident
 			{
-				// WHAT TO DO IN THIS CASE ?
-				//break;
-				node = in->GetFront();
-				continue;
+				// NOTE: what to do if ray is coincident with plane?
+				if (extSide < 0)
+					node = in->GetBack();
+				else 
+					node = in->GetFront();
+								
+				continue; // no far child
 			}
 		
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp	(revision 574)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp	(revision 645)
@@ -224,5 +224,5 @@
 
 	//TODO: remove for performance
-#if 0
+#if 1
 	if (1)
 	{
@@ -234,5 +234,6 @@
 		}
 	}
-	else
+	
+	if (1)
 	{
 		Vector3 vtx = mVertices.back();
@@ -241,5 +242,5 @@
 		for (it = mVertices.begin(); it != it_end; ++it)
 		{
-			if (!(EpsilonEqualV3(vtx, *it)))
+			if (EpsilonEqualV3(vtx, *it, 0.0001))
 			{
 				//Debug << "Malformed vertices:\n" << *this << endl;
