Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1473)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1548)
@@ -316,4 +316,6 @@
 		AxisAlignedBox3 *forcedViewSpace);
 
+	/** Use iteration to construct the object space hierarchy.
+	*/
 	void ConstructMultiLevel(
 		const VssRayContainer &sampleRays,
@@ -321,5 +323,11 @@
 		AxisAlignedBox3 *forcedViewSpace);
 
-	void ResetObjectSpaceSubdivision(const ObjectContainer &objects);
+	/** Reset the object space subdivision. 
+		E.g., deletes hierarchy and resets stats.
+		so construction can be restarted.
+	*/
+	void ResetObjectSpaceSubdivision(
+		const VssRayContainer &rays, 
+		const ObjectContainer &objects);
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1522)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1548)
@@ -1663,5 +1663,4 @@
 	mBvhStats.Reset();
 	mBvhStats.Start();
-
 	mBvhStats.nodes = 1;
 		
@@ -1669,8 +1668,10 @@
 	BvhSubdivisionCandidate::sBvHierarchy = this;
 	
+	// create new root
+	CreateRoot(objects);
+
 	// compute bounding box from objects
-	// note: we assume that root was already created
 	mBoundingBox = mRoot->GetBoundingBox();
-	BvhLeaf *bvhleaf = dynamic_cast<BvhLeaf *>(mRoot);
+	BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot);
 
 	// multiply termination criterium for comparison,
@@ -1693,5 +1694,5 @@
 
 	// create bvh traversal data
-	BvhTraversalData oData(bvhleaf, 0, prop, nRays);
+	BvhTraversalData oData(bvhLeaf, 0, prop, nRays);
 
 	// create sorted object lists for the first data
@@ -1709,5 +1710,5 @@
 
 	EvalSubdivisionCandidate(*oSubdivisionCandidate);
-	bvhleaf->SetSubdivisionCandidate(oSubdivisionCandidate);
+	bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate);
 
 	const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume();
@@ -1784,4 +1785,50 @@
 
 
+SubdivisionCandidate *BvHierarchy::Reset(const VssRayContainer &sampleRays, 
+										 const ObjectContainer &objects)
+{
+	// reset stats
+	mBvhStats.Reset();
+	mBvhStats.Start();
+	mBvhStats.nodes = 1;
+
+	// reset root
+	DEL_PTR(mRoot);
+	CreateRoot(objects);
+	
+#if PROBABILIY_IS_BV_VOLUME
+	mTermMinProbability *= mBoundingBox.GetVolume();
+	// probability that bounding volume is seen
+	const float prop = GetBoundingBox().GetVolume();
+#else
+	mTermMinProbability *= mVspTree->GetBoundingBox().GetVolume();
+	// probability that volume is "seen" from the view cells
+	const float prop = EvalViewCellsVolume(objects);
+#endif
+
+	const int nRays = CountRays(objects);
+	BvhLeaf *bvhLeaf = dynamic_cast<BvhLeaf *>(mRoot);
+
+	// create bvh traversal data
+	BvhTraversalData oData(bvhLeaf, 0, prop, nRays);
+
+	///////////////////
+	//-- add first candidate for object space partition	
+
+	BvhSubdivisionCandidate *oSubdivisionCandidate = 
+		new BvhSubdivisionCandidate(oData);
+
+	EvalSubdivisionCandidate(*oSubdivisionCandidate);
+	bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate);
+
+	const float viewSpaceVol = mHierarchyManager->GetViewSpaceBox().GetVolume();
+	mTotalCost = (float)objects.size() * prop / viewSpaceVol;
+
+	PrintSubdivisionStats(*oSubdivisionCandidate);
+
+	return oSubdivisionCandidate;
+}
+
+
 void BvhStatistics::Print(ostream &app) const
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1545)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1548)
@@ -2689,5 +2689,4 @@
 	}
 
-if (mUsePredefinedViewCells) return 0;
 	//////////////////
 	//-- merge leaves of the view cell hierarchy	
@@ -3197,5 +3196,6 @@
 	mBspTree->CollectLeaves(leaves);
 	vector<BspLeaf *>::const_iterator lit, lit_end = leaves.end();
-	
+	ViewCell::NewMail();
+
 	for (lit = leaves.begin(); lit != lit_end; ++ lit)
 	{
@@ -3203,11 +3203,14 @@
 		ViewCell *vc = leaf->GetViewCell();
 
-		vc->SetMergeCost(0.0f);
-		vcRoot->SetupChildLink(vc);
-	
-		volume += vc->GetVolume();
-		volume += vc->GetVolume();	
-
-		vcRoot->SetVolume(volume);
+		if (!vc->Mailed())
+		{
+			vc->Mail();
+			vc->SetMergeCost(0.0f);
+			vcRoot->SetupChildLink(vc);
+
+			volume += vc->GetVolume();
+			volume += vc->GetVolume();	
+			vcRoot->SetVolume(volume);
+		}
 	}
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1548)
@@ -646,8 +646,6 @@
 	float GetMemUsage() const;
 
-	/** Creates new root of hierarchy.
-	*/
-	void CreateRoot(const ObjectContainer &objects);
-
+	/** Associates the objects with their bvh leaves.
+	*/
 	static void AssociateObjectsWithLeaf(BvhLeaf *leaf);
 
@@ -655,5 +653,4 @@
 	/////////////////////////////
 	// Helper functions for local cost heuristics
-
 	
 	/** Prepare split candidates for cost heuristics using axis aligned splits.
@@ -769,4 +766,10 @@
 		const ObjectContainer &objects);
 
+	/** Resets bv hierarchy. E.g. deletes root and resets stats.
+	*/
+	SubdivisionCandidate *Reset(
+		const VssRayContainer &rays, 
+		const ObjectContainer &objects);
+
 	/** Evaluates volume of view cells that see the objects.
 	*/
@@ -783,5 +786,8 @@
 		BvhTraversalData &frontData,
 		BvhTraversalData &backData);
-
+	
+	/** Creates new root of hierarchy.
+	*/
+	void CreateRoot(const ObjectContainer &objects);
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1501)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1548)
@@ -640,5 +640,5 @@
 	  float sum = info.raysBack*(info.position - minBox) + info.raysFront*(maxBox - info.position);
 	  float newCost = ct_div_ci + sum/sizeBox;
-	  float oldCost = info.rays;
+	  float oldCost = (float)info.rays;
 	  info.costRatio = newCost/oldCost;
 	  break;
@@ -668,10 +668,10 @@
 		info.viewCellsFront*(maxBox - info.position);
 	  float newCost = ct_div_ci + sum/sizeBox;
-	  float oldCost = info.viewCells;
+	  float oldCost = (float)info.viewCells;
 	  info.costRatio = newCost/oldCost;
 	  break;
 	}
 	case 3: {
-	  float newCost = info.raysBack*info.pvsBack  + info.raysFront*info.pvsFront;
+	  float newCost = (float)(info.raysBack*info.pvsBack  + info.raysFront*info.pvsFront);
 	  float oldCost = (float)leaf->rays.size()*pvsSize;
 	  info.costRatio = newCost/oldCost;
@@ -695,10 +695,10 @@
 	case 2: {
 	  float newCost = (info.pvsBack  + info.pvsFront)*0.5f;
-	  float oldCost = pvsSize;
+	  float oldCost = (float)pvsSize;
 	  info.costRatio = newCost/oldCost;
 	  break;
 	}
 	case 3: {
-	  float newCost = abs(info.raysBack  - info.raysFront);
+	  float newCost = (float)abs(info.raysBack  - info.raysFront);
 	  float oldCost = (float)leaf->rays.size();
 	  info.costRatio = newCost/oldCost;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1522)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1548)
@@ -317,10 +317,10 @@
 #endif
 
+	mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType;
+	mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType;
+
 	mHierarchyStats.Stop();
 	mVspTree->mVspStats.Stop();
 	FinishObjectSpaceSubdivision(objects);
-
-	mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType;
-	mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType;
 }
 
@@ -330,6 +330,6 @@
 {
 	cout << "\nstarting view space hierarchy construction ... " << endl;
-
-	mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses
+	 // hack: reset global cost misses
+	mHierarchyStats.mGlobalCostMisses = 0;
 
 	RayInfoContainer *viewSpaceRays = new RayInfoContainer();
@@ -367,6 +367,5 @@
 
 	cout << "preparing bv hierarchy construction ... " << endl;
-		mBvHierarchy->CreateRoot(objects);
-
+	
 	// compute first candidate
 	SubdivisionCandidate *sc =
@@ -377,5 +376,6 @@
 
     mTQueue.Push(sc);
-	cout << "finished bv hierarchy preparation in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
+	cout << "finished bv hierarchy preparation in " 
+		 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 }
 
@@ -605,13 +605,29 @@
 
 
-void HierarchyManager::ResetObjectSpaceSubdivision(const ObjectContainer &objects)
-{
-	Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl;
-	cout << "\nresetting bv hierarchy" << endl;
-	mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes;
-	
-	DEL_PTR(mBvHierarchy);
-	mBvHierarchy = new BvHierarchy();
-	mBvHierarchy->mHierarchyManager = this;
+void HierarchyManager::ResetObjectSpaceSubdivision(const VssRayContainer &sampleRays, 
+												   const ObjectContainer &objects)
+{
+	switch (mObjectSpaceSubdivisionType)
+	{
+	case BV_BASED_OBJ_SUBDIV:
+        Debug << "old bv hierarchy:\n " << mBvHierarchy->mBvhStats << endl;
+		cout << "\nresetting bv hierarchy" << endl;
+		mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes;
+#if 0	
+		DEL_PTR(mBvHierarchy);
+		mBvHierarchy = new BvHierarchy();
+		mBvHierarchy->mHierarchyManager = this;
+
+		PrepareObjectSpaceSubdivision(sampleRays, objects);
+#else
+		mBvHierarchy->Reset(sampleRays, objects);
+#endif
+		break;
+	case KD_BASED_OBJ_SUBDIV:
+		// TODO
+		break;
+	default:
+		break;
+	}
 }
 
@@ -646,18 +662,24 @@
 	RunConstruction(false);
 
-	/////////////////
-    // now do view space subdivison on the sah bvh nodes
 	mViewSpaceSubdivisionType = mSavedViewSpaceSubdivisionType;
-	PrepareViewSpaceSubdivision(sampleRays, objects);
-	
-	// process view space candidates
-	RunConstruction(false);
-	
-	// again run object space subdivision on the view cells
-	ResetObjectSpaceSubdivision(objects);
-	PrepareObjectSpaceSubdivision(sampleRays, objects);
-
-	// process object space candidates
-	RunConstruction(false);
+
+	const int limit = 2;
+	for (int i = 0; i < limit; ++ i)
+	{
+       	// again run object space subdivision on the view cells
+		ResetObjectSpaceSubdivision(sampleRays, objects);
+	
+		// process object space candidates
+		RunConstruction(false);
+
+		 /////////////////
+		// now do view space subdivison using the current object space partition
+//		ResetViewSpaceSubdivision(sampleRays, objects);
+	
+		// process view space candidates
+		RunConstruction(false);
+	
+		cout << "íteration " << i << " of " << limit << " finished" << endl;
+	}
 	
 	cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
