Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1717)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1718)
@@ -838,13 +838,10 @@
   
 	const AxisAlignedBox3 nodeBbox = tData.mNode->GetBoundingBox();
-
-	const float minBox = nodeBbox.Min(axis);
-	const float maxBox = nodeBbox.Max(axis);
 	const float boxArea = nodeBbox.SurfaceArea();
 
 	float minSum = 1e20f;
   
-	float minBorder = maxBox;
-	float maxBorder = minBox;
+	float minBorder = nodeBbox.Max(axis);
+	float maxBorder = nodeBbox.Min(axis);
 	float areaLeft = 0, areaRight = 0;
 
@@ -854,29 +851,26 @@
 	vector<float> bordersRight;
 
-	if (mUseBboxAreaForSah)
-	{
-		// we keep track of both borders of the bounding boxes =>
-		// store the events in descending order
-
-		bordersRight.resize(mSubdivisionCandidates->size());
-
-		SortableEntryContainer::reverse_iterator rcit = 
-			mSubdivisionCandidates->rbegin(), rcit_end = 
-			mSubdivisionCandidates->rend();
-	
-		vector<float>::reverse_iterator rbit = bordersRight.rbegin();
-	
-		for (; rcit != rcit_end; ++ rcit, ++ rbit) 
-		{
-			Intersectable *obj = (*rcit).mObject;
-			const AxisAlignedBox3 obox = obj->GetBox();
-
-			if (obox.Min(axis) < minBorder)
-			{
-				minBorder = obox.Min(axis);
-			}
-
-			(*rbit) = minBorder;
-		}
+	// we keep track of both borders of the bounding boxes =>
+	// store the events in descending order
+
+	bordersRight.resize(mSubdivisionCandidates->size());
+
+	SortableEntryContainer::reverse_iterator rcit = 
+		mSubdivisionCandidates->rbegin(), rcit_end = 
+		mSubdivisionCandidates->rend();
+
+	vector<float>::reverse_iterator rbit = bordersRight.rbegin();
+
+	for (; rcit != rcit_end; ++ rcit, ++ rbit) 
+	{
+		Intersectable *obj = (*rcit).mObject;
+		const AxisAlignedBox3 obox = obj->GetBox();
+
+		if (obox.Min(axis) < minBorder)
+		{
+			minBorder = obox.Min(axis);
+		}
+
+		(*rbit) = minBorder;
 	}
 
@@ -899,36 +893,22 @@
 		const AxisAlignedBox3 obox = obj->GetBox();
 
-		if (mUseBboxAreaForSah)
-		{
-			AxisAlignedBox3 lbox = nodeBbox;
-			AxisAlignedBox3 rbox = nodeBbox;
-	
-			// the borders of the bounding boxes have changed
-			if (obox.Max(axis) > maxBorder)
-			{
-				maxBorder = obox.Max(axis);
-			}
-
-			minBorder = (*bit);
-
-			lbox.SetMax(axis, maxBorder);
-			rbox.SetMin(axis, minBorder);
-	
-			al = lbox.SurfaceArea();
-			ar = rbox.SurfaceArea();
-		}
-		else
-		{
-			// just add up areas of the objects itself
-			// As we are not sampling volumetric visibility,
-			// this should provide better heuristics
-			const float area = obj->GetArea();//obox.SurfaceArea();
-
-			al += area;
-			ar -= area;
-		}
+		// the borders of the bounding boxes have changed
+		if (obox.Max(axis) > maxBorder)
+		{
+			maxBorder = obox.Max(axis);
+		}
+
+		minBorder = (*bit);
+
+		AxisAlignedBox3 lbox = nodeBbox;
+		AxisAlignedBox3 rbox = nodeBbox;
+
+		lbox.SetMax(axis, maxBorder);
+		rbox.SetMin(axis, minBorder);
+
+		al = lbox.SurfaceArea();
+		ar = rbox.SurfaceArea();
 
 		const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small));
-
 		const float sum =  noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar;
       
@@ -1054,5 +1034,5 @@
 		AxisAlignedBox3 rbox = nodeBbox;
 	
-		// the borders of the bounding boxes have changed
+		// the borders of the left bounding box have changed
 		for (int i = 0; i < 3; ++ i)
 		{
@@ -2386,3 +2366,44 @@
 
 
-}
+void BvHierarchy::CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects)
+{
+	stack<BvhNode *> nodeStack;
+
+	nodeStack.push(mRoot);
+
+	while (!nodeStack.empty()) 
+	{
+		BvhNode *node = nodeStack.top();
+
+		nodeStack.pop();
+
+		if (node->IsLeaf()) 
+		{
+			BvhLeaf *leaf = (BvhLeaf *)node;
+
+			ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
+
+			for (oit = leaf->mObjects.begin(); oit != oit_end; ++oit) 
+			{
+				Intersectable *object = *oit;
+				if (Overlap(box, object->GetBox())) 
+				{
+					object->Mail();
+					objects.push_back(object);
+				}
+			}
+		} 
+		else 
+		{
+			BvhInterior *interior = (BvhInterior *)node;
+
+			if (Overlap(box, interior->GetBoundingBox()))
+				nodeStack.push(interior->GetFront());
+
+			if (Overlap(box, interior->GetBoundingBox()))
+				nodeStack.push(interior->GetBack());
+		}
+	}
+}
+
+}
