Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 859)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 871)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: út 25. IV 12:50:38 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: út 2. V 11:07:44 2006
 # Project:  preprocessor.pro
 # Template: app
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 870)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 871)
@@ -307,5 +307,5 @@
 	/** Writes view cells to disc.
 	*/
-	virtual bool ExportViewCells(const string filename);
+	virtual bool ExportViewCells(const string filename, const bool exportPvs);
 
 	/** Casts beam to collect view cells.
@@ -435,4 +435,7 @@
 	bool LoadBoundingBoxes(const string filename, IndexedBoundingBoxContainer &boxes) const;
 
+  bool GetExportPvs() const {
+	return mExportPvs;
+  }
 
 	/** Loads view cells from file. The view cells manager is created with 
@@ -678,5 +681,5 @@
 	void Finalize(ViewCell *viewCell, const bool createMesh);
 
-	bool ExportViewCells(const string filename);
+	bool ExportViewCells(const string filename, const bool exportPvs);
 
 	/** Constructs merge hierarchy which corresponds to the spatial hierarchy.
@@ -886,5 +889,5 @@
 	void CreateMesh(ViewCell *vc);
 
-	bool ExportViewCells(const string filename);
+	bool ExportViewCells(const string filename, const bool exportPvs);
 
 	int CastBeam(Beam &beam);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 871)
@@ -1673,4 +1673,20 @@
 				   "true");
 
+	RegisterOption("Preprocessor.exportVisibility",
+				   optBool,
+				   "preprocessor_export_visibility",
+				   "true");
+
+	RegisterOption("Preprocessor.visibilityFile",
+				   optString,
+				   "preprocessor_visibility_file=",
+				   "visibility.xml");
+
+	RegisterOption("Preprocessor.applyVisibilityFilter",
+				   optBool,
+				   "preprocessor_apply_filter",
+				   "true");
+
+
 
 	/**************************************************************************************/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.h	(revision 871)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.h	(revision 871)
@@ -0,0 +1,33 @@
+#ifndef _RenderSampler_H__
+#define _RenderSampler_H__
+
+#include <fstream>
+using namespace std;
+
+#include "Preprocessor.h"
+
+namespace GtpVisibilityPreprocessor {
+
+class Exporter;
+
+/** Sampling based visibility preprocessing. The implementation is based on heuristical
+    sampling of view space */
+class RenderSampler : public Preprocessor {
+
+public:
+  int mSamples;
+  
+  RenderSampler();
+  ~RenderSampler() {}
+  
+  virtual bool ComputeVisibility();
+  
+  
+protected:
+  ofstream mStats;
+  
+};
+
+};
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 870)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 871)
@@ -127,5 +127,11 @@
 	environment->GetBoolValue("Preprocessor.computeVisibility", mComputeVisibility);
 	environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
-
+	environment->GetBoolValue("Preprocessor.exportVisibility", mExportVisibility );
+
+	char buffer[256];
+	environment->GetStringValue("Preprocessor.visibilityFile",  buffer);
+	mVisibilityFileName = buffer;
+	environment->GetBoolValue("Preprocessor.visibilityFile", mApplyVisibilityFilter );
+	
 	Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
 	Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl;
@@ -255,6 +261,30 @@
 Preprocessor::ExportPreprocessedData(const string filename)
 {
-  return false;
-}
+  
+  mViewCellsManager->ExportViewCells(filename,
+									 true);
+  
+  return true;
+}
+
+bool
+Preprocessor::PostProcessVisibility()
+{
+  
+  if (mApplyVisibilityFilter) {
+	cout<<"Applying visibility filter...";
+	mViewCellsManager->ApplyFilter(mKdTree,
+								   0.05f,
+								   0.05f);
+	cout<<"done.";
+  }
+  
+  // export the preprocessed information to a file
+  if (mExportVisibility)
+	ExportPreprocessedData(mVisibilityFileName);
+  
+  return true;
+}
+
 
 bool
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 871)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 871)
@@ -0,0 +1,58 @@
+#include "Environment.h"
+#include "RenderSampler.h"
+#include "GlRenderer.h"
+
+namespace GtpVisibilityPreprocessor {
+
+
+RenderSampler::RenderSampler():Preprocessor()
+{
+  environment->GetIntValue("RenderSampler.samples", mSamples);
+  cout<<"mspamples"<<mSamples<<endl;
+}
+
+bool
+RenderSampler::ComputeVisibility()
+{
+  
+  cout<<"HERE I WAS!\n";
+
+  vector<RenderCostSample> samples;
+  
+  if (renderer)
+	renderer->SampleRenderCost(
+							   mSamples,
+							   samples
+							   );
+
+
+  // compute histogram from the samples
+  int bins = 100;
+  int maxPvs;
+
+  vector<int> histogram(bins);
+  
+  int i;
+  for (i = 0; i < bins; i++)
+	histogram[i] = 0;
+  
+  for (i = 0; i < mSamples; i++) {
+	if (samples[i].mVisibleObjects > maxPvs)
+	  maxPvs = samples[i].mVisibleObjects;
+  }
+  
+  for (i = 0; i < mSamples; i++) {
+	int bin = (samples[i].mVisibleObjects*bins)/maxPvs;
+	histogram[bin]++;
+  }
+
+  // output the histogram
+  for (i = 0; i < bins; i++) {
+	cout<<histogram[i]<<endl;
+  }
+
+  
+  return true;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 871)
@@ -512,5 +512,6 @@
 	SimpleRayContainer rays;
 
-	cout<<"Generating initial rays..."<<endl;
+	cout<<"Generating initial rays..."<<endl<<flush;
+
 	GenerateRays(mInitialSamples/4, SPATIAL_BOX_BASED_DISTRIBUTION, rays);
 	GenerateRays(mInitialSamples/4, OBJECT_BASED_DISTRIBUTION, rays);
@@ -518,5 +519,5 @@
 	GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays);
 	
-	cout<<"Casting initial rays..."<<endl;
+	cout<<"Casting initial rays..."<<endl<<flush;
 	CastRays(rays, mVssRays);
 
@@ -546,8 +547,8 @@
   if (mUseViewcells) {
 
-	cout<<"Computing sample contributions..."<<endl;
+	cout<<"Computing sample contributions..."<<endl<<flush;
 	// evaluate contributions of the intitial rays
 	mViewCellsManager->ComputeSampleContributions(mVssRays, true, false);
-	cout<<"done.\n";
+	cout<<"done.\n"<<flush;
 	
 	mStats <<
@@ -802,9 +803,7 @@
 
 
-  cout<<"Applying visibility filter...";
-  mViewCellsManager->ApplyFilter(mKdTree,
-								 0.05f,
-								 0.05f);
-  cout<<"done.";
+  //  mViewCellsManager->ExportViewCells("visibility.xml",
+  //									 true);
+  
   
   return true;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 871)
@@ -627,5 +627,5 @@
 	  VssRayContainer dummies;
 	  mViewCellsManager->Visualize(mObjects, dummies);
-	  mViewCellsManager->ExportViewCells("test.xml");
+	  mViewCellsManager->ExportViewCells("test.xml", mViewCellsManager->GetExportPvs());
   }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 871)
@@ -63,5 +63,5 @@
 		else
 		  if (preprocessorType == "render")
-;//			p = new RenderSampler();
+			p = new RenderSampler();
 		  else {
 			cerr<<"Unknown preprocessor type"<<endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 859)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 871)
@@ -9,8 +9,8 @@
 #	filename vienna.x3d
 # filename ../data/vienna/vienna-simple.x3d
-#filename ../data/vienna/vienna-buildings.x3d
+filename ../data/vienna/vienna-buildings.x3d
 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d
 # filename ../data/vienna/viewcells-25-sel.x3d
-filename ../data/atlanta/atlanta2.x3d
+#filename ../data/atlanta/atlanta2.x3d
 #filename ../data/soda/soda.dat
 #filename ../data/soda/soda5.dat
@@ -89,7 +89,7 @@
 
 RssPreprocessor {
-	samplesPerPass 1000000
+	samplesPerPass 500000
 	initialSamples 1000000
-	vssSamples 1000000
+	vssSamples 2000000
 	vssSamplesPerPass 1000000
 	useImportanceSampling false
@@ -274,6 +274,6 @@
 #	filename ../scripts/viewcells_atlanta.xml
 #	filename ../data/soda/soda5-viewcells2.xml
-	filename ../data/atlanta/viewcells_atlanta3.xml
-#	filename ../data/vienna/viewcells_vienna.xml
+#	filename ../data/atlanta/viewcells_atlanta3.xml
+	filename ../data/vienna/viewcells_vienna.xml
 #	filename ../data/PowerPlant/power_plant_viewcells_all3.xml
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 871)
@@ -69,5 +69,9 @@
     */
   virtual bool ComputeVisibility() = 0;
-  
+
+  /** Post Process the computed visibility. By default applys the visibility filter
+	  (if specified in the environment and export the preprocessed data */
+  virtual bool PostProcessVisibility();
+
   /** View cells are either loaded or prepared for generation, according to the chosen environment
       object. Important evironment options are, e.g, the view cell type.
@@ -163,4 +167,9 @@
   bool mComputeVisibility;
 
+  bool mExportVisibility;
+  string mVisibilityFileName;
+  
+  bool mApplyVisibilityFilter;
+  
   GlRendererBuffer *GetRenderer() { return renderer;}
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp	(revision 871)
@@ -26,4 +26,5 @@
     mPreprocessor->ComputeVisibility();
 	//	mPreprocessor->ExportPreprocessedData("scene.vis");
+	mPreprocessor->PostProcessVisibility();
   }
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 870)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 871)
@@ -1856,5 +1856,5 @@
 
 
-bool ViewCellsManager::ExportViewCells(const string filename)
+bool ViewCellsManager::ExportViewCells(const string filename, const bool exportPvs)
 {
 	return false;
@@ -2272,5 +2272,5 @@
 		char filename[100];
 		environment->GetStringValue("ViewCells.filename", filename);
-		ExportViewCells(filename);
+		ExportViewCells(filename, mExportPvs);
 	}
 	
@@ -2719,5 +2719,5 @@
 
 
-bool BspViewCellsManager::ExportViewCells(const string filename)
+bool BspViewCellsManager::ExportViewCells(const string filename, const bool exportPvs)
 {
 	cout << "exporting view cells to xml ... ";
@@ -2745,5 +2745,5 @@
 	stream << "<ViewCells>" << endl;
 
-	mViewCellsTree->Export(stream, mExportPvs);
+	mViewCellsTree->Export(stream, exportPvs);
 
 	stream << "</ViewCells>" << endl;
@@ -3964,5 +3964,5 @@
 		char filename[100];
 		environment->GetStringValue("ViewCells.filename", filename);
-		ExportViewCells(filename);
+		ExportViewCells(filename, mExportPvs);
 	}
 
@@ -4710,5 +4710,5 @@
 
 
-bool VspBspViewCellsManager::ExportViewCells(const string filename)
+bool VspBspViewCellsManager::ExportViewCells(const string filename, const bool exportPvs)
 {
 	cout << "exporting view cells to xml ... ";
@@ -4735,5 +4735,5 @@
 	stream << "<ViewCells>" << endl;
 	
-	mViewCellsTree->Export(stream, mExportPvs);
+	mViewCellsTree->Export(stream, exportPvs);
 
 	stream << "</ViewCells>" << endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 871)
@@ -841,11 +841,11 @@
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
-  ViewCell *viewcell;
+  ViewCell *viewcell = NULL;
 
   PrVs prvs;
   
-  if (!useFilter)
+  if (!useFilter) {
 	viewcell = mViewCellsManager->GetViewCell(mViewPoint);
-  else {
+  } else {
 	//  mViewCellsManager->SetMaxFilterSize(1);
 	mViewCellsManager->GetPrVS(mViewPoint, prvs);
