Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h	(revision 1379)
@@ -17,5 +17,5 @@
   virtual bool ParseFile(const std::string filename, 
 						 SceneGraphNode *root, 
-						 const bool loadPolygonsAsMeshes = false,
+						 const bool loadMeshes = false,
 						 vector<FaceParentInfo> *parents = NULL);
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1379)
@@ -30,5 +30,7 @@
 #include "ViewCellsManager.h"
 #include "ResourceManager.h"
+#include "IntersectableWrapper.h"
 #include <assert.h>
+
 
 namespace GtpVisibilityPreprocessor {
@@ -82,10 +84,10 @@
 // ---------------------------------------------------------------------------
 X3dParseHandlers::X3dParseHandlers(SceneGraphNode *root, 
-								   const bool loadPolygonsAsMeshes):
+								   const bool loadMeshes):
   mElementCount(0)
   , mAttrCount(0)
   , mCharacterCount(0)
   , mSpaceCount(0)
-  , mLoadPolygonsAsMeshes(loadPolygonsAsMeshes)
+  , mLoadMeshes(loadMeshes)
   , mCurrentMesh(NULL)
 {
@@ -224,16 +226,33 @@
 	 }
 
-	 
-	 //-- each polygon is one single mesh
-	 if (mLoadPolygonsAsMeshes)
+	 ////////////////////////////////////
+	 //-- each triangle is one single mesh
+
+	 if (!mLoadMeshes)
 	 {
 		 cout << "m";	
-		 FaceContainer::const_iterator fit, fit_end = mCurrentMesh->mFaces.end();
+		 Mesh tempMesh(*mCurrentMesh);
+		 ApplyTransformations(mTransformations, &tempMesh);
+
+		 FaceContainer::const_iterator fit, fit_end = tempMesh.mFaces.end();
 		
-		 for (fit = mCurrentMesh->mFaces.begin(); fit != fit_end; ++ fit)
+		 for (fit = tempMesh.mFaces.begin(); fit != fit_end; ++ fit)
 		 {
 			 cout << "f";
+			 // triangulate the faces
 			 Face *face = *fit;
-		
+			 vector<Triangle3> triangles;
+			 Polygon3 poly(face, &tempMesh);
+			 poly.Triangulate(triangles);
+
+			 vector<Triangle3>::const_iterator tit, tit_end = triangles.end();
+
+			 for (tit = triangles.begin(); tit != tit_end; ++ tit)
+			 {
+				 cout << "triangle: " << *tit << endl;
+				 TriangleIntersectable *ti = new TriangleIntersectable(*tit);
+				 mCurrentNode->mGeometry.push_back(ti);
+			 }
+#if 0
 			 // we create a new mesh for each face from the current mesh
 			 Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
@@ -249,10 +268,7 @@
 				 cout << "i";
 				 const int index = (*vit);
-
 				 // add vertices
 				 mesh->mVertices.push_back(mCurrentMesh->mVertices[index]);
-
-				 // indices don't make much sense if mesh == face, 
-				 // but we need them anyway ...
+				 // indices don't make much sense if mesh == face, but we need them anyway ...
 				 vcIndices.push_back(i);
 			 }
@@ -260,5 +276,5 @@
 			 mesh->mFaces.push_back(new Face(vcIndices));
 
-			 // write transformations directly in mesh 
+			 // write transformations directly into the mesh
 			 // note: could be transformed in parent mesh, save some transformations
 			 ApplyTransformations(mTransformations, mesh);
@@ -283,4 +299,5 @@
 				 }
 			 }
+#endif
 		 }
 
@@ -656,5 +673,5 @@
 X3dParser::ParseFile(const string filename,
 					 SceneGraphNode *root,
-					 const bool loadPolygonsAsMeshes,
+					 const bool loadMeshes,
 					 vector<FaceParentInfo> *parents)
 {
@@ -689,5 +706,5 @@
   //  to do.
   //
-  X3dParseHandlers handler(root, loadPolygonsAsMeshes);
+  X3dParseHandlers handler(root, loadMeshes);
   parser->setDocumentHandler(&handler);
   parser->setErrorHandler(&handler);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1370)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1379)
@@ -1670,8 +1670,8 @@
 					"rays.out");
 
-	RegisterOption("Preprocessor.loadPolygonsAsMeshes",
-					optBool,
-					"loadPolygonsAsMeshes=",
-					"false");
+	RegisterOption("Preprocessor.loadMeshes",
+					optBool,
+					"loadMeshes=",
+					"true");
 
 	RegisterOption("Preprocessor.pvsRenderErrorSamples",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1359)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1379)
@@ -145,5 +145,5 @@
   
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlDebugger", mUseGlDebugger);
-	Environment::GetSingleton()->GetBoolValue("Preprocessor.loadPolygonsAsMeshes", mLoadPolygonsAsMeshes);
+	Environment::GetSingleton()->GetBoolValue("Preprocessor.loadMeshes", mLoadMeshes);
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.quitOnFinish", mQuitOnFinish);
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.computeVisibility", mComputeVisibility);
@@ -161,5 +161,5 @@
 
 	Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
-	Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl;
+	Debug << "load meshes: " << mLoadMeshes << endl;
 
 	if (mRayCastMethod == 0)
@@ -259,10 +259,10 @@
 				filename, 
 				mSceneGraph->GetRoot(),
-				mLoadPolygonsAsMeshes,
+				mLoadMeshes,
 				&mFaceParents);
 		}
 		else
 		{ 
-			result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadPolygonsAsMeshes);
+			result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadMeshes);
 		}
 		
@@ -285,10 +285,10 @@
 				  filename, 
 				  node,
-				  mLoadPolygonsAsMeshes,
+				  mLoadMeshes,
 				  &mFaceParents);
 		  }
 		  else
 		  {
-			  success = parser->ParseFile(filename, node, mLoadPolygonsAsMeshes);
+			  success = parser->ParseFile(filename, node, mLoadMeshes);
 		  }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1370)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1379)
@@ -198,5 +198,7 @@
 	void PrintHierarchyStatistics(ofstream &stream) const;
 
-	VspTree *GetVspTree() { return mVspTree; }
+	VspTree *GetVspTree();
+
+	AxisAlignedBox3 GetViewSpaceBox() const;
 
 	void ExportObjectSpaceHierarchy(
@@ -266,6 +268,5 @@
 	void PrepareViewSpaceSubdivision(
 		const VssRayContainer &sampleRays,
-		const ObjectContainer &objects,
-		AxisAlignedBox3 *forcedViewSpace = NULL);
+		const ObjectContainer &objects);
 
 	bool ObjectSpaceSubdivisionConstructed() const;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h	(revision 1287)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h	(revision 1379)
@@ -37,4 +37,6 @@
 class KdTreeStatistics;
 class SubdivisionCandidate;
+class HierarchyManager;
+
 
 
@@ -738,5 +740,10 @@
 	ViewCellsTree *mViewCellsTree;
 
+	/// pointer to the view space partition
+	/// note: should be handled over the hierarchy manager
 	VspTree *mVspTree;
+
+	/// pointer to the hierarchy manager
+	HierarchyManager *mHierarchyManager;
 
 	/// The view cells manager
@@ -756,4 +763,5 @@
 
 
+	//////////////////////////////
 	//-- local termination
 
@@ -772,4 +780,5 @@
 
 
+	////////////////////////
 	//-- global criteria
 
@@ -786,4 +795,5 @@
 
 
+	///////////////////////////////////////////
 	//-- split heuristics based parameters
 	
@@ -793,13 +803,15 @@
 	/// if only driving axis should be used for split
 	bool mOnlyDrivingAxis;
-	
+	/// represents min and max band for sweep
+	float mSplitBorder;
+
+	////////////////////////////////////////////////
+
 	/// current time stamp (used for keeping split history)
 	int mTimeStamp;
 	// if rays should be stored in leaves
 	bool mStoreRays;
-
 	/// epsilon for geometric comparisons
 	float mEpsilon;
-
 	/// subdivision stats output file
 	ofstream  mSubdivisionStats;
@@ -810,15 +822,11 @@
 	/// number of currenly generated view cells
 	int mCreatedLeaves;
-
-	/// represents min and max band for sweep
-	float mSplitBorder;
-
+	
 	/// weight between  render cost decrease and node render cost
 	float mRenderCostDecreaseWeight;
 
-	/// stores the kd node intersectables used for pvs
+    /// stores the kd node intersectables used for pvs
 	KdIntersectableMap mKdIntersectables;
-
-
+	
 private:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h	(revision 1379)
@@ -16,5 +16,5 @@
   bool ParseFile(const string filename,
 				 SceneGraphNode *root,
-				 const bool loadPolygonsAsMeshes = false,
+				 const bool loadMeshes = true,
 				 vector<FaceParentInfo> *parents = NULL);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1292)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1379)
@@ -218,5 +218,5 @@
 
   bool mQuitOnFinish;
-  bool mLoadPolygonsAsMeshes;
+  bool mLoadMeshes;
   bool mComputeVisibility;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1357)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1379)
@@ -945,5 +945,4 @@
 	SubdivisionCandidate *PrepareConstruction(
 		const VssRayContainer &sampleRays,
-		AxisAlignedBox3 *forcedViewSpace,
 		RayInfoContainer &rays);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1370)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1379)
@@ -290,9 +290,15 @@
 										BvhTraversalData &backData)
 {
-	mBvhStats.nodes += 2; // we have two new leaves
-
 	const BvhTraversalData &tData = sc.mParentData;
 	BvhLeaf *leaf = tData.mNode;
 	AxisAlignedBox3 parentBox = leaf->GetBoundingBox();
+
+	// update stats
+	mBvhStats.nodes += 2; // we have two new leaves
+
+	if (tData.mDepth > mBvhStats.maxDepth)
+	{
+		mBvhStats.maxDepth = tData.mDepth;
+	}
 
 	// add the new nodes to the tree
@@ -471,27 +477,28 @@
 		splitCandidate.mParentData.mMaxCostMisses;
 
-	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
 	const float oldProp = EvalViewCellsVolume(leaf->mObjects);
-
-	const float oldRenderCost = oldProp * (float)leaf->mObjects.size() / viewSpaceVol;
-
+	const float oldRenderCost = EvalRenderCost(leaf->mObjects);
+		
 	// compute global decrease in render cost
-	float newRenderCost = EvalRenderCost(splitCandidate.mParentData,
-									     splitCandidate.mFrontObjects,
-										 splitCandidate.mBackObjects);
-
-	newRenderCost /=  viewSpaceVol;
+	const float newRenderCost = 
+		EvalRenderCost(splitCandidate.mFrontObjects) +
+		EvalRenderCost(splitCandidate.mBackObjects);
+
 	const float renderCostDecr = oldRenderCost - newRenderCost;
 
-	//Debug << "\nbvh render cost decr: " << renderCostDecr << endl;
+#ifdef _DEBUG
+	Debug << "old render cost: " << oldRenderCost << endl;
+	Debug << "new render cost: " << newRenderCost << endl;
+	Debug << "render cost decrease: " << renderCostDecr << endl;
+#endif
 	splitCandidate.SetRenderCostDecrease(renderCostDecr);
 
-#if 0
-	const float priority = (float)-splitCandidate.mParentData.mDepth;
-#else	
+#if 1
 	// take render cost of node into account 
 	// otherwise danger of being stuck in a local minimum!!
 	const float factor = mRenderCostDecreaseWeight;
 	const float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+#else
+	const float priority = (float)-splitCandidate.mParentData.mDepth;
 #endif
 
@@ -540,9 +547,4 @@
 	// depth related stuff
 
-	if (data.mDepth > mBvhStats.maxDepth)
-	{
-		mBvhStats.maxDepth = data.mDepth;
-	}
-
 	if (data.mDepth < mBvhStats.minDepth)
 	{
@@ -640,10 +642,7 @@
 	}
 
-	const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects);
-	//const float oldProp = tData.mProbability;
-
-	const float oldRenderCost = oldProb * (float)tData.mNode->mObjects.size();
+	const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects);
 	const float newRenderCost = 
-		EvalRenderCost(tData, objectsFront, objectsBack);
+		EvalRenderCost(objectsFront) * EvalRenderCost(objectsBack);
 
 	const float ratio = newRenderCost / oldRenderCost;
@@ -672,14 +671,15 @@
 		// object mailed => belongs to back objects
 		if (i < border) 
+		{
 			objectsBack.push_back(obj);
+		}
 		else
+		{
 			objectsFront.push_back(obj);
-	}
-
-	const float oldProp = EvalViewCellsVolume(tData.mNode->mObjects);
-	//const float oldProp = tData.mProbability;
-
-	const float oldRenderCost = oldProp * (float)tData.mNode->mObjects.size();
-	const float newRenderCost = EvalRenderCost(tData, objectsFront, objectsBack);
+		}
+	}
+
+	const float oldRenderCost = EvalRenderCost(tData.mNode->mObjects);
+	const float newRenderCost = EvalRenderCost(objectsFront) + EvalRenderCost(objectsBack);
 
 	const float ratio = newRenderCost / oldRenderCost;
@@ -694,9 +694,9 @@
 						   ObjectContainer &objectsBack)
 {
-	PrepareLocalSubdivisionCandidates(tData, axis);
-  
 	// go through the lists, count the number of objects left and right
 	// and evaluate the following cost funcion:
 	// C = ct_div_ci  + (ol + or)/queries
+	PrepareLocalSubdivisionCandidates(tData, axis);
+
 	int objectsLeft = 0, objectsRight = (int)tData.mNode->mObjects.size();
   
@@ -709,16 +709,20 @@
 	float minSum = 1e20f;
   
+	float minBorder = maxBox;
+	float maxBorder = minBox;
+	float areaLeft = 0, areaRight = 0;
+
+	SortableEntryContainer::const_iterator currentPos =
+		mSubdivisionCandidates->begin();
+
+	
+	// we keep track of both borders of the bounding boxes =>
+	// store the events in descending order
 	vector<float> bordersRight;
 	bordersRight.resize(mSubdivisionCandidates->size());
 
-	float minBorder = maxBox;
-	float maxBorder = minBox;
-
-	SortableEntryContainer::const_iterator currentPos =
-		mSubdivisionCandidates->begin();
-
 	SortableEntryContainer::reverse_iterator rcit = 
 		mSubdivisionCandidates->rbegin(), rcit_end = mSubdivisionCandidates->rend();
-		
+	
 	vector<float>::reverse_iterator rbit = bordersRight.rbegin();
 	
@@ -728,13 +732,15 @@
 		const AxisAlignedBox3 box = obj->GetBox();
 
-		if (box.Min() < minBorder)
+		if (box.Min(axis) < minBorder)
+		{
 			minBorder = box.Min(axis);
-		
+		}
+
 		(*rbit) = minBorder;
 	}
 
 	vector<float>::const_iterator bit = bordersRight.begin();
-	cout << "here42" << endl;
 	SortableEntryContainer::const_iterator cit, cit_end = mSubdivisionCandidates->end();
+
 	for (cit = mSubdivisionCandidates->begin(); cit != cit_end; ++ cit, ++ bit) 
 	{
@@ -749,23 +755,35 @@
 		const AxisAlignedBox3 obox = obj->GetBox();
 
+		// 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, *bit);
-	
-		const float sum = objectsLeft * lbox.SurfaceArea() + objectsRight * rbox.SurfaceArea();
+		rbox.SetMin(axis, minBorder);
+	
+		const float al = lbox.SurfaceArea();
+		const float ar = rbox.SurfaceArea();
+
+		const float sum = objectsLeft * al + objectsRight * ar;
       
-		cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=(" 
+		/*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=(" 
 			 << lbox.SurfaceArea() << "," << rbox.SurfaceArea() << ")" << endl;
+		cout << "minborder: " << minBorder << " maxborder: " << maxBorder << endl;
 	    cout << "cost= " << sum << endl;
-      
+*/
 		if (sum < minSum) 
 		{
-			minSum = sum;	
+			minSum = sum;
+			areaLeft = al;
+			areaRight = ar;
 			// objects belong to left side now
 			for (; currentPos != (cit + 1); ++ currentPos);
 		}
 	}
+
 
 	////////////////////////////////////////////
@@ -784,8 +802,8 @@
 	float ratio = newCost / oldCost;
   
-#if 0
-  cout<<"===================="<<endl;
-  cout<<"costRatio="<<ratio<<" pos="<<position<<" t="<<(position - minBox)/(maxBox - minBox)
-      <<"\t o=("<<objectsBack<<","<<objectsFront<<")"<<endl;
+#ifdef _DEBUG
+	cout << "\n\nobjects=(" << objectsBack.size() << "," << objectsFront.size() << " of " << tData.mNode->mObjects.size() << ")\t area=(" 
+		 << areaLeft << "," << areaRight << ")" << endl;
+	cout << "cost= " << minSum << endl;
 #endif
   return ratio;
@@ -855,5 +873,5 @@
 	int nObjectsLeft = 0;
 	const int nTotalObjects = (int)tData.mNode->mObjects.size();
-	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
+	const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume();
 
 	SortableEntryContainer::const_iterator backObjectsStart = mSubdivisionCandidates->begin();
@@ -1128,9 +1146,9 @@
 					//-- use surface area heuristic because view cells not constructed yet				
 					nCostRatio[axis] =
-						EvalLocalCostHeuristics(
-												tData,
-												axis,
-												nFrontObjects[axis],
-												nBackObjects[axis]);
+						EvalSah(
+								tData,
+								axis,
+								nFrontObjects[axis],
+								nBackObjects[axis]);
 				}
 			}
@@ -1138,5 +1156,4 @@
 			{
 				//-- split objects using some simple criteria
-
 				nCostRatio[axis] =
 					EvalLocalObjectPartition(
@@ -1245,27 +1262,34 @@
 
 
-float BvHierarchy::EvalRenderCost(const BvhTraversalData &tData,
-								  const ObjectContainer &objectsFront,
-								  const ObjectContainer &objectsBack) const
-{
-	// probability that view point lies in a view cell which sees this node
-	const float pFront = EvalViewCellsVolume(objectsFront);
-	const float pBack = EvalViewCellsVolume(objectsBack);
-		
-	//-- pvs rendering heuristics
-	const float newRenderCost = (int)objectsFront.size() * pFront + (int)objectsBack.size() * pBack;
-
-#ifdef _DEBUG
-	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
-	Debug << "\nbvh render cost\n" 
-		  << "back p: " << pBack / viewSpaceVol << " front p " << pFront / viewSpaceVol << endl
-		  << "new rc: " << newRenderCost / viewSpaceVol << endl;
-#endif
-	return newRenderCost;
+float BvHierarchy::EvalRenderCost(const ObjectContainer &objects) const
+{
+	if (mHierarchyManager->GetViewSpaceSubdivisionType() == HierarchyManager::NO_VIEWSPACE_SUBDIV)
+	{
+		if (objects.empty())
+			return 0.0f;
+
+		/////////////////////////////
+		//-- surface area heuristics
+
+		const AxisAlignedBox3 box = ComputeBoundingBox(objects);
+		const float area = box.SurfaceArea();
+
+		return (float)objects.size() * area;
+	}
+	else
+	{	/////////////////////////////
+		//-- render cost heuristics
+
+		const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume();
+		// probability that view point lies in a view cell which sees this node
+		const float p = EvalViewCellsVolume(objects) / viewSpaceVol;	
+
+		return (float)objects.size() * p;
+	}
 }
 
 
 AxisAlignedBox3 BvHierarchy::ComputeBoundingBox(const ObjectContainer &objects,
-												const AxisAlignedBox3 *parentBox)
+												const AxisAlignedBox3 *parentBox) const
 {
 	if (parentBox && objects.empty())
@@ -1325,4 +1349,9 @@
 								   const bool setCounter) const
 {
+	// no view cells yet
+	if (mHierarchyManager->GetViewSpaceSubdivisionType() == 
+		HierarchyManager::NO_VIEWSPACE_SUBDIV)
+		return;
+
 	ViewCell::NewMail();
 	ObjectContainer::const_iterator oit, oit_end = objects.end();
@@ -1348,5 +1377,5 @@
 		ViewCellContainer tmpViewCells;
 	
-		mVspTree->GetViewCells(*ray, tmpViewCells);
+		mHierarchyManager->mVspTree->GetViewCells(*ray, tmpViewCells);
 
 		ViewCellContainer::const_iterator vit, vit_end = tmpViewCells.end();
@@ -1645,5 +1674,5 @@
 	bvhleaf->SetSubdivisionCandidate(oSubdivisionCandidate);
 
-	const float viewSpaceVol = mVspTree->GetBoundingBox().GetVolume();
+	const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume();
 	mTotalCost = (float)objects.size() * prop / viewSpaceVol;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h	(revision 1020)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParserXerces.h	(revision 1379)
@@ -41,5 +41,5 @@
   //  Constructors and Destructor
   // -----------------------------------------------------------------------
-  X3dParseHandlers(SceneGraphNode *root, const bool loadPolygonsAsMeshes = false);
+  X3dParseHandlers(SceneGraphNode *root, const bool loadMeshes = false);
   ~X3dParseHandlers();
   
@@ -88,5 +88,5 @@
   Material *mCurrentMaterial;
   
-  bool mLoadPolygonsAsMeshes;
+  bool mLoadMeshes;
 
   typedef stack<Matrix4x4> TrafoStack;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1370)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1379)
@@ -312,9 +312,10 @@
 	friend class HierarchyManager;
 
-public:
-	
+protected:
 	struct SortableEntry;
 	typedef vector<SortableEntry> SortableEntryContainer;
 
+public:
+	
 	/** Additional data which is passed down the BSP tree during traversal.
 	*/
@@ -589,10 +590,7 @@
 	void EvalPriority(BvhTraversalData &tData) const;
 
-	/** Evaluates render cost of next split.
-	*/
-	float EvalRenderCost(
-		const BvhTraversalData &tData,
-		const ObjectContainer &objectsLeft,
-		const ObjectContainer &objectsRight) const;
+	/** Evaluates render cost of the bv induced by these objects
+	*/
+	float EvalRenderCost(const ObjectContainer &objects) const;
 
 	/** Evaluates tree stats in the BSP tree leafs.
@@ -704,5 +702,5 @@
 	AxisAlignedBox3 ComputeBoundingBox(
 		const ObjectContainer &objects, 
-		const AxisAlignedBox3 *parentBox = NULL);
+		const AxisAlignedBox3 *parentBox = NULL) const;
 
 	/** Collects list of invalid candidates. Candidates
@@ -785,6 +783,4 @@
 	/// pointer to the hierarchy of view cells
 	ViewCellsTree *mViewCellsTree;
-	/// pointer to the view space partition tree
-	VspTree *mVspTree;
 	/// The view cells manager
 	ViewCellsManager *mViewCellsManager;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1379)
@@ -44,5 +44,5 @@
 UnigraphicsParser::ParseFile(const string filename,
 							 SceneGraphNode *root,
-							 const bool loadPolygonsAsMeshes,
+							 const bool loadMeshes,
 							 vector<FaceParentInfo> *parents)
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h	(revision 1379)
@@ -20,5 +20,5 @@
   virtual bool ParseFile(const std::string filename,
 						 SceneGraphNode *root,
-						 const bool loadPolygonsAsMeshes = false,
+						 const bool loadMeshes = true,
 						 std::vector<FaceParentInfo> *parents = NULL) 
   {return false;};
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1370)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1379)
@@ -479,19 +479,18 @@
 	{
 		mBoundingBox = *forcedBoundingBox;
-	}
-	else // compute vsp tree bounding box
-	{
-		mBoundingBox.Initialize();
-		VssRayContainer::const_iterator rit, rit_end = rays.end();
-
-		//-- compute bounding box
-        for (rit = rays.begin(); rit != rit_end; ++ rit)
-		{
-			VssRay *ray = *rit;
-
-			// compute bounding box of view space
-			mBoundingBox.Include(ray->GetTermination());
-			mBoundingBox.Include(ray->GetOrigin());
-		}
+		return;
+	}
+	
+	//////////////////////////////////////////////
+	// bounding box of view space includes all visibility events
+	mBoundingBox.Initialize();
+	VssRayContainer::const_iterator rit, rit_end = rays.end();
+
+	for (rit = rays.begin(); rit != rit_end; ++ rit)
+	{
+		VssRay *ray = *rit;
+
+		mBoundingBox.Include(ray->GetTermination());
+		mBoundingBox.Include(ray->GetOrigin());
 	}
 }
@@ -769,4 +768,5 @@
 	VspLeaf *leaf = dynamic_cast<VspLeaf *>(tData.mNode);
 	
+	///////////////////////////////////////////////////////////////////
 	//-- the front and back traversal data is filled with the new values
 
@@ -784,11 +784,9 @@
 
 	//-- compute pvs
-
 	frontData.mPvs = EvalPvsSize(*frontData.mRays);
 	backData.mPvs = EvalPvsSize(*backData.mRays);
-
-	Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl;
-
-	// split front and back node geometry and compute area
+	//Debug << "f pvs: " << frontData.mPvs << " b pvs: " << backData.mPvs << " pvs " << tData.mPvs << endl;
+	
+	//-- split front and back node geometry and compute area
 	tData.mBoundingBox.Split(splitPlane.mAxis, 
 							 splitPlane.mPosition, 
@@ -799,13 +797,9 @@
 	backData.mProbability = tData.mProbability - frontData.mProbability;
 
-
-    ///////////////////////////////////////////
-	// subdivide further
-
-	// store maximal and minimal depth
+	// update some stats
+	// store maximal depth
 	if (tData.mDepth > mVspStats.maxDepth)
 	{
-		Debug << "max depth increases to " << tData.mDepth 
-			  << " at " << mVspStats.Leaves() << " leaves" << endl;
+		//Debug << "max depth increases to " << tData.mDepth << " at " << mVspStats.Leaves() << " leaves" << endl;
 		mVspStats.maxDepth = tData.mDepth;
 	}
@@ -813,10 +807,10 @@
 	// two more leaves
 	mVspStats.nodes += 2;
-    
+
+
+    ///////////////////////////////////////////
+	//-- create front and back and subdivide further
+
 	VspInterior *interior = new VspInterior(splitPlane);
-
-
-	//-- create front and back leaf
-
 	VspInterior *parent = leaf->GetParent();
 
@@ -862,4 +856,5 @@
 #endif
 
+	// set the time stamp so the order of traversal can be reconstructed
 	interior->mTimeStamp = mTimeStamp ++;
 	
@@ -1414,5 +1409,7 @@
 	const float viewSpaceVol = mBoundingBox.GetVolume();
 
-	// create unique ids for pvs heuristics
+	//////////////////////////////////////////////
+	// mark objects in the front / back / both using mailboxing
+	// then count pvs sizes
 	Intersectable::NewMail(3);
 	KdLeaf::NewMail(3);
@@ -1450,11 +1447,11 @@
 
 
-	//-- pvs rendering heuristics
+	////////////////////////////////////
+	//-- evaluate render cost heuristics
 
 	const int lowerPvsLimit = mViewCellsManager->GetMinPvsSize();
 	const int upperPvsLimit = mViewCellsManager->GetMaxPvsSize();
 
-	// only render cost heuristics or combined with standard deviation
-	const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);
+ 	const float penaltyOld = EvalPvsPenalty((int)totalPvs, lowerPvsLimit, upperPvsLimit);
     const float penaltyFront = EvalPvsPenalty((int)pvsFront, lowerPvsLimit, upperPvsLimit);
 	const float penaltyBack = EvalPvsPenalty((int)pvsBack, lowerPvsLimit, upperPvsLimit);
@@ -1463,8 +1460,10 @@
 	const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack;
 
+	// we also return the old render cost
 	normalizedOldRenderCost = oldRenderCost / viewSpaceVol;
 
+	// the render cost decrase for this split
 	const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol;
-	
+#ifdef _DEBUG
 	Debug << "\neval vsp render cost decrease" << endl
 		  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 
@@ -1472,5 +1471,5 @@
 		  << "old rc: " << normalizedOldRenderCost << " new rc: " << newRenderCost / viewSpaceVol << endl
 		  << "render cost decrease: " << renderCostDecrease << endl;
-
+#endif
 	return renderCostDecrease;
 }
@@ -2651,5 +2650,4 @@
 
 SubdivisionCandidate *VspTree::PrepareConstruction(const VssRayContainer &sampleRays,
-												   AxisAlignedBox3 *forcedViewSpace,
 												   RayInfoContainer &rays)
 {	
@@ -2661,7 +2659,4 @@
 	VspSubdivisionCandidate::sVspTree = this;
 	
-	// compute view space bounding box
-	ComputeBoundingBox(sampleRays, forcedViewSpace);
-
 	// initialise termination criteria
 	mTermMinProbability *= mBoundingBox.GetVolume();
@@ -2672,7 +2667,6 @@
 
 	const int pvsSize = EvalPvsSize(rays);
-	
-	Debug <<  "pvs size: " << (int)pvsSize << endl;
-	Debug <<  "rays size: " << (int)rays.size() << endl;
+	//Debug <<  "pvs size: " << (int)pvsSize << endl;
+	//Debug <<  "rays size: " << (int)rays.size() << endl;
 
 	//-- prepare view space partition
@@ -2851,4 +2845,5 @@
 				++ pvsSize;
 			}
+
 			++ obj->mCounter;	
 			break;
@@ -2870,4 +2865,5 @@
 				pvsSize += (int)leaf->mObjects.size();
 			}
+
 			++ leaf->mCounter;	
 			break;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h	(revision 1379)
@@ -17,5 +17,5 @@
   virtual bool ParseFile(const std::string filename, 
 						 SceneGraphNode *root,
-						 const bool loadPolygonsAsMeshes = false,
+						 const bool loadMeshes = true,
 						 vector<FaceParentInfo> *parents = NULL);
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1379)
@@ -177,5 +177,5 @@
 bool ObjParser::ParseFile(const string filename,
 						  SceneGraphNode *root,
-						  const bool loadPolygonsAsMeshes,
+						  const bool loadMeshes,
 						  vector<FaceParentInfo> *parents)
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1370)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1379)
@@ -46,12 +46,9 @@
 		mOspTree = new OspTree();
 		mOspTree->mVspTree = mVspTree;
-		
-		Debug << "creating osp tree" << endl;
+		mOspTree->mHierarchyManager = this;
 		break;
 	case BV_BASED_OBJ_SUBDIV:
         mBvHierarchy = new BvHierarchy();
-		mBvHierarchy->mVspTree = mVspTree;
-		
-		Debug << "creating bv hierachy" << endl;
+		mBvHierarchy->mHierarchyManager = this;
 		break;
 	default:
@@ -59,7 +56,7 @@
 	}
 
-	if (mVspTree)
-		mVspTree->mHierarchyManager = this;
-
+	// hierarchy manager links view space partition and object space partition
+	mVspTree->mHierarchyManager = this;
+	
 	ParseEnvironment();
 }
@@ -74,8 +71,5 @@
 	mOspTree->mVspTree = mVspTree;
 
-	Debug << "creating osp tree" << endl;
-
-	if (mVspTree)
-		mVspTree->mHierarchyManager = this;
+	mVspTree->mHierarchyManager = this;
 
 	ParseEnvironment();
@@ -160,4 +154,16 @@
 
 
+VspTree *HierarchyManager::GetVspTree() 
+{ 
+	return mVspTree; 
+}
+
+
+AxisAlignedBox3 HierarchyManager::GetViewSpaceBox() const
+{
+	return mVspTree->mBoundingBox;
+}
+
+
 SubdivisionCandidate *HierarchyManager::NextSubdivisionCandidate()
 {
@@ -223,5 +229,4 @@
 								 AxisAlignedBox3 *forcedViewSpace)
 {
-	
 	mHierarchyStats.Reset();
 	mHierarchyStats.Start();
@@ -233,4 +238,7 @@
 	cout << "Constructing view space / object space tree ... \n";
 	
+	// compute view space bounding box
+	mVspTree->ComputeBoundingBox(sampleRays, forcedViewSpace);
+
 	// use objects for evaluating vsp tree construction in the first levels
 	// of the subdivision
@@ -245,5 +253,5 @@
 	{
 		mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType;
-		PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace);
+		PrepareViewSpaceSubdivision(sampleRays, objects);
 	}
 	
@@ -270,6 +278,5 @@
 
 void HierarchyManager::PrepareViewSpaceSubdivision(const VssRayContainer &sampleRays,
-												   const ObjectContainer &objects,
-												   AxisAlignedBox3 *forcedViewSpace)
+												   const ObjectContainer &objects)
 {
 	cout << "starting view space hierarchy construction ... " << endl;
@@ -277,5 +284,5 @@
 	RayInfoContainer *viewSpaceRays = new RayInfoContainer();
 	SubdivisionCandidate *vsc = 
-		mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays);
+		mVspTree->PrepareConstruction(sampleRays, *viewSpaceRays);
 
 	mTQueue.Push(vsc);
@@ -491,5 +498,5 @@
 				 << mMinDepthForViewSpaceSubdivion << ") " << endl;
 
-			PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace);
+			PrepareViewSpaceSubdivision(sampleRays, objects);
 
 			cout << "reseting queue ... ";
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h	(revision 1379)
@@ -18,5 +18,5 @@
 				   const string filename, 
 				   SceneGraphNode *root, 
-				   const bool loadPolygonsAsMeshes = false,
+				   const bool loadMeshes = false,
 				   vector<FaceParentInfo> *parents = NULL);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp	(revision 1379)
@@ -260,5 +260,5 @@
 PlyParser::ParseFile(const string filename,
 					 SceneGraphNode *root,
-					 const bool loadPolygonsAsMeshes,
+					 const bool loadMeshes,
 					 vector<FaceParentInfo> *parents)
 {
