Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1663)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1664)
@@ -12,6 +12,6 @@
 
 #SCENE=vsposp_typical
-SCENE=soda5_vsposp
-#SCENE=soda_vsposp
+#SCENE=soda5_vsposp
+SCENE=soda_vsposp
 #SCENE=vienna_vsposp
 #SCENE=arena_vsposp
@@ -133,4 +133,26 @@
 
 
+###############################################################
+
+ METHOD=gradient-2
+ echo ********" $SCENE $METHOD ************"
+
+ $PROGRAM $ENVIRONMENT \
+ -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+ -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+ -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+ -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+ -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+ -hierarchy_construction_type=2 \
+ -hierarchy_construction_multilevel=false \
+ -hierarchy_construction_levels=4 \
+ -hierarchy_construction_consider_memory=true \
+ -bvh_construction_render_cost_decrease_weight=0.99 \
+ -vsp_construction_render_cost_decrease_weight=0.99 \
+ -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+
 ########################################################################
 
@@ -138,5 +160,5 @@
 echo "$SCENE $METHOD"
 
-#$PROGRAM $ENVIRONMENT \
+$PROGRAM $ENVIRONMENT \
  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
@@ -148,24 +170,4 @@
   -hierarchy_construction_type=2 \
   -hierarchy_construction_recompute_split_on_repair=true
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-###############################################################
-
- METHOD=gradient-multi
- echo ********" $SCENE $METHOD ************"
-
- $PROGRAM $ENVIRONMENT \
- -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
- -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
- -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
- -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
- -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
- -hierarchy_construction_type=2 \
- -hierarchy_construction_multilevel=true \
- -hierarchy_construction_levels=4 \
- -bvh_construction_render_cost_decrease_weight=0.6 \
- -vsp_construction_render_cost_decrease_weight=0.6 \
- -hierarchy_construction_recompute_split_on_repair=true
 
 sh movefiles.sh $LOG_PREFIX-$METHOD
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1664)
@@ -957,5 +957,5 @@
 {
 	// always try to load the kd tree
-	cout << "loading kd tree file " << internKdTree << " ... ";
+	cout << "loading kd tree file " << internKdTree << " ... " << endl;
 
 	if (!LoadKdTree(internKdTree))
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1664)
@@ -1086,5 +1086,4 @@
 	float mEpsilon;
 
-
 	/// subdivision stats output file
 	ofstream  mSubdivisionStats;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1664)
@@ -25,8 +25,5 @@
 #define PROBABILIY_IS_BV_VOLUME 1
 #define USE_FIXEDPOINT_T 0
-
 #define USE_VOLUMES_FOR_HEURISTICS 1
-
-#define CONSIDER_MEMORY 1
 
 int BvhNode::sMailId = 10000; //2147483647;
@@ -429,8 +426,5 @@
 			
 		// create new interior node and two leaf node
-		currentNode = SubdivideNode(
-			*sc, 
-			tFrontData, 
-			tBackData);
+		currentNode = SubdivideNode(*sc, tFrontData, tBackData);
 	
 		// decrease the weighted average cost of the subdivisoin
@@ -457,4 +451,5 @@
 		tBackData.mNode->SetSubdivisionCandidate(backCandidate);
 
+		//cout << "f: " << frontCandidate->GetPriority() << " b: " << backCandidate->GetPriority() << endl;
 		tQueue.Push(frontCandidate);
 		tQueue.Push(backCandidate);
@@ -466,5 +461,5 @@
 	if (currentNode->IsLeaf())
 	{
-		//////////////////////////////////////
+		/////////////////////
 		//-- store additional info
 		EvaluateLeafStats(tData);
@@ -530,7 +525,6 @@
 #endif
 
-#if 1
 	float priority;
-	
+
 	if (mHierarchyManager->GetViewSpaceSubdivisionType() == 
 		HierarchyManager::NO_VIEWSPACE_SUBDIV)
@@ -551,30 +545,30 @@
 		// take render cost of node into account 
 		// otherwise danger of being stuck in a local minimum!!
-		#if CONSIDER_MEMORY
-			const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
-		#else
-			const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-		#endif
-	}
-
-#else
-	const float priority = (float)-splitCandidate.mParentData.mDepth;
-#endif
+		if (mHierarchyManager->mConsiderMemory)
+		{
+			//cout << "here7 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl;
+			//priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();// / mBvhStats.Leaves();
+			priority = renderCostDecr / ((float)splitCandidate.GetPvsEntriesIncr() + 1.0f);
+		}
+		else
+		{
+			priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+		}
+	}
+
+  	// compute global decrease in render cost
+	splitCandidate.SetPriority(priority);
+}
+
+
+float BvHierarchy::EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const
+{
+	BvhLeaf *leaf = splitCandidate.mParentData.mNode;
+
+	const float oldRenderCost = EvalRenderCost(leaf->mObjects);
 
 	// compute global decrease in render cost
-	splitCandidate.SetPriority(priority);
-}
-
-
-float BvHierarchy::EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const
-{
-	BvhLeaf *leaf = splitCandidate.mParentData.mNode;
-
-	const float oldRenderCost = EvalRenderCost(leaf->mObjects);
-
-	// compute global decrease in render cost
-	const float newRenderCost = 
-		EvalRenderCost(splitCandidate.mFrontObjects) +
-		EvalRenderCost(splitCandidate.mBackObjects);
+	const float newRenderCost = EvalRenderCost(splitCandidate.mFrontObjects) +
+								EvalRenderCost(splitCandidate.mBackObjects);
 
 	const float renderCostDecr = oldRenderCost - newRenderCost;
@@ -586,17 +580,21 @@
 #endif
 
-#if 1
 	// take render cost of node into account 
 	// otherwise danger of being stuck in a local minimum!!
 	const float factor = mRenderCostDecreaseWeight;
+	
+	float priority;
+
 	// $$ matt temp
-#if CONSIDER_MEMORY
-	const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
-#else
-	const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-#endif
-#else
-	const float priority = (float)-splitCandidate.mParentData.mDepth;
-#endif
+	if (mHierarchyManager->mConsiderMemory)
+	{
+		//cout << "here5 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl;
+		//const float priority = factor * renderCostDecr - (1.0f - factor) * (float)splitCandidate.GetPvsEntriesIncr();
+		priority = renderCostDecr / ((float)splitCandidate.GetPvsEntriesIncr() + 1.0f);
+	}
+	else
+	{
+		priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+	}
 
 	return priority;
@@ -620,5 +618,5 @@
 			|| ((int)data.mNode->mObjects.size() <= mTermMinObjects)
 			//|| (data.mProbability <= mTermMinProbability)
-			//|| (data.mNumRays <= mTermMinRays)
+			|| (data.mNumRays <= mTermMinRays)
 		 );
 }
@@ -952,7 +950,8 @@
 	cout << "\n\nobjects=(" << (int)objectsBack.size() << "," << (int)objectsFront.size() << " of " 
 		 << (int)tData.mNode->mObjects.size() << ")\t area=(" 
-		 << areaLeft << "," << areaRight << ")" << endl;
-	cout << "cost= " << minSum << endl;
+		 << areaLeft << "," << areaRight << ")" << endl
+		 << "cost= " << minSum << endl;
 #endif
+
   return ratio;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1664)
@@ -418,5 +418,6 @@
 		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet)
 		{
-			BvhNode *n = sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet);
+			BvhNode *n = 
+				sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet);
 			// local or global termination criteria failed
 			return !n->IsLeaf();		
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1664)
@@ -28,5 +28,4 @@
 
 #define USE_FIXEDPOINT_T 0
-#define CONSIDER_MEMORY 1
 
 /////////////
@@ -819,17 +818,20 @@
 	splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr);
 
-#if 0
-	const float priority = (float)-splitCandidate.mParentData.mDepth;
-#else
 	// take render cost of node into account 
 	// otherwise danger of being stuck in a local minimum!!
 	const float factor = mRenderCostDecreaseWeight;
 
-#if CONSIDER_MEMORY
-	const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
-#else
-	const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-#endif
-#endif
+	float priority;
+
+	if (mHierarchyManager->mConsiderMemory)
+	{
+		//cout << "here4 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl;
+		//const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
+		priority = renderCostDecr / ((float)splitCandidate.GetPvsEntriesIncr() +  + 1.0f);
+	}
+	else
+	{
+		priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+	}
 	
 	splitCandidate.SetPriority(priority);
@@ -845,18 +847,21 @@
 														oldRenderCost);
     
-#if 0
-	const float priority = (float)-splitCandidate.mParentData.mDepth;
-#else
 	// take render cost of node into account 
 	// otherwise danger of being stuck in a local minimum!!
 	const float factor = mRenderCostDecreaseWeight;
-#if CONSIDER_MEMORY
-	const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
-#else
-	const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
-#endif
-
-#endif
-	
+
+	float priority;
+
+	if (mHierarchyManager->mConsiderMemory)
+	{
+		//cout << "here2 rc: " << factor * renderCostDecr << " pvs: " << (1.0f - factor) * splitCandidate.GetPvsEntriesIncr() << endl; 
+		//const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
+		priority = renderCostDecr / ((float)splitCandidate.GetPvsEntriesIncr() + 1.0f);
+	}
+	else
+	{
+		priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+	}
+
 	return priority;
 }
@@ -917,8 +922,5 @@
 
 	//-- subdivide rays
-	SplitRays(splitPlane,
-			  *tData.mRays,
-			  *frontData.mRays,
-			  *backData.mRays);
+	SplitRays(splitPlane, *tData.mRays, *frontData.mRays, *backData.mRays);
 
 	//-- compute pvs
@@ -946,5 +948,5 @@
 	// two more leaves per split
 	mVspStats.nodes += 2;
-	/// and a new split
+	// and a new split
 	++ mVspStats.splits[splitPlane.mAxis];
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1663)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1664)
@@ -428,5 +428,6 @@
 			vspPriority = viewSpaceQueue.Top()->GetPriority();
 
-			if (mConsiderMemory)
+			// rather take this into account directly when computing priority
+			if (0 && mConsiderMemory)
 				vspPriority /= ((float)viewSpaceQueue.Top()->GetPvsEntriesIncr() + Limits::Small);
 		}
@@ -436,11 +437,12 @@
 		}
 
-		float ospPriority = 0;
+		float ospPriority;
 		
 		if (!objectSpaceQueue.Empty())
 		{
 			ospPriority = objectSpaceQueue.Top()->GetPriority();
-		
-			if (mConsiderMemory)
+			
+			// rather take this into account directly when computing priority
+			if (0 && mConsiderMemory)
 				ospPriority /= ((float)objectSpaceQueue.Top()->GetPvsEntriesIncr() + Limits::Small);
 		}
@@ -516,5 +518,7 @@
 	mHierarchyStats.Reset();
 	mHierarchyStats.Start();
-	mHierarchyStats.mNodes = 2; // two nodes for view space and object space
+
+	// two nodes for view space and object space
+	mHierarchyStats.mNodes = 2; 
 	mHierarchyStats.mPvsEntries = 1;
 	mHierarchyStats.mMemory = sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f);
