Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1687)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1703)
@@ -20,5 +20,5 @@
 #SCENE=vienna
 
-LOG_PREFIX=../scripts/tests/i3d/$SCENE
+LOG_PREFIX=../scripts/tests/i3d/$SCENE-heur
 
 ENVIRONMENT=$SCENE.env
@@ -61,5 +61,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 \
@@ -78,10 +78,10 @@
 
 ############################################################################
-NODES=1000
+OBJ_SPLITS=3000
 
-  METHOD=sequential-$NODES
+  METHOD=sequential-$OBJ_SPLITS
   echo "$SCENE $METHOD"
 
-# $PROGRAM $ENVIRONMENT \
+ $PROGRAM $ENVIRONMENT \
   -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
   -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
@@ -90,16 +90,15 @@
   -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
   -hierarchy_construction_type=0 \
-  -bvh_term_max_leaves=$NODES
+  -bvh_term_max_leaves=$OBJ_SPLITS
 
 sh movefiles.sh $LOG_PREFIX-$METHOD
 
 ############################################################################
+OBJ_SPLITS=2000
 
-NODES=10000
-
-  METHOD=sequential-$NODES
+  METHOD=sequential-$OBJ_SPLITS
   echo "$SCENE $METHOD"
 
- #$PROGRAM $ENVIRONMENT \
+ $PROGRAM $ENVIRONMENT \
   -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
   -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
@@ -108,26 +107,22 @@
   -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
   -hierarchy_construction_type=0 \
-  -bvh_term_max_leaves=$NODES
+  -bvh_term_max_leaves=$OBJ_SPLITS
 
 sh movefiles.sh $LOG_PREFIX-$METHOD
 
+############################################################################
+OBJ_SPLITS=1000
 
-########################################################################
+  METHOD=sequential-$OBJ_SPLITS
+  echo "$SCENE $METHOD"
 
-METHOD=gradient_simplesplit
-echo "$SCENE $METHOD"
-
-#$PROGRAM $ENVIRONMENT \
- -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
- -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+ $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 \
-  -bvh_use_sah=true \
-  -vsp_use_cost_heuristics=true \
   -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
-  -hierarchy_construction_type=2 \
-  -hierarchy_construction_recompute_split_on_repair=true
+  -hierarchy_construction_type=0 \
+  -bvh_term_max_leaves=$OBJ_SPLITS
 
 sh movefiles.sh $LOG_PREFIX-$METHOD
-
-
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1692)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1703)
@@ -409,5 +409,5 @@
 	/** Evaluates the render cost of a view cell.
 	*/
-	float EvalRenderCost(Intersectable *obj) const;
+	static float EvalRenderCost(Intersectable *obj);
    
 	/** Sets pvs size of view cell as a scalar. Used when storing pvs only in the leaves
@@ -711,9 +711,11 @@
 	bool mViewCellsFinished;
 	bool mEvaluateViewCells;
-	int mRenderCostEvaluationType;
 
 	/// if pvs should be exported with view cells
 	bool mExportPvs;
 
+	static int sRenderCostEvaluationType;
+
+	/// if view cells geometry should be used from other sources
 	bool mUsePredefinedViewCells;
 };
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1698)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1703)
@@ -801,9 +801,12 @@
 	}
 
-	const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects);
-	const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack);
-
-	const float ratio = newRenderCost / oldRenderCost;
-	return ratio;
+	float heur = 0;
+
+	if (tData.mNode->GetBoundingBox().Size().DrivingAxis() == axis)
+	{
+		heur = -1;
+	}
+
+	return heur;
 }
 #endif
@@ -1111,8 +1114,12 @@
 #ifdef _DEBUG
 	Debug << "\n§§§§ bvh eval const decrease §§§§" << endl
-		  << "back pvs: " << (int)objectsBack.size() << " front pvs: " << (int)objectsFront.size() << " total pvs: " << nTotalObjects << endl 
-		  << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl
-		  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl
-		  << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl;
+		  << "back pvs: " << (int)objectsBack.size() << " front pvs: " 
+		  << (int)objectsFront.size() << " total pvs: " << nTotalObjects << endl 
+		  << "back p: " << volBack / viewSpaceVol << " front p " 
+		  << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl
+		  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " 
+		  << newRenderCost / viewSpaceVol << endl
+		  << "render cost decrease: " 
+		  << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl;
 #endif
 
@@ -1302,5 +1309,8 @@
 					//-- heuristics using objects weighted by view cells volume
 					nCostRatio[axis] =
-						EvalLocalCostHeuristics(tData, axis, nFrontObjects[axis], nBackObjects[axis]);
+						EvalLocalCostHeuristics(tData, 
+												axis, 
+												nFrontObjects[axis], 
+												nBackObjects[axis]);
 				}
 				else
@@ -1308,6 +1318,8 @@
 					//////////////////
 					//-- view cells not constructed yet	=> use surface area heuristic			
-					nCostRatio[axis] =
-						EvalSah(tData, axis, nFrontObjects[axis], nBackObjects[axis]);
+					nCostRatio[axis] = EvalSah(tData, 
+											   axis, 
+											   nFrontObjects[axis], 
+											   nBackObjects[axis]);
 				}
 			}
@@ -1319,12 +1331,8 @@
 			}
 
-			if (bestAxis == -1)
+			if ((bestAxis == -1) || (nCostRatio[axis] < nCostRatio[bestAxis]))
 			{
 				bestAxis = axis;
 			}
-			else if (nCostRatio[axis] < nCostRatio[bestAxis])
-			{
-				bestAxis = axis;
-			} 
 		}
 	}
@@ -1336,5 +1344,5 @@
 	backObjects = nBackObjects[bestAxis];
 
-	//Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;
+	//cout << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;
 	return nCostRatio[bestAxis];
 }
@@ -1419,5 +1427,5 @@
 
 
-float BvHierarchy::EvalAbsCost(const ObjectContainer &objects) const
+float BvHierarchy::EvalAbsCost(const ObjectContainer &objects)// const
 {
 #if USE_BETTER_RENDERCOST_EST
@@ -1426,5 +1434,5 @@
 	for (oit = objects.begin(); oit != oit_end; ++ oit)
 	{
-		objRenderCost += mViewCellsManager->GetRendercost(*oit);
+		objRenderCost += ViewCellsManager::GetRendercost(*oit);
 	}
 #else
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1701)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1703)
@@ -33,4 +33,6 @@
 #define KD_PVS_AREA (5*1e-4f)
 
+
+
 namespace GtpVisibilityPreprocessor {
 
@@ -38,5 +40,8 @@
 // HACK
 const static bool SAMPLE_AFTER_SUBDIVISION = true;
-const static bool CLAMP_TO_BOX = true;
+const static bool CLAMP_TO_BOX = false;
+
+int ViewCellsManager::sRenderCostEvaluationType = 0;
+
 
 template <typename T> class myless
@@ -101,5 +106,5 @@
 	Environment::GetSingleton()->GetIntValue("ViewCells.Filter.maxSize", mMaxFilterSize);
 	Environment::GetSingleton()->GetFloatValue("ViewCells.Filter.width", mFilterWidth);
-	Environment::GetSingleton()->GetIntValue("ViewCells.renderCostEvaluationType", mRenderCostEvaluationType);
+	Environment::GetSingleton()->GetIntValue("ViewCells.renderCostEvaluationType", sRenderCostEvaluationType);
 
 	Environment::GetSingleton()->GetBoolValue("ViewCells.exportBboxesForPvs", mExportBboxesForPvs);
@@ -179,9 +184,9 @@
 	if (strcmp(buf, "perobject") == 0)
 	{
-		mRenderCostEvaluationType = ViewCellsManager::PER_OBJECT;
-	}
-	else if (strcmp(buf, "directional") == 0)
-	{
-		mRenderCostEvaluationType = ViewCellsManager::PER_TRIANGLE;
+		sRenderCostEvaluationType = ViewCellsManager::PER_OBJECT;
+	}
+	else if (strcmp(buf, "pertriangle") == 0)
+	{
+		sRenderCostEvaluationType = ViewCellsManager::PER_TRIANGLE;
 	}
 	else 
@@ -224,5 +229,5 @@
 	Debug << "evaluate view cells: " << mEvaluateViewCells << endl;
 	Debug << "sampling type: " << mSamplingType << endl;
-	Debug << "render cost evaluation type: " << mRenderCostEvaluationType << endl;
+	Debug << "render cost evaluation type: " << sRenderCostEvaluationType << endl;
 	Debug << "evaluation sampling type: " << mEvaluationSamplingType << endl;
 	Debug << "show visualization: " << mShowVisualization << endl;
@@ -1091,14 +1096,13 @@
 
 
-float ViewCellsManager::EvalRenderCost(Intersectable *obj) const
-{
-	switch (mRenderCostEvaluationType)
+float ViewCellsManager::EvalRenderCost(Intersectable *obj) //const
+{
+	switch (sRenderCostEvaluationType)
 	{
 	case PER_OBJECT:
-		//cout << "perobject" << endl;
 		return 1.0f;
 	
 	case PER_TRIANGLE:
-		{//cout << "pertriangle" << endl;
+		{
 			return (float)obj->NumberOfFaces();
 		}
@@ -5187,4 +5191,5 @@
 		AxisAlignedBox3 bbox = mViewSpaceBox;
 		bbox.Scale(Vector3(0.5, 1, 0.5));
+
 		if (CLAMP_TO_BOX)
 		{	
@@ -5204,5 +5209,6 @@
 		}
 
-		mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL, false);
+		mHierarchyManager->ExportObjectSpaceHierarchy(exporter, 
+				objects, CLAMP_TO_BOX ? &bbox : NULL, false);
 		ExportViewCellsForViz(exporter, CLAMP_TO_BOX ? &bbox : NULL, GetClipPlane());
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1698)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1703)
@@ -609,5 +609,5 @@
 	/////////////////////////////////
 
-	float EvalAbsCost(const ObjectContainer &objects) const;
+	static float EvalAbsCost(const ObjectContainer &objects);
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1701)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1703)
@@ -106,5 +106,4 @@
 	{
 		string currentFile = *sit;
-		//cout << "here6 " << currentFile << endl;
 		string strippedFilename;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1586)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1703)
@@ -76,6 +76,6 @@
 
 
-/** Returns the the number of different objects in the leaves of the node.
-	We eliminate already accounted kd nodes and objects using mailboxing. 
+/** Returns the the number of new (unmailed) objects in the leaves of the node.
+	We eliminate already accounted bvh nodes and objects using mailboxing. 
 */
 static int EvalBvhNodeContribution(BvhIntersectable *bvhobj)
@@ -115,5 +115,5 @@
 
 				// add #objects exclusivly in this node
-				pvs += (int)leaf->mObjects.size();
+				pvs += BvHierarchy::EvalAbsCost(leaf->mObjects);
 			}
 			else // traverse tree
