Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1717)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1718)
@@ -2628,9 +2628,8 @@
 
 
-void
-ViewCellsManager::UpdatePvsForEvaluation()
-{
-  ObjectPvs objPvs;
-  UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), objPvs);
+void ViewCellsManager::UpdatePvsForEvaluation()
+{
+	ObjectPvs objPvs;
+	UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), objPvs);
 }
 
@@ -5725,85 +5724,4 @@
 
 #if 1
-#if TEST_EVALUATION
-void VspOspViewCellsManager::EvalViewCellPartition()
-{
-	const int castSamples = (int)storedRays.size();
-	char s[64]; 
-	char statsPrefix[100];
-
-	Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix);
-
-	Debug << "view cell stats prefix: " << statsPrefix << endl;
-
-	// should directional sampling be used?
-	const bool dirSamples = (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION);
-
-	cout << "reseting pvs ... ";
-	const bool startFromZero = true;
-
-	if (startFromZero)
-	{
-		// reset pvs and start over from zero
-		mViewCellsTree->ResetPvs();
-	}
-	else 
-	{
-		// statistics before casting more samples
-		cout << "compute new statistics ... ";
-		sprintf(s, "-%09d-eval.log", castSamples);
-		string fName = string(statsPrefix) + string(s);
-
-		mViewCellsTree->ExportStats(fName);
-		cout << "finished" << endl;
-	}
-	cout << "finished" << endl;
-
-    cout << "Evaluating view cell partition ... " << endl;
-
-	VssRayContainer evaluationSamples = storedRays;
-	const int samplingType = mEvaluationSamplingType;
-	
-	cout << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... ";
-	
-	ComputeSampleContributions(evaluationSamples, true, false);
-	
-	cout << "finished" << endl;
-	
-	cout << "compute new statistics ... ";
-	
-	// propagate pvs or pvs size information
-	ObjectPvs pvs;
-	UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs);
-
-
-	/////////////////////
-	// $§temporary matt: test render cost
-
-	sprintf(s, "-%09d-eval.log", castSamples);
-	string fileName = string(statsPrefix) + string(s);
-
-	ViewCellContainer leaves;
-
-	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
-	float rc = 0;
-
-	ViewCellContainer::const_iterator vit, vit_end = leaves.end();
-	
-	for (vit = leaves.begin(); vit != vit_end; ++ vit)
-	{
-		ViewCell *vc = *vit;
-		const float pvsCost = vc->GetPvs().EvalPvsCost();
-		const float vol = vc->GetVolume();
-		rc += pvsCost * vol;
-	}
-
-	Debug << "\nrendercost hack: " << rc / mViewSpaceBox.GetVolume() << endl;
-	mViewCellsTree->ExportStats(fileName);
-	cout << "finished" << endl;
-
-	disposeRays(evaluationSamples, NULL);
-}
-
-#else
 
 void VspOspViewCellsManager::EvalViewCellPartition()
@@ -5812,40 +5730,31 @@
 	int numSamples;
 	int castSamples = 0;
+	int oldSamples = 0;
+	int samplesForStats;
+	char statsPrefix[100];
+	char suffix[100];
 	int splitsStepSize;
 
-	char str[64]; 
-	
+
 	Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", samplesPerPass);
+	Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesForStats", samplesForStats);
 	Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samples", numSamples);
+	Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix);
 	Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.stepSize", splitsStepSize);
-
-	char statsPrefix[100];
-	Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix);
-
+	
+	Debug << "step size: " << splitsStepSize << endl;
 	Debug << "view cell evaluation samples per pass: " << samplesPerPass << endl;
 	Debug << "view cell evaluation samples: " << numSamples << endl;
 	Debug << "view cell stats prefix: " << statsPrefix << endl;
-	Debug << "step size: " << splitsStepSize << endl;
+
+	// should directional sampling be used?
+	bool dirSamples = 
+		(mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION);
 
 	cout << "reseting pvs ... ";
 		
-	const bool startFromZero = true;
-
 	// reset pvs and start over from zero
-	if (startFromZero)
-	{
-		mViewCellsTree->ResetPvs();
-	}
-	else // start from current sampless
-	{
-		// statistics before casting more samples
-		cout << "compute new statistics ... ";
-		sprintf(str, "-%09d-eval.log", castSamples);
-		string fName = string(statsPrefix) + string(str);
-
-		mViewCellsTree->ExportStats(fName);
-		cout << "finished" << endl;
-	}
-
+	mViewCellsTree->ResetPvs();
+	
 	cout << "finished" << endl;
     cout << "Evaluating view cell partition ... " << endl;
@@ -5853,10 +5762,8 @@
 	while (castSamples < numSamples)
 	{		
-		VssRayContainer evaluationSamples;
-
 		///////////////
 		//-- we have to use uniform sampling strategy for construction rays
 
-		//VssRayContainer evaluationSamples;
+		VssRayContainer evaluationSamples;
 		const int samplingType = mEvaluationSamplingType;
 
@@ -5871,8 +5778,9 @@
 
 		Real timeDiff = TimeDiff(startTime, GetTime());
-		Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl;
-		cout << "finished in " << timeDiff * 1e-3 << " secs" << endl;
-
+		
+		cout << "finished in " << timeDiff * 1e-3f << " secs" << endl;
 		cout << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... ";
+		
+		Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl;
 		Debug << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... ";
 
@@ -5885,24 +5793,46 @@
 		Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl;
 
-		startTime = GetTime();
-		cout << "compute new statistics ... " << endl;
-
-		///////////
-		//-- output stats
-
-		sprintf(str, "-%09d-eval.log", castSamples);
-		const string splitsFilename = string(statsPrefix) + string(str);
-
-		ofstream splitsStr(splitsFilename.c_str());
-		mHierarchyManager->EvaluateSubdivision2(splitsStr, splitsStepSize);
-
-		timeDiff = TimeDiff(startTime, GetTime());
-		cout << "finished in " << timeDiff * 1e-3 << " secs" << endl;
-		Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl;
-	
+		if ((castSamples >= samplesForStats + oldSamples) || (castSamples >= numSamples))
+		{
+			oldSamples += samplesForStats;
+
+			///////////
+			//-- output stats
+
+			sprintf(suffix, "-%09d-eval.log", castSamples);
+			const string filename = string(statsPrefix) + string(suffix);
+
+			startTime = GetTime();
+			cout << "compute new statistics ... " << endl;
+
+			ofstream ofstr(filename.c_str());
+			mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize);
+
+			timeDiff = TimeDiff(startTime, GetTime());
+			cout << "finished in " << timeDiff * 1e-3 << " secs" << endl;
+			Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl;
+
+			// only for debugging purpose
+			if (1)
+			{
+				ViewCellContainer viewCells;
+				mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), viewCells);
+
+				ViewCellContainer::const_iterator vit, vit_end = viewCells.end();
+				int pvsSize = 0;
+
+				for (vit = viewCells.begin(); vit != vit_end; ++ vit)
+				{
+					pvsSize += (*vit)->GetPvs().GetSize();
+				}
+
+				cout << "debug entries: " << pvsSize << ", memcost: " << (float)pvsSize * ObjectPvs::GetEntrySize() << endl;
+			}
+		}
+
 		disposeRays(evaluationSamples, NULL);
 	}
+	
 }
 #endif
-#endif
-}
+}
