Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1121)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1129)
@@ -1273,5 +1273,4 @@
 					"view_cells_evaluation_stats_prefix=",
 					"viewCells");
-
 	RegisterOption("ViewCells.Evaluation.histogram",
 					optBool,
@@ -1288,4 +1287,9 @@
 					"view_cells_render_cost_evaluation=",
 					"perobject");
+
+	RegisterOption("ViewCells.Evaluation.countKdPvs",
+					optBool,
+					"view_cells_evaluation_count_kd_pvs=",
+					"false");
 
 	RegisterOption("ViewCells.active",
@@ -2303,7 +2307,7 @@
 			"0.99");
 
-	RegisterOption("OspTree.Evaluation.countKdPvs",
+	RegisterOption("OspTree.Construction.useEqualWeightForHeuristics",
 		optBool,
-		"osp_evaluation_count_kd_pvs=",
+		"osp_construction_use_equal_weight_for_heuristics=",
 		"false");
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1123)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1129)
@@ -2647,5 +2647,6 @@
 OspTree::OspTree():
 mRoot(NULL),
-mTimeStamp(1)
+mTimeStamp(1),
+mUseEqualWeightForHeuristics(false)
 {
 	bool randomize = false;
@@ -2667,6 +2668,5 @@
 	Environment::GetSingleton()->GetFloatValue("OspTree.Termination.minGlobalCostRatio",
 		mTermMinGlobalCostRatio);
-	Environment::GetSingleton()->GetIntValue("OspTree.Termination.mTermGlobalCostMissTolerance);
-
+	
 
 	//-- factors for bsp tree split plane heuristics
@@ -2689,4 +2689,7 @@
 	Environment::GetSingleton()->GetFloatValue("OspTree.Construction.renderCostDecreaseWeight", mRenderCostDecreaseWeight);
 	
+	Environment::GetSingleton()->GetBoolValue("OspTree.Construction.useEqualWeightForHeuristics", mUseEqualWeightForHeuristics);
+
+
 	//-- debug output
 
@@ -2988,15 +2991,16 @@
 	// C = ct_div_ci  + (ol + or)/queries
 	
-	int pvsSize = PrepareHeuristics(node->mObjects);
-	int pvsl = 0, pvsr = pvsSize;
+	float totalVol = PrepareHeuristics(node->mObjects);
+	int voll = 0, volr = totalVol;
   
+	const int totalPvs = (int)node->mObjects.size();
+
 	const float minBox = box.Min(axis);
 	const float maxBox = box.Max(axis);
 
 	const float sizeBox = maxBox - minBox;
-	
-			
+				
 	// if no good split can be found, take mid split
-	position = minBox + 0.5f * sizeBox;
+	int pvsBack = totalPvs / 2;
 	
 	// the relative cost ratio
@@ -3009,18 +3013,16 @@
     float minSum = 1e20f;
 
-	int pvsBack = pvsl;
-	int pvsFront = pvsr;
-
-	float sum = (float)pvsSize * sizeBox;
-float dummy1 = 0;
-float dummy2 = 0;
+	float volBack = voll;
+	float volFront = volr;
+
+	float sum = (float)totalVol * sizeBox;
 
 	vector<SortableEntry>::const_iterator ci, ci_end = mSplitCandidates->end();
-cout << "***********" << endl;
+
+
 	//-- traverse through visibility events
 	for (ci = mSplitCandidates->begin(); ci != ci_end; ++ ci)
 	{
-		int pvslold = pvsl;
-		EvalPvsIncr(*ci, pvsl, pvsr);
+		EvalPvsIncr(*ci, voll, volr);
 
 		cout << "incr: " << ci->mObject->mViewCellPvs.GetSize() << " obj id " 
@@ -3030,8 +3032,9 @@
 		if (((*ci).value >= minBand) && ((*ci).value <= maxBand))
 		{
-			sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value);
-
-			cout << "pos=" << (*ci).value << "\t pvs=(" <<  pvsl << "," 
-				 << pvsr << ")" << "\t cost= " << sum << endl;
+			//sum = costl * ((*ci).value - minBox) + costr * (maxBox - (*ci).value);
+			sum = voll * (*ci).value +volr * (totalPvs - (*ci).value);
+
+			cout << "pos=" << (*ci).value << "\t volt=(" <<  voll << "," 
+				 << volr << ")" << "\t volt= " << sum << endl;
 
 			if (sum < minSum)
@@ -3040,8 +3043,8 @@
 
 				minSum = sum;
-				position = (*ci).value;
+				pvsBack = (*ci).value;
 				
-				pvsBack = pvsl;
-				pvsFront = pvsr;
+				volBack = voll;
+				volFront = volr;
 			}
 		}
@@ -3053,14 +3056,15 @@
 	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
 
-	const float pOverall = sizeBox;
-	const float pBack = position - minBox;
-	const float pFront = maxBox - position;
-
-	const float penaltyOld = EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit);
-    const float penaltyFront = EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);
-	const float penaltyBack = EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);
+	const float pOverall = totalVol;
+	const float pBack = volBack;
+	const float pFront = volFront;
+
+	const float penaltyOld = totalPvs;//EvalPvsPenalty(pvsSize, lowerPvsLimit, upperPvsLimit);
+    const float penaltyFront = totalPvs - pvsBack;//EvalPvsPenalty(pvsFront, lowerPvsLimit, upperPvsLimit);
+	const float penaltyBack = pvsBack;//EvalPvsPenalty(pvsBack, lowerPvsLimit, upperPvsLimit);
 	
 	const float oldRenderCost = penaltyOld * pOverall + Limits::Small;
 	const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack;
+
 
 	if (splitPlaneFound)
@@ -3072,5 +3076,5 @@
 	Debug << "axis=" << axis << " costRatio=" << ratio << " pos=" 
 		  << position << " t=" << (position - minBox) / (maxBox - minBox)
-	      << "\t pb=(" << pvsBack << ")\t pf=(" << pvsFront << ")" << endl;
+	      << "\t pb=(" << volBack << ")\t pf=(" << volFront << ")" << endl;
 
 	return ratio;
@@ -3097,14 +3101,16 @@
 
 	// insert all queries 
-	for(mi = node->mObjects.begin(); mi != mi_end; ++ mi) 
+	int pvs = 0;
+	for(mi = node->mObjects.begin(); mi != mi_end; ++ mi, ++ pvs) 
 	{
 		AxisAlignedBox3 box = (*mi)->GetBox();
 
+		// only first event should be sufficient
+		// but maybe introduces problems with symmetry ...
 		mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MIN,
-					box.Min(axis), *mi));
-
-
-		mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MAX,
-					box.Max(axis), *mi));
+					pvs, *mi));
+
+		//mSplitCandidates->push_back(SortableEntry(SortableEntry::BOX_MAX,
+		//			pvs, *mi));
 	}
 
@@ -3113,11 +3119,19 @@
 
 
-int OspTree::PrepareHeuristics(Intersectable *object)
-{
-	if (mUseSah)
+float OspTree::PrepareHeuristics(Intersectable *object)
+{
+	if (mUseEqualWeightForHeuristics)
+	{	
+		// like sah: each object has weight one for heuristics
 		return 1;
+	}
 	else
-		// the priotity of the object is the number of view cell pvs entries of the object
-		return object->mViewCellPvs.GetSize();
+	{
+		// the priotity of the object is the sum of view cells 
+		// weighted per their volume
+		float vol = 0;
+		return vol;
+		//return object->mViewCellPvs.GetSize();
+	}
 }
 
@@ -3129,21 +3143,21 @@
 
 
-int OspTree::PrepareHeuristics(const ObjectContainer &objects)
+float OspTree::PrepareHeuristics(const ObjectContainer &objects)
 {	
 	Intersectable::NewMail();
 	ViewCell::NewMail();
 
-	int pvsSize = 0;
+	float vol = 0;
 
 	ObjectContainer::const_iterator oit, oit_end = objects.end();
 
-	//-- set all pvs as belonging to the front pvs
+	//-- set all view cell volume as belonging to front volume
 	for (oit = objects.begin(); oit != oit_end; ++ oit)
 	{
 		Intersectable *obj = *oit;
-		pvsSize += PrepareHeuristics(obj);		
-	}
-
-	return pvsSize;
+ 		vol += PrepareHeuristics(obj);		
+	}
+
+	return vol;
 }
 
@@ -3184,5 +3198,5 @@
 void OspTree::RemoveContriFromPvs(Intersectable *object, int &pvs) const
 {
-	if (mUseSah)
+	if (mUseEqualWeightForHeuristics)
 		-- pvs;
 	else
@@ -3194,5 +3208,5 @@
 void OspTree::AddContriToPvs(Intersectable *object, int &pvs) const
 {
-	if (mUseSah)
+	if (mUseEqualWeightForHeuristics)
 		++ pvs;
 	else
@@ -3282,5 +3296,5 @@
 float OspTree::EvalViewCellPvsIncr(Intersectable *object) const
 {
-	if (mUseSah)
+	if (mUseEqualWeightForHeuristics)
 		return 1;
 	else
@@ -3784,4 +3798,5 @@
 	// makes no sense otherwise because only one kd cell available
 	// during view space partition
+	const int savedCountMethod =
 	mVspTree.mPvsCountMethod = VspTree::PER_OBJECT;
 
@@ -3858,4 +3873,6 @@
 	
 	cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;
+
+	mVspTree.mPvsCountMethod = savedCountMethod;
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1122)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1129)
@@ -4901,6 +4901,6 @@
 	long startTime;
 
-	//mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox);
-	mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox);
+	mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox);
+	//mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox);
 	
 	//-- stats
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1123)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1129)
@@ -738,16 +738,17 @@
 								ViewCellContainer &viewCells) const;
 
+	/** Remove the references of the parent view cell from the kd nodes associated with
+		the objects.
+	*/
+	void RemoveParentViewCellReferences(ViewCell *parent) const;
+
+	/** Adds references to the view cell to the kd nodes associated with the objects.
+	*/
+	void AddViewCellReferences(ViewCell *vc) const;
+
+
+
 	/// pointer to the hierarchy of view cells
 	ViewCellsTree *mViewCellsTree;
-
-	/** Remove the references of the parent view cell from the kd nodes associated with
-		the objects.
-	*/
-	void RemoveParentViewCellReferences(ViewCell *parent) const;
-
-	/** Adds references to the view cell to the kd nodes associated with the objects.
-	*/
-	void AddViewCellReferences(ViewCell *vc) const;
-
 
 protected:
@@ -1548,8 +1549,13 @@
 		@returns pvs size of the node
 	*/
-	int PrepareHeuristics(const ObjectContainer &objects);
-
-	int PrepareHeuristics(Intersectable *object);
-
+	float PrepareHeuristics(const ObjectContainer &objects);
+
+	/** Evaluates contribution for one object 
+		to heuristics preparation.
+	*/
+	float PrepareHeuristics(Intersectable *object);
+
+	/** Prepares construction for vsp and osp trees.
+	*/
 	void PrepareConstruction(const ObjectContainer &objects,
 		AxisAlignedBox3 *forcedBoundingBox);
@@ -1558,6 +1564,9 @@
 		vector<SplitCandidate *> &dirtyList);
 
+	/** Collect view cells which see this kd leaf.
+	*/
 	void CollectViewCells(KdLeaf *leaf, 
 		ViewCellContainer &viewCells);
+
 
 protected:
@@ -1627,5 +1636,5 @@
 
 
-	bool mUseSah;
+	bool mUseEqualWeightForHeuristics;
 
 	/// subdivision stats output file
