Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility_internal.sh
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility_internal.sh	(revision 2544)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility_internal.sh	(revision 2559)
@@ -14,11 +14,11 @@
 
 #NUM_SAMPLE_RAYS=200000000
-NUM_SAMPLE_RAYS=30000000
-#NUM_SAMPLE_RAYS=10000
+#NUM_SAMPLE_RAYS=30000000
+NUM_SAMPLE_RAYS=5000000
 
 $PREPROCESSOR -total_samples=$NUM_SAMPLE_RAYS \
 -scene_filename=$1 -view_cells_filename=$2 -preprocessor_visibility_file=$3 \
 -preprocessor_ray_cast_method=1 \
--samples_per_pass=1000000 \
+-samples_per_pass=500000 \
 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \
 -mutation_silhouette_prob=0.5 \
Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility.env
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility.env	(revision 2211)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/preprocess_visibility.env	(revision 2559)
@@ -63,6 +63,7 @@
 RssPreprocessor {
 
-	distributions mutation+spatial+object_direction
-#	distributions rss+object_direction
+#	distributions mutation+spatial+object_direction
+#	distributions mutation+spatial+object_direction+difference
+	distributions difference+object_direction+spatial
 #	distributions object_direction
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/mypreprocess_visibility.sh
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/mypreprocess_visibility.sh	(revision 2544)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/mypreprocess_visibility.sh	(revision 2559)
@@ -1,3 +1,3 @@
 #!/bin/sh
 
-./preprocess_visibility_internal.sh ../data/vienna/vienna_cropped.obj ../data/vienna/vienna_cropped-seq-3000-false-20-viewcells.xml.gz vienna-visibility2.bn
+./preprocess_visibility_internal.sh ../data/vienna/vienna_cropped.obj ../data/vienna/vienna_cropped-seq-3000-false-20-viewcells.xml.gz vienna-visibility3.bn
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2543)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2559)
@@ -164,5 +164,5 @@
 				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;;.\QtInterface\Release;&quot;$(CG_LIB_PATH)&quot;"
-				GenerateDebugInformation="TRUE"
+				GenerateDebugInformation="FALSE"
 				SubSystem="1"
 				LargeAddressAware="2"
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2543)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2559)
@@ -78,5 +78,6 @@
 
 	// pool of vss rays to be used in one pass of the sampling
-	struct VssRayPool {
+	struct VssRayPool 
+	{
 		VssRayPool(): mRays(NULL), mIndex(0), mNumber(0) 
 		{}
@@ -87,5 +88,6 @@
 		}
 
-		void Reserve(const int number) {
+		void Reserve(const int number) 
+		{
 			DEL_PTR(mRays);
 			mRays = new VssRay[number];
@@ -93,8 +95,11 @@
 		}
 
-		void Clear() {
+		void Clear() 
+		{
 			mIndex = 0;
 		}
-		VssRay *Alloc() {
+		
+		VssRay *Alloc() 
+		{
 			// reset pool
 			if (mIndex == mNumber)
@@ -110,9 +115,11 @@
 	VssRayPool mVssRayPool;
 
-	void ReserveVssRayPool(const int n) {
+	void ReserveVssRayPool(const int n) 
+	{
 		mVssRayPool.Reserve(n);
 	}
 
-	void InitPass() {
+	void InitPass() 
+	{
 		mVssRayPool.Clear();
 	}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2544)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2559)
@@ -1129,5 +1129,5 @@
 	}
 	
-	/////
+	/////////////////
 	//-- reserve constant block of rays
 	
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp	(revision 2548)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp	(revision 2559)
@@ -5,4 +5,5 @@
 #include "ViewCellsManager.h"
 #include "Preprocessor.h"
+#include "Timer/PerfTimer.h"
 
 
@@ -10,4 +11,6 @@
 #include "ArchModeler2MLRT.hxx"
 #endif
+
+PerfTimer sFilterTimer;
 
 
@@ -60,9 +63,13 @@
 	ObjectPvs filteredPvs;
 
-    PvsFilterStatistics pvsStats = mPreprocessor.
+	sFilterTimer.Entry();
+    
+	PvsFilterStatistics pvsStats = mPreprocessor.
 		mViewCellsManager->ApplyFilter2(vc, 
 		                                false, 
 										filterSize, 
 										filteredPvs);
+
+	sFilterTimer.Exit();
 
 	//mDifferencePvs.Clear(false);
@@ -72,4 +79,6 @@
 
 	GetPvsDifference(filteredPvs, pvs, mPvsDifference);
+
+	cerr << "found " << mPvsDifference.size() << " different objects" << endl;
 }
 
@@ -77,10 +86,16 @@
 bool DifferenceSampling::GenerateSample(SimpleRay &ray)
 {
-	if (mNumSamples -- <= 0)
+	if (mNumSamples <= 0)
 	{
+		// choose random view cell
 		ViewCellContainer &viewCells = mPreprocessor.mViewCellsManager->GetViewCells();
 		const int vcIdx = (int)RandomValue(0, (float)viewCells.size() - 0.5f);
 
 		mCurrentViewCell = viewCells[vcIdx];
+
+		if (mCurrentViewCell->GetPvs().Empty())
+			return false;
+
+		cout << "computing new  difference set" << endl;
 
 		ComputeDifferenceSet(mCurrentViewCell, mPvsDifference);
@@ -91,4 +106,10 @@
 	}
 
+	if (mPvsDifference.empty())
+		return false;
+
+	-- mNumSamples;
+
+	cout << "x";
 	Vector3 origin, direction; 
 	Vector3 point;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h	(revision 2542)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h	(revision 2559)
@@ -61,16 +61,21 @@
 	T Erase(T);
 
+	void Reserve(const size_t n);
+
 protected:
 
-	void Place(T x, const unsigned int i);
-	void Swap(const unsigned int i, const unsigned int j);
-
-	unsigned int Parent(const unsigned int i) const { return (i - 1) / 2; }
-	unsigned int Left(const unsigned int i) const { return 2 * i + 1; }
-	unsigned int Right(const unsigned int i) const { return 2 * i + 2; }
+	inline void Place(T x, const unsigned int i);
+	inline void Swap(const unsigned int i, const unsigned int j);
+
+	inline unsigned int Parent(const unsigned int i) const { return (i - 1) / 2; }
+	inline unsigned int Left(const unsigned int i) const { return 2 * i + 1; }
+	inline unsigned int Right(const unsigned int i) const { return 2 * i + 2; }
 
 	void UpHeap(const unsigned int i);
 	void DownHeap(const unsigned int i);
 
+
+	///////
+	
 	std::vector<T> mBuffer;
 };
@@ -104,4 +109,9 @@
 }
 
+template <typename T>
+void FlexibleHeap<T>::Reserve(const size_t n) 
+{ 
+	mBuffer.reserve(n); 
+}
 
 template <typename T>
@@ -273,8 +283,11 @@
 	t->NotInHeap();
 
+	if (i < (int)mBuffer.size())
+	{
 	if (mBuffer[i]->GetPriority() < t->GetPriority())
 		DownHeap(i);
 	else
 		UpHeap(i);
+	}
 
 	return t;
