Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 735)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 736)
@@ -552,4 +552,6 @@
 	maxRenderCost = viewCells.back()->GetRenderCost();
 
+	Debug << "histogram minrc: " << minRenderCost << " maxrc: " << maxRenderCost << endl;
+
 	const int intervals = min(10000, (int)viewCells.size());
 
@@ -561,10 +563,10 @@
 	const float totalRenderCost = mViewCellsTree->GetRoot()->GetRenderCost();
 	const float totalVol = GetViewSpaceBox().GetVolume();
-
-	float vol = 0;
-	int smallerCost = 0;
+	//const float totalVol = mViewCellsTree->GetRoot()->GetVolume();
+
+	//float vol = 0;
+	//int smallerCost = 0;
+	int j = 0;
 	int i = 0;
-	int j = 0;
-
 	
 	ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();		
@@ -574,4 +576,7 @@
     while (1)
 	{
+		float vol = 0;
+		int smallerCost = 0;
+
 		while ((i < (int)viewCells.size()) && (viewCells[i]->GetRenderCost() < currentRenderCost))
 		{
@@ -580,19 +585,23 @@
 			++ smallerCost;
 		}
-
-		if ((i >= (int)viewCells.size()) || (currentRenderCost >= maxRenderCost))
+		
+		if (i < (int)viewCells.size())
+			Debug << "new rc increase: " << viewCells[i]->GetRenderCost() / totalVol << " " << currentRenderCost / totalVol << endl;
+
+		if ((smallerCost >= (int)viewCells.size()) || (currentRenderCost >= maxRenderCost))
 			break;
-
+		
 		float rcRatio = currentRenderCost / maxRenderCost;
 		float volRatio = vol / totalVol;
 
-		outstream << "#Pass\n" << j ++ << endl;
-		outstream << "#RenderCost\n" << rcRatio << endl;
-		//fprintf(outstream, "#RenderCost\n%3.3f", rcRatio);
-		outstream << "#ViewCells\n" << i << endl;		
+		outstream << "#Pass\n" << j << endl;
+		outstream << "#RenderCostRatio\n" << rcRatio << endl;
+		outstream << "#WeightedCost\n" << currentRenderCost / totalVol << endl;
+		outstream << "#ViewCells\n" << smallerCost << endl;		
 		outstream << "#Volume\n" << volRatio << endl << endl;
 
 		// increase current render cost
 		currentRenderCost += stepSize;
+		++ j;
 	}
 
@@ -617,4 +626,6 @@
 	minPvsSize = viewCells.front()->GetPvs().GetSize();
 	maxPvsSize = viewCells.back()->GetPvs().GetSize();
+	
+	Debug << "histogram minpvssize: " << minPvsSize << " maxpvssize: " << maxPvsSize << endl;
 
 	const int intervals = min(10000, (int)viewCells.size());
@@ -629,22 +640,24 @@
 	int currentPvsSize = minPvsSize;//(int)ceil(minRenderCost);
 
-	float vol = 0;
-	int smallerCost = 0;
-
+	//float vol = 0;
 	int i = 0;
 	int j = 0;
 
-	
 	ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();		
 	
-	// note can skip computations for view cells already evaluated and delete them from vector ...
-    while (1)
-	{
+	while (1)
+	{
+		float vol = 0;
+		int smaller = 0;
+
 		while ((i < (int)viewCells.size()) && (viewCells[i]->GetPvs().GetSize() < currentPvsSize))
 		{
 			vol += viewCells[i]->GetVolume();
 			++ i;
-			++ smallerCost;
-		}
+			++ smaller;
+		}
+		
+		if (i < (int)viewCells.size())
+			Debug << "new pvs size increase: " << viewCells[i]->GetPvs().GetSize() << " " << currentPvsSize << endl;
 
 		if ((i >= (int)viewCells.size()) || (currentPvsSize >= maxPvsSize))
@@ -655,6 +668,5 @@
 		outstream << "#Pass\n" << j ++ << endl;
 		outstream << "#Pvs\n" << currentPvsSize << endl;
-		//fprintf(outstream, "#RenderCost\n%3.3f", rcRatio);
-		outstream << "#ViewCells\n" << i << endl;		
+		outstream << "#ViewCells\n" << smaller << endl;		
 		outstream << "#Volume\n" << volRatio << endl << endl;
 
@@ -756,4 +768,9 @@
 	environment->GetIntValue("ViewCells.Evaluation.histoPasses", histoPasses);
 
+	int numLeaves = mViewCellsTree->GetNumInitialViewCells(mViewCellsTree->GetRoot());
+
+	Debug << "number of leaves: " << numLeaves << endl;
+	cout << "number of leaves: " << numLeaves << endl;
+
 	if (useHisto)
 	{
@@ -763,5 +780,5 @@
 		for (int passes = 1; passes <= histoPasses; ++ passes)
 		{
-			int n = (int)mViewCells.size() * passes / histoPasses;
+			int n = numLeaves * passes / histoPasses;
 		
 			cout << "computing histogram for " << n << " view cells" << endl;
@@ -2292,5 +2309,5 @@
 	case 2: // merges
 		{
-            int lSize = mViewCellsTree->GetSize(vc);
+            int lSize = mViewCellsTree->GetNumInitialViewCells(vc);
 			importance = (float)lSize / (float)mCurrentViewCellsStats.maxLeaves;
 		}
@@ -3218,5 +3235,5 @@
 	case 2: // merged leaves
 		{
-        	int lSize = mViewCellsTree->GetSize(vc);
+        	int lSize = mViewCellsTree->GetNumInitialViewCells(vc);
 			importance = (float)lSize /
 				(float)mCurrentViewCellsStats.maxLeaves;
@@ -4146,5 +4163,5 @@
 	case 2: // merges
 		{
-            int lSize = mViewCellsTree->GetSize(vc);
+            int lSize = mViewCellsTree->GetNumInitialViewCells(vc);
 			importance = (float)lSize / (float)mCurrentViewCellsStats.maxLeaves;
 		}
