Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h	(revision 312)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h	(revision 341)
@@ -36,4 +36,6 @@
 	int Compress() {return 0;}
 	int GetSize() {return (int)mEntries.size();}
+	bool Empty() {return mEntries.size() == 0;}
+	void Merge(const Pvs<T> &a);
 
 	PvsData<T> *Find(T sample);
@@ -46,4 +48,14 @@
 };
 
+template <typename T>
+void Pvs<T>::Merge(const Pvs<T> &a)
+{
+	std::map<T, PvsData<T>, LtSample<T> >::iterator it, it_end = mEntries.end();
+
+	for (it = mEntries.begin(); it != mEntries.end(); ++ it)
+	{
+		// TODO
+	}
+}
 
 template <typename T>
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 338)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 341)
@@ -348,10 +348,11 @@
 	int CastRay(Ray &ray);
 
-	/** Merges view cells based on some criteria (e.g., empty view cells or
-		view cells which have a very similar PVS can be merged to one larger
-		view cell farther up in the BSP tree.
+	/** Merges view cells based on some criteria
+	    E.g., empty view cells can pe purged, view cells which have 
+		a very similar PVS can be merged to one larger view cell farther up 
+		in the BSP tree.
 		@returns the number of merged view cells
 	*/
-	int MergeViewCells();
+	//int MergeViewCells();
 
 	/** Set to true if new view cells shall be generated in each leaf.
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 339)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 341)
@@ -1579,31 +1579,80 @@
 	}
 }
-
+/*
 int BspTree::MergeViewCells()
 {
+	int prunedCells = 0;
+
 	stack<BspNode *> nodeStack;
+	stack<BspLeaf *> leafStack;
+
 	nodeStack.push(mRoot);
 
 	ViewCell::NewMail();
 
+	// collect leaves
 	while (!nodeStack.empty()) 
 	{
 		BspNode *node = nodeStack.top();
+		
 		nodeStack.pop();
 
-		if (node->IsLeaf()) 
-		{
-		}
-		else 
-		{
-			BspInterior *interior = dynamic_cast<BspInterior *>(node);
-
-			nodeStack.push(interior->mFront);
-			nodeStack.push(interior->mBack);
-		}
-	}
+		if (node->IsLeaf())
+		{
+			//if (!leafStack.empty() && leafStack.top()->mParent() == node->mParent)
+				leafStack.push(dynamic_cast<BspLeaf *>(node));
+
+		}
+		else
+		{
+			nodeStack.push_back(node->mFront);
+			nodeStack.push_back(node->mFront);
+		}
+	
+		while (!leafStack.empty())
+		{
+			BspLeaf *leaf = leafStack.top();
+			leafStack.pop();
+		}
+
+
 	return 0;
-}
-
+}*/
+/*
+BspLeaf *BspTree::MergeNodes(BspInterior *interior)
+{
+	BspNode *frontLeaf = MergeNodes(interior->mFront);
+	BspNode *backLeaf = MergeNodes(interior->mBack);
+
+	if (frontLeaf->IsLeaf() && backLeaf->IsLeaf())
+	{
+		if (!MergeNecessary(frontLeaf, backLeaf))
+			return interior;
+
+		DEL_PTR(frontLeaf->mViewCell);
+		DEL_PTR(interior->mFront);
+		
+		DEL_PTR(backLeaf->mViewCell);
+		DEL_PTR(interior->mBack);
+
+		BspLeaf *leaf = new BspLeaf(viewCell);
+					
+		// replace a link from node's parent
+		if (!interior->IsRoot())
+		{
+			parent->ReplaceChildLink(interior, leaf);
+			interior->SetParent(parent);
+		}
+		else // new root
+		{
+			mRoot = leaf;
+		}
+		
+		return leaf;
+	}
+
+	return interior;
+}
+*/
 void BspTree::SetGenerateViewCells(int generateViewCells)
 {
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 340)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 341)
@@ -57,5 +57,5 @@
 
 	ObjectContainer objects;
-	
+	int prunedCells = 0;
 	switch (BspTree::sConstructionMethod)
 	{
@@ -69,5 +69,5 @@
 		mSceneGraph->CollectObjects(&objects);
 		mBspTree->Construct(objects);
-		Debug << "collecting view cells" << endl;
+		
 		mBspTree->CollectViewCells(mViewCells);
 		break;
@@ -76,6 +76,9 @@
 		mBspTree->SetGenerateViewCells(true);
 		mBspTree->Construct(mSampleRays);
-		Debug << "collecting view cells" << endl;
+//		prunedCells = mBspTree->MergeViewCells();
+		
 		mBspTree->CollectViewCells(mViewCells);
+
+//		Debug << "Collected " << (int)mViewCells.size() << " cells (" << prunedCells << " pruned)" << endl;
 		break;
 	default:
