Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 470)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 471)
@@ -2163,4 +2163,5 @@
 
 	//Debug << mMinViewCells << " " << mMaxCostRatio << endl;
+
 	// use priority queue to merge leaves
 	while (!mergeQueue.empty() &&
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 470)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 471)
@@ -172,5 +172,5 @@
   /** Returns probability that view point lies in one view cell.
   */
-  virtual float GetProbability(ViewCell *viewCell) const = 0;
+  virtual float GetProbability(ViewCell *viewCell) = 0;
 
   /** Returns render cost of a single view cell given the render cost of an object.
@@ -261,5 +261,5 @@
 						ViewCellContainer &viewcells);
 	
-	float GetProbability(ViewCell *viewCell) const;
+	float GetProbability(ViewCell *viewCell);
 	float GetRendercost(ViewCell *viewCell, float objRendercost) const;
 
@@ -327,5 +327,5 @@
 	virtual void PrintStatistics(ostream &s) const;
 
-	float GetProbability(ViewCell *viewCell) const;
+	float GetProbability(ViewCell *viewCell);
 	float GetRendercost(ViewCell *viewCell, float objRendercost) const;
 
@@ -377,5 +377,5 @@
 						ViewCellContainer &viewcells);
 
-	float GetProbability(ViewCell *viewCell) const;
+	float GetProbability(ViewCell *viewCell);
 	float GetRendercost(ViewCell *viewCell, float objRendercost) const;
 
@@ -421,5 +421,5 @@
 						ViewCellContainer &viewcells);
 
-	float GetProbability(ViewCell *viewCell) const;
+	float GetProbability(ViewCell *viewCell);
 	float GetRendercost(ViewCell *viewCell, float objRendercost) const;
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 469)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp	(revision 471)
@@ -884,6 +884,9 @@
       KdLeaf *leaf = (KdLeaf *)node;
 	  // kdtree used as view cell container => create view cell
-	  leaf->mViewCell = new KdViewCell();
-      vc.push_back(leaf->mViewCell);
+	  KdViewCell *viewCell = new KdViewCell();
+	  leaf->mViewCell = viewCell;
+	  // push back pointer to this leaf
+	  viewCell->mLeaves.push_back(leaf);
+      vc.push_back(viewCell);
     } else {
       KdInterior *interior = (KdInterior *)node;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h	(revision 470)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h	(revision 471)
@@ -24,5 +24,5 @@
 public:
 	ViewCell();
-	
+
 	/** Constructor taking a mesh representing the shape of	the viewcell.
 	*/
@@ -32,5 +32,5 @@
 	*/
 	virtual ~ViewCell() {}
-	/** Returns Pvs. 
+	/** Returns Pvs.
 	*/
 	const ObjectPvs &GetPvs() const;
@@ -38,8 +38,8 @@
 
 	int Type() const;
-	
+
 	/** Adds a passing ray to the passing ray container.
 	*/
-	void AddPassingRay(const Ray &ray, const int contributions);	
+	void AddPassingRay(const Ray &ray, const int contributions);
 
 	/** Returns volume of the view cell.
@@ -51,5 +51,5 @@
 	void SetVolume(float size);
 
-	/// Ray set description of the rays passing through this node.	
+	/// Ray set description of the rays passing through this node.
 	PassingRaySet mPassingRays;
 
@@ -73,5 +73,5 @@
 public:
 	HierarchyViewCell<T>(): mLeaves(0) {}
-	HierarchyViewCell<T>(Mesh *mesh): 
+	HierarchyViewCell<T>(Mesh *mesh):
 		ViewCell(mesh), mLeaves(0) {}
 
@@ -87,4 +87,5 @@
 /** Statistics for a view cell partition.
 */
+
 class ViewCellsStatistics: public StatisticsBase
 {
@@ -96,5 +97,5 @@
 	/// size of the PVS
 	int pvs;
-  
+
 	/// largest PVS of all view cells
 	int maxPvs;
@@ -109,9 +110,9 @@
 	int leaves;
 
-	/// largest number of leaves covered by one view cell  
+	/// largest number of leaves covered by one view cell
 	int maxLeaves;
 
     // Constructor
-	ViewCellsStatistics() 
+	ViewCellsStatistics()
 	{
 		Reset();
@@ -120,9 +121,9 @@
 	double AvgLeaves() const {return (double)leaves / (double)viewCells;};
 	double AvgPvs() const {return (double)pvs / (double)viewCells;};
-  
-	void Reset() 
+
+	void Reset()
 	{
-		viewCells = 0;	
-		pvs = 0;  
+		viewCells = 0;
+		pvs = 0;
 		maxPvs = 0;
 
@@ -135,9 +136,9 @@
 	void Print(ostream &app) const;
 
-	friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat) 
+	friend ostream &operator<<(ostream &s, const ViewCellsStatistics &stat)
 	{
 		stat.Print(s);
 		return s;
-	}  
+	}
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 470)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 471)
@@ -396,17 +396,9 @@
 
 
-float BspViewCellsManager::GetProbability(ViewCell *viewCell) const
-{
-	PolygonContainer geom;
-
-	// compute view cell area
-	mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom);
-	
-	const float area = Polygon3::GetArea(geom);
-	const float viewspaceArea = GetTotalArea();// mBspTree->GetBoundingBox().SurfaceArea();
-
-	CLEAR_CONTAINER(geom);
-
-	return area / viewspaceArea;
+float BspViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	// compute view cell area as subsititute for probability
+	return GetArea(viewCell) / mBspTree->GetBoundingBox().SurfaceArea();
+	//return GetArea(viewCell) / GetTotalArea();
 }
 
@@ -898,11 +890,11 @@
 }
 
-float KdViewCellsManager::GetProbability(ViewCell *viewCell) const
-{
-	KdViewCell *vc = dynamic_cast<KdViewCell *>(viewCell);
-
-	AxisAlignedBox3 box = mKdTree->GetBox(vc->mLeaves[0]);
-
-	return box.SurfaceArea();
+float KdViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	// compute view cell area as subsititute for probability
+	AxisAlignedBox3 box = mKdTree->GetBox(mKdTree->GetRoot());
+
+	return GetArea(viewCell) / box.SurfaceArea();
+	//return GetArea(viewCell) / GetTotalArea();
 }
 
@@ -1161,15 +1153,11 @@
 }
 
-float VspKdViewCellsManager::GetProbability(ViewCell *viewCell) const
-{
-/*	AxisAlignedBox3 box = mKdTree->GetBox(*it);
-			
+float VspKdViewCellsManager::GetProbability(ViewCell *viewCell)
+{
 	// volume or area substitutes for view point probability
-	if (0)
-		return box.GetVolume(); 
-	else
-		return box.SurfaceArea();
-*/
-	return dynamic_cast<VspKdViewCell *>(viewCell)->GetVolume();
+	AxisAlignedBox3 box = mVspKdTree->GetBBox(mVspKdTree->GetRoot());
+
+	return GetArea(viewCell) / box.SurfaceArea();
+	//return GetArea(viewCell) / GetTotalArea();
 }
 
@@ -1389,17 +1377,8 @@
 }
 
-float VspBspViewCellsManager::GetProbability(ViewCell *viewCell) const
-{
-	PolygonContainer geom;
-
-	// compute view cell area
-	mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom);
-	
-	const float area = Polygon3::GetArea(geom);
-	const float accArea = mVspBspTree->GetBoundingBox().SurfaceArea();
-
-	CLEAR_CONTAINER(geom);
-
-	return area / accArea;
+float VspBspViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	return GetArea(viewCell) / mVspBspTree->GetBoundingBox().SurfaceArea();
+	//return GetArea(viewCell) / GetTotalArea();
 }
 
