Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1727)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1765)
@@ -41,7 +41,7 @@
 
 // pvs penalty can be different from pvs size
-inline static float EvalPvsPenalty(const int pvs, 
-								   const int lower,
-								   const int upper)
+inline static float EvalPvsPenalty(const float pvs, 
+								   const float lower,
+								   const float upper)
 {
 	// clamp to minmax values
@@ -2267,6 +2267,8 @@
 		AddObjToPvs((*rit).mRay->mTerminationObject, side, pvsFront, pvsBack, pvsTotal);
 
-		if (COUNT_ORIGIN_OBJECTS) 
+		if (COUNT_ORIGIN_OBJECTS)
+		{
 			AddObjToPvs((*rit).mRay->mOriginObject, side, pvsFront, pvsBack, pvsTotal);
+		}
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1757)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1765)
@@ -934,7 +934,7 @@
 }
 
-bool Preprocessor::GenerateRays(const int number,
-								const int sampleType,
-								SimpleRayContainer &rays)
+int Preprocessor::GenerateRays(const int number,
+							   const int sampleType,
+							   SimpleRayContainer &rays)
 {
 	const int startSize = (int)rays.size();
@@ -943,8 +943,10 @@
 	if (!strategy)
 	{
-		return false;
-	}
-
-	for (int i=0; (int)rays.size() - startSize < number; ++ i) 
+		return 0;
+	}
+
+	int castRays = 0;
+
+	for (int i = 0; (int)rays.size() - startSize < number; ++ i) 
 	{
 		SimpleRay newRay;
@@ -954,6 +956,8 @@
 #if 1
 			rays.AddRay(newRay);
+			++ castRays;
 #else
 			GenerateRayBundle(rays, newRay, 16, 0);
+			castRays += 16;
 #endif
 		}	
@@ -961,5 +965,5 @@
 
 	delete strategy;
-    return true;
+    return castRays;
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1761)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1765)
@@ -56,5 +56,5 @@
 
 
-bool
+int
 RssPreprocessor::GenerateRays(
 							  const int number,
@@ -63,5 +63,5 @@
 							  )
 {
-  bool result = false;
+  int result = 0;
   
   Debug<<"Generate rays...\n"<<flush;
@@ -71,6 +71,5 @@
   case SamplingStrategy::RSS_SILHOUETTE_BASED_DISTRIBUTION:
 	if (mRssTree) {
-	  GenerateImportanceRays(mRssTree, number, rays);
-	  result = true;
+	  result = GenerateImportanceRays(mRssTree, number, rays);
 	}
 	break;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1740)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1765)
@@ -121,7 +121,7 @@
 	bool ExportKdTree(const string filename);
 
-	virtual bool GenerateRays(const int number,
-							  const int raysType,
-							  SimpleRayContainer &rays);
+	virtual int GenerateRays(const int number,
+							 const int raysType,
+							 SimpleRayContainer &rays);
 
 	bool GenerateRayBundle(SimpleRayContainer &rayBundle,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1764)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1765)
@@ -384,5 +384,5 @@
 						 const int depth, 
 						 RayInfoContainer *rays,
-						 const int pvs,
+						 const float pvs,
 						 const float p,
 						 const AxisAlignedBox3 &box):
@@ -441,5 +441,5 @@
 		AxisAlignedBox3 mBoundingBox;
 		/// pvs size
-		int mPvs;
+		float mPvs;
 		/// how often this branch has missed the max-cost ratio
 		int mMaxCostMisses;
@@ -817,7 +817,7 @@
 							 float maxBand);
 
-	/** Evaluate pvs size as induced by the samples.
-	*/
-	int EvalPvsSize(const RayInfoContainer &rays) const;
+	/** Evaluate render cost of this pvs.
+	*/
+	float EvalPvsCost(const RayInfoContainer &rays) const;
 
 	int EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate) const;
@@ -826,5 +826,7 @@
 	*/
 	int EvalPvsEntriesSize(const RayInfoContainer &rays) const;
+
 	int EvalPvsEntriesContribution(const VssRay &ray, const bool isTermination) const;
+
 	/** Computes best cost for axis aligned planes.
 	*/
@@ -832,5 +834,6 @@
 								  const AxisAlignedBox3 &box,
 								  const int axis,
-								  float &position);
+								  float &position,
+								  const RayInfoContainer &usedRays);
 
 
@@ -843,5 +846,5 @@
 		@param rightPvs updates the right pvs
 	*/
-	void EvalHeuristics(const SortableEntry &ve, int &pvsLeft, int &pvsRight) const;
+	void EvalHeuristics(const SortableEntry &ve, float &pvsLeft, float &pvsRight) const;
 
 	/** Evaluates contribution of min event to pvs
@@ -865,12 +868,13 @@
 		@returns pvs size as seen by the rays.
 	*/
-	int PrepareHeuristics(const RayInfoContainer &rays);
+	float PrepareHeuristics(const RayInfoContainer &rays);
 	
 	/** Prepare a single ray for heuristics.
 	*/
-	int PrepareHeuristics(const VssRay &ray, const bool isTermination);
+	float PrepareHeuristics(const VssRay &ray, const bool isTermination);
+
 	/** Prepare a single kd leaf for heuristics.
 	*/
-	int PrepareHeuristics(KdLeaf *leaf);
+	float PrepareHeuristics(KdLeaf *leaf);
 
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1763)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1765)
@@ -1542,5 +1542,7 @@
 			}
 		}
+
 #if COUNT_ORIGIN_OBJECTS
+
 		if (ray->mOriginObject)
 		{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h	(revision 1737)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h	(revision 1765)
@@ -133,5 +133,5 @@
 
   /** Redefininition of the get sample rays method from the preprocessor */
-  bool
+  int
   GenerateRays(
 			   const int number,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1764)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1765)
@@ -316,22 +316,25 @@
 
 	// create one third of each type
-	int stype;
-	
-	const int numStrategies = 3;
-
-	stype = SamplingStrategy::OBJECT_BASED_DISTRIBUTION;
-	mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays);
-	
-	stype = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION;
-	mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays);
-	
-	if (0)
-	{
-		stype = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION;
-		mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays);
-	}
-
-	stype = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION;
-	mPreprocessor->GenerateRays(samplesPerPass / numStrategies, sampleType, simpleRays);
+	int castRays = 0;
+	
+	vector<int> strategies;
+	 
+	strategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+	strategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+	strategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+
+	const int numRaysPerPass = samplesPerPass / (int)strategies.size();
+
+	vector<int>::const_iterator iit, iit_end = strategies.end();
+
+	for (iit = strategies.begin(); iit != iit_end; ++ iit)
+	{
+		int stype = *iit;
+		const int newRays = 
+			mPreprocessor->GenerateRays(numRaysPerPass, stype, simpleRays);
+	
+		cout << "cast " << newRays << " rays of strategy " << stype << endl;
+		castRays += newRays;
+	}
 
 	cout << "generated " << samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
@@ -2708,7 +2711,7 @@
 			if (vcValid)
 			{
-				m.mDiffuseColor.r = 0.5f + RandomValue(0.0f, 0.5f);
-				m.mDiffuseColor.g = 0.5f + RandomValue(0.0f, 0.5f);
-				m.mDiffuseColor.b = 0.5f + RandomValue(0.f, 0.5f);
+				m.mDiffuseColor.r = 0.2f + RandomValue(0.0f, 0.8f);
+				m.mDiffuseColor.g = 0.2f + RandomValue(0.0f, 0.8f);
+				m.mDiffuseColor.b = 0.2f + RandomValue(0.0f, 0.8f);
 			}
 			else
@@ -2753,6 +2756,6 @@
 	// special color code for invalid view cells
 	m.mDiffuseColor.r = importance;
-	m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r;
-	m.mDiffuseColor.b = vcValid ? 1.0f : 0.0f;
+	m.mDiffuseColor.g = vcValid ? 0.0f : 1.0f;
+	m.mDiffuseColor.b = 1.0f - importance;
 
 	//Debug << "importance: " << importance << endl;
@@ -5435,5 +5438,5 @@
 	Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl");
 
-	Vector3 scale(1.0f, 0.9f, 1.0f);
+	Vector3 scale(0.9f, 0.9f, 0.9f);
 	if (exporter)
 	{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1763)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1765)
@@ -364,10 +364,6 @@
 public:
 
-	/// Rays piercing this leaf.
-	//VssRayContainer mVssRays;
 	/// objects
 	ObjectContainer mObjects;
-	/// universal counter
-	int mCounter;
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp	(revision 1763)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp	(revision 1765)
@@ -61,7 +61,7 @@
 {
 	// random barycentric coordinates
-	float a = RandomValue(0,1);
-	float b = RandomValue(0,1);
-	float c = RandomValue(0,1);
+	float a = RandomValue(0.0f, 1.0f);
+	float b = RandomValue(0.0f, 1.0f);
+	float c = RandomValue(0.0f, 1.0f);
 	
 	const float sum = a + b + c;
@@ -95,8 +95,8 @@
 											  Vector3 &normal)
 {
-	int edge = Random(3);
+	const int edge = Random(3);
 
-	Vector3 a = mItem.mVertices[edge];
-	Vector3 b = mItem.mVertices[(edge + 1) % 3];
+	const Vector3 a = mItem.mVertices[edge];
+	const Vector3 b = mItem.mVertices[(edge + 1) % 3];
 
 	const float factor = RandomValue(0.0f, 1.0f);
@@ -112,5 +112,5 @@
   IntersectableWrapper<KdNode *>(item)
 {
-  mBox = box;
+	mBox = box;
 }
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1764)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1765)
@@ -40,7 +40,7 @@
 
 // pvs penalty can be different from pvs size
-inline static float EvalPvsPenalty(const int pvs, 
-								   const int lower,
-								   const int upper)
+inline static float EvalPvsPenalty(const float pvs, 
+								   const float lower,
+								   const float upper)
 {
 	// clamp to minmax values
@@ -734,5 +734,5 @@
 			
 		mTotalCost -= sc->GetRenderCostDecrease();
-		mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs;
+		mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs);
 		mPvsEntries += sc->GetPvsEntriesIncr();
 
@@ -932,6 +932,6 @@
 
 	//-- compute pvs
-	frontData.mPvs = EvalPvsSize(*frontData.mRays);
-	backData.mPvs = EvalPvsSize(*backData.mRays);
+	frontData.mPvs = EvalPvsCost(*frontData.mRays);
+	backData.mPvs = EvalPvsCost(*backData.mRays);
 		
 	//-- split front and back node geometry and compute area
@@ -1120,7 +1120,7 @@
 
 
-int VspTree::PrepareHeuristics(KdLeaf *leaf)
+float VspTree::PrepareHeuristics(KdLeaf *leaf)
 {	
-	int pvsSize = 0;
+	float pvsSize = 0;
 	
 	if (!leaf->Mailed())
@@ -1160,5 +1160,5 @@
 
 
-int VspTree::PrepareHeuristics(const RayInfoContainer &rays)
+float VspTree::PrepareHeuristics(const RayInfoContainer &rays)
 {	
 	Intersectable::NewMail();
@@ -1166,5 +1166,5 @@
 	BvhLeaf::NewMail();
 
-	int pvsSize = 0;
+	float pvsSize = 0;
 
 	RayInfoContainer::const_iterator ri, ri_end = rays.end();
@@ -1243,6 +1243,6 @@
 
 void VspTree::EvalHeuristics(const SortableEntry &ci,
-							 int &pvsLeft,
-							 int &pvsRight) const
+							 float &pvsLeft,
+							 float &pvsRight) const
 {
 	VssRay *ray = ci.ray;
@@ -1251,7 +1251,6 @@
 	if (ci.type == SortableEntry::ERayMin)
 	{
+		pvsLeft += EvalMinEventContribution(*ray, true);
 #if COUNT_ORIGIN_OBJECTS
-		pvsLeft += EvalMinEventContribution(*ray, true);
-#else
 		pvsLeft += EvalMinEventContribution(*ray, false);
 #endif
@@ -1259,7 +1258,6 @@
 	else // eval changes in pvs causes by max event 
 	{
+		pvsRight -= EvalMaxEventContribution(*ray, true);
 #if COUNT_ORIGIN_OBJECTS
-		pvsRight -= EvalMaxEventContribution(*ray, true);
-#else
 		pvsRight -= EvalMaxEventContribution(*ray, false);
 #endif
@@ -1271,22 +1269,7 @@
 									   const AxisAlignedBox3 &box,
 									   const int axis,
-									   float &position)
-{
-	// get subset of rays
-	RayInfoContainer randomRays;
-	randomRays.reserve(mMaxTests);
-
-	RayInfoContainer *usedRays;
-
-	if (mMaxTests < (int)tData.mRays->size())
-	{
-		GetRayInfoSets(*tData.mRays, mMaxTests, randomRays);
-		usedRays = &randomRays;
-	}
-	else
-	{
-		usedRays = tData.mRays;
-	}
-
+									   float &position,
+									   const RayInfoContainer &usedRays)
+{
 	const float minBox = box.Min(axis);
 	const float maxBox = box.Max(axis);
@@ -1297,9 +1280,9 @@
 	const float maxBand = minBox + mMaxBand * sizeBox;
 
-	SortSubdivisionCandidates(*usedRays, axis, minBand, maxBand);
+	SortSubdivisionCandidates(usedRays, axis, minBand, maxBand);
 
 	// prepare the sweep
 	// note: returns pvs size => no need t give pvs size as function parameter
-	const int pvsSize = PrepareHeuristics(*usedRays);
+	const float pvsCost = PrepareHeuristics(usedRays);
 
 	// go through the lists, count the number of objects left and right
@@ -1307,11 +1290,11 @@
 	// C = ct_div_ci  + (ql*rl + qr*rr)/queries
 
-	int pvsl = 0;
-	int pvsr = pvsSize;
-
-	int pvsBack = pvsl;
-	int pvsFront = pvsr;
-
-	float sum = (float)pvsSize * sizeBox;
+	float pvsl = 0;
+	float pvsr = pvsCost;
+
+	float pvsBack = pvsl;
+	float pvsFront = pvsr;
+
+	float sum = pvsCost * sizeBox;
 	float minSum = 1e20f;
 
@@ -1327,9 +1310,14 @@
 	BvhLeaf::NewMail();
 
-	//-- traverse through visibility events
-	vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end();
-
-#ifdef GTPGTP_DEBUG
-	const float volRatio = tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume());
+	const float volRatio = 
+		tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume());
+
+	////////
+	//-- iterate through visibility events
+
+	vector<SortableEntry>::const_iterator ci, 
+		ci_end = mLocalSubdivisionCandidates->end();
+
+#ifdef GTP_DEBUG
 	const int leaves = mVspStats.Leaves();
 	const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90));
@@ -1370,5 +1358,5 @@
 			sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value);
 			
-#ifdef GTPGTP_DEBUG
+#ifdef GTP_DEBUG
 			if (printStats)
 			{
@@ -1404,6 +1392,6 @@
 	//-- compute cost
 
-	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
-	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
+	const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize();
+	const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize();
 
 	const float pOverall = sizeBox;
@@ -1411,5 +1399,5 @@
 	const float pFront = maxBox - position;
 
-	const float penaltyOld = EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit);
+	const float penaltyOld = EvalPvsPenalty(pvsCost, lowerPvsLimit, upperPvsLimit);
     const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);
 	const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);
@@ -1423,11 +1411,11 @@
 	}
 	
-#ifdef GTPGTP_DEBUG
-	Debug << "\n§§§§ eval local cost §§§§" << endl
+//#ifdef GTP_DEBUG
+	cout << "\n((((( eval local cost )))))" << endl
 		  << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl 
 		  << "back p: " << pBack * volRatio << " front p " << pFront * volRatio << " p: " << pOverall * volRatio << endl
 		  << "old rc: " << oldRenderCost * volRatio << " new rc: " << newRenderCost * volRatio << endl
 		  << "render cost decrease: " << oldRenderCost * volRatio - newRenderCost * volRatio << endl;
-#endif
+//#endif
 	return ratio;
 }
@@ -1454,4 +1442,20 @@
 		mOnlyDrivingAxis || mCirculatingAxis;
 	
+	// get subset of rays
+	RayInfoContainer randomRays;
+	randomRays.reserve(mMaxTests);
+
+	RayInfoContainer *usedRays;
+
+	if (mMaxTests < (int)tData.mRays->size())
+	{
+		GetRayInfoSets(*tData.mRays, mMaxTests, randomRays);
+		usedRays = &randomRays;
+	}
+	else
+	{
+		usedRays = tData.mRays;
+	}
+
 	if (mCirculatingAxis)
 	{
@@ -1460,5 +1464,7 @@
 
 		if (parent)
+		{
 			parentAxis = dynamic_cast<VspInterior *>(parent)->GetAxis();
+		}
 
 		sAxis = (parentAxis + 1) % 3;
@@ -1476,13 +1482,16 @@
 			{
 				//-- place split plane using heuristics
+
 				nCostRatio[axis] =
 					EvalLocalCostHeuristics(tData,
 											box,
 											axis,
-											nPosition[axis]);			
+											nPosition[axis],
+											*usedRays);			
 			}
 			else
 			{
 				//-- split plane position is spatial median				
+				
 				nPosition[axis] = (box.Min()[axis] + box.Max()[axis]) * 0.5f;
 				nCostRatio[axis] = EvalLocalSplitCost(tData,
@@ -1505,5 +1514,5 @@
 	}
 
-	////////////////////////////////
+	/////////////////////////
 	//-- assign values of best split
 
@@ -1571,13 +1580,13 @@
 
 
-	////////////////////////////////////
+	///////////////////
 	//-- evaluate render cost heuristics
 
-	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
-	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
-
- 	const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);
-    const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit);
-	const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit);
+	const float lowerPvsLimit = (float)mViewCellsManager->GetMinPvsSize();
+	const float upperPvsLimit = (float)mViewCellsManager->GetMaxPvsSize();
+
+ 	const float penaltyOld = EvalPvsPenalty(totalPvs, lowerPvsLimit, upperPvsLimit);
+    const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);
+	const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);
 			
 	const float oldRenderCost = pOverall * penaltyOld;
@@ -1590,5 +1599,5 @@
 	const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol;
 
-#ifdef GTPGTP_DEBUG
+#ifdef GTP_DEBUG
 	Debug << "\nvsp render cost decrease" << endl
 		  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 
@@ -1619,5 +1628,5 @@
 	KdLeaf::NewMail(3);
 
-	const int pvsSize = data.mPvs;
+	const float pvsSize = data.mPvs;
 	RayInfoContainer::const_iterator rit, rit_end = data.mRays->end();
 
@@ -1863,8 +1872,8 @@
 	if (data.mPvs > mVspStats.maxPvs)
 	{
-		mVspStats.maxPvs = data.mPvs;
-	}
-
-	mVspStats.pvs += data.mPvs;
+		mVspStats.maxPvs = (int)data.mPvs;
+	}
+
+	mVspStats.pvs += (int)data.mPvs;
 
 	if (data.mDepth < mVspStats.minDepth)
@@ -2215,7 +2224,7 @@
 
 
-int VspTree::EvalPvsSize(const RayInfoContainer &rays) const
-{
-	int pvsSize = 0;
+float VspTree::EvalPvsCost(const RayInfoContainer &rays) const
+{
+	float pvsCost = 0;
 	
 	Intersectable::NewMail();
@@ -2228,12 +2237,13 @@
 	{
 		VssRay *ray = (*rit).mRay;
+		
+		pvsCost += EvalContributionToPvs(*ray, true);
+
 #if COUNT_ORIGIN_OBJECTS
-		pvsSize += EvalContributionToPvs(*ray, true);
-#else
-		pvsSize += EvalContributionToPvs(*ray, false);
+		pvsCost += EvalContributionToPvs(*ray, false);
 #endif
 	}
 	
-	return pvsSize;
+	return pvsCost;
 }
 
@@ -2307,7 +2317,8 @@
 	{
 		VssRay *ray = (*rit).mRay;
+
+		pvsSize += EvalPvsEntriesContribution(*ray, true);
+
 #if COUNT_ORIGIN_OBJECTS
-		pvsSize += EvalPvsEntriesContribution(*ray, true);
-#else
 		pvsSize += EvalPvsEntriesContribution(*ray, false);
 #endif
@@ -2890,5 +2901,5 @@
 
 	/// collect pvs from rays
-	const int pvsSize = EvalPvsSize(rays);
+	const float pvsCost = EvalPvsCost(rays);
 	
 	// root and bounding box were already constructed
@@ -2901,5 +2912,5 @@
 	
 	// first vsp traversal data
-	VspTraversalData vData(leaf, 0, &rays, pvsSize, prop, mBoundingBox);
+	VspTraversalData vData(leaf, 0, &rays, pvsCost, prop, mBoundingBox);
 
 
@@ -2923,5 +2934,5 @@
 	leaf->SetSubdivisionCandidate(splitCandidate);
 
-	mTotalCost = (float)pvsSize;
+	mTotalCost = pvsCost;
 	mPvsEntries = EvalPvsEntriesSize(rays);
 
@@ -3057,7 +3068,7 @@
 
 
-int VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination)
-{
-	int pvsSize = 0;
+float VspTree::PrepareHeuristics(const VssRay &ray, const bool isTermination)
+{
+	float pvsSize = 0;
 	
 	Intersectable *obj;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1763)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1765)
@@ -166,11 +166,14 @@
 
 	object->GetRandomSurfacePoint(point, normal);
+	
 	direction = origin - point;
-
-	// $$ jb the pdf is yet not correct for all sampling methods!
-	const float c = Magnitude(direction);
-
-	if (c <= Limits::Small) 
-		return false;
+	
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float c = Magnitude(direction);
+	
+	if ((c <= Limits::Small) || (DotProd(direction, normal) < 0))
+	{
+		return false;
+	}
 
 	// $$ jb the pdf is yet not correct for all sampling methods!
@@ -178,4 +181,7 @@
 	//cout << "p: " << point << " ";
 	direction *= 1.0f / c;
+	// a little offset
+	point += direction * 0.01f;
+
 	ray = SimpleRay(point, direction, pdf);
 	
@@ -220,4 +226,5 @@
 }
 
+
 #if 0
 bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const
