Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 448)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 468)
@@ -249,4 +249,10 @@
 			</File>
 			<File
+				RelativePath="..\src\Renderer.cpp">
+			</File>
+			<File
+				RelativePath="..\src\Renderer.h">
+			</File>
+			<File
 				RelativePath="..\src\RenderSimulator.cpp">
 			</File>
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 466)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 468)
@@ -1901,17 +1901,18 @@
 
 
-int VspKdTree::CastRay(Ray &ray)
+int VspKdTree::CastLineSegment(const Vector3 &origin,
+							   const Vector3 &termination,
+							   vector<ViewCell *> &viewcells)
 {
 	int hits = 0;
 
-	stack<RayTraversalData> tStack;
-
-	float maxt = 1e6;
-	float mint = 0;
+	float mint = 0.0f, maxt = 1.0f;
+	const Vector3 dir = termination - origin;
+
+	stack<LineSegmentTraversalData > tStack;
 
 	Intersectable::NewMail();
 
-	if (!mBox.GetMinMaxT(ray, &mint, &maxt))
-		return 0;
+	//if (!mBox.GetMinMaxT(ray, &mint, &maxt)) return 0;
 
 	if (mint < 0)
@@ -1920,6 +1921,6 @@
 	maxt += Limits::Threshold;
 
-	Vector3 entp = ray.Extrap(mint);
-	Vector3 extp = ray.Extrap(maxt);
+	Vector3 entp = origin;
+	Vector3 extp = termination;
 
 	VspKdNode *node = mRoot;
@@ -1969,7 +1970,7 @@
  			// $$ modification 3.5.2004 - hints from Kamil Ghais
 			// case N4 or P4
-			float tdist = (position - ray.GetLoc(axis)) / ray.GetDir(axis);
+			float tdist = (position - origin[axis]) / dir[axis];
 			//tStack.push(RayTraversalData(farChild, extp, maxt)); //TODO
-			extp = ray.GetLoc() + ray.GetDir()*tdist;
+			extp = origin + dir * tdist;
 			maxt = tdist;
 		}
@@ -1977,24 +1978,12 @@
 		{
 			// compute intersection with all objects in this leaf
-			/*KdLeaf *leaf = (KdLeaf *) node;
-			if (ray.mFlags & Ray::STORE_KDLEAVES)
-				ray.kdLeaves.push_back(leaf);
-
-			ObjectContainer::const_iterator mi;
-			for ( mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); mi++)
-			{
-				Intersectable *object = *mi;
-				if (!object->Mailed() )
-				{
-					object->Mail();
-					if (ray.mFlags & Ray::STORE_TESTED_OBJECTS)
-						ray.testedObjects.push_back(object);
-					hits += object->CastRay(ray);
-				}
-			}
-
-			if (hits && ray.GetType() == Ray::LOCAL_RAY)
-				if (ray.intersections[0].mT <= maxt)
-					break;
+			VspKdLeaf *leaf = dynamic_cast<VspKdLeaf *>(node);
+			ViewCell *vc = leaf->GetViewCell();
+
+			if (!vc->Mailed())
+			{
+				vc->Mail();
+				viewcells.push_back(vc);
+			}
 
 			// get the next node from the stack
@@ -2004,13 +1993,10 @@
 			entp = extp;
 			mint = maxt;
-			if (ray.GetType() == Ray::LINE_SEGMENT && mint > 1.0f)
-				break;
-
-			RayTraversalData &s  = tStack.top();
+			
+			LineSegmentTraversalData &s  = tStack.top();
 			node = s.mNode;
 			extp = s.mExitPoint;
 			maxt = s.mMaxT;
 			tStack.pop();
-			*/
 		}
 	}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Renderer.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Renderer.h	(revision 468)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Renderer.h	(revision 468)
@@ -0,0 +1,31 @@
+#ifndef _Renderer_h__
+#define _Renderer_h__
+
+#include "common.h"
+
+class ViewCellsManager;
+
+/** Abstract class used to render the scene.
+*/
+class Renderer
+{
+
+public:
+
+	Renderer();
+	Renderer(ViewCellsManager *vcm);
+
+	~Renderer();
+
+	/** Renders the scene using the current view cell partition.
+	*/
+	virtual bool RenderScene() = 0;
+
+	void SetViewCellsManager(ViewCellsManager *vcm);
+
+protected:
+	ViewCellsManager *mViewCellsManager;
+};
+
+
+#endif // Renderer
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h	(revision 463)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.h	(revision 468)
@@ -4,11 +4,6 @@
 #include "common.h"
 #include "Statistics.h"
+#include "Renderer.h"
 
-class BspTree;
-class KdTree;
-class ViewCell;
-class KdLeaf;
-class VspKdTree;
-class VspBspTree;
 
 class SimulationStatistics: public StatisticsBase
@@ -47,7 +42,7 @@
 
 /** Simulated rendering using a simple render heuristics. Used to evaluate the 
-	quality of the view cell partition.
+	quality of the view cell partition. Evaluates some statistics of the simulation.
 */
-class RenderSimulator
+class RenderSimulator: public Renderer
 {
 
@@ -59,9 +54,4 @@
 	*/
 	RenderSimulator(float objRendercost, float vcOverhead, float moveSpeed);
-
-	/** Simulates rendering of the view cells.
-		@returns the statistics of the simulation.
-	*/
-	virtual SimulationStatistics SimulateRendering() = 0;
 
 	/** Sets estimated render time for a single object in the PVS.
@@ -77,100 +67,29 @@
 	void SetMoveSpeed(const float moveSpeed);
 
+	/** Returns simulation statistics.
+	*/
+	void GetStatistics(SimulationStatistics &simStats) const;
+
+	/** Simulates rendering of the scene.
+	*/
+	bool RenderScene();
 
 protected:
 
+	/** Probability for crossing one view cell.
+	*/
+	float GetCrossVcProbability();
+
 	/// render time for single object of the PVS
 	float mObjRenderCost;
+	
 	/// const overhead for crossing a view cell border
 	float mVcOverhead;
+
 	/// move speed of player
 	float mMoveSpeed;
-};
 
-class BspRenderSimulator: public RenderSimulator
-{
-public:
-	BspRenderSimulator(BspTree *bspTree);
-
-	BspRenderSimulator(float objRenderCost, 
-							   float vcOverhead, 
-							   float moveSpeed, 
-							   BspTree *bspTree);
-
-	SimulationStatistics SimulateRendering();
-
-protected:
-	/** Simulates rendering of the pvs of one view cell, with given rendering time for an object.
-		@param viewCell the view cell holding the Pvs
-		@param objRenderTime estimated render time for one object of the Pvs
-	*/
-	Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const;
-
-private:
-	BspTree *mBspTree;
-};
-
-class VspBspRenderSimulator: public RenderSimulator
-{
-public:
-	VspBspRenderSimulator(VspBspTree *vspBspTree);
-
-	VspBspRenderSimulator(float objRenderCost, 
-						  float vcOverhead, 
-						  float moveSpeed, 
-						  VspBspTree *vspBspTree);
-
-	SimulationStatistics SimulateRendering();
-
-protected:
-	/** Simulates rendering of the pvs of one view cell, with given rendering time for an object.
-		@param viewCell the view cell holding the Pvs
-		@param objRenderTime estimated render time for one object of the Pvs
-	*/
-	Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const;
-
-private:
-	VspBspTree *mVspBspTree;
-};
-
-class KdRenderSimulator: public RenderSimulator
-{
-public:
-	KdRenderSimulator(KdTree *kdTree);
-
-	KdRenderSimulator(float objRenderCost, 
-							  float vcOverhead, 
-							  float moveSpeed, 
-							  KdTree *kdTree);
-	SimulationStatistics SimulateRendering();
-
-protected:
-
-	Real RenderPvs(KdLeaf *leaf, float objRenderTime) const;
-
-	KdTree *mKdTree;
-};
-
-class VspKdRenderSimulator: public RenderSimulator
-{
-public:
-	VspKdRenderSimulator(VspKdTree *vspKdTree);
-
-	VspKdRenderSimulator(float objRenderCost, 
-						 float vcOverhead, 
-						 float moveSpeed, 
-						 VspKdTree *vspKdTree);
-
-	SimulationStatistics SimulateRendering();
-
-protected:
-	/** Simulates rendering of the pvs of one view cell, with given rendering time for an object.
-		@param viewCell the view cell holding the Pvs
-		@param objRenderTime estimated render time for one object of the Pvs
-	*/
-	Real RenderPvs(ViewCell &viewCell, const float objRenderTime) const;
-
-private:
-	VspKdTree *mVspKdTree;
+	/// Simulation statistics
+	SimulationStatistics mSimulationStatistics;
 };
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 467)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 468)
@@ -62,6 +62,5 @@
 		@param contributingSamples returns the number of contributingSamples
 	*/
-  void  ComputeSampleContributions(const VssRayContainer &rays
-								   );
+  void  ComputeSampleContributions(const VssRayContainer &rays);
 
 
@@ -94,9 +93,4 @@
 	virtual int GetType() const = 0;
 
-	/** Simulates rendering with the given view cell partition.
-		@returns render time statistics
-	*/
-	SimulationStatistics SimulateRendering() const;
-
 	/** Load the input viewcells. The input viewcells should be given as a collection
 		of meshes. Each mesh is assume to form a bounded polyhedron defining the interior of
@@ -176,6 +170,17 @@
   PrintPvsStatistics(ostream &s);
 
+  /** Returns probability that view point lies in one view cell.
+  */
+  virtual float GetProbability(ViewCell *viewCell) = 0;
+
+  /** Returns render cost of a single view cell given the render cost of an object.
+  */
+  virtual float GetRendercost(ViewCell *viewCell, float objRendercost) = 0;
+
+  /** Returns vector of loaded / generated view cells.
+  */
+  ViewCellContainer &GetViewCells();
+
 protected:
-	
 	
 
@@ -239,10 +244,11 @@
 	~BspViewCellsManager();
 
-  int CastLineSegment(const Vector3 &origin,
-					  const Vector3 &termination,
-					  ViewCellContainer &viewcells
-					  );
-
-  
+	int CastLineSegment(const Vector3 &origin,
+						const Vector3 &termination,
+						ViewCellContainer &viewcells);
+	
+	float GetProbability(ViewCell *viewCell);
+	float GetRendercost(ViewCell *viewCell, float objRendercost);
+
 protected:
 
@@ -305,4 +311,7 @@
 	*/
 	virtual void PrintStatistics(ostream &s) const;
+
+	float GetProbability(ViewCell *viewCell);
+	float GetRendercost(ViewCell *viewCell, float objRendercost);
 
 protected:
@@ -353,6 +362,8 @@
     int CastLineSegment(const Vector3 &origin,
 						const Vector3 &termination,
-						ViewCellContainer &viewcells
-						) ;
+						ViewCellContainer &viewcells);
+
+	float GetProbability(ViewCell *viewCell);
+	float GetRendercost(ViewCell *viewCell, float objRendercost);
 
 protected:
@@ -394,9 +405,12 @@
 
 	void PrintStatistics(ostream &s) const;
-
-  int CastLineSegment(const Vector3 &origin,
-					  const Vector3 &termination,
-					  ViewCellContainer &viewcells
-					  ) ;
+	
+	int CastLineSegment(const Vector3 &origin,
+						const Vector3 &termination,
+						ViewCellContainer &viewcells);
+
+	float GetProbability(ViewCell *viewCell);
+	float GetRendercost(ViewCell *viewCell, float objRendercost);
+
 
 protected:
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 466)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 468)
@@ -1863,9 +1863,7 @@
 
 
-int
-BspTree::CastLineSegment(const Vector3 &origin,
-						 const Vector3 &termination,
-						 vector<ViewCell *> &viewcells
-						 )
+int BspTree::CastLineSegment(const Vector3 &origin,
+							 const Vector3 &termination,
+							 vector<ViewCell *> &viewcells)
 {
   int hits = 0;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp	(revision 465)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/RenderSimulator.cpp	(revision 468)
@@ -5,4 +5,5 @@
 #include "VspBspTree.h"
 #include "VspKdTree.h"
+#include "ViewCellsManager.h"
 
 void SimulationStatistics::Print(ostream &app) const
@@ -52,28 +53,8 @@
 }
 
-/********************************************************/
-/*     class BspRenderSimulator implementation          */
-/********************************************************/
-
-
-BspRenderSimulator::BspRenderSimulator(BspTree *bspTree):
-mBspTree(bspTree)
+bool RenderSimulator::RenderScene()
 {
-}
-
-BspRenderSimulator::BspRenderSimulator(float objRenderCost, 
-											   float vcOverhead, 
-											   float moveSpeed,
-											   BspTree *bspTree):
-RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mBspTree(bspTree)
-{
-}
-
-SimulationStatistics BspRenderSimulator::SimulateRendering()
-{
-	SimulationStatistics simStat;
-
-	simStat.Reset();
-	simStat.Start();
+	mSimulationStatistics.Reset();
+	mSimulationStatistics.Start();
 
 	Real renderTime = 0;
@@ -81,355 +62,46 @@
 	// overhead for loading the PVS of the view cells
 	float loadPvsOverhead = 0;
-	// probability that view point lies in a view cell
-	float pInVcTotal = 0;
+	
+	ViewCellContainer::const_iterator it, 
+		it_end = mViewCellsManager->GetViewCells().end();
 
-	// total probability that a view cell border is crossed
-	const float pCrossVcTotal = mBspTree->GetBoundingBox().SurfaceArea();
+	for (it = mViewCellsManager->GetViewCells().begin(); it != it_end; ++ it)
+	{
+		ViewCell *vc = *it;
 
-	// collect all view cells
-	ViewCellContainer viewCells;
-	mBspTree->CollectViewCells(viewCells);
-
-	ViewCellContainer::const_iterator it, it_end = viewCells.end();
-
-	// surface area substitute for probability
-	PolygonContainer geom;
-float overallarea = 0;
-	for (it = viewCells.begin(); it != it_end; ++ it)
-	{
-		// compute view cell area
-		mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
-		const float area = Polygon3::GetArea(geom);
-		if (area < 0.0001)
-			Debug << "warning, area: " << area << endl;
-		CLEAR_CONTAINER(geom);
-
-		// area substitute for view point probability
-		float pInVc = area;
+		// probability of view cell
+		const float pInVc = mViewCellsManager->GetProbability(vc);
 				
 		// compute render time of PVS times probability that view point is in view cell
-		float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
-		//Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
+		const float vcCost = pInVc * mViewCellsManager->GetRendercost(vc, mObjRenderCost);
+		
+		// crossing the border of a view cell is depending on the move speed
+		// and the probability that a view cell border is crossed
+		loadPvsOverhead += GetCrossVcProbability() * mVcOverhead;
+
+		//-- update statistics
 		renderTime += vcCost;
 
-		if (vcCost > simStat.maxCost)
-			simStat.maxCost = vcCost;
-		else if (vcCost < simStat.minCost)
-			simStat.minCost = vcCost;
+		if (vcCost > mSimulationStatistics.maxCost)
+			mSimulationStatistics.maxCost = vcCost;
+		else if (vcCost < mSimulationStatistics.minCost)
+			mSimulationStatistics.minCost = vcCost;
+	}
+	
+	mSimulationStatistics.avgRtWithoutOverhead = renderTime;
+	mSimulationStatistics.avgRenderTime = renderTime + loadPvsOverhead;
+	
+	mSimulationStatistics.Stop();
 
-		// probability that a view cell border is crossed
-		float pCrossVc = area * mMoveSpeed;
-
-		// crossing the border of a view cell is also depending on the move speed
-		loadPvsOverhead += pCrossVc * mVcOverhead;
-overallarea += area;
-		pInVcTotal += pInVc;
-	}
-	Debug << "overall area: " << overallarea << endl;
-	
-	renderTime /= pInVcTotal;
-	loadPvsOverhead /= pCrossVcTotal;
-
-	simStat.avgRtWithoutOverhead = renderTime;
-	simStat.avgRenderTime = renderTime + loadPvsOverhead;
-	
-	simStat.maxCost /= pInVcTotal;
-	simStat.minCost /= pInVcTotal;
-
-	simStat.Stop();
-
-	return simStat;
+	return true;
 }
 
-Real BspRenderSimulator::RenderPvs(ViewCell &viewCell, 
-								   float objRenderTime) const
+float RenderSimulator::GetCrossVcProbability()
 {
-	return viewCell.GetPvs().GetSize() * objRenderTime;
+	return 0;
 }
 
-/*******************************************************/
-/*     class KdenderSimulator implementation           */
-/*******************************************************/
-
-KdRenderSimulator::KdRenderSimulator(float objRenderCost, 
-											 float vcOverhead,
-											 float moveSpeed,
-											 KdTree *kdTree):
-RenderSimulator(objRenderCost, vcOverhead, moveSpeed), mKdTree(kdTree)
+void RenderSimulator::GetStatistics(SimulationStatistics &simStats) const
 {
+	simStats = mSimulationStatistics;
 }
-
-KdRenderSimulator::KdRenderSimulator(KdTree *kdTree):
-mKdTree(kdTree)
-{
-}
-
-SimulationStatistics KdRenderSimulator::SimulateRendering()
-{
-	SimulationStatistics simStat;
-
-	//mKdTree->CollectLeavesPvs();
-	simStat.Reset();
-	simStat.Start();
-
-	// total render time
-	Real renderTime = 0;
-	// overhead for loading a view cell
-	float loadPvsOverhead = 0;
-
-	// probability that view point lies in a view cell
-	float pInVcTotal = 0;//mKdTree->GetBox().GetVolume();
-
-	// total probability that a view cell border is crossed
-	const float pCrossVcTotal = mKdTree->GetBox().SurfaceArea();
-
-	vector<KdLeaf *> leaves;
-	mKdTree->CollectLeaves(leaves);
-	
-	AxisAlignedBox3 box;
-
-	vector<KdLeaf *>::const_iterator it, it_end = leaves.end();
-	
-	for (it = leaves.begin(); it != it_end; ++ it)
-	{
-		box = mKdTree->GetBox(*it);
-			
-		// volume substitute for view point probability
-		float pInVc = 0;
-		
-		if (0)
-			pInVc = box.GetVolume(); 
-		else
-			pInVc = box.SurfaceArea();
-		
-		float vcCost = pInVc * RenderPvs(*it, mObjRenderCost);
-		renderTime += vcCost;
-
-		if (vcCost > simStat.maxCost)
-			simStat.maxCost = vcCost;
-		else if (vcCost < simStat.minCost)
-			simStat.minCost = vcCost;
-
-		// probability that a view cell border is crossed
-		const float pCrossVc = box.SurfaceArea() * mMoveSpeed;
-
-		loadPvsOverhead += pCrossVc * mVcOverhead;
-
-		pInVcTotal += pInVc;
-	}
-
-	renderTime /= pInVcTotal;
-	loadPvsOverhead /= pCrossVcTotal;
-
-    simStat.avgRtWithoutOverhead = renderTime;
-	simStat.avgRenderTime = renderTime + loadPvsOverhead;
-
-	simStat.maxCost /= pInVcTotal;
-	simStat.minCost /= pInVcTotal;
-
-	simStat.Stop();
-
-	return simStat;
-}
-
-Real KdRenderSimulator::RenderPvs(KdLeaf *leaf, 
-								  float objRenderTime) const
-{
-	return leaf->mKdPvs.GetSize() * objRenderTime;
-}
-
-/**********************************************************/
-/*       class BspRenderSimulator implementation          */
-/**********************************************************/
-
-VspBspRenderSimulator::VspBspRenderSimulator(VspBspTree *vspBspTree):
-mVspBspTree(vspBspTree)
-{
-}
-
-VspBspRenderSimulator::VspBspRenderSimulator(float objRenderCost, 
-											 float vcOverhead, 
-											 float moveSpeed,
-											 VspBspTree *vspBspTree):
-RenderSimulator(objRenderCost, vcOverhead, moveSpeed), 
-mVspBspTree(vspBspTree)
-{
-}
-
-SimulationStatistics VspBspRenderSimulator::SimulateRendering()
-{
-	SimulationStatistics simStat;
-
-	simStat.Reset();
-	simStat.Start();
-
-	Real renderTime = 0;
-	
-	// overhead for loading the PVS of the view cells
-	float loadPvsOverhead = 0;
-	// probability that view point lies in a view cell
-	float pInVcTotal = 0;
-
-	// total probability that a view cell border is crossed
-	const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea();
-
-	// collect all view cells
-	ViewCellContainer viewCells;
-	mVspBspTree->CollectViewCells(viewCells);
-
-	ViewCellContainer::const_iterator it, it_end = viewCells.end();
-
-	// surface area substitute for probability
-	PolygonContainer geom;
-float overallarea = 0;
-	for (it = viewCells.begin(); it != it_end; ++ it)
-	{
-		// compute view cell area
-		mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
-
-		const float area = Polygon3::GetArea(geom);
-		if (area < 0.0001)
-			Debug << "warning, area: " << area << endl;
-		CLEAR_CONTAINER(geom);
-
-		// area substitute for view point probability
-		float pInVc = area;
-				
-		// compute render time of PVS times probability that view point is in view cell
-		float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
-		//Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
-		renderTime += vcCost;
-
-		if (vcCost > simStat.maxCost)
-			simStat.maxCost = vcCost;
-		else if (vcCost < simStat.minCost)
-			simStat.minCost = vcCost;
-
-		// probability that a view cell border is crossed
-		float pCrossVc = area * mMoveSpeed;
-
-		// crossing the border of a view cell is also depending on the move speed
-		loadPvsOverhead += pCrossVc * mVcOverhead;
-overallarea += area;
-		pInVcTotal += pInVc;
-	}
-	Debug << "overall area: " << overallarea << endl;
-	
-	renderTime /= pInVcTotal;
-	loadPvsOverhead /= pCrossVcTotal;
-
-	simStat.avgRtWithoutOverhead = renderTime;
-	simStat.avgRenderTime = renderTime + loadPvsOverhead;
-	
-	simStat.maxCost /= pInVcTotal;
-	simStat.minCost /= pInVcTotal;
-
-	simStat.Stop();
-
-	return simStat;
-}
-
-Real VspBspRenderSimulator::RenderPvs(ViewCell &viewCell, 
-									  float objRenderTime) const
-{
-	return viewCell.GetPvs().GetSize() * objRenderTime;
-}
-
-
-
-/*************************************************************/
-/*        class VspKdRenderSimulator implementation          */
-/*************************************************************/
-
-
-VspKdRenderSimulator::VspKdRenderSimulator(VspKdTree *vspKdTree):
-mVspKdTree(vspKdTree)
-{
-}
-
-VspKdRenderSimulator::VspKdRenderSimulator(float objRenderCost, 
-										   float vcOverhead, 
-										   float moveSpeed,
-										   VspKdTree *vspKdTree):
-RenderSimulator(objRenderCost, vcOverhead, moveSpeed), 
-mVspKdTree(vspKdTree)
-{
-}
-
-SimulationStatistics VspKdRenderSimulator::SimulateRendering()
-{SimulationStatistics simStat;
-
-	simStat.Reset();
-	simStat.Start();
-
-	Real renderTime = 0;
-	
-	// overhead for loading the PVS of the view cells
-	float loadPvsOverhead = 0;
-	// probability that view point lies in a view cell
-	float pInVcTotal = 0;
-
-	// total probability that a view cell border is crossed
-/*	const float pCrossVcTotal = mVspBspTree->GetBoundingBox().SurfaceArea();
-
-	// collect all view cells
-	ViewCellContainer viewCells;
-	mVspBspTree->CollectViewCells(viewCells);
-
-	ViewCellContainer::const_iterator it, it_end = viewCells.end();
-
-	// surface area substitute for probability
-	PolygonContainer geom;
-float overallarea = 0;
-	for (it = viewCells.begin(); it != it_end; ++ it)
-	{
-		// compute view cell area
-		mVspBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(*it), geom);
-
-		const float area = Polygon3::GetArea(geom);
-		if (area < 0.0001)
-			Debug << "warning, area: " << area << endl;
-		CLEAR_CONTAINER(geom);
-
-		// area substitute for view point probability
-		float pInVc = area;
-				
-		// compute render time of PVS times probability that view point is in view cell
-		float vcCost = pInVc * RenderPvs(*(*it), mObjRenderCost);
-		//Debug << "p: " << pInVc << " rendercost: " << RenderPvs(*(*it), mObjRenderCost) << endl;
-		renderTime += vcCost;
-
-		if (vcCost > simStat.maxCost)
-			simStat.maxCost = vcCost;
-		else if (vcCost < simStat.minCost)
-			simStat.minCost = vcCost;
-
-		// probability that a view cell border is crossed
-		float pCrossVc = area * mMoveSpeed;
-
-		// crossing the border of a view cell is also depending on the move speed
-		loadPvsOverhead += pCrossVc * mVcOverhead;
-overallarea += area;
-		pInVcTotal += pInVc;
-	}
-	Debug << "overall area: " << overallarea << endl;
-	
-	renderTime /= pInVcTotal;
-	loadPvsOverhead /= pCrossVcTotal;
-
-	simStat.avgRtWithoutOverhead = renderTime;
-	simStat.avgRenderTime = renderTime + loadPvsOverhead;
-	
-	simStat.maxCost /= pInVcTotal;
-	simStat.minCost /= pInVcTotal;
-
-	simStat.Stop();
-*/
-	return simStat;
-}
-
-Real VspKdRenderSimulator::RenderPvs(ViewCell &viewCell, 
-									 float objRenderTime) const
-{
-	return 0; // TODO
-}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 467)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 468)
@@ -642,6 +642,8 @@
   cout << "\nevaluating bsp view cells render time after merge ... ";
   
-  const SimulationStatistics ss = mViewCellsManager->SimulateRendering();
-  
+  mRenderSimulator->RenderScene();
+  SimulationStatistics ss;
+  mRenderSimulator->GetStatistics(ss);
+
   cout << " finished" << endl;
   cout << ss << endl;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 466)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 468)
@@ -27,5 +27,5 @@
   environment->GetBoolValue("VssPreprocessor.useImportanceSampling", mUseImportanceSampling);
   environment->GetIntValue("BspTree.Construction.samples", mBspConstructionSamples);
-	
+
   mStats.open("stats.log");
 }
@@ -37,6 +37,6 @@
 
 void
-VssPreprocessor::SetupRay(Ray &ray, 
-						  const Vector3 &point, 
+VssPreprocessor::SetupRay(Ray &ray,
+						  const Vector3 &point,
 						  const Vector3 &direction
 						  )
@@ -62,5 +62,5 @@
   if (!sbox.IsInside(viewPoint))
 	return 0;
-	
+
   SetupRay(ray, viewPoint, direction);
   // cast ray to KD tree to find intersection with other objects
@@ -81,17 +81,17 @@
 	}
 	pointA = ray.Extrap(tmax);
-		
+
   }
 
   bool detectEmptyViewSpace = true;
-	
+
   if (detectEmptyViewSpace) {
 	SetupRay(ray, pointA, -direction);
   } else
 	SetupRay(ray, viewPoint, -direction);
-	
-	
+
+
   if (mKdTree->CastRay(ray)) {
-		
+
 	objectB = ray.intersections[0].mObject;
 	pointB = ray.Extrap(ray.intersections[0].mT);
@@ -105,5 +105,5 @@
 	  //			cerr<<"ray"<<ray<<endl;
 	}
-		
+
 	pointB = ray.Extrap(tmax);
   }
@@ -118,5 +118,5 @@
 	}
   }
-	
+
   if (validSample) {
 	if (objectA) {
@@ -128,5 +128,5 @@
 	  hits ++;
 	}
-		
+
 	if (objectB) {
 	  vssRay = new VssRay(pointA,
@@ -138,5 +138,5 @@
 	}
   }
-	
+
   return hits;
 }
@@ -147,10 +147,10 @@
 {
   AxisAlignedBox3 box;
-	
+
   if (viewSpaceBox)
 	box =*viewSpaceBox;
-  else 
+  else
 	box = mKdTree->GetBox();
-	
+
   // shrink the box in the y direction
   return box.GetRandomPoint();
@@ -170,14 +170,14 @@
   } else {
 	AxisAlignedBox3 box;
-		
+
 	if (viewSpaceBox)
 	  box =*viewSpaceBox;
-	else 
+	else
 	  box = mKdTree->GetBox();
-		
+
 	point = box.GetRandomPoint();
 	point.y = viewpoint.y;
   }
-	
+
   return point - viewpoint;
 }
@@ -194,14 +194,14 @@
 	float maxRayContribution;
 	float avgRayContribution;
-		
+
 	vssTree->GetRayContributionStatistics(minRayContribution,
 										  maxRayContribution,
 										  avgRayContribution);
-		
+
 	cout<<
 	  "#MIN_RAY_CONTRIB\n"<<minRayContribution<<endl<<
 	  "#MAX_RAY_CONTRIB\n"<<maxRayContribution<<endl<<
 	  "#AVG_RAY_CONTRIB\n"<<avgRayContribution<<endl;
-		
+
 	float p = desiredSamples/(float)(avgRayContribution*vssTree->stat.Leaves());
 	num = vssTree->GenerateRays(p, rays);
@@ -210,7 +210,7 @@
 	num = vssTree->GenerateRays(desiredSamples, leaves, rays);
   }
-	
+
   cout<<"Generated "<<num<<" rays."<<endl;
-	
+
   return num;
 }
@@ -224,5 +224,5 @@
 {
   cout<<"Exporting vss rays..."<<endl<<flush;
-	
+
   float prob = number/(float)vssRays.size();
 
@@ -241,5 +241,5 @@
 	exporter->ResetForcedMaterial();
   }
-	
+
   VssRayContainer rays;	for (int i=0; i < vssRays.size(); i++)
 	if (RandomValue(0,1) < prob)
@@ -247,5 +247,5 @@
 
   exporter->ExportRays(rays, RgbColor(1, 0, 0));
-	
+
   delete exporter;
 
@@ -280,5 +280,5 @@
   exporter->SetWireframe();
   exporter->ExportKdTree(*mKdTree);
-	
+
   if (mViewSpaceBox) {
 	exporter->SetForcedMaterial(RgbColor(1,0,0));
@@ -286,9 +286,9 @@
 	exporter->ResetForcedMaterial();
   }
-	
+
   exporter->SetForcedMaterial(RgbColor(0,0,1));
   exporter->ExportBox(tree->GetBBox(leaf));
   exporter->ResetForcedMaterial();
-	
+
   VssRayContainer rays[4];
   for (int i=0; i < leaf->rays.size(); i++) {
@@ -296,5 +296,5 @@
 	rays[k].push_back(leaf->rays[i].mRay);
   }
-	
+
   // SOURCE RAY
   exporter->ExportRays(rays[0], RgbColor(1, 0, 0));
@@ -342,5 +342,5 @@
   for (it = viewcells.begin(); it != it_end; ++ it)
 	sum += tree->GetPvsSize(*it);
-	
+
   return sum/(float)viewcells.size();
 }
@@ -349,9 +349,9 @@
 VssPreprocessor::ComputeVisibility()
 {
-  
+
   mSceneGraph->CollectObjects(&mObjects);
-	
+
   long startTime = GetTime();
-  
+
   int totalSamples = 0;
 
@@ -368,5 +368,5 @@
 	box->SetMax(box->Max() + translation);
   } else {
-		
+
 	// sample city like heights
 	box->SetMin(1, box->Min(1) + box->Size(1)*0.2);
@@ -376,10 +376,10 @@
   if (use2dSampling)
 	box->SetMax(1, box->Min(1));
-	
+
   if (useViewSpaceBox)
 	mViewSpaceBox = box;
   else
 	mViewSpaceBox = NULL;
-		
+
 
   VssTree *vssTree = NULL;
@@ -390,16 +390,16 @@
 	int passSamples = 0;
 	int index = 0;
-		
+
 	int sampleContributions;
-		
+
 	int s = Min(mSamplesPerPass, mInitialSamples);
 	for (int k=0; k < s; k++) {
-			
+
 	  Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
 	  Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
-			
+
 	  sampleContributions = CastRay(viewpoint, direction, mVssRays);
-			
-			
+
+
 	  //-- CORR matt: put block inside loop
 	  if (sampleContributions) {
@@ -410,23 +410,23 @@
 	  totalSamples++;
 	}
-    
+
 	mPass++;
-		
+
 	int pvsSize = 0;
-	float avgRayContrib = (passContributingSamples > 0) ? 
+	float avgRayContrib = (passContributingSamples > 0) ?
 	  passSampleContributions/(float)passContributingSamples : 0;
-		
+
 	cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
-	cout << "#TotalSamples=" << totalSamples/1000 
-		 << "k   #SampleContributions=" << passSampleContributions << " (" 
+	cout << "#TotalSamples=" << totalSamples/1000
+		 << "k   #SampleContributions=" << passSampleContributions << " ("
 		 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS="
-		 << pvsSize/(float)mObjects.size() << endl 
+		 << pvsSize/(float)mObjects.size() << endl
 		 << "avg ray contrib=" << avgRayContrib << endl;
-		
+
 	mStats <<
 	  "#Pass\n" <<mPass<<endl<<
 	  "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<<
 	  "#TotalSamples\n" << totalSamples<< endl<<
-	  "#SampleContributions\n" << passSampleContributions << endl << 
+	  "#SampleContributions\n" << passSampleContributions << endl <<
 	  "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl <<
 	  "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl <<
@@ -435,10 +435,10 @@
 
 
-		
-  }
-	
+
+  }
+
   cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl;
   cout << "#totalRayStackSize=" << mVssRays.size() << endl <<flush;
-	
+
   //int numExportRays = 10000;
   int numExportRays = 0;
@@ -449,5 +449,5 @@
 	ExportRays(filename, mVssRays, numExportRays);
   }
-	
+
   mSceneGraph->CollectObjects(&mObjects);
 
@@ -457,8 +457,8 @@
   vssTree = new VssTree;
   // viewcells = Construct(mVssRays);
-	
+
   vssTree->Construct(mVssRays, mViewSpaceBox);
   cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl;
-  
+
   if (0)
   {
@@ -482,10 +482,10 @@
 	  if (RandomValue(0.0f,1.0f) < prob)
 		kdViewcells.push_back(mKdTree->GetBox(*it));
-		
+
 	float avgPvs = GetAvgPvsSize(vssTree, kdViewcells);
 	cout<<"Initial average PVS size = "<<avgPvs<<endl;
   }
 
-	
+
   int samples = 0;
   int pass = 0;
@@ -498,5 +498,5 @@
 	SimpleRayContainer rays;
 	VssRayContainer vssRays;
-		
+
 	if (!mUseImportanceSampling) {
 	  for (int j=0; j < num; j++) {
@@ -508,10 +508,10 @@
 	  num = GenerateImportanceRays(vssTree, num, rays);
 	}
-	
+
 	for (int i=0; i < rays.size(); i++)
 	  CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);
-		
+
 	vssTree->AddRays(vssRays);
-		
+
 	if (0) {
 	  int subdivided = vssTree->UpdateSubdivision();
@@ -528,5 +528,5 @@
 	  else
 		sprintf(filename, "vss-rays-%04d.x3d", pass);
-			
+
 	  ExportRays(filename, vssRays, numExportRays);
 	}
@@ -547,4 +547,5 @@
   }
 
+
   {
 	VssRayContainer storedRays;
@@ -552,8 +553,8 @@
 										 mViewCellsManager->GetPostProcessSamples(),
 										 mViewCellsManager->GetVisualizationSamples()));
-	
+
 	//-- post process view cells
 	mViewCellsManager->PostProcess(mObjects, storedRays);
-	
+
 	//-- several visualizations and statistics
 	mViewCellsManager->PrintStatistics(Debug);
@@ -563,17 +564,22 @@
 	CLEAR_CONTAINER(storedRays);
   }
+
+  //-- render simulation after merge
+  cout << "\nevaluating bsp view cells render time after merge ... ";
 
   //-- render simulation after merge
   cout << "\nevaluating bsp view cells render time after merge ... ";
   
-  const SimulationStatistics ss = mViewCellsManager->SimulateRendering();
-  
+  mRenderSimulator->RenderScene();
+  SimulationStatistics ss;
+  mRenderSimulator->GetStatistics(ss);
+
   cout << " finished" << endl;
   cout << ss << endl;
   Debug << ss << endl;
-  
-  
+
+
   delete vssTree;
-  
+
   return true;
 }
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 463)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 468)
@@ -15,4 +15,5 @@
 class VspKdTree;
 class VspBspTree;
+class RenderSimulator;
 
 /** Namespace for the external visibility preprocessor
@@ -100,4 +101,8 @@
   VspKdTree *mVspKdTree;
 
+  /** Simulates rendering of the scene.
+  */
+  RenderSimulator *mRenderSimulator;
+
 protected:
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Renderer.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Renderer.cpp	(revision 468)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Renderer.cpp	(revision 468)
@@ -0,0 +1,20 @@
+#include "Renderer.h"
+
+
+Renderer::Renderer():
+mViewCellsManager(NULL)
+{
+}
+Renderer::Renderer(ViewCellsManager *vcm):
+mViewCellsManager(vcm)
+{
+}
+
+Renderer::~Renderer()
+{}
+
+void Renderer::SetViewCellsManager(ViewCellsManager *vcm)
+{
+	mViewCellsManager = vcm;
+}
+
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 465)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 468)
@@ -488,20 +488,34 @@
 				leafb->GetPvsSize() * (float)leafb->rays.size();
 #endif
-    }
-  };
-  
-  /** Simplified data for ray traversal only.
-  */
-  struct RayTraversalData 
-  {
-	  RayInfo mRayData;
-	  VspKdNode *mNode;
-      
-	  RayTraversalData() {}
+		}
+	};
+  
+	/** Simplified data for ray traversal only.
+	*/
+	struct RayTraversalData 
+	{
+		RayInfo mRayData;
+		VspKdNode *mNode;
+
+		RayTraversalData() {}
 	  
-	  RayTraversalData(VspKdNode *n, const RayInfo &data):
-	  mRayData(data), mNode(n) {}
-  };
-	
+		RayTraversalData(VspKdNode *n, const RayInfo &data):
+		mRayData(data), mNode(n) {}
+	};
+	
+	struct LineSegmentTraversalData 
+	{
+		VspKdNode *mNode;
+		Vector3 mExitPoint;
+		
+		float mMaxT;
+    
+		LineSegmentTraversalData () {}
+		LineSegmentTraversalData (VspKdNode *n,
+								  const Vector3 &p,
+								  const float maxt):
+		mNode(n), mExitPoint(p), mMaxT(maxt) {}
+	};
+
 public:
 
@@ -558,5 +572,7 @@
 		@returns the number of intersections with objects stored in the tree.
 	*/
-	int CastRay(Ray &ray);
+	int CastLineSegment(const Vector3 &origin,
+						const Vector3 &termination,
+						vector<ViewCell *> &viewcells);
 
 	/** Collects view cells generated by this tree.
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 466)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 468)
@@ -394,9 +394,14 @@
 	cout << "\nevaluating bsp view cells render time after merge ... ";
 		 
-	const SimulationStatistics ss = mViewCellsManager->SimulateRendering();
-		 
-	cout << " finished" << endl;
-	cout << ss << endl;
-	Debug << ss << endl;
+	 //-- render simulation after merge
+	cout << "\nevaluating bsp view cells render time after merge ... ";
+	
+	 mRenderSimulator->RenderScene();
+	 SimulationStatistics ss;
+	 mRenderSimulator->GetStatistics(ss);
+	 
+	 cout << " finished" << endl;
+	 cout << ss << endl;
+	 Debug << ss << endl;
 	
 	// $$JB temporary removed
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 467)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 468)
@@ -164,11 +164,4 @@
 }
 
-SimulationStatistics ViewCellsManager::SimulateRendering() const
-{
-	if (!ViewCellsConstructed() || !mRenderSimulator)
-		return SimulationStatistics();
-
-	return mRenderSimulator->SimulateRendering();
-}
 
 ViewCell *ViewCellsManager::GenerateViewCell(Mesh *mesh) const
@@ -242,4 +235,40 @@
 }
 
+ViewCellContainer &ViewCellsManager::GetViewCells()
+{
+	return mViewCells;
+}
+
+void ViewCellsManager::ComputeSampleContributions(VssRay &ray)
+{
+	ViewCellContainer viewcells;
+	
+	CastLineSegment(ray.mOrigin,
+					ray.mTermination,
+					viewcells);
+	
+	ray.mPvsContribution = 0;
+	ray.mRelativePvsContribution = 0.0f;
+  
+	ViewCellContainer::const_iterator it = viewcells.begin();
+	
+	for (; it != viewcells.end(); ++it) 
+	{ 	
+		ViewCell *viewcell = *it;
+	
+		// if ray not outside of view space
+		float contribution;
+		bool added = 
+			viewcell->GetPvs().AddSample(ray.mTerminationObject,
+										 contribution);
+		
+		if (added)
+			ray.mPvsContribution++;
+		
+		ray.mRelativePvsContribution += contribution;
+	}
+}
+
+
 /**********************************************************************/
 /*                   BspViewCellsManager implementation               */
@@ -250,6 +279,4 @@
 mBspTree(bspTree)
 {
-   mRenderSimulator = new BspRenderSimulator(bspTree);
-   InitRenderSimulator();
 }
 
@@ -306,48 +333,37 @@
 }
 
-void
-ViewCellsManager::ComputeSampleContributions(VssRay &ray)
-{
-
-  ViewCellContainer viewcells;
-  
-  CastLineSegment(ray.mOrigin,
-				  ray.mTermination,
-				  viewcells
-				  );
-
-  ray.mPvsContribution = 0;
-  ray.mRelativePvsContribution = 0.0f;
-  
-  ViewCellContainer::const_iterator it = viewcells.begin();
-  for (; it != viewcells.end(); ++it) { 	
-	ViewCell *viewcell = *it;
-	
-	// if ray not outside of view space
-	float contribution;
-	bool added = 
-	  viewcell->GetPvs().AddSample(ray.mTerminationObject,
-								   contribution
-								   );
-	if (added)
-	  ray.mPvsContribution++;
-	
-	ray.mRelativePvsContribution += contribution;
-  }
-  
-}
-
-int
-BspViewCellsManager::CastLineSegment(const Vector3 &origin,
-									 const Vector3 &termination,
-									 ViewCellContainer &viewcells
-									 )
-{
-  return mBspTree->CastLineSegment(origin, termination, viewcells);
-}
-
-int
-BspViewCellsManager::PostProcess(const ObjectContainer &objects, 
-								 const VssRayContainer &rays)
+
+float BspViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	PolygonContainer geom;
+
+	// compute view cell area
+	mBspTree->ConstructGeometry(dynamic_cast<BspViewCell *>(viewCell), geom);
+	
+	const float area = Polygon3::GetArea(geom);
+	const float accArea = mBspTree->GetBoundingBox().SurfaceArea();
+
+	CLEAR_CONTAINER(geom);
+
+	return area / accArea;
+}
+
+
+float BspViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost)
+{
+	return viewCell->GetPvs().GetSize() * objRendercost;
+}
+
+
+int BspViewCellsManager::CastLineSegment(const Vector3 &origin,
+										 const Vector3 &termination,
+										 ViewCellContainer &viewcells)
+{
+	return mBspTree->CastLineSegment(origin, termination, viewcells);
+}
+
+
+int BspViewCellsManager::PostProcess(const ObjectContainer &objects, 
+									 const VssRayContainer &rays)
 {
   if (!ViewCellsConstructed())
@@ -392,10 +408,15 @@
 		//-- render simulation
 		cout << "\nevaluating bsp view cells render time before merge ... ";
-		 
-		const SimulationStatistics ss = SimulateRendering();
-			 
-		cout << " finished" << endl;
-		cout << ss << endl;
-		Debug << ss << endl;
+		//-- render simulation after merge
+		cout << "\nevaluating bsp view cells render time after merge ... ";
+  
+		 mRenderSimulator->RenderScene();
+		 SimulationStatistics ss;
+		 mRenderSimulator->GetStatistics(ss);
+         
+		 cout << " finished" << endl;
+		 cout << ss << endl;
+		 Debug << ss << endl;
+
 	}
 
@@ -819,6 +840,15 @@
 mKdPvsDepth(100)
 {
-   mRenderSimulator = new KdRenderSimulator(mKdTree);
-   InitRenderSimulator();
+}
+
+float KdViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	return 0;
+}
+
+
+float KdViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost)
+{
+	return 0;
 }
 
@@ -970,10 +1000,25 @@
 mVspKdTree(vspKdTree)
 {
-   mRenderSimulator = new VspKdRenderSimulator(vspKdTree);
-   mVspKdTree->SetViewCellsManager(this);
-
-   InitRenderSimulator();
-}
-
+	mVspKdTree->SetViewCellsManager(this);
+}
+
+float VspKdViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	/*AxisAlignedBox3 box = mKdTree->GetBox(*it);
+			
+	// volume or area substitutes for view point probability
+	if (0)
+		return box.GetVolume(); 
+	else
+		return box.SurfaceArea();*/
+
+	return dynamic_cast<VspKdViewCell *>(viewCell)->GetSize();
+}
+
+
+float VspKdViewCellsManager::GetRendercost(ViewCell *viewCell, float objRendercost)
+{
+	return 0;//leaf->mKdPvs.GetSize() * objRendercost;
+}
 
 VspKdViewCellsManager::~VspKdViewCellsManager()
@@ -1181,9 +1226,26 @@
 mVspBspTree(vspBspTree)
 {
-	mRenderSimulator = new VspBspRenderSimulator(vspBspTree);
-	InitRenderSimulator();
-}
-
-
+}
+
+float VspBspViewCellsManager::GetProbability(ViewCell *viewCell)
+{
+	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::GetRendercost(ViewCell *viewCell, float objRendercost)
+{
+	return viewCell->GetPvs().GetSize() * objRendercost;
+}
 
 VspBspViewCellsManager::~VspBspViewCellsManager()
