Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 880)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 881)
@@ -143,5 +143,4 @@
 mParent(NULL),
 mMergeCost(0),
-mIsActive(false),
 mPvsSize(0),
 mPvsSizeValid(false)
@@ -157,6 +156,4 @@
 mParent(NULL),
 mMergeCost(0),
-mIsActive(false),
-mLastUpdated(sLastUpdated),
 mPvsSize(0),
 mPvsSizeValid(false)
@@ -278,18 +275,4 @@
 	return mMergeCost;
 }
-
-
-void ViewCell::SetActive()
-{
-	mIsActive = true;
-	mLastUpdated = sLastUpdated;
-}
-
-
-bool ViewCell::IsActive() const
-{
-	return mIsActive  && (mLastUpdated == sLastUpdated);
-}
-
 
 /************************************************************************/
@@ -342,5 +325,4 @@
 		mChildren.erase(it);
 }
-
 
 
@@ -539,7 +521,7 @@
 	//static float expectedValue = pvsStats.avgPvs;
 	
-	// the current view cells are kept in this container
-	// we start with the current view cells from the view cell manager. 
-	// The active view cells will change with subsequent merges
+	//-- the current view cells are kept in this container
+	//-- we start with the current view cells from the view cell manager. 
+	//-- The active view cells will change with subsequent merges
 	
 	// todo: should rather take initial view cells
@@ -582,6 +564,5 @@
 	//-- use priority queue to merge leaf pairs
 
-	//const float maxAvgCost = 350;
-	while (!mMergeQueue.empty())//nmNumActiveViewCells > mMergeMinViewCells))
+	while (!mMergeQueue.empty())
 	{
 		//-- reset merge queue if the ratio of current expected cost / real expected cost
@@ -1815,12 +1796,7 @@
 
 
-ViewCell *ViewCellsTree::GetActiveViewCell(ViewCell *vc) const
-{
-	while (vc->GetParent() && !vc->IsActive())
-	{
-		vc = vc->GetParent();
-	}
-
-	return vc;
+ViewCell *ViewCellsTree::GetActiveViewCell(ViewCellLeaf *vc) const
+{
+	return vc->GetActiveViewCell();
 }
 
@@ -2020,5 +1996,5 @@
 		stream << "<Leaf ";
 		stream << "id=\"" << viewCell->GetId() << "\" ";
-		stream << "active=\"" << viewCell->IsActive() << "\" ";
+		stream << "active=\"" << dynamic_cast<ViewCellLeaf *>(viewCell)->GetActiveViewCell()->GetId() << "\" ";
 		stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" ";
 		stream << "pvs=\"";
@@ -2037,5 +2013,4 @@
 		stream << "<Interior ";
 		stream << "id=\"" << viewCell->GetId() << "\" ";
-		stream << "active=\"" << viewCell->IsActive() << "\" ";
 		stream << "mergecost=\"" << viewCell->GetMergeCost() << "\" ";
 		stream << "pvs=\"";
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 860)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 881)
@@ -23,4 +23,5 @@
 class ViewCellsManager;
 class ViewCellsTree;
+class ViewCellLeaf;
 
 class BspNodeGeometry
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 880)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 881)
@@ -22,4 +22,5 @@
 class MergeCandidate;
 class ViewCellsManager;
+class ViewCellLeaf;
 
 /** Statistics for a view cell partition.
@@ -217,11 +218,4 @@
 
 
-	/** Sets this view cell to be an active view cell.
-	*/
-	void SetActive();
-	/** Returns if this view cell is active.
-	*/
-	bool IsActive() const;
-
 
 	// last mail id -> warning not thread safe!
@@ -230,5 +224,4 @@
 	static int sReservedMailboxes;
 
-	static int sLastUpdated;
 	
 protected:
@@ -244,7 +237,5 @@
 	bool mValid;
 
-	int mLastUpdated;
-	bool mIsActive;
-	/** color used for consistent visualization */
+	/// color used for consistent visualization
 	RgbColor mColor;
 
@@ -252,4 +243,5 @@
 	/// pvs size, used for lazy pvs computation
 	int mPvsSize;
+	/// if the given pvs size is the real pvs size
 	bool mPvsSizeValid;
 
@@ -287,16 +279,14 @@
 };
 
+
 /**
-	View cell belonging to a hierarchy.
+	Leaf of the view cell.
 */
-template<typename T>
 class ViewCellLeaf: public ViewCell
 {
 public:
-
-	ViewCellLeaf<T>(): mLeaf(NULL) { SetActive(); }
-	ViewCellLeaf<T>(Mesh *mesh):
-	ViewCell(mesh), mLeaf(NULL) { SetActive(); }
-	
+	ViewCellLeaf()  {  mActiveViewCell = this; }
+	ViewCellLeaf(Mesh *mesh):
+	ViewCell(mesh) { mActiveViewCell = this; }
 
 	bool IsLeaf() const
@@ -304,4 +294,38 @@
 		return true;
 	}
+
+	/** Returns if this view cell is active.
+	*/
+	ViewCell *GetActiveViewCell() const 
+	{ return mActiveViewCell; }
+
+	/** Sets this view cell to be an active view cell.
+	*/
+	void SetActiveViewCell(ViewCell *vc)
+	{ mActiveViewCell = vc;}
+
+	
+	/// points to the currently active view cell.
+	ViewCell *mActiveViewCell;
+};
+
+/**
+	Leaf of the view cell hierarchy corresponding to a leaf in a spatial hierarchy.
+*/
+template<typename T>
+class HierarchyLeafViewCell: public ViewCellLeaf
+{
+public:
+
+	HierarchyLeafViewCell<T>(): ViewCellLeaf() {  }
+	HierarchyLeafViewCell<T>(Mesh *mesh):
+	ViewCellLeaf(mesh) {  }
+		
+
+	bool IsLeaf() const
+	{
+		return true;
+	}
+
 
 	/// Leaf of some hierarchy which is part of this view cell.
@@ -310,7 +334,7 @@
 
 
-typedef ViewCellLeaf<BspLeaf *> BspViewCell;
-typedef ViewCellLeaf<KdLeaf *> KdViewCell;
-typedef ViewCellLeaf<VspKdLeaf *> VspKdViewCell;
+typedef HierarchyLeafViewCell<BspLeaf *> BspViewCell;
+typedef HierarchyLeafViewCell<KdLeaf *> KdViewCell;
+typedef HierarchyLeafViewCell<VspKdLeaf *> VspKdViewCell;
 
 
@@ -399,5 +423,5 @@
 	/** Returns active view cell that is in the path of this view cell.
 	*/
-	ViewCell *GetActiveViewCell(ViewCell *vc) const;
+	ViewCell *GetActiveViewCell(ViewCellLeaf *vc) const;
 
 	/** Sets the leaves to be the currently active view cells.
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 880)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 881)
@@ -324,5 +324,5 @@
 			viewCell->SetId(id);
 		}
-		else if (attrName == "active")
+		/*else if (attrName == "active")
 		{
 			StrX attrValue(attributes.getValue(i));
@@ -334,5 +334,5 @@
 			if (isActive)
 				viewCell->SetActive();
-		}
+		}*/
 		else if (attrName == "mergecost")
 		{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 880)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 881)
@@ -1873,8 +1873,16 @@
 {
 	++ ViewCell::sLastUpdated;
+
 	ViewCellContainer::const_iterator it, it_end = mViewCells.end();
 	for (it = mViewCells.begin(); it != it_end; ++ it)
 	{
-		(*it)->SetActive();
+		ViewCellContainer leaves;
+		mViewCellsTree->CollectLeaves(*it, leaves);
+
+		ViewCellContainer::const_iterator lit, lit_end = leaves.end();
+		for (lit = mViewCells.begin(); lit != lit_end; ++ lit)
+		{
+			dynamic_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(*it);
+		}
 	}
 }
