Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 557)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 561)
@@ -253,9 +253,16 @@
 	/** Checks if view cell is considered as valid.
 	*/
-	virtual bool CheckValid(ViewCell *vc) const;
+	virtual bool CheckValidity(ViewCell *vc, 
+							   float minPvsRatio, 
+							   float maxPvsRatio) const;
 
 	/** Returns maximal allowed pvs size.
 	*/
 	int GetMaxPvsSize() const;
+
+	/** Returns maximal ratio. i.e., currentPVs / maxPvs,
+		where pvs is still considered valid.
+	*/
+	float GetMaxPvsRatio() const;
 
 	/** Exports view cell geometry.
@@ -327,14 +334,8 @@
 	int mVisualizationSamples;
 
-	//-- thresholds used for view cells merge
-	int mMinPvsDif;
-	int mMinPvs;
-	int mMaxPvs;
-
 	float mTotalAreaValid;
 	float mTotalArea;
 
 	int mMaxPvsSize;
-
 	float mMaxPvsRatio;
 
@@ -410,12 +411,4 @@
 	void CollectViewCells();
 
-	/** Merges view cells front and back leaf view cell.
-	*/
-	bool MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const;
-
-	/** Returns true if front and back leaf should be merged.
-	*/
-	bool ShouldMerge(BspLeaf *front, BspLeaf *back) const;
-
 	void ConstructBspRays(const VssRayContainer &rays,
 						  const int numSamples);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 560)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 561)
@@ -510,8 +510,7 @@
 		}
 		
-		if (!mViewCellsManager->CheckValid(viewCell))
+		if (!mViewCellsManager->CheckValidity(viewCell, 0.0, mViewCellsManager->GetMaxPvsRatio()))
 		{
 			viewCell->SetValid(false);
-
 			leaf->SetTreeValid(false);
 			PropagateUpValidity(leaf);
@@ -1645,5 +1644,5 @@
 				BspViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();
 			
-				if (!mViewCellsManager->CheckValid(viewCell))
+				if (!mViewCellsManager->CheckValidity(viewCell, 0.0, mViewCellsManager->GetMaxPvsRatio()))
 				{
 					vector<BspLeaf *>::const_iterator it, it_end = viewCell->mLeaves.end();
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 558)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 561)
@@ -26,5 +26,6 @@
 mTotalArea(0.0f),
 mViewCellsFinished(false),
-mMaxPvsSize(99999)
+mMaxPvsSize(99999),
+mMaxPvsRatio(1.0)
 {
 	mViewSpaceBox.Initialize();
@@ -109,8 +110,13 @@
 
 
-bool ViewCellsManager::CheckValid(ViewCell *vc) const
-{
-	if (vc->GetPvs().GetSize() > mMaxPvsSize)
+bool ViewCellsManager::CheckValidity(ViewCell *vc, 
+									 float minPvsRatio, 
+									 float maxPvsRatio) const
+{
+	if ((vc->GetPvs().GetSize() > mMaxPvsSize * maxPvsRatio) ||
+		(vc->GetPvs().GetSize() < mMaxPvsSize * minPvsRatio))
+	{	
 		return false;
+	}
 
 	return true;
@@ -421,4 +427,10 @@
 
 
+float ViewCellsManager::GetMaxPvsRatio() const
+{
+	return mMaxPvsRatio;
+}
+
+
 void ViewCellsManager::ComputeSampleContributions(VssRay &ray)
 {
@@ -778,5 +790,5 @@
 		if (ray->intersections.size() < 2)
 			continue;
-
+#if 0
 		iit = ray->intersections.begin();
 
@@ -797,4 +809,5 @@
 			previousLeaf = leaf;
 		}
+#endif
 	}
 
@@ -1024,62 +1037,4 @@
 }
 
-
-bool BspViewCellsManager::MergeBspLeafViewCells(BspLeaf *front, BspLeaf *back) const
-{
-	BspViewCell *viewCell =
-		dynamic_cast<BspViewCell *>(MergeViewCells(*front->GetViewCell(),
-												   *back->GetViewCell()));
-
-	if (!viewCell)
-		return false;
-
-	//-- change pointer to view cells of all leaves associated with the previous view cells
-	BspViewCell *fVc = front->GetViewCell();
-	BspViewCell *bVc = back->GetViewCell();
-
-	vector<BspLeaf *> fLeaves = fVc->mLeaves;
-	vector<BspLeaf *> bLeaves = bVc->mLeaves;
-
-	vector<BspLeaf *>::const_iterator it;
-
-	for (it = fLeaves.begin(); it != fLeaves.end(); ++ it)
-	{
-		(*it)->SetViewCell(viewCell);
-		viewCell->mLeaves.push_back(*it);
-	}
-	for (it = bLeaves.begin(); it != bLeaves.end(); ++ it)
-	{
-		(*it)->SetViewCell(viewCell);
-		viewCell->mLeaves.push_back(*it);
-	}
-
-	DEL_PTR(fVc);
-	DEL_PTR(bVc);
-
-	return true;
-}
-
-bool BspViewCellsManager::ShouldMerge(BspLeaf *front, BspLeaf *back) const
-{
-	ViewCell *fvc = front->GetViewCell();
-	ViewCell *bvc = back->GetViewCell();
-
-	if ((fvc == mBspTree->GetRootCell()) || (bvc == mBspTree->GetRootCell()) || (fvc == bvc))
-		return false;
-
-	int fdiff = fvc->GetPvs().Diff(bvc->GetPvs());
-
-	if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs)
-	{
-		if ((fvc->GetPvs().GetSize() < mMinPvs) ||
-			(bvc->GetPvs().GetSize() < mMinPvs) ||
-			((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif)))
-		{
-			return true;
-		}
-	}
-
-	return false;
-}
 
 
@@ -1976,5 +1931,5 @@
 	int merged = 0;
 
-	cout << "starting merge using " << mPostProcessSamples << " samples ... ";
+	cout << "starting merge using " << mPostProcessSamples << " samples ... " << endl;
 	long startTime = GetTime();
 
@@ -1983,5 +1938,5 @@
 
 	//-- stats and visualizations
-	cout << "finished" << endl;
+	cout << "finished merging" << endl;
 	cout << "merged " << merged << " view cells in "
 		 << TimeDiff(startTime, GetTime()) *1e-3 << " secs" << endl;
@@ -2099,5 +2054,4 @@
 
 	// real meshes are only contructed only at this stage
-	//CreateViewCellMeshes();
 	FinalizeViewCells(true);
 
@@ -2419,9 +2373,8 @@
 										 ViewCell *vc) const
 {
-	if (CheckValid(vc) && (mColorCode == 0)) // Random color
+	if (CheckValidity(vc, 0.0, mMaxPvsRatio) && (mColorCode == 0)) // Random color
 		return;
 
 	float importance = 0;
-	
 	Material m;
 	
@@ -2453,5 +2406,5 @@
 	}
 
-	m.mDiffuseColor.b = CheckValid(vc) ? 1.0f : 0.0f;
+	m.mDiffuseColor.b = CheckValidity(vc, 0.0, mMaxPvsRatio) ? 1.0f : 0.0f;
 	m.mDiffuseColor.r = importance;
 	m.mDiffuseColor.g = 1.0f - m.mDiffuseColor.r;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 556)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 561)
@@ -925,5 +925,5 @@
 	//glFrustum(-1, 1, -1, 1, 1, 20000);
 
-    const Vector3 center = viewPoint + beam.GetMainDirection() * (zfar - znear) * 0.3;
+    const Vector3 center = viewPoint + beam.GetMainDirection() * (zfar - znear) * 0.3f;
 	const Vector3 up = 
 		Normalize(CrossProd(beam.mPlanes[0].mNormal, beam.mPlanes[4].mNormal));
