Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1680)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1687)
@@ -6,7 +6,5 @@
 #TARGET=debug
 TARGET=release
-
 PROGRAM=../bin/$TARGET/Preprocessor.exe
-
 echo "starting $TARGET mode"
 
@@ -29,6 +27,6 @@
 
 
- METHOD=interleaved_full
- echo "$SCENE $METHOD"
+# METHOD=interleaved
+# echo "$SCENE $METHOD"
 
 # $PROGRAM $ENVIRONMENT \
@@ -41,10 +39,10 @@
 # -hierarchy_construction_recompute_split_on_repair=true
 
-sh movefiles.sh $LOG_PREFIX-$METHOD
+#sh movefiles.sh $LOG_PREFIX-$METHOD
 
 ###########################################################################
 
- METHOD=interleaved
- echo "$SCENE $METHOD"
+# METHOD=interleaved-norepair
+# echo "$SCENE $METHOD"
 
 # $PROGRAM $ENVIRONMENT \
@@ -57,9 +55,8 @@
 # -hierarchy_construction_recompute_split_on_repair=false
 
-sh movefiles.sh $LOG_PREFIX-$METHOD
+#sh movefiles.sh $LOG_PREFIX-$METHOD
 
 ##################################################################################
-MEMCONST=1.0
- METHOD=gradient-mem2-$MEMCONST
+ METHOD=gradient
  echo "$SCENE $METHOD"
 
@@ -75,5 +72,4 @@
  -vsp_construction_render_cost_decrease_weight=0.99 \
   -hierarchy_construction_multilevel=false \
-  -hierarchy_term_memory_const=$MEMCONST \
   -hierarchy_construction_recompute_split_on_repair=true
 
@@ -81,50 +77,6 @@
 
 
-##################################################################################
-MEMCONST=0.5
- METHOD=gradient-mem2-$MEMCONST
- 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_consider_memory2=true \
- -bvh_construction_render_cost_decrease_weight=0.99 \
- -vsp_construction_render_cost_decrease_weight=0.99 \
-  -hierarchy_construction_multilevel=false \
-  -hierarchy_term_memory_const=$MEMCONST \
-  -hierarchy_construction_recompute_split_on_repair=true
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-##################################################################################
-MEMCONST=0.2
- METHOD=gradient-mem2-$MEMCONST
- 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_consider_memory2=true \
- -bvh_construction_render_cost_decrease_weight=0.99 \
- -vsp_construction_render_cost_decrease_weight=0.99 \
-  -hierarchy_construction_multilevel=false \
-  -hierarchy_term_memory_const=$MEMCONST \
-  -hierarchy_construction_recompute_split_on_repair=true
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
-
 ############################################################################
-NODES=10000
+NODES=1000
 
   METHOD=sequential-$NODES
@@ -144,5 +96,5 @@
 ############################################################################
 
-NODES=70000
+NODES=10000
 
   METHOD=sequential-$NODES
@@ -157,111 +109,4 @@
   -hierarchy_construction_type=0 \
   -bvh_term_max_leaves=$NODES
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
-############################################################################
-
-NODES=30000
-
-  METHOD=sequential-$NODES
-  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=0 \
-  -bvh_term_max_leaves=$NODES
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
-############################################################################
-
-NODES=100000
-
-  METHOD=sequential-$NODES
-  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=0 \
-   -bvh_term_max_leaves=$NODES
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
-##################################################################################
-MEMCONST=1.0
- METHOD=gradient-multi-$MEMCONST
- 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_consider_memory2=true \
- -bvh_construction_render_cost_decrease_weight=0.99 \
- -vsp_construction_render_cost_decrease_weight=0.99 \
-  -hierarchy_construction_multilevel=true \
- -hierarchy_construction_levels=4 \
-  -hierarchy_term_memory_const=$MEMCONST \
-  -hierarchy_construction_recompute_split_on_repair=true
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
-###############################################################
-MEMCONST=1.0
- METHOD=gradient-$MEMCONST
- 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 \
- -hierarchy_term_memory_const=$MEMCONST \
- -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
-
-#########################################################################
-
-MEMCONST=0.1
- METHOD=gradient-$MEMCONST
- 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 \
- -hierarchy_term_memory_const=$MEMCONST \
- -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
@@ -286,23 +131,3 @@
 sh movefiles.sh $LOG_PREFIX-$METHOD
 
-##########################################################
- METHOD=gradient-500
- 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_consider_memory=false \
-  -hierarchy_construction_min_steps_same_type=500 \
-  -hierarchy_construction_multilevel=false \
-  -hierarchy_construction_recompute_split_on_repair=true
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
-############################################################################
-
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1686)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1687)
@@ -415,7 +415,7 @@
 	backData.mMaxCostMisses = sc.GetMaxCostMisses();
 	
-	//node->mRenderCostDecr = sc.GetRenderCostDecrease();
-	//node->mPvsEntriesIncr = sc.GetPvsEntriesIncr();
-
+	// set the time stamp so the order of traversal can be reconstructed
+	node->mTimeStamp = mHierarchyManager->mTimeStamp ++;
+		
 	// assign the objects in sorted order
 	if (mUseGlobalSorting)
@@ -449,9 +449,4 @@
 		currentNode = SubdivideNode(*sc, tFrontData, tBackData);
 	
-		// set the time stamp so the order of traversal can be reconstructed
-		currentNode->mTimeStamp = mHierarchyManager->mTimeStamp ++;
-		//currentNode->mRenderCostDecr = sc.GetRenderCostDecrease();
-		//currentNode->mPvsEntriesIncr = sc.GetPvsEntriesIncr();
-
 		// decrease the weighted average cost of the subdivisoin
 		mTotalCost -= sc->GetRenderCostDecrease();
@@ -899,5 +894,5 @@
 			// (as we are not sampling volumetric visibility,
 			// this should provide better heuristics
-			const float area = //obox.SurfaceArea();
+			const float area = obj->GetArea();//obox.SurfaceArea();
 
 			al += area;
@@ -2141,7 +2136,7 @@
 		currentNode = SubdivideNode(*sc, tFrontData, tBackData);
 	
-		currentNode->mRenderCostDecr = oldNode->mRenderCostDecr + sc->GetRenderCostDecrease();
-		currentNode->mPvsEntriesIncr = oldNode->mPvsEntriesIncr + sc->GetPvsEntriesIncr();
-
+		oldNode->mRenderCostDecr += sc->GetRenderCostDecrease();
+		oldNode->mPvsEntriesIncr += sc->GetPvsEntriesIncr();
+cout << "here5" << endl;
 		///////////////////////////
 		//-- push the new split candidates on the queue
@@ -2151,5 +2146,5 @@
 
 		frontCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp);
-		backCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp);
+		backCandidate->SetPriority((float)-oldInterior->GetBack()->mTimeStamp);
 
 		frontCandidate->mEvaluationHack = oldInterior->GetFront();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1686)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1687)
@@ -721,10 +721,4 @@
 		tBackData.mMaxCostMisses = maxCostMisses;
 			
-		//newNode->mRenderCostDecr = sc->GetRenderCostDecrease();
-		//newNode->mPvsEntriesIncr = sc->GetPvsEntriesIncr();
-
-		// set the time stamp so the order of traversal can be reconstructed
-		newNode->mTimeStamp = mHierarchyManager->mTimeStamp ++;
-	
 		mTotalCost -= sc->GetRenderCostDecrease();
 		mTotalPvsSize += tFrontData.mPvs + tBackData.mPvs - tData.mPvs;
@@ -970,4 +964,7 @@
 	CreateViewCell(frontData, false);
 	CreateViewCell(backData, false);
+
+	// set the time stamp so the order of traversal can be reconstructed
+	interior->mTimeStamp = mHierarchyManager->mTimeStamp ++;
 
 #if WORK_WITH_VIEWCELL_PVS
@@ -3306,15 +3303,14 @@
 		// create new interior node and two leaf node
 		const AxisAlignedPlane splitPlane = oldInterior->GetPlane();
-		const int maxCostMisses = sc->GetMaxCostMisses();
+		
+		// evaluate the changes in render cost and pvs entries
+		EvalSubdivisionCandidate(*sc, false);
 
 		newNode = SubdivideNode(splitPlane, tData, tFrontData, tBackData);
 	
-		// how often was max cost ratio missed in this branch?
-		tFrontData.mMaxCostMisses = maxCostMisses;
-		tBackData.mMaxCostMisses = maxCostMisses;
-			
-		newNode->mRenderCostDecr = oldNode->mRenderCostDecr + sc->GetRenderCostDecrease();
-		newNode->mPvsEntriesIncr = oldNode->mPvsEntriesIncr + sc->GetPvsEntriesIncr();
-
+		oldNode->mRenderCostDecr += sc->GetRenderCostDecrease();
+		oldNode->mPvsEntriesIncr += sc->GetPvsEntriesIncr();
+cout << "here4" << endl;
+		
 		/////////////
 		//-- evaluate new split candidates for global greedy cost heuristics
@@ -3324,5 +3320,5 @@
 
 		frontCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp);
-		backCandidate->SetPriority((float)-oldInterior->GetFront()->mTimeStamp);
+		backCandidate->SetPriority((float)-oldInterior->GetBack()->mTimeStamp);
 
 		frontCandidate->mEvaluationHack = oldInterior->GetFront();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 1686)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 1687)
@@ -112,56 +112,56 @@
   virtual float GetArea() const {return 0; }
   virtual int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
-  
-	virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
-											 Vector3 &normal,
-											 const Vector3 &viewpoint,
-											 const int maxTries) = 0;
-  
-	virtual ostream &Describe(ostream &s) = 0;
-	
-	virtual int GenerateSilhouetteRays(const int nrays,
-									   const AxisAlignedBox3 &originBox,
-									   const AxisAlignedBox3 &directionBox, VssRayContainer &rays) 
-	{
-		return 0;
-	}
 
-	static bool GreaterCounter(const Intersectable *a,
-							 const Intersectable *b) 
-	{
-		return a->mCounter > b->mCounter;
-	}
+  virtual int GetRandomVisibleSurfacePoint(Vector3 &point,
+	  Vector3 &normal,
+	  const Vector3 &viewpoint,
+	  const int maxTries) = 0;
 
-	static string GetTypeName(Intersectable *obj)
-	{
-		switch(obj->Type())
-		{
-		case MESH_INSTANCE:
-			return "mesh_instance\n";
-		
-		case TRANSFORMED_MESH_INSTANCE:
-			return "transformed_mesh_instance\n";
-			
-		case SPHERE:
-			return "sphere\n";
+  virtual ostream &Describe(ostream &s) = 0;
 
-		case VIEW_CELL:
-			return "view cell\n";
-		
-		case OGRE_MESH_INSTANCE:
-			return "ogre_mesh_instance\n";
+  virtual int GenerateSilhouetteRays(const int nrays,
+	  const AxisAlignedBox3 &originBox,
+	  const AxisAlignedBox3 &directionBox, VssRayContainer &rays) 
+  {
+	  return 0;
+  }
 
-		case KD_INTERSECTABLE:
-			return "kd_intersectable\n";
+  static bool GreaterCounter(const Intersectable *a,
+	  const Intersectable *b) 
+  {
+	  return a->mCounter > b->mCounter;
+  }
 
-		default:
-			return "unknown\n";
-		}
-	}
+  static string GetTypeName(Intersectable *obj)
+  {
+	  switch(obj->Type())
+	  {
+	  case MESH_INSTANCE:
+		  return "mesh_instance\n";
 
-	/** returns normal from the face with the specified index.
-		PROBLEM: Does not fit to all intersectable types (e.g., spheres)
-	*/
-	virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
+	  case TRANSFORMED_MESH_INSTANCE:
+		  return "transformed_mesh_instance\n";
+
+	  case SPHERE:
+		  return "sphere\n";
+
+	  case VIEW_CELL:
+		  return "view cell\n";
+
+	  case OGRE_MESH_INSTANCE:
+		  return "ogre_mesh_instance\n";
+
+	  case KD_INTERSECTABLE:
+		  return "kd_intersectable\n";
+
+	  default:
+		  return "unknown\n";
+	  }
+  }
+
+  /** returns normal from the face with the specified index.
+  PROBLEM: Does not fit to all intersectable types (e.g., spheres)
+  */
+  virtual Vector3 GetNormal(const int idx) const { return Vector3(0, 0, 0); }
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1686)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1687)
@@ -1667,4 +1667,7 @@
 	firstBvh->mEvaluationHack = oldBvhRoot;
 
+	firstVsp->SetPriority((float)-oldVspRoot->mTimeStamp);
+	firstBvh->SetPriority((float)-oldBvhRoot->mTimeStamp);
+
 	tQueue.Push(firstVsp);
 	tQueue.Push(firstBvh);
@@ -1726,14 +1729,28 @@
 		cout << "next candidate: " << nextCandidate->GetPriority() << endl;
 
-		if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE)
+        if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE)
+		{
+			cout << "here8" << endl;
 			mVspTree->SubdivideAndCopy(tQueue, nextCandidate);
+
+			VspNode *oldNode = (VspNode *)nextCandidate->mEvaluationHack;
+			
+			totalRenderCost -= oldNode->mRenderCostDecr;
+			entriesInPvs += oldNode->mPvsEntriesIncr;
+		}
 		else
+		{cout << "here9" << endl;
 			mBvHierarchy->SubdivideAndCopy(tQueue, nextCandidate);
-
-		totalRenderCost -= nextCandidate->GetRenderCostDecrease();
-		entriesInPvs += nextCandidate->GetPvsEntriesIncr();
+			
+			BvhNode *oldNode = (BvhNode *)nextCandidate->mEvaluationHack;
+			
+			totalRenderCost -= oldNode->mRenderCostDecr;
+			entriesInPvs += oldNode->mPvsEntriesIncr;
+		}		
 
 		++ steps;
-		
+		cout << "rc: " << nextCandidate->GetRenderCostDecrease() << endl;
+		cout << "pvs: " << nextCandidate->GetPvsEntriesIncr() << endl;
+
 		const float memoryCost = (float)entriesInPvs * (float)ObjectPvs::GetEntrySize();
 		UpdateStats(stats, steps, totalRenderCost, entriesInPvs, memoryCost, false);
