Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1584)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer.cpp	(revision 1585)
@@ -942,5 +942,5 @@
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
-  gluPerspective(angle, ww/(float)hh, 1.0f, 40.0f);
+  gluPerspective(angle, ww/(float)hh, 0.1f, 1000.0f);
   glMatrixMode(GL_MODELVIEW);
 }
@@ -1219,5 +1219,4 @@
 	}
 	
-	RenderInfo();
   }
 
@@ -1250,4 +1249,6 @@
 	if (mShowRenderCost) 
 	  RenderRenderCost();
+
+	RenderInfo();
   }
   mFrame++;
@@ -1421,4 +1422,6 @@
 		for (int i=0;  i < costFunction.size(); i++) {
 		  //		  cout<<i<<":"<<costFunction[i]<<" ";
+		  // update cost function to an absolute value based on the total geometry count
+		  costFunction[i]*=mSceneGraph->GetRoot()->mGeometry.size();
 		  if (costFunction[i] > maxCost)
 			maxCost = costFunction[i];
@@ -1433,5 +1436,5 @@
 	if (currentPos < costFunction.size())
 	  currentCost = costFunction[currentPos];
-#if 0	
+#if 1	
 	cout<<"costFunction.size()="<<costFunction.size()<<endl;
 	cout<<"CP="<<currentPos<<endl;
@@ -1440,9 +1443,11 @@
 #endif
 	if (costFunction.size()) {
+	  float scaley = 1.0f/log10(maxCost);
+	  float scalex = 1.0f/(float)costFunction.size();
+
 	  glDisable(GL_DEPTH_TEST);
 	  // init ortographic projection
 	  glMatrixMode(GL_PROJECTION);
-
-
+	  
 	  glPushMatrix();
 	  
@@ -1460,6 +1465,6 @@
 	  
 	  for (int i=0;  i < costFunction.size(); i++) {
-		float x =  i/(float)costFunction.size();
-		float y = costFunction[i]/(maxCost*0.5f);
+		float x =  i*scalex;
+		float y = log10(costFunction[i])*scaley;
 		glVertex3f(x,y,0.0f);
 	  }
@@ -1468,5 +1473,5 @@
 	  glColor3f(1.0f,0,0);
 	  glBegin(GL_LINES);
-	  float x =  currentPos/(float)costFunction.size();
+	  float x =  currentPos*scalex;
 	  glVertex3f(x,0.0,0.0f);
 	  glVertex3f(x,1.0f,0.0f);
@@ -1483,14 +1488,17 @@
 
 	  glBegin(GL_LINES);
-	  for (int i=0;  i < 50000 && i < costFunction.size(); i+=10000) {
-		float x =  i/(float)costFunction.size();
+	  for (int i=0;  i < costFunction.size(); i += 1000) {
+		float x =  i*scalex;
 		glVertex3f(x,0.0,0.0f);
 		glVertex3f(x,1.0f,0.0f);
 	  }
 
-	  for (int i=0;  i < maxCost; i+=100) {
-		float y = i/(maxCost*0.5f);
-		glVertex3f(0,y,0.0f);
-		glVertex3f(1,y,0.0f);
+	  for (int i=0;  pow(10, i) < maxCost; i+=1) {
+		float y = i*scaley;
+		//		QString s;
+		//		s.sprintf("%d", (int)pow(10,i));
+		//		renderText(width()/2+5, y*height(), s);
+		glVertex3f(0.0f, y, 0.0f);
+		glVertex3f(1.0f, y, 0.0f);
 	  }
 
@@ -1513,4 +1521,42 @@
 QtGlRendererWidget::RenderInfo()
 {
+
+  // $$JB temporal hack for two windows separation
+  if (1) {
+
+	// model view 
+	glPushMatrix();
+	glLoadIdentity();
+	
+	// init ortographic projection
+	glMatrixMode(GL_PROJECTION);
+	glPushMatrix();
+	
+	glLoadIdentity();
+	gluOrtho2D(0, 1.0f, 0, 1.0f);
+	
+	float w = 0.01f;
+	float h = 1.0f;
+	float px = 0.0f;
+	float py = 0.0f;
+	
+	glColor3f(0.8f, 0.8f, 0.8f);
+	glBegin(GL_QUADS);
+	
+	glVertex3f(px+w, py, 0);
+	glVertex3f(px+w, py+h + w, 0);
+	glVertex3f(px, py+h, 0);
+	glVertex3f(px, py, 0);
+	glEnd();
+	
+	// projection
+	glPopMatrix();
+	
+	glMatrixMode(GL_MODELVIEW);
+	// model view
+	glPopMatrix();
+  }
+
+
   QString s;
   int vc = 0;
@@ -1521,5 +1567,7 @@
 	filter = mViewCellsManager->GetMaxFilterSize();
 
-  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",
+  glColor3f(1.0f,1.0f,1.0f);
+
+  s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)",
 			mFrame,
 			mViewPoint.x,
@@ -1528,14 +1576,20 @@
 			mViewDirection.x,
 			mViewDirection.y,
-			mViewDirection.z,
+			mViewDirection.z
+			);
+
+  renderText(20,20,s);
+
+  s.sprintf("viewcells:%04d filter:%04d pvs:%04d error:%5.5f\%",
 			vc,
-
 			filter,
 			mPvsSize,
-			mRenderError*100.0f
-			);
-  
-  glColor3f(0.0f,0.0f,0.0f);
-  renderText(0,20,s);
+			mRenderError*100.0f);
+
+
+  renderText(20,40,s);
+
+  
+
   
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1584)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1585)
@@ -426,5 +426,5 @@
 	Environment::GetSingleton()->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells);
 	char buf[100];
-	
+
 	if (mLoadViewCells)
 	{	
@@ -902,5 +902,5 @@
 		  }
 		if (i % 10000 == 0)
-		  cout<<".";
+		  cout<<i<<"/"<<rays.size()<<"\r";
 	}
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1583)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1585)
@@ -427,7 +427,7 @@
 
 	if (mUseImportanceSampling) {
-	  GenerateRays(mInitialSamples/3, SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION, rays);
-	  GenerateRays(mInitialSamples/3, SamplingStrategy::OBJECT_BASED_DISTRIBUTION, rays);
-	  GenerateRays(mInitialSamples/3, SamplingStrategy::DIRECTION_BASED_DISTRIBUTION, rays);
+	  GenerateRays(mInitialSamples/2, SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION, rays);
+	  //	  GenerateRays(mInitialSamples/3, SamplingStrategy::OBJECT_BASED_DISTRIBUTION, rays);
+	  GenerateRays(mInitialSamples/2, SamplingStrategy::DIRECTION_BASED_DISTRIBUTION, rays);
 	  //	GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays);
 	} else {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1584)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1585)
@@ -6,6 +6,6 @@
 Scene {
 
-#filename ../data/City4M/City4M.obj
-#filename ../data/CityModel/CityModel.obj
+# filename ../data/City4M/City4M.obj
+filename ../data/CityModel/CityModel.obj
 # filename ../data/GrandCanyon/grandcanyon1_RotXmin90.obj
 # filename ../data/glasgow/glasgow1.x3d
@@ -14,6 +14,7 @@
 # filename ../data/vienna/vienna-buildings.x3d
 # filename ../data/vienna/city1500_flat_1.x3d
-# filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
-#;../data/vienna/vienna-plane.x3d;../data/vienna/vienna-roads.x3d
+filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
+
+# ../data/vienna/vienna-plane.x3d;
 # filename ../data/vienna/viewcells-25-sel.x3d
 #filename ../data/atlanta/atlanta2.x3d
@@ -53,5 +54,5 @@
 	visibilityFilterWidth	0.01
 	visibilityFile visibility.xml
-	loadMeshes true
+	loadMeshes false
 	loadKdTree	false
 	exportKdTree false
@@ -59,5 +60,5 @@
 
 ObjParser {
-	meshGrouping 1
+	meshGrouping 2
 }
 
@@ -144,8 +145,7 @@
 		minCost 0.95
 		maxDepth 30
-		maxCostRatio 1.0
+		maxCostRatio 0.98
 		ct_div_ci 0.5
 		maxNodes 100000
-#200000
 #500000	
 	}
@@ -194,5 +194,6 @@
 	#type vspKdTree
 	#type bspTree
-	type vspBspTree
+#	type vspBspTree
+	type vspOspTree
 	#type sceneDependent
 	
@@ -277,5 +278,5 @@
 #	filename ../data/vienna/vienna-viewcells-5000.xml
 #	filename ../data/vienna/vienna-viewcells-1000.xml.zip
-
+	filename ../data/vienna/vsposp-seq-viewCells.xml.gz
 
 #	filename ../data/PowerPlant/power_plant_viewcells1.xml
@@ -339,7 +340,7 @@
 		missTolerance		6
 		globalCostMissTolerance 4
-		#minGlobalCostRatio      0.0000001
-		minGlobalCostRatio      0.0001
-# $$ MAX	
+		minGlobalCostRatio      0.0000001
+#		minGlobalCostRatio      0.0001
+# $$MAXVIEWCELLS
 		maxViewCells		5000
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1581)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1585)
@@ -12,4 +12,5 @@
 #include "Triangle3.h"
 #include "IntersectableWrapper.h"
+#include "BvHierarchy.h"
 
 //#include <Cg/cg.h>
@@ -126,4 +127,12 @@
 	RenderTriangle(dynamic_cast<TriangleIntersectable *>(object));
 	break;
+  case Intersectable::BVH_INTERSECTABLE: {
+
+	BvhNode *node = (dynamic_cast<BvhIntersectable *>(object))->GetItem();
+	//	RenderBvhNode(node);
+	RenderBox(node->GetBoundingBox());
+	break;
+  }
+	
   default:
 	cerr<<"Rendering this object not yet implemented\n";
@@ -564,3 +573,67 @@
 
 
-}
+void
+GlRenderer::RenderBox(const AxisAlignedBox3 &box)
+{
+
+  glBegin(GL_LINE_LOOP);
+  glVertex3d(box.Min().x, box.Max().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Max().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Min().y, box.Min().z );
+  glVertex3d(box.Min().x, box.Min().y, box.Min().z );
+  glEnd();
+
+  glBegin(GL_LINE_LOOP);
+  glVertex3d(box.Min().x, box.Min().y, box.Max().z );
+  glVertex3d(box.Max().x, box.Min().y, box.Max().z );
+  glVertex3d(box.Max().x, box.Max().y, box.Max().z );
+  glVertex3d(box.Min().x, box.Max().y, box.Max().z );
+  glEnd();
+
+  glBegin(GL_LINE_LOOP);
+  glVertex3d(box.Max().x, box.Min().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Min().y, box.Max().z );
+  glVertex3d(box.Max().x, box.Max().y, box.Max().z );
+  glVertex3d(box.Max().x, box.Max().y, box.Min().z );
+  glEnd();
+
+  glBegin(GL_LINE_LOOP);
+  glVertex3d(box.Min().x, box.Min().y, box.Min().z );
+  glVertex3d(box.Min().x, box.Min().y, box.Max().z );
+  glVertex3d(box.Min().x, box.Max().y, box.Max().z );
+  glVertex3d(box.Min().x, box.Max().y, box.Min().z );
+  glEnd();
+
+  glBegin(GL_LINE_LOOP);
+  glVertex3d(box.Min().x, box.Min().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Min().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Min().y, box.Max().z );
+  glVertex3d(box.Min().x, box.Min().y, box.Max().z );
+  glEnd();
+
+  glBegin(GL_LINE_LOOP);
+  glVertex3d(box.Min().x, box.Max().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Max().y, box.Min().z );
+  glVertex3d(box.Max().x, box.Max().y, box.Max().z );
+  glVertex3d(box.Min().x, box.Max().y, box.Max().z );
+
+  glEnd();
+
+}
+
+void
+GlRenderer::RenderBvhNode(BvhNode *node)
+{
+  if (node->IsLeaf()) {
+	BvhLeaf *leaf = (BvhLeaf *) node;
+	for (int i=0; i < mObjects.size(); i++)
+	  RenderIntersectable(mObjects[i]);
+  } else {
+	BvhInterior *in = (BvhInterior *)node;
+	RenderBvhNode(in->GetBack());
+	RenderBvhNode(in->GetFront());
+  }
+  
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1570)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1585)
@@ -2163,24 +2163,24 @@
 ViewCellsTree::GetCostFunction(vector<float> &costFunction)
 {
-	TraversalQueue tqueue;
-	tqueue.push(mRoot);
-	
-	while (!tqueue.empty()) 
-	{
-		ViewCell *vc = tqueue.top();
-		tqueue.pop();
-		// save the view cells if it is a leaf or if enough view cells have already been traversed
-		// because of the priority queue, this will be the optimal set of v
-		if (!vc->IsLeaf()) {	
-			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
-			costFunction.push_back(interior->GetMergeCost());
-
-			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
-
-			for (it = interior->mChildren.begin(); it != it_end; ++ it) {
-				tqueue.push(*it);
-			}
-
-		}
+  TraversalQueue tqueue;
+  tqueue.push(mRoot);
+  
+  while (!tqueue.empty()) 
+	{
+	  ViewCell *vc = tqueue.top();
+	  tqueue.pop();
+	  // save the view cells if it is a leaf or if enough view cells have already been traversed
+	  // because of the priority queue, this will be the optimal set of v
+	  if (!vc->IsLeaf()) {	
+		ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+		costFunction.push_back(interior->GetMergeCost());
+		
+		ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
+		
+		for (it = interior->mChildren.begin(); it != it_end; ++ it) {
+		  tqueue.push(*it);
+		}
+		
+	  }
 	}
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1581)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1585)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: so 7. X 21:56:30 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: ne 8. X 23:47:35 2006
 # Project:  preprocessor.pro
 # Template: app
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1581)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1585)
@@ -25,5 +25,6 @@
 class TransformedMeshInstance;
 class TriangleIntersectable;
-
+  class BvhNode;
+  
 struct VssRayContainer;
 
@@ -107,4 +108,10 @@
   RenderTriangle(TriangleIntersectable *object);
 
+  void
+  RenderBox(const AxisAlignedBox3 &box);
+
+  void
+  RenderBvhNode(BvhNode *node);
+	
   bool
   RenderScene();
