Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1663)
@@ -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
@@ -64,5 +64,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 \
@@ -84,5 +84,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 \
@@ -102,5 +102,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 \
@@ -138,5 +138,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 \
@@ -153,17 +153,19 @@
 ###############################################################
 
-# METHOD=gradient-multi
-# echo "$SCENE $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 \
-# -hierarchy_construction_recompute_split_on_repair=true
+ $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
@@ -173,5 +175,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 \
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1663)
@@ -2171,5 +2171,5 @@
 				optFloat,
 				"vsp_construction_render_cost_decrease_weight=",
-				"0.99");
+				"1.0");
 
 	RegisterOption("VspTree.Termination.maxDepth",
@@ -2459,5 +2459,5 @@
 				   optFloat,
 				   "bvh_construction_render_cost_decrease_weight=",
-				   "0.99");
+				   "1.0");
 	
 	RegisterOption("BvHierarchy.Construction.useGlobalSorting",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1663)
@@ -387,4 +387,5 @@
 	*/
 	int GetObjectSpaceSubdivisionLeaves() const;
+	int GetObjectSpaceSubdivisionNodes() const;
 
 	/** Construct object space partition interleaved with view space partition.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1663)
@@ -462,5 +462,8 @@
 				sVspTree->EvalSubdivisionCandidate(*this);	
 			else
+			{
+				mPvsEntriesIncr = sVspTree->EvalPvsEntriesIncr(*this);
 				mPriority = sVspTree->EvalPriority(*this);
+			}
 		}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1663)
@@ -28,4 +28,5 @@
 #define USE_VOLUMES_FOR_HEURISTICS 1
 
+#define CONSIDER_MEMORY 1
 
 int BvhNode::sMailId = 10000; //2147483647;
@@ -502,7 +503,8 @@
 	const bool maxCostRatioViolated = mTermMaxCostRatio < ratio;
 
+	const int previousMisses = splitCandidate.mParentData.mMaxCostMisses;
+
 	splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 
-		splitCandidate.mParentData.mMaxCostMisses + 1 :
-		splitCandidate.mParentData.mMaxCostMisses);
+		previousMisses + 1 : previousMisses);
 
 	const float oldProp = EvalViewCellsVolume(leaf->mObjects);
@@ -516,4 +518,10 @@
 	const float renderCostDecr = oldRenderCost - newRenderCost;
 	
+	splitCandidate.SetRenderCostDecrease(renderCostDecr);
+
+	// increase in pvs entries
+	const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate);
+	splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr);
+
 #ifdef _DEBUG
 	Debug << "old render cost: " << oldRenderCost << endl;
@@ -539,8 +547,13 @@
 	else
 	{
+		const float factor = mRenderCostDecreaseWeight;
+		
 		// take render cost of node into account 
 		// otherwise danger of being stuck in a local minimum!!
-		priority = mRenderCostDecreaseWeight * renderCostDecr + 
-				   (1.0f - mRenderCostDecreaseWeight) * oldRenderCost;
+		#if CONSIDER_MEMORY
+			const float priority = factor * renderCostDecr - (1.0f - factor) * splitCandidate.GetPvsEntriesIncr();
+		#else
+			const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+		#endif
 	}
 
@@ -548,10 +561,4 @@
 	const float priority = (float)-splitCandidate.mParentData.mDepth;
 #endif
-
-	splitCandidate.SetRenderCostDecrease(renderCostDecr);
-
-	// increase in pvs entries
-	const int pvsEntriesIncr = EvalPvsEntriesIncr(splitCandidate);
-	splitCandidate.SetPvsEntriesIncr(pvsEntriesIncr);
 
 	// compute global decrease in render cost
@@ -583,5 +590,10 @@
 	// otherwise danger of being stuck in a local minimum!!
 	const float factor = mRenderCostDecreaseWeight;
+	// $$ 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;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1663)
@@ -406,7 +406,12 @@
 		{
 			if (computeSplitplane)
+			{
 				sBvHierarchy->EvalSubdivisionCandidate(*this);	
+			}
 			else
+			{
+				mPvsEntriesIncr = sBvHierarchy->EvalPvsEntriesIncr(*this);
 				mPriority = sBvHierarchy->EvalPriority(*this);
+			}
 		}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1663)
@@ -28,5 +28,5 @@
 
 #define USE_FIXEDPOINT_T 0
-
+#define CONSIDER_MEMORY 1
 
 /////////////
@@ -825,5 +825,10 @@
 	// 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
 	
@@ -846,5 +851,10 @@
 	// 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
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1663)
@@ -790,4 +790,20 @@
 
 
+int HierarchyManager::GetObjectSpaceSubdivisionNodes() const
+{
+	int maxLeaves = 0;
+
+	if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV)
+	{
+		maxLeaves = mOspTree->mOspStats.nodes;
+	}
+	else if (mObjectSpaceSubdivisionType == BV_BASED_OBJ_SUBDIV)
+	{
+		maxLeaves = mBvHierarchy->mBvhStats.nodes;
+	}
+
+	return maxLeaves;
+}
+
 bool HierarchyManager::StartObjectSpaceSubdivision() const
 {
@@ -954,15 +970,19 @@
 			cout << "\nreseting bv hierarchy" << endl;
 			Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl;
+				
+			// rather use this: remove previous nodes and add the two new ones
+			//mHierarchyStats.mNodes -= mBvHierarchy->mBvhStats.nodes + 1;
+			mHierarchyStats.mNodes = mVspTree->mVspStats.nodes;
 			
+			// create root
 			mBvHierarchy->Initialise(objects);
 	
-			// rather use this: remove previous nodes and add the two new ones
-			mHierarchyStats.mNodes -= mBvHierarchy->mBvhStats.nodes + 1;
+			firstCandidate = mBvHierarchy->Reset(sampleRays, objects);
+
+			mHierarchyStats.mTotalCost = mBvHierarchy->mTotalCost;
 			
-			firstCandidate = mBvHierarchy->Reset(sampleRays, objects);
-
-			mHierarchyStats.mTotalCost = mBvHierarchy->mTotalCost;
 			//mHierarchyStats.mPvsEntries -= mBvHierarchy->mPvsEntries + 1;
 			mHierarchyStats.mPvsEntries = mBvHierarchy->CountViewCells(objects);
+
 			mHierarchyStats.mMemory = mHierarchyStats.mPvsEntries *
 				sizeof(PvsData) + sizeof(Intersectable *) / (1024.0f * 1024.0f);
@@ -1003,5 +1023,5 @@
 	
 	//-- reset stats
-    mHierarchyStats.mNodes = -mVspTree->mVspStats.nodes + 1;
+    mHierarchyStats.mNodes = GetObjectSpaceSubdivisionNodes();//-mVspTree->mVspStats.nodes + 1;
 	
 	SubdivisionCandidate *vsc = PrepareViewSpaceSubdivision(sampleRays, objects);
