Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj	(revision 938)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj	(revision 991)
@@ -80,5 +80,5 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="xerces-c_2.lib zdll.lib zziplib.lib devil.lib qtmain.lib QtOpenGL4.lib QtCored4.lib QtGuid4.lib Qt3Support4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib"
+				AdditionalDependencies="xerces-c_2.lib zdll.lib zziplib.lib devil.lib qtmain.lib QtGuid4.lib Qt3Support4.lib QAxContainer.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib QtCore4.lib QtOpenGL4.lib"
 				OutputFile="$(OutDir)/Preprocessor.exe"
 				LinkIncremental="1"
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 979)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 991)
@@ -973,4 +973,8 @@
 	void VisualizeWithFromPointQueries();
 
+	/** Evaluate from point queries for the current scene.
+	*/
+	void EvalFromPointQueries();
+
 
 	/// the view space partition BSP tree.
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 878)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 991)
@@ -182,5 +182,7 @@
   }
   
-  friend Mesh *CreateBox(const AxisAlignedBox3 &box);
+  /** Creates a mesh from a axis aligned bounding box
+  */
+  friend Mesh *CreateMeshFromBox(const AxisAlignedBox3 &box);
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 975)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 991)
@@ -1697,5 +1697,13 @@
 				   "0.02");
 
-	
+	RegisterOption("Preprocessor.histogram.maxValue", 
+					optInt,
+					"preprocessor_histogram_max_value=",
+					"1000");
+
+	RegisterOption("Preprocessor.histogram.intervals", 
+					optInt,
+					"preprocessor_histogram_intervals=",
+					"20");
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 944)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 991)
@@ -41,5 +41,5 @@
 			const Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
 			AxisAlignedBox3 box(pt2, pt2 + boxSize);
-			Mesh *mesh = CreateBox(box);
+			Mesh *mesh = CreateMeshFromBox(box);
 
 			mesh->Preprocess();
@@ -60,5 +60,5 @@
 			Vector3 boxSize = sceneBox.Size() * Vector3(0.0025, 0.01, 0.0025);
 			AxisAlignedBox3 box(pt2, pt2 + boxSize);
-			Mesh *mesh = CreateBox(box);
+			Mesh *mesh = CreateMeshFromBox(box);
 
 			mesh->Preprocess();
@@ -78,5 +78,5 @@
 		Vector3 boxSize = sceneBox.Size() * Vector3(0.005, 0.02, 0.005);
 		AxisAlignedBox3 box(pt2 + 0.1, pt2 + boxSize);
-		Mesh *mesh = CreateBox(box);
+		Mesh *mesh = CreateMeshFromBox(box);
 
 		mesh->Preprocess();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 897)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 991)
@@ -9,5 +9,5 @@
 {
   environment->GetIntValue("RenderSampler.samples", mSamples);
-  cout<<"mspamples"<<mSamples<<endl;
+  cout << "number of render samples: " << mSamples << endl;
 }
 
@@ -15,44 +15,96 @@
 RenderSampler::ComputeVisibility()
 {
+	long startTime = GetTime();
+	
+	int histoMaxVal = 0;
+	int histoIntervals = 0;
+	
+    environment->GetIntValue("Preprocessor.histogram.maxValue", histoMaxVal);
+	environment->GetIntValue("Preprocessor.histogram.intervals", histoIntervals);
+
+	const int intervals = histoIntervals;
+
+	cout << "starting sampling of render cost ... ";
+
+	vector<RenderCostSample> samples;
   
-  cout<<"HERE I WAS!\n";
+	if (renderer)
+	{cout << "here18 " << mSamples << endl;
+		renderer->SampleRenderCost(mSamples, samples);
+	}
 
-  vector<RenderCostSample> samples;
-  
-  if (renderer)
-	renderer->SampleRenderCost(
-							   mSamples,
-							   samples
-							   );
+	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
 
-  // compute histogram from the samples
-  int bins = 100;
-  int maxPvs = 0;
+	//-- Evaluate properties
+	
 
-  vector<int> histogram(bins);
+	//-- compute histogram from the samples
+	int avgPvs = 0;
+	int maxPvs = 0;
+
+	vector<int> histogram(intervals);
   
-  int i;
-  for (i = 0; i < bins; i++)
-	histogram[i] = 0;
+	int i;
+
+	/// initialise histogram
+	for (i = 0; i < intervals; ++ i)
+	{
+		histogram[i] = 0;
+	}
+
+	
+
+	for (i = 0; i < mSamples; ++ i) 
+	{
+		if (samples[i].mVisibleObjects > maxPvs)
+		{
+			maxPvs = samples[i].mVisibleObjects;
+		}
+
+		avgPvs += samples[i].mVisibleObjects;
+	}
+
+	// sometimes need need to unifiy maximum pvs to compare with other method's histograms
+	// => choose histoMaxPvs accordingly (higher than all pvsss)
+	const int maxVal = max(histoMaxVal, maxPvs);
+	
+	for (i = 0; i < mSamples; ++ i) 
+	{
+		const int bin = (samples[i].mVisibleObjects * intervals) / maxVal;
+
+		++ histogram[bin];
+	}
+
+
+	//-- output the histogram
+
+	const string filename("fromPointHisto.log");
+	std::ofstream outstream;
+	outstream.open(filename.c_str());
+
+
+
+	Debug << "****************************************" << endl;
+	Debug << "From point queries: " << endl;
+
+	for (i = 0; i < intervals; ++ i) 
+	{
+		outstream << "#Pass\n" << i << endl;
+		outstream << "#Pvs\n" << histogram[i] << endl;
+		//cout << histogram[i] << endl;
+	}
+
+	outstream.close();
+
+	avgPvs /= mSamples;
+		
+	Debug << "max pvs: " << maxPvs << endl;
+	Debug << "avg pvs: " << avgPvs << endl;
   
-  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;
+	return true;
 }
 
+
+
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 878)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 991)
@@ -28,6 +28,7 @@
 int
 main(int argc, char **argv)
-{
-	
+{QApplication *app = new QApplication(argc, argv);
+
+	cout << "here222237" << endl;
 //Now just call this function at the start of your program and if you're
 //compiling in debug mode (F5), any leaks will be displayed in the Output
@@ -38,10 +39,11 @@
     _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
     _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 
-
-  Debug.open("debug.log");
+cout << "here3" << endl;
+  Debug.open("debug.log");cout << "here2" << endl;
   environment = new Environment;
+  cout << "here122223" << endl; cout.flush();
   environment->Parse(argc, argv, USE_EXE_PATH);
   MeshKdTree::ParseEnvironment();
-
+cout << "here222283" << endl;
   char buff[128];
   environment->GetStringValue("Preprocessor.type", buff);
@@ -49,7 +51,9 @@
 	
   Preprocessor *p;
-
+cout << "here22223" << endl;
   if (preprocessorType == "vss")
+  {cout << "here223" << endl;
 	p = new VssPreprocessor();
+  }
   else
 	if (preprocessorType == "rss")
@@ -63,5 +67,8 @@
 		else
 		  if (preprocessorType == "render")
+		  {
+			  cout << "here23" << endl;
 			p = new RenderSampler();
+		  }
 		  else {
 			cerr<<"Unknown preprocessor type"<<endl;
@@ -70,12 +77,14 @@
 		  }
   
-
-  QApplication *app = NULL;
+ 
+  //QApplication *app = NULL;
 
   if (p->mUseGlRenderer || p->mUseGlDebugger) {
+	  cout << "here1111" << endl;
 	// create a qt application first (must be created before any opengl widget...
-	app = new QApplication(argc, argv);
-	
+	//app = new QApplication(argc, argv);
+	  cout << "here1112" << endl;
 	if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
+		cout << "here1133" << endl;cout.flush();
 	  QMessageBox::information(0, "OpenGL pbuffers", 
 							   "This system does not support OpenGL/pbuffers.",
@@ -83,6 +92,7 @@
 	  return -1;
 	}
+	  cout << "here1119" << endl;
   }
-  
+   cout << "here1123" << endl;
   preprocessor = p;
   
@@ -93,9 +103,9 @@
   p->BuildKdTree();
   p->KdTreeStatistics(cout);
-  
+   cout << "here1199" << endl;
   // parse view cells related options
   p->PrepareViewCells();
   
-
+ cout << "here1117" << endl;
   // create a preprocessor thread
   PreprocessorThread *pt = new PreprocessorThread(p, app);
@@ -106,12 +116,13 @@
     p->Export(filename + "-kdtree.x3d", false, true, false);	
   }
-
+ cout << "here1118" << endl;
   if (p->mUseGlRenderer) {
-	
+	  cout << "here1114" << endl;
 	rendererWidget = new GlRendererWidget(p->mSceneGraph, p->mViewCellsManager, p->mKdTree);
 	//  renderer->resize(640, 480);
+	 cout << "here1115" << endl;
 	rendererWidget->resize(640, 480);
 	rendererWidget->show();
-	
+	  cout << "here1113" << endl;
 	if (p->GetRenderer()) {
 	  
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 884)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 991)
@@ -63,4 +63,6 @@
   }
   
+  Vector3 mPosition;
+
   // visible object from the given point
   int mVisibleObjects;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 979)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 991)
@@ -566,7 +566,8 @@
 	maxRenderCost = viewCells.back()->GetRenderCost();
 
-	Debug << "histogram minrc: " << minRenderCost << " maxrc: " << maxRenderCost << endl;
-
-	const int intervals = min(50, (int)viewCells.size());
+	Debug << "histogram min rc: " << minRenderCost << " max rc: " << maxRenderCost << endl;
+
+
+	const int intervals = min(20, (int)viewCells.size());
 
 	const float range = maxRenderCost - minRenderCost;
@@ -614,5 +615,5 @@
 		const float volRatioDif = volDif / totalVol;
 
-		outstream << "#Pass\n" << j << endl;
+		outstream << "#Pass\n" << j ++ << endl;
 		outstream << "#RenderCostRatio\n" << rcRatio << endl;
 		outstream << "#WeightedCost\n" << currentRenderCost / totalVol << endl;
@@ -624,5 +625,4 @@
 		// increase current render cost
 		currentRenderCost += stepSize;
-		++ j;
 	}
 
@@ -763,4 +763,5 @@
 	maxPvsSize = viewCells.back()->GetPvs().GetSize();
 	minPvsSize = 0;
+	// hack: normalize pvs size
 	maxPvsSize = 1200;
 	minPvsSize = 0;
@@ -768,4 +769,5 @@
 
 	Debug << "histogram minpvssize: " << minPvsSize << " maxpvssize: " << maxPvsSize << endl;
+
 
 	const int intervals = min(20, (int)viewCells.size());
@@ -826,4 +828,5 @@
 		currentPvsSize += stepSize;
 	}
+
 	outstream.close();
 }
@@ -902,14 +905,4 @@
 		cout << "compute new statistics ... ";
 
-/*Debug << "*******+" << endl;
-float overall = 0;
-stable_sort(leaves.begin(), leaves.end(), ViewCell::SmallerPvs);
-	for (int i = 0; i < leaves.size(); ++ i)
-	{
-		overall += leaves[i]->GetPvs().GetSize();
-		Debug << "i " << i << " !size: " << leaves[i]->GetPvs().GetSize() << " vol: " << leaves[i]->GetVolume() << " overall " << overall << endl;
-		
-	}
-*/
 
 		//-- propagate pvs or pvs size information
@@ -1242,9 +1235,11 @@
 							  int maxPvsSize) const
 {
-  ViewCellContainer::const_iterator it, it_end = mViewCells.end();
-
-  for (it = mViewCells.begin(); it != it_end; ++ it) {
-	SetValidity(*it, minPvsSize, maxPvsSize);
-  }
+	ViewCellContainer::const_iterator it, it_end = mViewCells.end();
+
+
+	for (it = mViewCells.begin(); it != it_end; ++ it) 
+	{
+		SetValidity(*it, minPvsSize, maxPvsSize);
+	}
 }
 
@@ -1261,17 +1256,22 @@
 
   for (int i=0; i < mViewCells.size(); i++)
-	mViewCells[i]->SetValid(i >= start && i <= end);
-}
-
-int
-ViewCellsManager::CountValidViewcells() const
-{
-  ViewCellContainer::const_iterator it, it_end = mViewCells.end();
-  int valid = 0;
-  for (it = mViewCells.begin(); it != it_end; ++ it) {
-	if ((*it)->GetValid())
-	  valid ++;
+  {
+	  mViewCells[i]->SetValid(i >= start && i <= end);
+  
   }
-  return valid;
+}
+
+int ViewCellsManager::CountValidViewcells() const
+{
+	ViewCellContainer::const_iterator it, it_end = mViewCells.end();
+	int valid = 0;
+
+	for (it = mViewCells.begin(); it != it_end; ++ it) 
+	{	
+		if ((*it)->GetValid())
+			++ valid;
+	}
+
+	return valid;
 }
 
@@ -4708,4 +4708,5 @@
 {
 	int numSamples;
+
 	environment->GetIntValue("RenderSampler.samples", numSamples);
 	cout << "samples" << numSamples << endl;
@@ -4716,5 +4717,5 @@
 		return;
 
-	// doing the query
+	//start the from point queries
 	long startTime = GetTime();
 	cout << "starting sampling of render cost ... ";
@@ -4728,8 +4729,23 @@
 	vector<RenderCostSample>::const_iterator rit, rit_end = samples.end();
 
+	//std::map<ViewCell *, ObjectPvs> sampleMap;
+
 	for (rit = samples.begin(); rit != rit_end; ++ rit)
 	{
 		RenderCostSample sample = *rit;
-		//ViewCell *vc = GetViewCell(sample.)pos;
+		
+		ViewCell *vc = GetViewCell(sample.mPosition);
+		
+		AxisAlignedBox3 box(sample.mPosition - Vector3(1, 1, 1), sample.mPosition + Vector3(1, 1, 1));
+	
+		Mesh *hMesh = CreateMeshFromBox(box);
+		
+		DEL_PTR(hMesh);
+#if 0
+		if (!sampleMap.find(vc))
+			sampleMap.insert(vc, sample.mVisibleObjects);
+		else
+			sampleMap[vc].Merge(Merge(sample.mVisibleObjects);
+#endif
 	}
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 931)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 991)
@@ -449,5 +449,7 @@
 {
   mViewCellsManager->GetViewPoint(mViewPoint);
-  cout<<mViewPoint<<endl;
+  sample.mPosition = mViewPoint;
+
+  cout << mViewPoint << endl;
   
   // take a render cost sample by rendering a cube
@@ -573,5 +575,5 @@
 								   vector<RenderCostSample> &samples
 								   )
-{
+{cout << "here1" << endl;
   makeCurrent();
 
@@ -586,27 +588,34 @@
   int i;
   int numQ = 500;
-  
-  if (mOcclusionQueries.size() < numQ) {
-	cout<<"allocating occ queries..."<<endl;
-	
-	numQ;
-	unsigned int *queries = new unsigned int[numQ];
-	for (i=0; i < numQ; i++)
-	  queries[i] = 111;
-	
-	glGenOcclusionQueriesNV(numQ, queries);
-	
-	mOcclusionQueries.resize(numQ);
-	
-	for (i=0; i < numQ; i++)
-	  mOcclusionQueries[i] = queries[i];
-	
-	delete queries;
-  }
-  
-  for (i=0; i < n; i++)
-	EvalRenderCostSample(
-						 samples[i]
-						 );
+
+  cout << "here2988" << endl;
+
+  if (mOcclusionQueries.size() < numQ) 
+  {
+	  cout << "allocating occ queries..." << endl;
+	
+	  unsigned int *queries = new unsigned int[numQ];
+	  
+	  // matt: ?
+	  for (i = 0; i < numQ; ++ i)
+          queries[i] = 111;
+	
+	  glGenOcclusionQueriesNV(numQ, queries);
+
+	  mOcclusionQueries.resize(numQ);
+	
+	  for (i=0; i < numQ; ++ i)
+	  {
+		  mOcclusionQueries[i] = queries[i];
+	  }
+    
+	  DEL_PTR(queries);
+  }
+  
+  for (i=0; i < n; ++ i)
+  {
+	  cout << i << " ";
+	  EvalRenderCostSample(samples[i]);
+  }
 
   doneCurrent();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 878)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 991)
@@ -601,5 +601,5 @@
 
 
-Mesh *CreateBox(const AxisAlignedBox3 &box)
+Mesh *CreateMeshFromBox(const AxisAlignedBox3 &box)
 {
 	Mesh *mesh = new Mesh;
