Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env	(revision 2070)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env	(revision 2071)
@@ -12,5 +12,5 @@
 
 Preprocessor {
-samplesPerPass 3000000
+	samplesPerPass 3000000
 	useGlRenderer false
 	type vss
@@ -19,7 +19,7 @@
 	loadMeshes false
 	# internal raycaster
-	rayCastMethod 0
+#	rayCastMethod 0
 	# intel raycaster
-#	rayCastMethod 1
+	rayCastMethod 1
 	exportVisibility false
 	loadKdTree false
@@ -190,5 +190,5 @@
 VspBspTree {
 	Construction {
-		samples 200000
+		samples 2000000
 		epsilon 0.0000001
 		randomize false
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2063)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2071)
@@ -473,5 +473,5 @@
   static Vector3 shifts[packetSize];
   // mutate the 
-  float alpha = RandomValue(0.0f, 2.0f*M_PI);
+  float alpha = RandomValue(0.0f, Real(2.0*M_PI));
   //float alpha = vr2.x*2.0f*M_PI;
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 2070)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 2071)
@@ -27,5 +27,5 @@
 #define COUNT_ORIGIN_OBJECTS 1
 
-#define STORE_PVS 0
+#define STORE_PVS 1
 
 
@@ -959,6 +959,6 @@
 		EvalSubdivisionCandidate(backCandidate);
 	
-		cout << "f cost: " << frontCandidate.mPriority << endl;
-		cout << "b cost: " << backCandidate.mPriority << endl;
+		cout << "f cost: " << frontCandidate.mPriority << " " << frontCandidate.mRenderCostDecr << endl;
+		cout << "b cost: " << backCandidate.mPriority << " " << backCandidate.mRenderCostDecr << endl;
 		tQueue.push(frontCandidate);
 		tQueue.push(backCandidate);
@@ -1273,5 +1273,5 @@
 		if (ray->mTerminationObject) 
 		{
-			cout << "m";
+			//cout << "m";
 			if (vc->AddPvsSample(ray->mTerminationObject, ray->mPdf, contribution))
 				madeContrib = true;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2069)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2071)
@@ -3655,8 +3655,5 @@
 
 	///////////
-	//-- faster way of computing pvs:
-	//-- construct merged pvs by adding
-	//-- and only those of the next pvs which were not mailed.
-	//-- note: sumpdf is not correct!!
+	//-- merge pvss
 
 	vector<ObjectPvs>::iterator oit = pvsList.begin();
@@ -3666,5 +3663,5 @@
 		ObjectPvsIterator pit = (*oit).GetIterator();
 		
-		// first mark all object from this pvs
+		// add pvss to new pvs: use mailing to avoid adding entries two times.
 		while (pit.HasMoreEntries())
 		{		
@@ -3677,15 +3674,10 @@
 				intersect->Mail();
 
-				if (pvs.AddSampleDirtyCheck(intersect, entry.mData.mSumPdf))
-				{
-					if (pvs.RequiresResort())
-					{
-						pvs.SimpleSort();
-					}
-				}
-				
+				pvs.AddSampleDirty(intersect, entry.mData.mSumPdf);
 			}
 		}
 	}
+
+	if (0) pvs.Sort();
 
 	// store pvs in this node
@@ -3699,5 +3691,5 @@
 	
 #else 
-	// really merge cells: slow put sumPdf is correct
+	// really merge cells: slow but sumPdf is correct
 	viewCellInterior->GetPvs().Merge(backVc->GetPvs());
 	viewCellInterior->GetPvs().Merge(frontVc->GetPvs());
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2066)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2071)
@@ -265,5 +265,4 @@
 							float &contribution)
 { 
-	cout<<"e";
 	const bool result = mPvs.AddSample(sample, pdf);//, contribution);
 	// have to recompute pvs size
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 2066)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 2071)
@@ -712,5 +712,5 @@
 template <typename T, typename S>
 float Pvs<T, S>::AddSample(T sample, const float pdf)
-{cout << "t";
+{
 	++ mSamples;
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp	(revision 2070)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp	(revision 2071)
@@ -201,4 +201,7 @@
 #endif
 
+	AxisAlignedBox3 ebox = sbox;
+	ebox.Enlarge(Vector3(1e-3f));
+
 	SimpleRayContainer::const_iterator sit, sit_end = rays.end();
 
@@ -207,5 +210,5 @@
 	{
 		CastRay(*sit, vssRays, sbox, castDoubleRays, pruneInvalidRays);
-		if (!vssRays.empty() && (!vssRays.back() || !sbox.IsInside(*vssRays.back())))
+		if (!vssRays.empty() && (!vssRays.back() || !ebox.IsInside(*vssRays.back())))
 		cout << "error " << *vssRays.back()<<endl;
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2063)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2071)
@@ -912,5 +912,5 @@
 		}
 		if (attrName == "pvs") 
-		{//cout <<"e";
+		{
 			StrX attrValue(attributes.getValue(i));
 			const char *ptr = attrValue.LocalForm();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2069)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2071)
@@ -205,4 +205,22 @@
 bool SpatialBoxBasedDistribution::GenerateSample(SimpleRay &ray)
 {
+		Vector3 origin, direction; 
+
+	mPreprocessor.mViewCellsManager->GetViewPoint(origin);
+	direction = mPreprocessor.mKdTree->GetBox().GetRandomPoint() - origin;
+	//cout << "z";
+	const float c = Magnitude(direction);
+
+	if (c <= Limits::Small) 
+		return false;
+
+	const float pdf = 1.0f;
+
+	direction *= 1.0f / c;
+	ray = SimpleRay(origin, direction, SPATIAL_BOX_BASED_DISTRIBUTION, pdf);
+
+	return true;
+
+	/*
   Vector3 origin, direction; 
 
@@ -226,5 +244,5 @@
   ray = SimpleRay(origin, direction, SPATIAL_BOX_BASED_DISTRIBUTION, pdf);
   
-  return true;
+  return true;*/
 }
 
