Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 370)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 373)
@@ -20,5 +20,5 @@
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="..\include"
+				AdditionalIncludeDirectories="..\support;..\support\devil\include;..\support\zlib\include;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\Qt&quot;;..\include"
 				PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
 				MinimalRebuild="TRUE"
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 373)
@@ -341,5 +341,5 @@
 	/** Returns list of BSP leaves.
 	*/
-	void CollectLeaves(vector<BspLeaf *> &leaves);
+	void CollectLeaves(vector<BspLeaf *> &leaves) const;
 
 	/** Returns box which bounds the whole tree.
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 362)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h	(revision 373)
@@ -78,4 +78,10 @@
   ExportPolygons(const PolygonContainer &polys) = 0;
 
+  virtual void
+  ExportBspViewCellPartition(const BspTree &tree) = 0;
+
+  virtual void 
+  ExportBspLeaves(const BspTree &tree) = 0;
+
   void SetExportRayDensity(const bool d) { mExportRayDensity = d; }
   
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 373)
@@ -1486,5 +1486,5 @@
 }
 
-void BspTree::CollectLeaves(vector<BspLeaf *> &leaves)
+void BspTree::CollectLeaves(vector<BspLeaf *> &leaves) const
 {
 	stack<BspNode *> nodeStack;
@@ -1499,8 +1499,8 @@
 		if (node->IsLeaf()) 
 		{
-			BspLeaf *leaf = (BspLeaf *)node;
-			
+			BspLeaf *leaf = (BspLeaf *)node;		
 			leaves.push_back(leaf);
-		} else 
+		} 
+		else 
 		{
 			BspInterior *interior = dynamic_cast<BspInterior *>(node);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 362)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h	(revision 373)
@@ -85,5 +85,10 @@
 			 const RgbColor &color = RgbColor(1,1,1));
 
-  static ViewCellContainer foundViewCells; // todo: remove this
+  virtual void
+  ExportBspViewCellPartition(const BspTree &tree);
+
+  virtual void 
+  ExportBspLeaves(const BspTree &tree);
+
 protected:
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h	(revision 373)
@@ -12,4 +12,12 @@
 class SamplingPreprocessor : public Preprocessor {
 public:
+		
+  SamplingPreprocessor();
+
+  ~SamplingPreprocessor();
+
+  virtual bool ComputeVisibility();
+
+protected:
 	int mPass;
 
@@ -22,10 +30,5 @@
   int mBspConstructionSamples;
   int mPostProcessSamples;
-	
-  SamplingPreprocessor();
 
-  ~SamplingPreprocessor();
-
-  virtual bool ComputeVisibility();
 
   void
@@ -93,4 +96,6 @@
 	/** Post processes view cells (i.e., merges or subdivides view cells based
 		on the PVS and the ray sets.
+		@param rays a set of rays which carries the visibility information 
+		the merging / subdivision is based on.
 		@returns number of merged view cells.
 	*/
@@ -100,5 +105,11 @@
 		quality of the view cell partition.
 	*/
-	Real EvaluateRenderHeuristics();
+	Real SimulateRendering();
+	/** 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;
+
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp	(revision 373)
@@ -8,5 +8,4 @@
 #include "ViewCell.h"
 #include "Polygon3.h"
-ViewCellContainer X3dExporter::foundViewCells; // TODO: delete later
 
 X3dExporter::X3dExporter(const string filename):Exporter(filename)
@@ -177,4 +176,41 @@
 	for (it = viewCells.begin(); it != it_end; ++ it)
 		ExportViewCell(*it);
+}
+
+void 
+X3dExporter::ExportBspViewCellPartition(const BspTree &tree)
+{
+	ViewCellContainer viewCells;
+	tree.CollectViewCells(viewCells);
+
+	ViewCellContainer::const_iterator it, it_end = viewCells.end();
+
+	for (it = viewCells.begin(); it != it_end; ++ it)
+	{
+		if ((*it)->GetMesh())
+			ExportViewCell(*it);
+		else
+		{
+			PolygonContainer cell;
+			tree.ConstructGeometry(dynamic_cast<BspViewCell *>(*it), cell);
+			ExportPolygons(cell);
+		}
+	}
+}
+
+void 
+X3dExporter::ExportBspLeaves(const BspTree &tree)
+{
+	vector<BspLeaf *> leaves;
+	tree.CollectLeaves(leaves);
+
+	vector<BspLeaf *>::const_iterator it, it_end = leaves.end();
+
+	for (it = leaves.begin(); it != it_end; ++ it)
+	{
+		PolygonContainer cell;
+		tree.ConstructGeometry(*it, cell);
+		ExportPolygons(cell);
+	}
 }
 
@@ -477,37 +513,6 @@
 		}
 	}
-	else // export view cells
-	{
-		while (!tStack.empty()) 
-		{
-            BspNode *node = tStack.top();
-    
-			tStack.pop();
-	
-			if (node->IsLeaf()) 
-			{
-				ViewCell *viewCell = dynamic_cast<BspLeaf *>(node)->GetViewCell();
-				if (viewCell)
-					foundViewCells.push_back(viewCell);
-			}
-			else
-			{
-				BspInterior *interior = dynamic_cast<BspInterior *>(node);
-      
-				tStack.push(interior->GetFront());
-				tStack.push(interior->GetBack());
-			}
-		}
-
-		Debug << "Number of view cells with dublicates: " << (int)foundViewCells.size() << endl;
-
-        //-- erase dublicates
-		sort(foundViewCells.begin(), foundViewCells.end());
-		ViewCellContainer::iterator new_end = unique(foundViewCells.begin(), foundViewCells.end());
-		foundViewCells.erase(new_end, foundViewCells.end());
-		ExportViewCells(foundViewCells);
-
-		Debug << "Number of view cells after erasing dublicates: " << (int)foundViewCells.size() << endl;
-	}
+	// export view cells
+	ExportBspViewCellPartition(tree);	
 
 	return true;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 372)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 373)
@@ -550,5 +550,5 @@
 
 		cout << "evaluating render time heuristics ... ";
-		Real rt = EvaluateRenderHeuristics();
+		Real rt = SimulateRendering();
 		cout << "finished" << endl;
 
@@ -877,6 +877,4 @@
 				if (!objects[j]->Mailed())
 				{
-					//if (j == 2198)m.mDiffuseColor = RgbColor(1, 0, 1);
-					//else m.mDiffuseColor = RgbColor(1, 1, 0);
 					exporter->SetForcedMaterial(m);
 					exporter->ExportIntersectable(objects[j]);
@@ -886,12 +884,41 @@
 		DEL_PTR(exporter);
 	}
-}
-
-Real SamplingPreprocessor::EvaluateRenderHeuristics()
+
+	if (1) // export view cells and leaves
+	{
+		Exporter *exporter = Exporter::GetExporter("viewCells.x3d");
+		if (exporter)
+		{
+			exporter->ExportBspViewCellPartition(*mBspTree);
+			delete exporter;
+		}
+
+		exporter = Exporter::GetExporter("bspLeaves.x3d");
+
+		if (exporter)
+		{
+			exporter->ExportBspLeaves(*mBspTree);
+			delete exporter;
+		}
+	}
+
+}
+
+
+
+Real SamplingPreprocessor::RenderPvs(ViewCell &viewCell, 
+									 const float objRenderTime) const
+{
+	return viewCell.GetPvs().GetSize() * objRenderTime;
+}
+
+Real SamplingPreprocessor::SimulateRendering()
 {
 	Real renderTime = 0;
 
-	const float objRt = 1.0f; // render time for 1 object of PVS
-	const float vcOverhead = 1.0f; // const overhead for crossing a view cell border
+	// render time for 1 object of PVS
+	const float objRt = 1.0f; 
+	 // const overhead for crossing a view cell border
+	const float vcOverhead = 0.01f;
 	
 	float totalArea = 0;
@@ -915,5 +942,5 @@
 			area += (*pit)->GetArea();
 		
-		renderTime += area * (*it)->GetPvs().GetSize() * objRt;
+		renderTime += area * RenderPvs(*(*it), objRt);
 		totalArea += area;
 	}
