Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 660)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 663)
@@ -28,5 +28,5 @@
 struct BspRay;
 
-#define OCTREE_HACK 0
+//#define OCTREE_HACK 0
 /**
 	This is a view space partitioning specialised BSPtree.  
@@ -44,6 +44,7 @@
 	/** Additional data which is passed down the BSP tree during traversal.
 	*/
-	struct VspBspTraversalData
+	class VspBspTraversalData
 	{  
+	public:
 		/// the current node
 		BspNode *mNode;
@@ -64,12 +65,10 @@
 		/// if this node is a kd-node (i.e., boundaries are axis aligned
 		bool mIsKdNode;
-
-
-#if OCTREE_HACK // OCTREE HACK
+		// hack for octree
 		int mAxis;
-#endif
-		/// bounding box of current view space.
-		///AxisAlignedBox3 mBbox;
-		
+		float mPriority;
+
+		static bool sBreathFirstSplits;
+
 		/** Returns average ray contribution.
 		*/
@@ -129,19 +128,8 @@
 		float GetCost() const
 		{
-#if 1
-			return mPvs * mProbability;
-#endif
-#if 0
-			return (float) (-mDepth); // for regular grid
-#endif
-#if 0
-			return (float)(mPvs * (int)mRays->size());
-#endif
-#if 0
-			return (float)mPvs;
-#endif
-#if 0
-			return mProbabiliy * (float)mRays->size();
-#endif
+			if (sBreathFirstSplits)
+				return mPvs * mProbability;
+			else
+				return (float) (-mDepth); // for kd tree
 		}
 
@@ -160,4 +148,5 @@
     };
 	
+
 	typedef std::priority_queue<VspBspTraversalData> VspBspTraversalQueue;
 	
@@ -788,14 +777,18 @@
 
 	//int mSplits;
-
+	/// subdivision stats output file
 	ofstream mSubdivsionStats;
-
+	/// if random split axis should be used
 	bool mUseRandomAxis;
-
+	/// use polygon split whenever there are polys left
 	bool mUsePolygonSplitIfAvailable;
-
+	/// current time stamp (used for keeping split history)
 	int mTimeStamp;
-
+	/// number of currenly generated view cells
 	int mCreatedViewCells;
+	/// if vsp bsp tree should simulate octree
+	bool mSimulateOctree;
+
+	int mBreathFirstSplits;
 
 private:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 660)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 663)
@@ -37,5 +37,5 @@
 int VspBspTree::sFrontAndBackId = 0;
 
-
+bool VspBspTraversalData::sBreathFirstSplits = false;
 
 
@@ -129,4 +129,6 @@
 	environment->GetBoolValue("VspBspTree.useCostHeuristics", mUseCostHeuristics);
 	environment->GetBoolValue("VspBspTree.useSplitCostQueue", mUseSplitCostQueue);
+	environment->GetBoolValue("VspBspTree.simulateOctree", mSimulateOctree);
+	environment->GetBoolValue("VspBspTree.breathFirstSplits", VspBspTraversalData::sBreathFirstSplits);
 
 	char subdivisionStatsLog[100];
@@ -143,14 +145,23 @@
 	Debug << "min rays: " << mTermMinRays << endl;
 	Debug << "max ray contri: " << mTermMaxRayContribution << endl;
-	//Debug << "VSP BSP mininam accumulated ray lenght: ", mTermMinAccRayLength) << endl;
 	Debug << "max cost ratio: " << mTermMaxCostRatio << endl;
 	Debug << "miss tolerance: " << mTermMissTolerance << endl;
 	Debug << "max view cells: " << mMaxViewCells << endl;
 	Debug << "max polygon candidates: " << mMaxPolyCandidates << endl;
-	Debug << "max plane candidates: " << mMaxRayCandidates << endl;
+	//Debug << "max plane candidates: " << mMaxRayCandidates << endl;
 	Debug << "randomize: " << randomize << endl;
 
 	Debug << "using area for pvs: " << mUseAreaForPvs << endl;
 	Debug << "render cost weight: " << mRenderCostWeight << endl;
+	Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl;
+	Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl;
+	Debug << "only driving axis: " << mOnlyDrivingAxis << endl;
+	Debug << "max memory: " << mMaxMemory << endl;
+	Debug << "use poly split if available: " << mUsePolygonSplitIfAvailable << endl;
+	Debug << "use cost heuristics: " << mUseCostHeuristics << endl;
+	Debug << "use split cost queue: " << mUseSplitCostQueue << endl;
+	Debug << "subdivision stats log: " << subdivisionStatsLog << endl;
+	
+
 	Debug << "Split plane strategy: ";
 
@@ -163,5 +174,5 @@
 		Debug << "axis aligned ";
 	}
-	if (mSplitPlaneStrategy & LEAST_RAY_SPLITS)
+	/*if (mSplitPlaneStrategy & LEAST_RAY_SPLITS)
 	{
 		mCostNormalizer += mLeastRaySplitsFactor;
@@ -177,5 +188,5 @@
 		mCostNormalizer += mPvsFactor;
 		Debug << "pvs";
-	}
+	}*/
 
 
@@ -451,7 +462,11 @@
 							  prop,
 							  geom);
-#if OCTREE_HACK
-tData.mAxis = 0;
-#endif
+
+	tData.mPriority = mBreathFirstSplits ? 
+		(float)-frontData.mDepth : tData.mPvs * tData.mProbability;
+
+	if (mSimulateOctree)
+        tData.mAxis = 0;
+
 	// first node is kd node, i.e. an axis aligned box
 	if (1)
@@ -560,4 +575,7 @@
 							  geom);
 
+	tData.mPriority = mBreathFirstSplits ? 
+		(float)-tData.mDepth : tData.mPvs * tData.mProbability;
+
 	// compute first split candidate
 	VspBspSplitCandidate splitCandidate;
@@ -684,12 +702,12 @@
 		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
+		if (mSimulateOctree)
+		{	// choose axes in circular motion
+			tFrontData.mAxis = (tData.mAxis + 1) % 3;
+			tBackData.mAxis = (tData.mAxis + 1) % 3;
+		}
+
 		// create new interior node and two leaf nodes
 		// or return leaf as it is (if maxCostRatio missed)
-
 		int splitAxis;
 		bool splitFurther = true;
@@ -721,7 +739,11 @@
 
 			tFrontData.mIsKdNode = tBackData.mIsKdNode = (tData.mIsKdNode && splitAxis < 3);
+
 			// how often was max cost ratio missed in this branch?
 			tFrontData.mMaxCostMisses = maxCostMisses;
 			tBackData.mMaxCostMisses = maxCostMisses;
+
+			ComputePriority(tFrontData);
+			ComputePriority(tBackData);
 
 			if (1)
@@ -843,5 +865,11 @@
 		tBackData.mMaxCostMisses = maxCostMisses;
 		
-
+		ComputePriority(tFrontData);
+		ComputePriority(tBackData);
+
+		frontData.mPriority = mBreathFirstSplits ? 
+		(float)-frontData.mDepth : frontData.mPvs * frontData.mProbability;
+	backData.mPriority = mBreathFirstSplits ? 
+		(float)-backData.mDepth : backData.mPvs * backData.mProbability;
 		if (1)
 		{
@@ -937,5 +965,6 @@
 
 	// compute locally best split plane
-	bool success = SelectPlane(splitData.mSplitPlane, leaf, tData, frontData, backData, splitAxis);
+	bool success = SelectPlane(splitData.mSplitPlane, leaf, tData, 
+							   frontData, backData, splitAxis);
 
 	// TODO: reuse
@@ -1004,5 +1033,5 @@
 		}
 	}
-	
+
 	
     // subdivide polygons
@@ -1324,13 +1353,28 @@
 			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
+
+	int sAxis = 0;
+
+	bool useSpecialAxis = false;
+
+	if (mSimulateOctree)
+	{
+		sAxis = tData.mAxis;
+		useSpecialAxis = true;
+	}
+	else if (mUseRandomAxis)
+	{
+		sAxis = Random(3);
+		useSpecialAxis = true;
+	}
+	else if (mOnlyDrivingAxis)
+	{
+		sAxis = box.Size().DrivingAxis();
+		useSpecialAxis = true;
+	}
+
 	for (axis = 0; axis < 3; ++ axis)
 	{
-		if (!mOnlyDrivingAxis || (axis == sAxis))
+		if (!useSpecialAxis || (axis == sAxis))
 		{
 			if (!mUseCostHeuristics)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 663)
@@ -1172,6 +1172,4 @@
 				 "100000");
 
-
-
   RegisterOption("VssPreprocessor.useImportanceSampling",
 				 optBool,
@@ -1992,5 +1990,4 @@
 			"0.5");
 
-
 	RegisterOption("VspBspTree.Construction.randomize", 
 		optBool, 
@@ -1998,5 +1995,9 @@
 		"false");
 
-	
+	RegisterOption("VspBspTree.simulateOctree", 
+		optBool, 
+		"vsp_bsp_simulate_octree=", 
+		"false");
+
 	RegisterOption("VspBspTree.maxTotalMemory", 
 		optFloat, 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 660)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 663)
@@ -277,4 +277,5 @@
 	if (SAMPLE_AFTER_SUBDIVISION)
 		ComputeSampleContributions(postProcessSamples, true, storeViewCells);
+
 	// merge the view cells
 	PostProcess(preprocessor->mObjects, postProcessSamples);
@@ -310,6 +311,10 @@
 	environment->GetIntValue("ViewCells.Evaluation.samples", numSamples);
 
+	Debug << "view cells evaluation samples per pass: " << samplesPerPass << endl;
+	Debug << "view cells evaluation samples: " << numSamples << endl;
+
 	while (castSamples < numSamples)
 	{
+
 	}
 	//char s[64]; sprintf(s, "bsp-pvs%04d.x3d", i);
