Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1297)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1311)
@@ -2427,4 +2427,10 @@
 
 
+	RegisterOption("Hierarchy.Construction.minDepthForOsp",
+					optInt,
+					"hierarchy_construction_min_depth_for_osp=",
+					"-1");
+
+
 	//////////////////////////////////////////////////////////////////////////////////
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1308)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1311)
@@ -169,9 +169,9 @@
 	/** The type of object space subdivison
 	*/
-	inline int GetObjectSpaceSubdivisonType() const
+	int HierarchyManager::GetObjectSpaceSubdivisionType() const
 	{
 		return mObjectSpaceSubdivisionType;
 	}
-	
+		
 	void SetViewCellsManager(ViewCellsManager *vcm);
 
@@ -207,5 +207,9 @@
 		const ObjectContainer &objects);
 
-	void RunConstruction();
+	void RunConstruction(
+		const VssRayContainer &sampleRays,
+		const ObjectContainer &objects,
+		AxisAlignedBox3 *forcedViewSpace);
+
 	bool ApplySubdivisionCandidate(SubdivisionCandidate *sc);
 
@@ -238,5 +242,4 @@
 	void ExportBvHierarchy(Exporter *exporter, const ObjectContainer &objects) const;
 
-
 	void PrepareBvHierarchy(
 		const VssRayContainer &sampleRays,
@@ -250,4 +253,9 @@
 
 	bool StartObjectSpaceSubdivision() const;
+
+	void PrepareViewSpaceSubdivision(
+		const VssRayContainer &sampleRays,
+		const ObjectContainer &objects,
+		AxisAlignedBox3 *forcedViewSpace);
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1281)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1311)
@@ -485,6 +485,5 @@
   }
 #endif
-  VssTree *vssTree = NULL;
-  
+  VssTree *vssTree = NULL; 
 
   long initialTime = GetTime();
@@ -499,5 +498,4 @@
   else
   {
-	
 	while (totalSamples < mInitialSamples) {
 		int passContributingSamples = 0;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1302)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1311)
@@ -362,5 +362,5 @@
 	startTime = GetTime();
 
-	// -- stats after construction
+	//-- stats after construction
 	ResetViewCells();
   	Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl;
@@ -1319,5 +1319,4 @@
 {
 	mCurrentViewCellsStats.Reset();
-
 	ViewCellContainer::const_iterator it, it_end = mViewCells.end();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1297)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1311)
@@ -1762,9 +1762,6 @@
 	}
 	
-	// interior node
-	
 	// interior nodes: pvs is either stored as a scalar or
 	// has to be reconstructed from the leaves
-
 	// the stored pvs size is the valid pvs size => just return scalar
 	if (vc->mPvsSizeValid)
@@ -1959,9 +1956,8 @@
 {
 	int pvsSize = 0;
-
 	Intersectable::NewMail();
 
 	////////////////////////////////////////////////
-	//  for interiors, pvs can be stored using different methods
+	// for interiors, pvs can be stored using different methods
 	//
 
@@ -1969,13 +1965,9 @@
 	{
 	case PVS_IN_LEAVES: //-- store pvs only in leaves
-		{			
-			pvsSize = GetPvsSizeForLeafStorage(vc);			
-			break;
-		}
+		pvsSize = GetPvsSizeForLeafStorage(vc);			
+		break;
 	case COMPRESSED:
-		{
-			pvsSize = GetPvsSizeForCompressedStorage(vc);
-			break;
-		}
+		pvsSize = GetPvsSizeForCompressedStorage(vc);
+		break;
 	case PVS_IN_INTERIORS:
 	default:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1308)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1311)
@@ -102,6 +102,7 @@
 		"Hierarchy.Construction.type", mConstructionType);
 
-	mMinDepthForObjectSpaceSubdivion = -1;
-
+	Environment::GetSingleton()->GetIntValue(
+		"Hierarchy.Construction.minDepthForOsp", mMinDepthForObjectSpaceSubdivion);
+	
 	Debug << "******** Hierachy Manager Parameters ***********" << endl;
 	Debug << "max leaves: " << mTermMaxLeaves << endl;
@@ -196,29 +197,34 @@
 
 void HierarchyManager::Construct(const VssRayContainer &sampleRays,
-								const ObjectContainer &objects,
-								AxisAlignedBox3 *forcedViewSpace)
-{
-	
-	RayInfoContainer *viewSpaceRays = new RayInfoContainer();
-
+								 const ObjectContainer &objects,
+								 AxisAlignedBox3 *forcedViewSpace)
+{
+	
 	mHierarchyStats.Reset();
 	mHierarchyStats.Start();
-
-	// start with view space subdivison: prepare vsp tree for traversal
+	
+	mTotalCost = (float)objects.size();
+	Debug << "setting total cost to " << mTotalCost << endl;
+
+	const long startTime = GetTime();
+	cout << "Constructing view space / object space tree ... \n";
+	
+	// process object space candidates
+	RunConstruction(sampleRays, objects, forcedViewSpace);
+	
+	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
+	mVspTree->mVspStats.Stop();
+}
+
+
+void HierarchyManager::PrepareViewSpaceSubdivision(const VssRayContainer &sampleRays,
+												   const ObjectContainer &objects,
+												   AxisAlignedBox3 *forcedViewSpace)
+{
+	RayInfoContainer *viewSpaceRays = new RayInfoContainer();
 	SubdivisionCandidate *vsc = 
 		mVspTree->PrepareConstruction(sampleRays, forcedViewSpace, *viewSpaceRays);
+
 	mTQueue.Push(vsc);
-
-	mTotalCost = (float)objects.size();
-	Debug << "setting total cost to " << mTotalCost << endl;
-
-	const long startTime = GetTime();	
-	cout << "Constructing view space / object space tree ... \n";
-	
-	// process object space candidates
-	RunConstruction();
-	
-	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-	mVspTree->mVspStats.Stop();
 }
 
@@ -313,31 +319,42 @@
 bool HierarchyManager::StartObjectSpaceSubdivision() const
 {
-	const bool constructAfterViewSpace = (mConstructionType == 1) && mTQueue.Empty();
-
-	return 
-		NO_OBJ_SUBDIV &&
-		((mMinDepthForObjectSpaceSubdivion < 0/*mVspTree->mVspStats.mMaxDepth*/) || constructAfterViewSpace);
-}
-
-
-void HierarchyManager::RunConstruction()
+	const bool ospDepthReached = 
+		(mMinDepthForObjectSpaceSubdivion == mVspTree->mVspStats.maxDepth);
+	const bool stillNotOsp = (mObjectSpaceSubdivisionType == NO_OBJ_SUBDIV);
+	
+	Debug << "here10 " << mMinDepthForObjectSpaceSubdivion << " " << mVspTree->mVspStats.maxDepth << endl;
+    
+	return stillNotOsp && (mTQueue.Empty() || ospDepthReached);
+}
+
+
+void HierarchyManager::RunConstruction(const VssRayContainer &sampleRays,
+									   const ObjectContainer &objects,
+									   AxisAlignedBox3 *forcedViewSpace)
 {
 	mHierarchyStats.nodes = 0;
 	mGlobalCostMisses = 0;
-
-	// use objects for evaluating vsp tree construction
+Debug << "here2" << endl;
+	// use objects for evaluating vsp tree construction in the first levels
+	// of the subdivision
 	const int savedObjectSpaceSubdivisionType = mObjectSpaceSubdivisionType;
 	mObjectSpaceSubdivisionType = NO_OBJ_SUBDIV;
-
-	//const bool repairQueue = false;
-	const bool repairQueue = true;
-
-	do
-	{
-		// use objects for evaluating vsp tree construction until a certain depth
+Debug << "here3" << endl;
+	// start with view space subdivison: prepare vsp tree for traversal
+	PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace);
+
+	const bool repairQueue = false;
+	//const bool repairQueue = true;
+
+	while (!FinishedConstruction());
+	{Debug << "here7" << endl;
+		// we use objects for evaluating vsp tree construction until 
+		// a certain depth once a certain depth existiert ....
 		if (StartObjectSpaceSubdivision())
 		{
+			Debug << "here8" << endl;
 			mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;
-			//PrepareObjectSpaceSubdivision();
+			PrepareObjectSpaceSubdivision(sampleRays, objects);
+			Debug << "here9" << endl;
 		}
 
@@ -365,8 +382,9 @@
 			// this would be object space splits and other way round
 			if (repairQueue) RepairQueue();
-		}	
+		}
+
 		DEL_PTR(mCurrentCandidate);
 	}
-	while (!FinishedConstruction());
+	
 
 	mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;
@@ -377,4 +395,27 @@
 {
 	return mTQueue.Empty();
+}
+
+
+int HierarchyManager::GetObjectSpaceSubdivisionType()
+{
+	if (!ObjectSpaceSubdivisionConstructed())
+		return NO_OBJECT_SUBDIV;
+
+	return mObjectSpaceSubdivisionType;
+}
+
+
+bool HierarchyManager::ObjectSpaceSubdivisionConstructed()
+{
+	switch (mObjectSpaceSubdivisionType)
+	{
+	case KD_BASED_OBJ_SUBDIV:
+		return mOspTree && mOspTree->GetRoot();
+	case BV_BASED_OBJ_SUBDIV:
+		return mBvHierarchy && mOspTree->GetRoot();
+	default:
+        return false;
+	}
 }
 
