Index: /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1841)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1842)
@@ -21,5 +21,5 @@
 				Optimization="0"
 				AdditionalIncludeDirectories="..\include;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;NO_QT"
 				MinimalRebuild="TRUE"
 				BasicRuntimeChecks="3"
@@ -35,5 +35,5 @@
 				Name="VCLinkerTool"
 				AdditionalDependencies="xerces-c_2D.lib zdll.lib zziplibd.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib glew32.lib"
-				OutputFile="$(OutDir)/Preprocessor.exe2"
+				OutputFile="$(OutDir)/Preprocessor.exe"
 				LinkIncremental="2"
 				AdditionalLibraryDirectories="..\include;..\src\GL;&quot;..\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib"
@@ -79,5 +79,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;NO_QT"
 				RuntimeLibrary="2"
 				RuntimeTypeInfo="TRUE"
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1841)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1842)
@@ -667,5 +667,5 @@
 	{
 		cout << "bvh local termination criteria met:" << endl;
-		cout << "objects: " << tData.mNode->mObjects.size() << " " << mTermMinObjects << endl;
+		cout << "objects: " << (int)tData.mNode->mObjects.size() << " " << mTermMinObjects << endl;
 	}
 #endif
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1841)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1842)
@@ -32,5 +32,5 @@
 
 // $$JB HACK
-#define USE_KD_PVS 1
+#define USE_KD_PVS 0
 
 #define KD_PVS_AREA (1e-5f)
@@ -4588,4 +4588,6 @@
 	{
 		int pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot());
+		
+		cout << "number of entries before compress: " << pvsEntries << endl;
 		Debug << "number of entries before compress: " << pvsEntries << endl;
 
@@ -4593,5 +4595,7 @@
 
 		pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot());
+		
 		Debug << "number of entries after compress: " << pvsEntries << endl;
+		cout << "number of entries after compress: " << pvsEntries << endl;
 	}
 
@@ -5432,5 +5436,5 @@
 	if (!ViewCellsConstructed())
 	{
-		Debug << "postprocess error: no view cells constructed" << endl;
+		Debug << "post process error: no view cells constructed" << endl;
 		return 0;
 	}
@@ -5502,4 +5506,6 @@
 	{
 		int pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot());
+		
+		cout << "number of entries before compress: " << pvsEntries << endl;
 		Debug << "number of entries before compress: " << pvsEntries << endl;
 
@@ -5507,5 +5513,7 @@
 
 		pvsEntries = mViewCellsTree->CountStoredPvsEntries(mViewCellsTree->GetRoot());
+		
 		Debug << "number of entries after compress: " << pvsEntries << endl;
+		cout << "number of entries after compress: " << pvsEntries << endl;
 	}
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1789)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1842)
@@ -1488,6 +1488,20 @@
 		}
 
+		/*cout << "***************\nbefore pulling up:\n";
+		for (it = interior->mChildren.begin(); it != it_end; ++ it)
+		{
+			cout << "vc:\n" << (*it)->GetPvs() << endl;
+		}*/
+
 		// compress root node
 		PullUpVisibility(interior);
+
+		/*cout << "after pulling up:\n";
+		cout << "interior:\n" << interior->GetPvs() << endl;
+
+		for (it = interior->mChildren.begin(); it != it_end; ++ it)
+		{
+			cout << "vc:\n" << (*it)->GetPvs() << endl;
+		}*/
 	}
 }
@@ -1650,9 +1664,10 @@
 void ViewCellsTree::PullUpVisibility(ViewCellInterior *interior)
 {
-	Intersectable::NewMail((int)interior->mChildren.size());
+	const int mail = (int)interior->mChildren.size();
+	Intersectable::NewMail(mail);
 
 	ViewCellContainer::const_iterator cit, cit_end = interior->mChildren.end();
 
-	// mail all objects in the leaf sets
+    // mail all objects in the leaf sets
 	// we are interested in the objects which are present in all leaves
 	// => count how often an object is part of a child set
@@ -1660,22 +1675,31 @@
 	{
 		ViewCell *vc = *cit;
-
 		ObjectPvsIterator pit = vc->GetPvs().GetIterator();
 
 		while (pit.HasMoreEntries())
 		{		
-			ObjectPvsEntry entry = pit.Next();
+			const ObjectPvsEntry &entry = pit.Next();
 			Intersectable *obj = entry.mObject;
-
-			if ((cit == interior->mChildren.begin()) && !obj->Mailed())
-			{
-				obj->Mail();
-			}
-
-			int incm = obj->IncMail();
-		}
-	}
-
-	interior->GetPvs().Clear();
+			obj->Mail();
+		}
+	}
+
+	for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit)
+	{
+		ViewCell *vc = *cit;
+
+		ObjectPvsIterator pit = vc->GetPvs().GetIterator();
+
+		while (pit.HasMoreEntries())
+		{		
+			const ObjectPvsEntry &entry = pit.Next();
+			Intersectable *obj = entry.mObject;
+
+			obj->IncMail();
+		}
+	}
+
+	// reset pvs
+    interior->GetPvs().Clear(false);
 		
 	// only the objects which are present in all leaf pvs 
@@ -1692,5 +1716,5 @@
 			ObjectPvsEntry entry = pit.Next();
 
-			if (entry.mObject->Mailed((int)interior->mChildren.size()))
+			if (entry.mObject->Mailed(mail))
 			{	
 				interior->GetPvs().AddSample(entry.mObject, entry.mData.mSumPdf);
@@ -1699,18 +1723,29 @@
 	}
 
-	// delete all the objects from the leaf sets which were moved to parent pvs
-	ObjectPvsIterator pit = interior->GetPvs().GetIterator();
-
-	while (pit.HasMoreEntries())
-	{		
-		ObjectPvsEntry entry = pit.Next();
-
-		for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit)
-		{
-			if (!(*cit)->GetPvs().RemoveSample(entry.mObject, Limits::Infinity))
+	// delete entries which are pulled up
+	// note: could be inefficent, rather gather unmailed pvs and reassign
+	for (cit = interior->mChildren.begin(); cit != cit_end; ++ cit)
+	{
+		ViewCell *vc = *cit;
+		ObjectPvsIterator pit = vc->GetPvs().GetIterator();
+
+		ObjectPvs newPvs;
+
+		while (pit.HasMoreEntries())
+		{		
+			const ObjectPvsEntry &entry = pit.Next();
+			Intersectable *obj = entry.mObject;
+
+			/*if (obj->Mailed(mail))
 			{
-				Debug << "should not come here!" << endl;
+				vc->GetPvs().RemoveSample(entry.mObject, Limits::Infinity))
+			}*/
+			if (!obj->Mailed(mail))
+			{
+				newPvs.AddSampleDirty(obj, entry.mData.mSumPdf);
 			}
 		}
+
+		vc->SetPvs(newPvs);
 	}
 }
@@ -2465,4 +2500,5 @@
 
 
+
 /**************************************************************************/
 /*                     MergeCandidate implementation                      */
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1790)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1842)
@@ -868,4 +868,13 @@
 
 
+////////////
+//-- typedefs
+
+typedef PvsEntry<Intersectable *, PvsData> ObjectPvsEntry;
+typedef std::vector<ObjectPvsEntry> ObjectPvsEntries;
+typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs;
+typedef PvsIterator<Intersectable *, PvsData> ObjectPvsIterator;
+
+
 class ObjectPvs: public Pvs<Intersectable *, PvsData>
 {
@@ -876,14 +885,24 @@
 	*/
 	float EvalPvsCost() const;
+
+	friend ostream &operator<<(ostream &s, const ObjectPvs &p) 
+	{
+		ObjectPvsIterator pit = p.GetIterator();
+
+		while (pit.HasMoreEntries())
+		{		
+			const ObjectPvsEntry &entry = pit.Next();
+			Intersectable *obj = entry.mObject;
+
+			cout << (int)obj << " ";
+		}
+		
+		return s;
+	}
+
 };
 
 
-////////////
-//-- typedefs
-
-typedef PvsEntry<Intersectable *, PvsData> ObjectPvsEntry;
-typedef std::vector<ObjectPvsEntry> ObjectPvsEntries;
-typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs;
-typedef PvsIterator<Intersectable *, PvsData> ObjectPvsIterator;
+
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 1771)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 1842)
@@ -228,7 +228,4 @@
 	*/
 	bool AddPvsSample(Intersectable *sample, const float pdf, float &contribution);
-  
-	/// Rays piercing this view cell.
-	//RayContainer mPiercingRays;
 
 	/** if this is a view cell correspending to a leaf in a hierarchy.
@@ -705,4 +702,5 @@
 					 const ViewCellsTreeStats &vcStats);
 
+	
 
 	//////////////////////////////////////
@@ -721,5 +719,5 @@
 	/// if merged view cells are refined.
 	bool mRefineViewCells;
-	/// weights between variance and render cost increase (must be between zero and one)
+	/// weights between variance and render cost increase in the range [0 .. 1].
 	float mRenderCostWeight;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h	(revision 1500)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Plane3.h	(revision 1842)
@@ -69,5 +69,5 @@
   friend SimpleRay GetPlaneIntersection(const Plane3 &plane1, const Plane3 &plane2);
 
-  friend ostream &operator<<(ostream &s, const Plane3 p) {
+  friend ostream &operator<<(ostream &s, const Plane3 &p) {
     s<<p.mNormal<<" "<<p.mD;
     return s;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1841)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1842)
@@ -37,9 +37,9 @@
 #include "GlRenderer.h"
 
-//#if USE_QT
+#ifndef NO_QT
 #include "QtPreprocessorThread.h"
 #include "QtGlRenderer.h"
 #include "QtGlViewer.h"
-//#endif
+#endif
 
 #define USE_EXE_PATH false
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1830)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1842)
@@ -1780,5 +1780,7 @@
 
 
-void HierarchyManager::ComputePvs(const ObjectPvs &pvs, float &rc, int &pvsEntries)
+void HierarchyManager::ComputePvs(const ObjectPvs &pvs, 
+								  float &rc, 
+								  int &pvsEntries)
 {
 	BvhNode::NewMail();
@@ -1788,13 +1790,17 @@
 	while (pit.HasMoreEntries())
 	{
-		ObjectPvsEntry entry = pit.Next();
-
+		const ObjectPvsEntry &entry = pit.Next();
+
+		if (entry.mObject->Type() != Intersectable::BVH_INTERSECTABLE)
+			cout << "error " << entry.mObject->Type() << endl;
+
+		BvhNode *intersect = dynamic_cast<BvhNode *>(entry.mObject);
 		BvhNode *activeNode;
-		BvhNode *intersect = dynamic_cast<BvhNode *>(entry.mObject);
 
 		// hack for choosing which node to account for
 		if (intersect->IsLeaf())
 		{
-			activeNode = dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode();
+			activeNode = 
+				dynamic_cast<BvhLeaf *>(intersect)->GetActiveNode();
 		}
 		else
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h	(revision 1613)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.h	(revision 1842)
@@ -2,5 +2,5 @@
 #define __QT_PREPROCESSOR_THREAD_H
 
-
+#ifndef NO_QT
 #include <QThread>
 #include "PreprocessorThread.h"
@@ -29,4 +29,4 @@
 
 }
-
 #endif
+#endif
