Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1889)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1893)
@@ -265,6 +265,4 @@
   
 	Intersectable *GetIntersectable(Intersectable *obj, const Vector3 &point) const;
-  
-	float AvgRayContribution(const float pvs, const float rays) const;
 
 	/** Export object space partition bounding boxes.
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1890)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1893)
@@ -585,4 +585,10 @@
 
 
+static float AvgRayContribution(const int pvs, const int nRays)
+{
+	return (float)pvs / (float)nRays;
+}
+
+
 void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate, 
 										   bool computeSplitPlane)
@@ -591,5 +597,5 @@
 	{
 		const bool sufficientSamples = 
-				splitCandidate.mParentData.mNumRays > mMinRaysForVisibility;
+			splitCandidate.mParentData.mNumRays > mMinRaysForVisibility;
 
 		const bool useVisibiliyBasedHeuristics = 
@@ -609,6 +615,6 @@
 		const int previousMisses = splitCandidate.mParentData.mMaxCostMisses;
 
-		splitCandidate.SetMaxCostMisses(
-			maxCostRatioViolated ? previousMisses + 1 : previousMisses);
+		splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 
+										previousMisses + 1 : previousMisses);
 	}
 
@@ -629,11 +635,5 @@
 	const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate);
 	splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr);
-
-	const int numViewCells = CountViewCells(leaf->mObjects);
-
-	const float avgRayContrib = 
-		(float)splitCandidate.mParentData.mNumRays / (float)numViewCells;
-
-	cout << "avgRayContrib: " << avgRayContrib << endl;
+	
 #ifdef GTP_DEBUG
 	Debug << "old render cost: " << oldRenderCost << endl;
@@ -642,8 +642,24 @@
 #endif
 
-	const float priority = EvalPriority(splitCandidate, 
-										oldRenderCost, 
-										renderCostDecr);
-	
+	float priority = EvalPriority(splitCandidate, 
+								  oldRenderCost, 
+								  renderCostDecr);
+	
+	// avg ray contri: this leaf is a pvs entry in all the view cells
+	// that see one of the objects.
+	const int numViewCells = CountViewCells(leaf->mObjects);
+	
+	const float avgRayContri = 
+		AvgRayContribution(numViewCells, splitCandidate.mParentData.mNumRays);
+
+	cout << "avgRayContri: " << avgRayContri << endl;
+
+	// avg ray contri very high. i.e., the result is influenced by undersampling
+	// => decrease priority
+	if (avgRayContri > 99925)
+	{
+		priority /= avgRayContri;
+	}
+
   	// compute global decrease in render cost
 	splitCandidate.SetPriority(priority);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1845)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1893)
@@ -827,5 +827,6 @@
 		const int maxCostMisses = splitCandidate.mParentData.mMaxCostMisses;
 		// max cost threshold violated?
-		splitCandidate.SetMaxCostMisses(maxCostRatioViolated  ? maxCostMisses + 1: maxCostMisses);
+		splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 
+										maxCostMisses + 1: maxCostMisses);
 	}
 	
@@ -848,27 +849,22 @@
 	const float factor = mRenderCostDecreaseWeight;
 
-	float priority;
-
-	if (1)
-	{
-		priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-		if (mHierarchyManager->mConsiderMemory)
-		{
-			priority /= ((float)splitCandidate.GetPvsEntriesIncr() + mMemoryConst);
-		}
-	}
-	else
-	{
-		if (!mHierarchyManager->mConsiderMemory)
-		{
-			priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-		}
-		else
-		{
-			const float ratio = 
-				renderCostDecr / ((float)splitCandidate.GetPvsEntriesIncr() + mMemoryConst);
-
-			priority = factor * ratio + (1.0f - factor) * oldRenderCost;
-		}
+	float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+
+	if (mHierarchyManager->mConsiderMemory)
+	{
+		priority /= ((float)splitCandidate.GetPvsEntriesIncr() + mMemoryConst);
+	}
+
+	/////////////
+	// avg ray contri
+
+	const float avgRayContri = splitCandidate.mParentData.GetAvgRayContribution();
+	cout << "vsp avgRayContri: " << avgRayContri << endl;
+
+	// avg ray contri very high. i.e., the result is influenced by undersampling
+	// => decrease priority
+	if (avgRayContri > 99925)
+	{
+		priority /= avgRayContri;
 	}
 
@@ -1869,5 +1865,4 @@
 	VspLeaf *leaf = dynamic_cast<VspLeaf *>(data.mNode);
 
-
 	if (data.mPvs > mVspStats.maxPvs)
 	{
@@ -1885,5 +1880,4 @@
 	{
         ++ mVspStats.maxDepthNodes;
-		//Debug << "new max depth: " << mVspStats.maxDepthNodes << endl;
 	}
 
@@ -1908,5 +1902,5 @@
 	++ mCreatedViewCells;
 
-#ifdef GTPGTP_DEBUG
+#ifdef GTP_DEBUG
 	Debug << "BSP stats: "
 		  << "Depth: " << data.mDepth << " (max: " << mTermMaxDepth << "), "
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1889)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1893)
@@ -284,10 +284,4 @@
 
 
-float HierarchyManager::AvgRayContribution(const float pvs, const float rays) const
-{
-	return (float)pvs / rays;
-}
-
-
 void HierarchyManager::EvalSubdivisionStats()
 {
