Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1719)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1723)
@@ -79,4 +79,21 @@
 
 
+void HierarchySubdivisionStats::Print(ostream &app) const
+{
+	app << "#Pass\n" << 0 << endl
+		<< "#Splits\n" << mNumSplits << endl 
+		<< "#TotalRenderCost\n" << mTotalRenderCost << endl
+		<< "#TotalEntriesInPvs\n" << mEntriesInPvs << endl
+		<< "#Memory\n" << mMemoryCost << endl
+		<< "#StepsView\n" << mViewSpaceSplits << endl
+		<< "#StepsObject\n" << mObjectSpaceSplits << endl
+		<< "#VspOspRatio\n" << VspOspRatio() << endl
+		<< "#FullMem\n" << mFullMemory << endl
+		<< "#RenderCostDecrease\n" << mRenderCostDecrease << endl
+		<< "#FpsPerMb\n" << FpsPerMb() << endl
+		<< endl;
+}
+
+
 void HierarchyManager::ParseEnvironment()
 {
@@ -265,20 +282,18 @@
 {
 	// question: should I also add the mem usage of the hierarchies?
-	const float objectSpaceMem = 0;//GetObjectSpaceMemUsage();
-	const float viewSpaceMem = 0;//mVspTree->GetMemUsage();
-	
-	// calculate cost in MB
-	const float memoryCost = mHierarchyStats.mMemory  / float(1024 * 1024)
-							 + objectSpaceMem + viewSpaceMem;
-
-	//cout << "pvs entries " << mHierarchyStats.pvsEntries << endl;
-	AddSubdivisionStats(mHierarchyStats.Leaves(),
-						mHierarchyStats.mRenderCostDecrease,
-						mHierarchyStats.mTotalCost,
-						mHierarchyStats.mPvsEntries,
-						memoryCost,
-						1.0f / (mHierarchyStats.mTotalCost * memoryCost),
-						(float)mVspTree->mVspStats.Leaves() / (float)GetObjectSpaceSubdivisionLeaves()
-						);
+	const float objectSpaceMem = GetObjectSpaceMemUsage();
+	const float viewSpaceMem = mVspTree->GetMemUsage();
+		
+	HierarchySubdivisionStats stats;
+	stats.mNumSplits = mHierarchyStats.Leaves();
+	stats.mTotalRenderCost = mHierarchyStats.mTotalCost;
+	stats.mEntriesInPvs = mHierarchyStats.mPvsEntries;
+	stats.mMemoryCost = mHierarchyStats.mMemory  / float(1024 * 1024);
+	stats.mFullMemory = mHierarchyStats.mMemory  / float(1024 * 1024)
+						+ objectSpaceMem + viewSpaceMem;
+	stats.mViewSpaceSplits = mVspTree->mVspStats.Leaves();
+	stats.mObjectSpaceSplits = GetObjectSpaceSubdivisionLeaves();
+	
+	stats.Print(mSubdivisionStats);
 }
 
@@ -299,5 +314,6 @@
 			<< "#Memory\n" << memory << endl
 			<< "#FpsPerMb\n" << renderCostPerStorage << endl
-			<< "#VspOspRatio\n" << vspOspRatio << endl;
+			<< "#VspOspRatio\n" << vspOspRatio << endl
+			<< endl;
 }
 
@@ -882,5 +898,6 @@
 
 			cout << "\nstarting object space subdivision after " 
-				 << mVspTree->mVspStats.nodes << " (" << mMinStepsOfSameType << ") " << endl;
+				 << mVspTree->mVspStats.nodes << " (" << mMinStepsOfSameType << ") steps, mem=" 
+				 << mHierarchyStats.mMemory / float(1024 * 1024) << " MB" << endl;
 
 			SubdivisionCandidate *ospSc = PrepareObjectSpaceSubdivision(sampleRays, objects);
@@ -897,7 +914,8 @@
 			mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType;
 
-			cout << "\nstarting view space subdivision at depth " 
+			cout << "\nstarting view space subdivision at " 
 				 << GetObjectSpaceSubdivisionLeaves() << " (" 
-				 << mMinStepsOfSameType << ") " << endl;
+				 << mMinStepsOfSameType << ") , mem=" 
+				 << mHierarchyStats.mMemory / float(1024 * 1024) << " MB" << endl;
 
 			SubdivisionCandidate *vspSc = PrepareViewSpaceSubdivision(sampleRays, objects);
@@ -1602,24 +1620,4 @@
 
 
-static void UpdateStats(ofstream &stats,
-						const int splits,
-						const float totalRenderCost,
-						const int entriesInPvs,
-						const float memoryCost,
-						const int viewSpaceSplits,
-						const int objectSpaceSplits)
-{
-	stats << "#Pass\n" << 0 << endl
-		   << "#Splits\n" << splits << endl 
-		   << "#TotalRenderCost\n" << totalRenderCost << endl
-		   << "#TotalEntriesInPvs\n" << entriesInPvs << endl
-		   << "#Memory\n" << memoryCost << endl
-		   << "#ViewSpaceSplits\n" << viewSpaceSplits << endl
-		   << "#ObjectSpaceSplits\n" << objectSpaceSplits << endl
-		   << "#VspOspRatio\n" << (float)viewSpaceSplits / (float)objectSpaceSplits << endl
-		   << endl;
-}
-
-
 class HierarchyNodeWrapper;
 
@@ -1863,17 +1861,21 @@
 								   const ObjectContainer &objects)
 {
-	float totalRenderCost = (float)objects.size();
-	int entriesInPvs = 1;
-	int steps = 0;
-	int viewSpaceSplits = 0;
-	int objectSpaceSplits = 0;
+	HierarchySubdivisionStats subStats;
+	subStats.Reset();
+
+	/////////////
+	//-- initial situation
+
+	subStats.mNumSplits = 0;
+	subStats.mTotalRenderCost = (float)objects.size();
+	subStats.mEntriesInPvs = 1;
+	subStats.mMemoryCost = (float)ObjectPvs::GetEntrySize();
+	subStats.mFullMemory = subStats.mMemoryCost;
+	subStats.mViewSpaceSplits = 0;
+	subStats.mObjectSpaceSplits = 0;
+	
+	subStats.Print(stats);
 
 	cout << "exporting vsposp stats ... " << endl;
-	const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize();
-
-	/////////////
-	//-- first view cell
-
-	UpdateStats(stats, 2, totalRenderCost, entriesInPvs, memoryCost, viewSpaceSplits, objectSpaceSplits);
 
 	//-- go through tree in the order of render cost decrease
@@ -1898,5 +1900,5 @@
 			
 			isLeaf = newNode->IsLeaf();
-			rcDecr = oldNode->mRenderCostDecr;
+			subStats.mRenderCostDecrease = oldNode->mRenderCostDecr;
 			entriesIncr = oldNode->mPvsEntriesIncr;
 		}
@@ -1909,5 +1911,5 @@
 			
 			isLeaf = newNode->IsLeaf();
-			rcDecr = oldNode->mRenderCostDecr;
+			subStats.mRenderCostDecrease = oldNode->mRenderCostDecr;
 			entriesIncr = oldNode->mPvsEntriesIncr;
 		}		
@@ -1915,25 +1917,29 @@
 		if (!isLeaf)
 		{
-			totalRenderCost -= rcDecr;
-			entriesInPvs += entriesIncr;
+			subStats.mTotalRenderCost -= subStats.mRenderCostDecrease;
+			subStats.mEntriesInPvs += entriesIncr;
+
 			// if (rcDecr <= 0)
 			if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE)
 			{
-				++ viewSpaceSplits;
+				++ subStats.mViewSpaceSplits;
 				cout << "v";//cout << "vsp t: " << timeStamp << " rc: " << rcDecr << " pvs: " << entriesIncr << endl;
 			}
 			else
 			{
-				++ objectSpaceSplits;
+				++ subStats.mObjectSpaceSplits;
 				cout << "o";//"osp t: " << timeStamp << " rc: " << rcDecr << " pvs: " << entriesIncr << endl;
 			}
 
-			++ steps;
-
-			if ((steps % 500) == 499)
-				cout << steps << " steps taken" << endl;
-
-			const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize();
-			UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, viewSpaceSplits, objectSpaceSplits);
+			++ subStats.mNumSplits;
+
+			if ((subStats.mNumSplits % 500) == 499)
+				cout << subStats.mNumSplits << " steps taken" << endl;
+
+			subStats.mMemoryCost = (float)subStats.mEntriesInPvs * (float)ObjectPvs::GetEntrySize();
+			subStats.mFullMemory = subStats.mMemoryCost;
+
+			subStats.Print(stats);
+			
 		}
 
@@ -2023,33 +2029,39 @@
 											const int splitsStepSize)
 {
+	HierarchySubdivisionStats subStats;
+	
 	int splits = 0;
 
-	float renderCost;
-	float memory;
-	int pvsEntries;
-	int viewSpaceSplits;
-	int objectSpaceSplits;
-
 	while (1)
 	{
-		const int numSplits = ExtractStatistics(splits, 
+		subStats.mNumSplits = ExtractStatistics(splits, 
 												99999.0, 
-												renderCost, 
-												memory, 
-												pvsEntries,
-												viewSpaceSplits,
-												objectSpaceSplits);
+												subStats.mTotalRenderCost, 
+												subStats.mMemoryCost, 
+												subStats.mEntriesInPvs,
+												subStats.mViewSpaceSplits,
+												subStats.mObjectSpaceSplits);
+
 		
-		UpdateStats(splitsStats, 
-					numSplits, 
-					renderCost, 
-					pvsEntries, 
-					memory, 
-					viewSpaceSplits, 
-					objectSpaceSplits);
+		const float objectSpaceHierarchyMem = float(
+											  subStats.mObjectSpaceSplits * sizeof(BvhLeaf *) + 
+											  (subStats.mObjectSpaceSplits - 1) * sizeof(BvhInterior *) + 
+											  sizeof(BvHierarchy)
+											  ) / float(1024 * 1024);
+
+			
+		const float viewSpaceHierarchyMem = float(
+											subStats.mViewSpaceSplits * sizeof(VspLeaf *) + 
+											(subStats.mViewSpaceSplits - 1) * sizeof(VspInterior *) + 
+											sizeof(VspTree)
+											)  / float(1024 * 1024);
+
+		subStats.mFullMemory = subStats.mMemoryCost + objectSpaceHierarchyMem + viewSpaceHierarchyMem;
+		
+		subStats.Print(splitsStats);
 
 		splits += splitsStepSize;
 
-		if (numSplits == mHierarchyStats.Leaves())
+		if (subStats.mNumSplits == mHierarchyStats.Leaves())
 			break;
 	}
