Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1099)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1101)
@@ -750,6 +750,6 @@
 			Intersectable *object = (*oit).first;
 			// HACK: make sure that the view cell is removed from the pvs
-			const float high_contri = 99999999999;
-			object->mViewCellPvs.RemoveSample(parent, 999999);
+			const float high_contri = 9999999;
+			object->mViewCellPvs.RemoveSample(parent, high_contri);
 		}
 	}
@@ -3454,20 +3454,71 @@
 
 
-void HierarchyManager::Construct(const VssRayContainer &sampleRays,
+void HierarchyManager::Construct2(const VssRayContainer &sampleRays,
 								 const ObjectContainer &objects,
 								 AxisAlignedBox3 *forcedViewSpace)
 {
 	RayInfoContainer *rays = new RayInfoContainer();
-	
-	// prepare vsp and osp trees for traversal
-	PrepareConstruction(sampleRays, objects, forcedViewSpace, *rays);
-
-	mVspTree.mVspStats.Reset();
-	mVspTree.mVspStats.Start();
-
-	cout << "Constructing view space / object space tree ... \n";
-	const long startTime = GetTime();	
-	
+
+	mVspTree.PrepareConstruction(sampleRays, forcedViewSpace);
+
+	long startTime = GetTime();
+
+	cout << "storing rays ... ";
+
+	Intersectable::NewMail();
+
+	VssRayContainer::const_iterator rit, rit_end = sampleRays.end();
+
+	//-- store rays
+	for (rit = sampleRays.begin(); rit != rit_end; ++ rit)
+	{
+		VssRay *ray = *rit;
+
+		float minT, maxT;
+
+		static Ray hray;
+		hray.Init(*ray);
+		
+		// TODO: not very efficient to implictly cast between rays types
+		if (mVspTree.GetBoundingBox().GetRaySegment(hray, minT, maxT))
+		{
+			float len = ray->Length();
+
+			if (!len)
+				len = Limits::Small;
+
+			rays->push_back(RayInfo(ray, minT / len, maxT / len));
+		}
+	}
+
+	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
+
+
+	const int pvsSize = mVspTree.ComputePvsSize(*rays);
+
+
+	// -- prepare view space partition
+
+	// add first candidate for view space partition
+	mVspTree.mRoot = new VspLeaf();
+	const float prop = mVspTree.mBoundingBox.GetVolume();
+
+	// first vsp traversal data
+	VspTree::VspTraversalData vData(mVspTree.mRoot,
+									0,
+									rays,
+									pvsSize,	
+									prop,
+									mVspTree.mBoundingBox);
+
+
+	//-- compute first split candidate
+	VspTree::VspSplitCandidate *splitCandidate = new VspTree::VspSplitCandidate(vData);
+    mVspTree.EvalSplitCandidate(*splitCandidate);
+
+	mTQueue.Push(splitCandidate);
+
 	int i = 0;
+
 	while (!FinishedConstruction())
 	{
@@ -3487,5 +3538,115 @@
 
 		//-- subdivide leaf node
-		//-- we have either a object space or view space split
+
+		// we have either a object space or view space split
+		VspTree::VspSplitCandidate *sc = 
+			dynamic_cast<VspTree::VspSplitCandidate *>(splitCandidate);
+
+		VspNode *r = mVspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet);
+	
+		DEL_PTR(splitCandidate);
+	}
+
+	cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;
+
+	mVspTree.mVspStats.Stop();
+
+
+
+	//-- object space partition
+
+	mOspTree.PrepareConstruction(objects, forcedViewSpace);
+
+	// add first candidate for view space partition
+	KdLeaf *leaf = new KdLeaf(NULL, 0);
+	leaf->mObjects = objects;
+
+	mOspTree.mRoot = leaf;
+	
+
+	//-- first osp traversal data
+	OspTree::OspTraversalData oData(mOspTree.mRoot,
+									0,
+									rays,
+									pvsSize,
+									prop,
+									mOspTree.mBoundingBox);
+
+		
+	mOspTree.ProcessLeafObjects(leaf, NULL);
+
+	// compute first split candidate
+	OspTree::OspSplitCandidate *oSplitCandidate = new OspTree::OspSplitCandidate(oData);
+    mOspTree.EvalSplitCandidate(*oSplitCandidate);
+
+	mTQueue.Push(splitCandidate);
+
+	i = 0;
+	while (!FinishedConstruction())
+	{
+		SplitCandidate *splitCandidate = NextSplitCandidate();
+	    
+		const bool globalTerminationCriteriaMet = 
+			GlobalTerminationCriteriaMet(splitCandidate);
+
+		cout << "view cells: " << i ++ << endl;
+
+		// cost ratio of cost decrease / totalCost
+		const float costRatio = splitCandidate->GetPriority() / mTotalCost;
+		//Debug << "cost ratio: " << costRatio << endl;
+
+		if (costRatio < mTermMinGlobalCostRatio)
+			++ mGlobalCostMisses;
+
+		//-- subdivide leaf node
+
+		// object space split
+		OspTree::OspSplitCandidate *sc = 
+			dynamic_cast<OspTree::OspSplitCandidate *>(splitCandidate);
+
+		KdNode *r = mOspTree.Subdivide(mTQueue, *sc, globalTerminationCriteriaMet);
+		
+		DEL_PTR(splitCandidate);
+	}
+
+	cout << "finished in " << TimeDiff(startTime, GetTime())*1e-3 << " secs" << endl;
+}
+
+
+void HierarchyManager::Construct(const VssRayContainer &sampleRays,
+								 const ObjectContainer &objects,
+								 AxisAlignedBox3 *forcedViewSpace)
+{
+	RayInfoContainer *rays = new RayInfoContainer();
+	
+	// prepare vsp and osp trees for traversal
+	PrepareConstruction(sampleRays, objects, forcedViewSpace, *rays);
+
+	mVspTree.mVspStats.Reset();
+	mVspTree.mVspStats.Start();
+
+	cout << "Constructing view space / object space tree ... \n";
+	const long startTime = GetTime();	
+	
+	int i = 0;
+	while (!FinishedConstruction())
+	{
+		SplitCandidate *splitCandidate = NextSplitCandidate();
+	    
+		const bool globalTerminationCriteriaMet = 
+			GlobalTerminationCriteriaMet(splitCandidate);
+
+		cout << "view cells: " << i ++ << endl;
+
+		// cost ratio of cost decrease / totalCost
+		const float costRatio = splitCandidate->GetPriority() / mTotalCost;
+		//Debug << "cost ratio: " << costRatio << endl;
+
+		if (costRatio < mTermMinGlobalCostRatio)
+			++ mGlobalCostMisses;
+
+		//-- subdivide leaf node
+
+		// we have either a object space or view space split
 		if (splitCandidate->Type() == SplitCandidate::VIEW_SPACE)
 		{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1099)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1101)
@@ -1672,4 +1672,9 @@
 				   AxisAlignedBox3 *forcedViewSpace);
 
+	/** Constructs first view cells, then object space partition.
+	*/
+	void Construct2(const VssRayContainer &sampleRays,
+					const ObjectContainer &objects,
+					AxisAlignedBox3 *forcedViewSpace);
 public:
 	VspTree &mVspTree;
