Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1740)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1745)
@@ -206,5 +206,5 @@
 				Name="VCLinkerTool"
 				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib QtCore4.lib qtmain.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtGlRenderer.lib"
-				OutputFile="../bin/release/Preprocessor.exe"
+				OutputFile="../bin/release/Preprocessor2.exe"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;&quot;$(QTDIR)\lib&quot;;.\QtGlRenderer\Release"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1745)
@@ -288,5 +288,4 @@
 
 	inline bool ConsiderMemory() const { return mConsiderMemory; }
-	//inline float GetMemoryConst() const { return mMemoryConst; }
 	
 	void EvaluateSubdivision(const VssRayContainer &sampleRays,											 
@@ -295,5 +294,6 @@
 
 	void EvaluateSubdivision2(ofstream &splitsStats,
-							  const int splitsStepSize);
+							  const int splitsStepSize,
+							  const bool useFilter);
 
 
@@ -523,6 +523,8 @@
 						  int &pvsEntries,
 						  int &viewSpaceSplits,
-						  int &objectSpaceSplits);
-
+						  int &objectSpaceSplits,
+						  const bool useFilter);
+
+	void ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries);
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1745)
@@ -6055,5 +6055,5 @@
 
 			ofstream ofstr(filename.c_str());
-			mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize);
+			mHierarchyManager->EvaluateSubdivision2(ofstr, splitsStepSize, false);
 
 			timeDiff = TimeDiff(startTime, GetTime());
@@ -6062,4 +6062,24 @@
 
 			Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl;
+
+#if 0
+			////////////////////////////
+			// filtered stats
+			sprintf(suffix, "-%09d-eval-filter.log", castSamples);
+			const string filename2 = string(statsPrefix) + string(suffix);
+
+			startTime = GetTime();
+			
+			cout << "compute new statistics for filtered pvs ... " << endl;
+
+			ofstream ofstr2(filename2.c_str());
+			mHierarchyManager->EvaluateSubdivision2(ofstr2, splitsStepSize, true);
+
+			timeDiff = TimeDiff(startTime, GetTime());
+			cout << "finished in " << timeDiff * 1e-3 << " secs" << endl;
+			cout << "*************************************" << endl;
+
+			Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl;
+#endif
 
 			// only for debugging purpose
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1742)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1745)
@@ -1748,7 +1748,7 @@
 	
 		// add newly found pvs to merged pvs
-		ObjectPvs interPvs;
+		//cout << "samples vc: " << vc->GetPvs().GetSamples() << " samples pvs: " << pvs.GetSamples() << endl;
 		pvs.MergeInPlace(vc->GetPvs());
-
+		//cout << "new samples: " << pvs.GetSamples() << endl;
 		if (!vc->IsLeaf()) // interior cells: go down to leaf level
 		{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1745)
@@ -441,27 +441,4 @@
 
 
-/*template <typename T, typename S> void Pvs<T, S>::QuickMerge(const Pvs<T, S> &a)
-{
-	const int samples = mSamples + a.mSamples;
-
-	std::vector<PvsEntry<T, S>> >::const_iterator it;
-
-	for (it = mEntries.begin(); it != mEntries.end(); ++ it)
-	{
-		it->first->Mail();
-	}
-
-    for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it)
-	{
-		if (!it->first->Mailed())
-		{
-			mEntries.push_back(*it);
-		}
-	}
-
-	mSamples = samples;
-}*/
-
-
 template <typename T, typename S> void Pvs<T, S>::Clear()
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1744)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1745)
@@ -737,9 +737,8 @@
 
 	if (sc->IsDirty())
-		cout << "*******************************error!" << endl;
+		cerr << "Error: Should never come here!" << endl;
 
 	if (!success) // split was not taken
 	{
-		cout << "x";
 		return false;
 	}
@@ -988,6 +987,5 @@
 		if ((steps >= maxSteps) || ((priority < threshold) && !(steps < minSteps)))
 		{
-			cout << "\n**************** breaking on " << priority 
-				 << " smaller than " << threshold << endl;
+			cout << "\nbreaking on " << priority << " smaller than " << threshold << endl;
 			break;
 		}
@@ -1831,4 +1829,34 @@
 
 
+void HierarchyManager::ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries)
+{
+	BvhNode::NewMail();
+
+	ObjectPvsIterator pit = pvs.GetIterator();
+
+	while (pit.HasMoreEntries())
+	{
+		ObjectPvsEntry entry = pit.Next();
+
+		BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>(entry.mObject);
+
+		BvhLeaf *leaf = intersect->GetItem();
+		BvhNode *activeNode = leaf->GetActiveNode();
+
+		if (!activeNode->Mailed())
+		{
+			activeNode->Mail();
+
+			ObjectContainer objects;
+			activeNode->CollectObjects(objects);
+
+			++ pvsEntries;
+			rc += mBvHierarchy->EvalAbsCost(objects);
+			//cout << " pvs: " << mBvHierarchy->EvalAbsCost(leaf->mObjects);
+		}
+	}
+}
+
+
 int HierarchyManager::ExtractStatistics(const int maxSplits,
 										const float maxMemoryCost,
@@ -1837,5 +1865,6 @@
 										int &pvsEntries,
 										int &viewSpaceSplits,
-										int &objectSpaceSplits)
+										int &objectSpaceSplits,
+										const bool useFilter)
 {
 	ViewCellContainer viewCells;
@@ -1858,39 +1887,22 @@
 	renderCost = 0.0f;
 
-	//BvhNode::NewMail();
-	//int dummy = 0;
 	for (vit = viewCells.begin(); vit != vit_end; ++ vit)
 	{
 		float rc = 0;
 		ViewCell *vc = *vit;
+
 		ObjectPvs pvs;
 		mVspTree->mViewCellsTree->GetPvs(vc, pvs);
-		//dummy+=pvs.GetSize();
-		BvhNode::NewMail();
-
-		// hack: should not be done here
-		ObjectPvsIterator pit = pvs.GetIterator();
-
-		while (pit.HasMoreEntries())
-		{
-			ObjectPvsEntry entry = pit.Next();
-
-			BvhIntersectable *intersect = dynamic_cast<BvhIntersectable *>(entry.mObject);
-
-			BvhLeaf *leaf = intersect->GetItem();
-			BvhNode *activeNode = leaf->GetActiveNode();
-
-			if (!activeNode->Mailed())
-			{
-				activeNode->Mail();
-
-				ObjectContainer objects;
-				activeNode->CollectObjects(objects);
-
-				++ pvsEntries;
-				rc += mBvHierarchy->EvalAbsCost(objects);
-				//cout << " pvs: " << mBvHierarchy->EvalAbsCost(leaf->mObjects);
-			}
-		}
+
+		if (useFilter)
+		{
+			ObjectPvs filteredPvs;
+			mVspTree->mViewCellsManager->ApplyFilter2(vc, false, 1.0f, filteredPvs);
+			ComputePvs(filteredPvs, rc, pvsEntries);
+		}
+		else
+		{
+			ComputePvs(pvs, rc, pvsEntries);
+		}		
 
 		rc *= vc->GetVolume();
@@ -2082,5 +2094,6 @@
 
 void HierarchyManager::EvaluateSubdivision2(ofstream &splitsStats,
-											const int splitsStepSize)
+											const int splitsStepSize,
+											const bool useFilter)
 {
 	HierarchySubdivisionStats subStats;
@@ -2096,5 +2109,6 @@
 												subStats.mEntriesInPvs,
 												subStats.mViewSpaceSplits,
-												subStats.mObjectSpaceSplits);
+												subStats.mObjectSpaceSplits,
+												useFilter);
 
 		
@@ -2123,4 +2137,5 @@
 		cout << subStats.mNumSplits << " ";
 	}
+
 	cout << endl;
 }
