Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1142)
@@ -655,6 +655,4 @@
 	/// if pvs should be exported with view cells
 	bool mExportPvs;
-// matt§§: need this?
-	bool mCountKdPvs;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1142)
@@ -1288,9 +1288,4 @@
 					"perobject");
 
-	RegisterOption("ViewCells.Evaluation.countKdPvs",
-					optBool,
-					"view_cells_evaluation_count_kd_pvs=",
-					"false");
-
 	RegisterOption("ViewCells.active",
 					optInt,
@@ -2219,5 +2214,5 @@
 	RegisterOption("VspTree.storeKdPvs",
 					optBool,
-					"vsp_storeKdPvs=",
+					"vsp_store_kd_pvs=",
 					"true");
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1142)
@@ -523,5 +523,5 @@
 
 
-void VspTree::CreateViewCell(VspTraversalData &tData)
+void VspTree::CreateViewCell(VspTraversalData &tData, const bool updatePvs)
 {
 	//-- create new view cell
@@ -530,15 +530,20 @@
 	VspViewCell *viewCell = new VspViewCell();
     leaf->SetViewCell(viewCell);
-		
-	//-- update pvs
+	
 	int conSamp = 0;
 	float sampCon = 0.0f;
-	AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp);
-
-	// update scalar pvs size value
-	mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs());
-
-	mVspStats.contributingSamples += conSamp;
-	mVspStats.sampleContributions +=(int) sampCon;
+
+	//-- update pvs
+	if (updatePvs)
+	{
+		AddSamplesToPvs(leaf, *tData.mRays, sampCon, conSamp);
+
+		// update scalar pvs size value
+		mViewCellsManager->SetScalarPvsSize(viewCell, viewCell->GetPvs().CountPvs());
+
+		mVspStats.contributingSamples += conSamp;
+		mVspStats.sampleContributions += (int)sampCon;
+	}
+
 
 	//-- store additional info
@@ -766,6 +771,6 @@
 
 	// explicitely create front and back view cell
-	CreateViewCell(frontData);
-	CreateViewCell(backData);
+	CreateViewCell(frontData, true);
+	CreateViewCell(backData, true);
 
 	
@@ -773,6 +778,7 @@
 	// add front and back view cell to "Potentially Visbilie View Cells" 
 	// of the objects in front and back pvs
-	AddViewCellReferences(frontLeaf->GetViewCell());
-	AddViewCellReferences(backLeaf->GetViewCell());
+
+	//AddViewCellReferences(frontLeaf->GetViewCell());
+	//AddViewCellReferences(backLeaf->GetViewCell());
 
 	interior->mTimeStamp = mTimeStamp ++;
@@ -4004,5 +4010,5 @@
 	mVspTree.mVspStats.nodes = 1;
 
-	// prepare bounding box
+	// compute view space bounding box
 	mVspTree.ComputeBoundingBox(rays, forcedViewSpace);
 
@@ -4032,5 +4038,5 @@
 
 	// create first view cell
-	mVspTree.CreateViewCell(vData);
+	mVspTree.CreateViewCell(vData, true);
 		
 	// add first view cell to all the objects view cell pvs
@@ -4179,8 +4185,13 @@
 	mVspTree.mVspStats.Stop();
 	
+	
+	///////////////////////////////////////////////////////////////
+	//-- object space partition
+	/////////////////////////////////////////////////////////////
+
+
+	cout << "starting osp contruction ... " << endl;
 	startTime = GetTime();
-	cout << "starting osp contruction ... " << endl;
-
-	//-- object space partition
+
 	SplitCandidate *osc =
 		PrepareOsp(sampleRays, objects, forcedViewSpace, *objectSpaceRays);
@@ -4222,4 +4233,52 @@
 	mVspTree.mStoreKdPvs = savedStoreMethod;
 }
+
+
+void HierarchyManager::Construct3(const VssRayContainer &sampleRays,
+								  const ObjectContainer &objects,
+								  AxisAlignedBox3 *forcedViewSpace)
+{
+	RayInfoContainer *viewSpaceRays = new RayInfoContainer();
+
+	SplitCandidate *sc = PrepareVsp(sampleRays, forcedViewSpace, *viewSpaceRays);
+	mTQueue.Push(sc);
+
+	cout << "starting vsp contruction ... " << endl;
+
+	long startTime = GetTime();
+	int i = 0;
+
+	while (!FinishedConstruction())
+	{
+		SplitCandidate *splitCandidate = NextSplitCandidate();
+	    
+		const bool globalTerminationCriteriaMet = 
+			GlobalTerminationCriteriaMet(splitCandidate);
+
+		cout << "vsp nodes: " << i ++ << endl;
+
+		// cost ratio of cost decrease / totalCost
+		const float costRatio = splitCandidate->GetPriority() / mTotalCost;
+		//cout << "cost ratio: " << costRatio << endl;
+
+		if (costRatio < mTermMinGlobalCostRatio)
+			++ mGlobalCostMisses;
+
+		//-- subdivide leaf node
+
+		// 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();
+}
+
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1142)
@@ -100,5 +100,5 @@
 	Environment::GetSingleton()->GetBoolValue("ViewCells.exportBboxesForPvs", mExportBboxesForPvs);
 	Environment::GetSingleton()->GetBoolValue("ViewCells.exportPvs", mExportPvs);
-	Environment::GetSingleton()->GetBoolValue("ViewCells.Evaluation.countKdPvs", mCountKdPvs);
+	
 
 	char buf[100];
@@ -214,5 +214,5 @@
 	Debug << "export bounding boxes: " << mExportBboxesForPvs << endl;
 	Debug << "export pvs for view cells: " << mExportPvs << endl;
-	Debug << "count kd pvs: " << mCountKdPvs << endl;
+	
 	
 	Debug << endl;
@@ -788,5 +788,5 @@
 	sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs);
 
-	maxPvs = mViewCellsTree->GetPvsSize(viewCells.back(), mCountKdPvs);
+	maxPvs = mViewCellsTree->GetPvsSize(viewCells.back());
 	minVal = 0;
 
@@ -832,5 +832,5 @@
 
 		while ((i < (int)viewCells.size()) && 
-			   (mViewCellsTree->GetPvsSize(viewCells[i], mCountKdPvs) < currentPvs))
+			   (mViewCellsTree->GetPvsSize(viewCells[i]) < currentPvs))
 		{
 			volDif += viewCells[i]->GetVolume();
@@ -843,5 +843,5 @@
 		
 		if (0 && (i < (int)viewCells.size()))
-			Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i], mCountKdPvs) 
+			Debug << "new pvs size increase: " << mViewCellsTree->GetPvsSize(viewCells[i]) 
 			<< " " << currentPvs << endl;
 	
@@ -1706,5 +1706,5 @@
 		ViewCell *viewcell = *it;
 
-		const int pvsSize = mViewCellsTree->GetPvsSize(viewcell, mCountKdPvs);
+		const int pvsSize = mViewCellsTree->GetPvsSize(viewcell);
 
 		if (pvsSize < stat.minPvs)
@@ -1957,5 +1957,5 @@
 float ViewCellsManager::GetRendercost(ViewCell *viewCell) const
 {
-	return mViewCellsTree->GetPvsSize(viewCell, mCountKdPvs);
+	return mViewCellsTree->GetPvsSize(viewCell);
 }
 
@@ -2409,5 +2409,5 @@
 			{
 				importance = 
-					(float)mViewCellsTree->GetPvsSize(vc, mCountKdPvs) / 
+					(float)mViewCellsTree->GetPvsSize(vc) / 
 					(float)mCurrentViewCellsStats.maxPvs;
 			}
@@ -4390,5 +4390,5 @@
 		Exporter *exporter = Exporter::GetExporter(s);
 		
-		Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc, mCountKdPvs) << endl;
+		Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl;
 
 		//-- export the sample rays
@@ -4904,7 +4904,8 @@
 	long startTime;
 
-	mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox);
 	//mHierarchyManager->Construct(constructionRays, objects, &mViewSpaceBox);
-	
+	//mHierarchyManager->Construct2(constructionRays, objects, &mViewSpaceBox);
+	mHierarchyManager->Construct3(constructionRays, objects, &mViewSpaceBox);
+
 	//-- stats
 	Debug << mVspTree->GetStatistics() << endl;
@@ -5301,5 +5302,5 @@
 	}
 
-	if (1) 
+	if (1 && mOspTree->GetRoot()) 
 	{	
 		//-- export final object partition
@@ -5383,5 +5384,5 @@
 		Exporter *exporter = Exporter::GetExporter(s);
 		
-		Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc, mCountKdPvs) << endl;
+		Debug << i << ": pvs size=" << (int)mViewCellsTree->GetPvsSize(vc) << endl;
 
 		//-- export the sample rays
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1142)
@@ -1677,49 +1677,13 @@
 
 
-int ViewCellsTree::CountKdPvs(const ViewCellLeaf *vc) const
-{
-	ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end();
-
+int ViewCellsTree::GetPvsSize(ViewCell *vc) const
+{
 	int pvsSize = 0;
 
 	Intersectable::NewMail();
 
-	for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
-	{
-		Intersectable *obj = (*oit).first;
-
-/*		KdLeaf *leaf = ;
-
-			pvsSize += ((int)leaf->mObjects.size() - (int)leaf->mMultipleObjects.size());
-
-			//-- handle objects of several kd leaves separately
-			ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end();
-
-			for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit)
-			{
-				Intersectable *object = *oit;
-
-				// object not previously in left pvs
-				if (!object->Mailed())
-				{
-					object->Mail();
-					++ pvsSize;
-				}
-			}		
-		}*/
-	}
-
-	return pvsSize;
-}
-
-
-int ViewCellsTree::GetPvsSize(ViewCell *vc, const bool countKdPvs) const
-{
-	int pvsSize = 0;
-
-	Intersectable::NewMail();
-
-	//////////////////////////
-	// for interiors, pvs can be stored using different methods
+	////////////////////////////////////////////////
+	//-- for interiors, pvs can be stored using different methods
+	///////////////////////////////////////////////
 
 	switch (mViewCellsStorage)
@@ -1730,9 +1694,5 @@
 			if (vc->IsLeaf())
 			{
-				if (countKdPvs)
-					pvsSize = vc->GetPvs().CountPvs();
-				else
-					pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc));
-				break;
+				pvsSize = vc->GetPvs().CountPvs();
 			}
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1142)
@@ -1012,5 +1012,5 @@
 		ViewCell *back) const;
 
-	void CreateViewCell(VspTraversalData &tData);
+	void CreateViewCell(VspTraversalData &tData, const bool updatePvs);
 
 	void CollectDirtyCandidates(VspSplitCandidate *sc, 
@@ -1748,4 +1748,10 @@
 					AxisAlignedBox3 *forcedViewSpace);
 
+	/** Constructs only vsp tree.
+	*/
+	void Construct3(const VssRayContainer &sampleRays,
+					const ObjectContainer &objects,
+					AxisAlignedBox3 *forcedViewSpace);
+
 public:
 	VspTree &mVspTree;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 1141)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 1142)
@@ -439,8 +439,7 @@
 	void GetPvs(ViewCell *vc, ObjectPvs &pvs) const;
 
-	/** Returns pvs size of view cell.
-	*/
-	//int GetPvsSize(ViewCell *vc) const;
-	int GetPvsSize(ViewCell *vc, const bool countKdPvs = false) const;
+	/** Returns pvs size (i.e. the number of entries weighted by their "importance".
+	*/
+	int GetPvsSize(ViewCell *vc) const;
 
 	/** Returns actual number of object in this pvs and the children.
