Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 610)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 611)
@@ -28,5 +28,5 @@
 struct BspRay;
 
-
+#define OCTREE_HACK 0
 /**
 	This is a view space partitioning specialised BSPtree.  
@@ -64,4 +64,7 @@
 		/// if this node is a kd-node (i.e., boundaries are axis aligned
 		bool mIsKdNode;
+#if OCTREE_HACK // OCTREE HACK
+		int mAxis;
+#endif
 		/// bounding box of current view space.
 		///AxisAlignedBox3 mBbox;
@@ -124,8 +127,8 @@
 		float GetCost() const
 		{
-#if 1
+#if 0
 			return mPvs * mProbability;
 #endif
-#if 0
+#if 1
 			return (float) (-mDepth); // for regular grid
 #endif
@@ -708,5 +711,5 @@
 	int mTotalPvsSize;
 
-	int mSplits;
+	//int mSplits;
 
 	ofstream mSubdivsionStats;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 610)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 611)
@@ -9,4 +9,6 @@
 #include "VssRay.h"
 #include "ViewCell.h"
+
+
 
 class ViewCell;
@@ -430,4 +432,7 @@
 #endif
 #if 1
+			return (float) (-mDepth); // for regular grid
+#endif
+#if 0
 			return mProbability;
 #endif
@@ -958,4 +963,10 @@
 
 	int mTimeStamp;
+
+	float mTotalCost;
+	int mTotalPvsSize;
+
+	//int mSplits;
+	ofstream  mSubdivisionStats;
 
 private:
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 610)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 611)
@@ -426,5 +426,7 @@
 							  prop,
 							  geom);
-
+#if OCTREE_HACK
+tData.mAxis = 0;
+#endif
 	// first node is kd node, i.e. an axis aligned box
 	if (1)
@@ -528,5 +530,10 @@
 		VspBspTraversalData tFrontData;
 		VspBspTraversalData tBackData;
-
+#if OCTREE_HACK
+		//Debug << "new axis:" << (tData.mAxis + 1) % 3 << endl;
+
+		tFrontData.mAxis = (tData.mAxis + 1) % 3;
+		tBackData.mAxis = (tData.mAxis + 1) % 3;
+#endif
 		// create new interior node and two leaf nodes
 		// or return leaf as it is (if maxCostRatio missed)
@@ -537,14 +544,10 @@
 			if (1)
 			{
-				float cFront = tFrontData.mPvs * tFrontData.mProbability;
-				float cBack = tBackData.mPvs * tBackData.mProbability;
-				float cData = tData.mPvs * tData.mProbability;;
+				float cFront = (float)tFrontData.mPvs * tFrontData.mProbability;
+				float cBack = (float)tBackData.mPvs * tBackData.mProbability;
+				float cData = (float)tData.mPvs * tData.mProbability;;
 
                 float costDecr = 
 					(cFront + cBack - cData) / mBox.GetVolume();
-
-				int pvsFront = tFrontData.mPvs * tFrontData.mProbability;
-				int pvsBack = tBackData.mPvs * tBackData.mProbability;
-				int pvsData = tData.mPvs * tData.mProbability;;
 
 				mTotalCost += costDecr;
@@ -979,7 +982,10 @@
 			box.Include((*ri).ExtrapTermination());
 	}
-
+#if OCTREE_HACK
+	//Debug << "choosing axis:" << tData.mAxis << endl;
+	const int sAxis = tData.mAxis;
+#else
 	const int sAxis = mUseRandomAxis ? Random(3) : box.Size().DrivingAxis();
-
+#endif
 	for (axis = 0; axis < 3; ++ axis)
 	{
@@ -1130,5 +1136,5 @@
 
 	// cost ratio miss
-	if (!mUsePolygonSplitIfAvailable || data.mPolygons->empty())
+	if (mUsePolygonSplitIfAvailable && !data.mPolygons->empty())
 	{
 		frontData.mIsKdNode = backData.mIsKdNode = false;
@@ -1183,5 +1189,7 @@
 	// cost ratio miss
 	if (lowestCost > mTermMaxCostRatio)
+	{
 		return false;
+	}
 
 	return true;
@@ -1629,4 +1637,5 @@
 	if (data.mDepth >= mTermMaxDepth)
 		++ mBspStats.maxDepthNodes;
+
 	// accumulate rays to compute rays /  leaf
 	mBspStats.accumRays += (int)data.mRays->size();
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 607)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 611)
@@ -1912,5 +1912,5 @@
 					optBool,
                     "vsp_bsp_usePolygonSplitIfAvailable=",
-					"true");
+					"false");
 
 	RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 610)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 611)
@@ -262,5 +262,7 @@
 
 	environment->GetFloatValue("BspTree.Construction.epsilon", mEpsilon);
-	
+
+	mSubdivisionStats.open("subdivisionStats.log");
+
     Debug << "BSP max depth: " << mTermMaxDepth << endl;
 	Debug << "BSP min PVS: " << mTermMinPvs << endl;
@@ -841,8 +843,21 @@
 						   geom);
 
+	mTotalCost = tData.mPvs * tData.mProbability / mBox.GetVolume();
+	mTotalPvsSize = tData.mPvs;
+	
+	mSubdivisionStats 
+			<< "#ViewCells\n1\n" <<  endl
+			<< "#RenderCostDecrease\n0\n" << endl 
+			<< "#TotalRenderCost\n" << mTotalCost << endl
+			<< "#AvgRenderCost\n" << mTotalPvsSize << endl;
+
 	tStack.push(tData);
 
+	// used for intermediate time measurements and progress
+	long interTime = GetTime();	
+	int nleaves = 500;
+
 	mStat.Start();
-	cout << "Contructing bsp tree ... ";
+	cout << "Contructing bsp tree ...\n";
 	long startTime = GetTime();
 	while (!tStack.empty()) 
@@ -858,4 +873,15 @@
             Debug << "BSP tree construction time spent at root: " 
 				  << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;
+
+		if (mStat.Leaves() >= nleaves)
+		{
+			nleaves += 500;
+			
+			cout << "leaves=" << mStat.Leaves() << endl;
+			Debug << "needed "
+				  << TimeDiff(interTime, GetTime())*1e-3 
+				  << " secs to create 500 leaves" << endl;
+			interTime = GetTime();
+		}
 	}
 
@@ -937,8 +963,30 @@
 							   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
 	BspInterior *interior = 
 		SubdivideNode(tData, tFrontData, tBackData, coincident);
 
+
+	if (1)
+	{
+		float cFront = (float)tFrontData.mPvs * tFrontData.mProbability;
+		float cBack = (float)tBackData.mPvs * tBackData.mProbability;
+		
+		float costDecr = 
+			(cFront + cBack - cData) / mBox.GetVolume();
+
+		
+		mTotalCost += costDecr;
+		mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - pvsData;
+
+		mSubdivisionStats 
+			<< "#ViewCells\n" << mStat.Leaves() << endl
+			<< "#RenderCostDecrease\n" << -costDecr << endl 
+			<< "#TotalRenderCost\n" << mTotalCost << endl
+			<< "#AvgRenderCost\n" << mTotalPvsSize / mStat.Leaves() << endl;
+	}
 
 	// extract view cells from coincident polygons according to plane normal
@@ -1006,10 +1054,5 @@
 	BspLeaf *leaf = dynamic_cast<BspLeaf *>(tData.mNode);
 
-	long startTime;
-	if (0)
-	{
-		Debug << "*********************" << endl;
-		startTime = GetTime();
-	}
+	
 	
 	// select subdivision plane
@@ -1017,9 +1060,5 @@
 		new BspInterior(SelectPlane(leaf, tData)); 
 	
-	if (0)
-	{
-		Debug << "time used for split plane selection: " 
-			  << TimeDiff(startTime, GetTime()) * 1e-3 << "s" << endl;
-	}
+	
 #ifdef _DEBUG
 	Debug << interior << endl;
@@ -1027,20 +1066,8 @@
 	
 
-	if (0)
-	{
-		Debug << "number of rays: " << (int)tData.mRays->size() << endl;
-		Debug << "number of polys: " << (int)tData.mPolygons->size() << endl;
-
-		startTime = GetTime();
-	}	
-	
 	// subdivide rays into front and back rays
 	SplitRays(interior->mPlane, *tData.mRays, *frontData.mRays, *backData.mRays);
 	
-	if (0)
-	{
-		Debug << "time used for rays splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
-		startTime = GetTime();
-	}
+	
 
 	// subdivide polygons with plane
@@ -1051,8 +1078,5 @@
 									  coincident);
 
-	if (0)
-	{
-		Debug << "time used for polygon splitting: " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
-	}
+	
 
     // compute pvs
@@ -1070,11 +1094,15 @@
 	
 		
-		frontData.mProbability = frontData.mGeometry->GetVolume();
-		backData.mProbability = backData.mGeometry->GetVolume();
-	}
-
-	// compute accumulated ray length
-	//frontData.mAccRayLength = AccumulatedRayLength(*frontData.mRays);
-	//backData.mAccRayLength = AccumulatedRayLength(*backData.mRays);
+		if (mUseAreaForPvs)
+		{
+			frontData.mProbability = frontData.mGeometry->GetArea();
+			backData.mProbability = backData.mGeometry->GetArea();
+		}
+		else
+		{
+			frontData.mProbability = frontData.mGeometry->GetVolume();
+			backData.mProbability = tData.mProbability - frontData.mProbability;
+		}
+	}
 
 	//-- create front and back leaf
@@ -1582,7 +1610,7 @@
 inline void BspTree::GenerateUniqueIdsForPvs()
 {
-	Intersectable::NewMail(); sBackId = ViewCell::sMailId;
-	Intersectable::NewMail(); sFrontId = ViewCell::sMailId;
-	Intersectable::NewMail(); sFrontAndBackId = ViewCell::sMailId;
+	ViewCell::NewMail(); sBackId = ViewCell::sMailId;
+	ViewCell::NewMail(); sFrontId = ViewCell::sMailId;
+	ViewCell::NewMail(); sFrontAndBackId = ViewCell::sMailId;
 }
 
@@ -1895,5 +1923,5 @@
 		return 0;
 
-	Intersectable::NewMail();
+	ViewCell::NewMail();
 
 	Vector3 entp = ray.Extrap(mint);
