Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj	(revision 728)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj	(revision 734)
@@ -83,5 +83,5 @@
 				AdditionalDependencies="xerces-c_2.lib zdll.lib zziplib.lib devil.lib qtmain.lib QtOpenGL4.lib QtCore4.lib QtGui4.lib Qt3Supportd4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib"
 				AdditionalLibraryDirectories="..\support\xercesc\lib\;..\support\zlib\lib\;..\support\devil\lib;&quot;$(QTDIR)\lib&quot;;..\include;..\src\GL;&quot;$(CG_LIB_PATH)&quot;;&quot;$(GTPDIR)\NonGTP\Xerces&quot;;&quot;$(GTPDIR)\NonGTP\Xerces\xercesc\lib&quot;;&quot;$(GTPDIR)\NonGTP\zlib\lib&quot;;&quot;$(GTPDIR)\NonGTP\Devil\lib&quot;"
-				GenerateDebugInformation="TRUE"
+				GenerateDebugInformation="FALSE"
 				LargeAddressAware="2"/>
 			<Tool
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 729)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 734)
@@ -811,5 +811,5 @@
 	/// if we should use breath first priority for the splits
 	bool mBreathFirstSplits;
-
+	bool mDepthFirstSplits;
 	bool mEmptyViewCellsMergeAllowed;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 729)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 734)
@@ -532,5 +532,5 @@
 	// frequency stats are updated
 	const int statsOut = 500;
-	Debug << "here3" << endl; Debug.flush();
+	
 	// passes are needed for statistics, because we don't want to record
 	// every merge
@@ -546,5 +546,5 @@
 	int maxMergesPerPass;
 	int numMergedViewCells = 0;
-	Debug << "here5" << endl; Debug.flush();
+	
 	environment->GetIntValue("ViewCells.PostProcess.maxMergesPerPass", maxMergesPerPass);
 	environment->GetFloatValue("ViewCells.PostProcess.avgCostMaxDeviation", avgCostMaxDeviation);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 729)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 734)
@@ -155,4 +155,6 @@
 	Debug << "use random axis: " << mUseRandomAxis << endl;
 	Debug << "breath first splits: " << mBreathFirstSplits << endl;
+	Debug << "depth first splits: " << mDepthFirstSplits << endl;
+
 	Debug << "empty view cells merge: " << mEmptyViewCellsMergeAllowed << endl;
 
@@ -940,6 +942,10 @@
 void VspBspTree::EvalPriority(VspBspTraversalData &tData) const
 {
-    tData.mPriority = mBreathFirstSplits ? 
-		(float)-tData.mDepth : tData.mPvs * tData.mProbability;
+	if (mBreathFirstSplits)
+		tData.mPriority = (float)-tData.mDepth;
+	else if (mDepthFirstSplits)
+		tData.mPriority = (float)tData.mDepth;
+	else
+		tData.mPriority = tData.mPvs * tData.mProbability;
 	//cout << "priority: " << tData.mPriority << endl;
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 728)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 734)
@@ -2064,4 +2064,9 @@
 		"false");
 
+	RegisterOption("VspBspTree.useDepthFirstSplits",
+		optBool,
+		"vsp_bsp_depth_first_splits=",
+		"false");
+
 	RegisterOption("VspBspTree.useRandomAxis",
 		optBool,
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 729)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 734)
@@ -178,4 +178,8 @@
   }
 
+ static bool SmallerRenderCost(const ViewCell *a, const ViewCell *b) 
+ {
+	 return a->GetRenderCost() < b->GetRenderCost();
+ }
 
 	void SetMergeCost(const float mergeCost);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 729)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 734)
@@ -91,5 +91,5 @@
 	environment->GetIntValue("ViewCells.Filter.maxSize", mMaxFilterSize);
 	environment->GetFloatValue("ViewCells.Filter.width", mFilterWidth);
-	environment->GetIntValue("ViewCells.mRenderCostEvaluationType", mRenderCostEvaluationType);
+	environment->GetIntValue("ViewCells.renderCostEvaluationType", mRenderCostEvaluationType);
 
 	char buf[100];
@@ -129,5 +129,5 @@
 	environment->GetStringValue("ViewCells.renderCostEvaluationType", buf);
 	
-	if (strcmp(buf, "box") == 0)
+	if (strcmp(buf, "perobject") == 0)
 	{
 		mRenderCostEvaluationType = ViewCellsManager::PER_OBJECT;
@@ -535,4 +535,5 @@
 }
 
+
 void ViewCellsManager::EvalViewCellHistogram(const string filename, const int nViewCells)
 {
@@ -540,10 +541,18 @@
 	outstream.open(filename.c_str());
 
+	Debug << "here3" << endl;
 	ViewCellContainer viewCells;
 	mViewCellsTree->CollectBestViewCellSet(mViewCells, nViewCells);
 
 	float maxRenderCost, minRenderCost;
+
 	/// find out the range for valid render cost
 	ComputeMinMaxRenderCost(minRenderCost, maxRenderCost, viewCells);
+
+	// sort by render cost
+	sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerRenderCost);
+
+	minRenderCost = viewCells.front()->GetRenderCost();
+	maxRenderCost = viewCells.back()->GetRenderCost();
 
 	const int intervals = 10000;
@@ -552,4 +561,55 @@
 	const int stepSize = (int)((float)range / (float)intervals);
 
+	float vol = 0;
+	int smallerCost = 0;
+
+	ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();		
+
+	int i = 0;
+
+	// note can skip computations for view cells already evaluated and delete them from vector ...
+    while (1)
+	{
+	Debug << "here4" << endl;
+		while ((i < (int)viewCells.size()) && (viewCells[i]->GetRenderCost() < currentRenderCost))
+		{
+			
+	Debug << "here5" << endl;
+			++ i;
+			++ smallerCost;
+			vol += viewCells[i]->GetVolume();
+		}
+
+		currentRenderCost += stepSize;
+		
+		outstream << "#RenderCost: " << currentRenderCost << endl;
+		outstream << "#ViewCells: " << smallerCost << endl;		
+		outstream << "#Volume: " << vol << endl << endl;
+	}
+	outstream.close();
+	Debug << "here6" << endl;
+}
+
+/*
+void ViewCellsManager::EvalViewCellHistogramForPvs(const string filename, const int nViewCells)
+{
+	std::ofstream outstream;
+	outstream.open(filename.c_str());
+
+	ViewCellContainer viewCells;
+	mViewCellsTree->CollectBestViewCellSet(mViewCells, nViewCells);
+
+	float maxRenderCost, minRenderCost;
+	/// find out the range for valid render cost
+	ComputeMinMaxRenderCost(minRenderCost, maxRenderCost, viewCells);
+
+	const int intervals = 10000;
+	const float range = maxRenderCost - minRenderCost;
+	int currentRenderCost = (int)ceil(minRenderCost);
+	const int stepSize = (int)((float)range / (float)intervals);
+	float vol = 0;
+
+	ViewCell::NewMail();
+
 	for (; currentRenderCost < (int)maxRenderCost; currentRenderCost += stepSize)
 	{
@@ -558,10 +618,17 @@
 		int smallerCost = 0;
 
-		for (it = viewCells.begin(); it != viewCells.end(); ++ it)
-		{
+		// note can skip computations for view cells already evaluated and delete them from vector ...
+        for (it = viewCells.begin(); it != viewCells.end(); ++ it)
+		{
+			if (!vc->Mailed())
+			{
+				vc->Mail();
 			ViewCell *vc = *it;
 
 			if (EvalRenderCost(vc) < currentRenderCost)
+			{
 				++ smallerCost;
+				vol = (*it)->GetVolume();
+			}
 		}
 		// note: can remove already found view cells
@@ -572,8 +639,8 @@
 		outstream << "#RenderCost: " << currentRenderCost << endl;
 		outstream << "#ViewCells: " << smallerCost << endl;		
-	}
-
-}
-
+		outstream << "#Volume: " << vol << endl << endl;
+	}
+}
+*/
 
 void ViewCellsManager::EvalViewCellPartition(Preprocessor *preprocessor)
@@ -660,9 +727,26 @@
 	}
 	
-	string filename = "histogram.log";
-	int nViewCells = 5000;
-
-	EvalViewCellHistogram(filename, nViewCells);
-
+#if 0
+	// evaluate view cells in a histogram
+	vector<int> nViewCells;
+	nViewCells.push_back(10000);
+	nViewCells.push_back(5000);
+	nViewCells.push_back(1000);
+	nViewCells.push_back(500);
+	nViewCells.push_back(100);
+
+	vector<int>::const_iterator iit, iit_end = nViewCells.end();
+	char filename[64];
+
+	for (iit = nViewCells.begin(); iit != nViewCells.end(); ++ iit)
+	{
+		Debug << "here2" << endl;
+		int n = *iit;
+		
+		sprintf(filename, "histogram%06d.log", n);
+		EvalViewCellHistogram(filename, n);
+	}
+
+#endif
 	// find empty view cells bug
 	if (TEST_EMPTY_VIEW_CELLS)
@@ -687,9 +771,9 @@
 	int i = 0;
 
-	ViewCellContainer::const_iterator it, it_end = neighborhood.end();
-
-	for (it = neighborhood.begin(); it != it_end; ++ it, ++ i)
-	{
-		const float mc = EvalMergeCost(root, *it);
+	ViewCellContainer::const_iterator vit, vit_end = neighborhood.end();
+
+	for (vit = neighborhood.begin(); vit != vit_end; ++ vit, ++ i)
+	{
+		const float mc = EvalMergeCost(root, *vit);
 		
 		if (mc < mergeCost)
