Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1912)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1913)
@@ -346,5 +346,4 @@
 VspLeaf::VspLeaf(): 
 mViewCell(NULL), mSubdivisionCandidate(NULL)
-//, mPvs(NULL)
 {
 }
@@ -380,5 +379,4 @@
 VspLeaf::VspLeaf(VspInterior *parent): 
 VspNode(parent), mViewCell(NULL)
-//, mPvs(NULL)
 {}
 
@@ -386,5 +384,4 @@
 VspLeaf::VspLeaf(VspInterior *parent, ViewCellLeaf *viewCell): 
 VspNode(parent), mViewCell(viewCell)
-//, mPvs(NULL)
 {
 }
@@ -735,5 +732,5 @@
 			
 		mTotalCost -= sc->GetRenderCostDecrease();
-		mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs);
+		//mTotalPvsSize += (int)(tFrontData.mPvs + tBackData.mPvs - tData.mPvs);
 		mPvsEntries += sc->GetPvsEntriesIncr();
 
@@ -899,15 +896,16 @@
 	}
 
-	const float oldPvsRatio = oldPvsSize / splitCandidate.mParentData.mPvs;
+	const float oldPvsRatio = (splitCandidate.mParentData.mPvs > 0) ? 
+		oldPvsSize / splitCandidate.mParentData.mPvs : 1;
 	const float correctedOldPvs = splitCandidate.mParentData.mCorrectedPvs * oldPvsRatio;
 
 	cout <<"here102 "<< endl;
 	cout << "old pvs ratio: " << oldPvsRatio << endl;
-	const float correctedFrontPvs = 
+	splitCandidate.mCorrectedFrontPvs = 
 		mHierarchyManager->EvalCorrectedPvs(fPvsSize, 
 											correctedOldPvs, 
 											splitCandidate.GetAvgRayContribution());
 	cout <<"here103 "<< endl;
-	const float correctedBackPvs = 
+	splitCandidate.mCorrectedBackPvs = 
 		mHierarchyManager->EvalCorrectedPvs(bPvsSize, 
 											correctedOldPvs, 
@@ -915,8 +913,8 @@
 
 	
-	cout << "vsp front entries " << fPvsSize << " corrected: " << correctedFrontPvs << endl;
-	cout << "vsp back entries " << bPvsSize << " corrected: " << correctedBackPvs << endl;
-
-	return (int)(correctedFrontPvs + correctedBackPvs - correctedOldPvs);
+	cout << "vsp front entries " << fPvsSize << " corrected: " << splitCandidate.mCorrectedFrontPvs << endl;
+	cout << "vsp back entries " << bPvsSize << " corrected: " << splitCandidate.mCorrectedBackPvs << endl;
+
+	return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - correctedOldPvs);
 }
 
@@ -961,9 +959,9 @@
 
 	//-- compute render cost
-	frontData.mRenderCost = (float)EvalRenderCost(*frontData.mRays);
-	backData.mRenderCost = (float)EvalRenderCost(*backData.mRays);
-	
-	frontData.mCorrectedRenderCost = sc.mCorrectedFrontPvs;
-	backData.mCorrectedRenderCost = sc.mCorrectedBackPvs;
+	frontData.mRenderCost = (float)EvalPvsCost(*frontData.mRays);
+	backData.mRenderCost = (float)EvalPvsCost(*backData.mRays);
+	
+	frontData.mCorrectedRenderCost = sc.mCorrectedFrontRenderCost;
+	backData.mCorrectedRenderCost = sc.mCorrectedBackRenderCost;
 
 	////////
@@ -1605,18 +1603,20 @@
 	//-- evaluate render cost heuristics
 
-	const float oldRenderCostRatio = tData.mPvs ? (totalPvs / tData.mPvs) : 1;
-
-	const float penaltyOld = tData.mCorrectedPvs * oldRenderCostRatio;
-
-	cout <<"here107 " << penaltyOld << endl;
-	sc.mCorrectedFrontPvs = mHierarchyManager->EvalCorrectedPvs(pvsFront, penaltyOld, avgRayContri);
-	cout <<"here108 " << tData.mCorrectedPvs << " " << oldRenderCostRatio << endl;
-	sc.mCorrectedBackPvs = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRayContri);
-
-	cout << "vsp front pvs " << pvsFront << " corrected: " << sc.mCorrectedFrontPvs << endl;
-	cout << "vsp back pvs " << pvsBack << " corrected: " << sc.mCorrectedBackPvs << endl;
+	const float oldRenderCostRatio = (tData.mRenderCost > 0)? 
+		(totalPvs / tData.mRenderCost) : 1;
+
+	const float penaltyOld = tData.mCorrectedRenderCost * oldRenderCostRatio;
+
+	cout <<"here107 old render cost ratio " << oldRenderCostRatio << " old cost: " << penaltyOld << endl;
+	sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsFront, penaltyOld, avgRayContri);
+	cout <<"here108 " << tData.mCorrectedRenderCost << " " << oldRenderCostRatio << endl;
+	sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRayContri);
+
+	cout << "vsp front pvs " << pvsFront << " corrected: " << sc.mCorrectedFrontRenderCost << endl;
+	cout << "vsp back render cost " << pvsBack << " corrected: " << sc.mCorrectedBackRenderCost << endl;
 
 	const float oldRenderCost = pOverall * penaltyOld;
-	const float newRenderCost = sc.mCorrectedFrontPvs * pFront + sc.mCorrectedBackPvs * pBack;
+	const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront + 
+								sc.mCorrectedFrontRenderCost * pBack;
 
 	// we also return the old render cost
@@ -2934,5 +2934,4 @@
 	VspTraversalData vData(leaf, 0, &rays, pvsCost, prop, mBoundingBox);
 
-
 #if WORK_WITH_VIEWCELL_PVS
 	// add first view cell to all the objects view cell pvs
@@ -2947,6 +2946,6 @@
 #endif
 
-	mTotalCost = vData.mCorrectedPvs = pvsCost;
-	mPvsEntries = EvalPvsEntriesSize(rays);
+	mTotalCost = vData.mCorrectedRenderCost = vData.mRenderCost = pvsCost;
+	mPvsEntries = vData.mCorrectedPvs = vData.mPvs = EvalPvsEntriesSize(rays);
 
 	//////////////
