Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 878)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: út 2. V 11:07:44 2006
+# Generated by qmake (2.00a) (Qt 4.1.2) on: út 2. V 11:18:23 2006
 # Project:  preprocessor.pro
 # Template: app
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.h	(revision 863)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.h	(revision 878)
@@ -28,5 +28,5 @@
     mWidth = 1400;
     mHeight = 1000;
-    mFovy = 60.0f*(float)M_PI/180.0f;
+    mFovy = 90.0f*(float)M_PI/180.0f;
   }
   
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 870)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 878)
@@ -13,4 +13,6 @@
 
 namespace GtpVisibilityPreprocessor {
+
+extern bool MeshDebug;
 
 struct Triangle3;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 878)
@@ -1688,4 +1688,10 @@
 				   "true");
 
+	RegisterOption("Preprocessor.visibilityFilterWidth",
+				   optFloat,
+				   "preprocessor_visibility_filter_width=",
+				   "0.02");
+
+	
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 863)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 878)
@@ -24,4 +24,6 @@
 KdTree::KdTree()
 {
+
+  
   mRoot = new KdLeaf(NULL, 0);
   environment->GetIntValue("KdTree.Termination.maxNodes", mTermMaxNodes);
@@ -585,5 +587,18 @@
 		  if (ray.mFlags & Ray::STORE_TESTED_OBJECTS)
 			ray.testedObjects.push_back(object);
+
+		  static int oi=1;
+		  if (MeshDebug) 
+			cout<<"Object "<<oi++;
+		  
 		  hits += object->CastRay(ray);
+
+		  if (MeshDebug) {
+			if (ray.intersections.size()) 
+			cout<<"nearest t="<<ray.intersections[0].mT<<endl;
+		  else
+			cout<<"nearest t=-INF"<<endl;
+		  }
+		  
 		}
 	  }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 878)
@@ -132,6 +132,7 @@
 	environment->GetStringValue("Preprocessor.visibilityFile",  buffer);
 	mVisibilityFileName = buffer;
-	environment->GetBoolValue("Preprocessor.visibilityFile", mApplyVisibilityFilter );
-	
+	environment->GetBoolValue("Preprocessor.applyVisibilityFilter", mApplyVisibilityFilter );
+	environment->GetFloatValue("Preprocessor.visibilityFilterWidth", mVisibilityFilterWidth);
+
 	Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
 	Debug << "load polygons as meshes: " << mLoadPolygonsAsMeshes << endl;
@@ -274,7 +275,9 @@
   if (mApplyVisibilityFilter) {
 	cout<<"Applying visibility filter...";
+	cout<<"filyter width = "<<mVisibilityFilterWidth<<endl;
+
 	mViewCellsManager->ApplyFilter(mKdTree,
-								   0.05f,
-								   0.05f);
+								   mVisibilityFilterWidth,
+								   mVisibilityFilterWidth);
 	cout<<"done.";
   }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 860)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 878)
@@ -201,5 +201,5 @@
 /** KdTree for indexing scene entities - occluders/occludees/viewcells */
 class KdTree {
-
+  
 protected:
   struct TraversalData
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 878)
@@ -14,5 +14,5 @@
 #include "SceneGraph.h"
 #include "PreprocessorThread.h"
-//#include "RenderSampler.h"
+#include "RenderSampler.h"
 
 #include <QApplication>
@@ -135,11 +135,12 @@
   }
   
+
+  if (app)
+	return app->exec();
+
   // clean up
   DEL_PTR(p);
   DEL_PTR(environment);
 
-  if (app)
-	return app->exec();
-  
   return 0;
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 878)
@@ -9,5 +9,6 @@
 #	filename vienna.x3d
 # filename ../data/vienna/vienna-simple.x3d
-filename ../data/vienna/vienna-buildings.x3d
+#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-plane.x3d;../data/vienna/vienna-roads.x3d
 # filename ../data/vienna/viewcells-25-sel.x3d
@@ -39,4 +40,7 @@
 	quitOnFinish false
 	computeVisibility true
+	applyVisibilityFilter	true
+	visibilityFilterWidth	0.01
+	visibilityFile visibility.xml
 }
 
@@ -160,5 +164,7 @@
 		maxCostRatio 1.0
 		ct_div_ci 0.5
-		maxNodes 500000	
+		maxNodes 100000
+
+#500000	
 	}
 
@@ -170,5 +176,5 @@
 MeshKdTree {
 	Termination {
-		minCost 40
+		minCost 8
 		maxDepth 18
 		maxCostRatio 0.9
@@ -276,4 +282,6 @@
 #	filename ../data/atlanta/viewcells_atlanta3.xml
 	filename ../data/vienna/viewcells_vienna.xml
+#	filename ../data/vienna/viewcells_vienna2.xml
+#	filename ../data/vienna/vienna_simple-21-04-avs2-viewCells.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 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 878)
@@ -171,4 +171,6 @@
   
   bool mApplyVisibilityFilter;
+
+  float mVisibilityFilterWidth;
   
   GlRendererBuffer *GetRenderer() { return renderer;}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/PreprocessorThread.cpp	(revision 878)
@@ -23,19 +23,17 @@
 {
   
-  if (mPreprocessor->mComputeVisibility) {
-    mPreprocessor->ComputeVisibility();
-	//	mPreprocessor->ExportPreprocessedData("scene.vis");
-	mPreprocessor->PostProcessVisibility();
-  }
-  
   Camera camera;
 
   if (0) {
-    // camera.LookAtBox(mPreprocessor->mKdTree->GetBox());
-	//	camera.LookInBox(mPreprocessor->mKdTree->GetBox());
+	// camera.LookAtBox(mPreprocessor->mKdTree->GetBox());
+	 //	camera.LookInBox(mPreprocessor->mKdTree->GetBox());
 	camera.SetPosition(Vector3(3473, 6.778, -1699));
 	camera.SetDirection(Vector3(-0.2432, 0, 0.97));
+	//	camera.SetPosition(Vector3(991.7, 187.8, -271));
+	//	camera.SetDirection(Vector3(0.9, 0, -0.4));
+
     camera.SnapImage("camera.jpg", mPreprocessor->mKdTree, mPreprocessor->mSceneGraph);
-  }
+  } 
+
   if (0) {
     camera.LookInBox(mPreprocessor->mKdTree->GetBox());
@@ -50,4 +48,11 @@
   }
 
+  if (mPreprocessor->mComputeVisibility) {
+    mPreprocessor->ComputeVisibility();
+	//	mPreprocessor->ExportPreprocessedData("scene.vis");
+	mPreprocessor->PostProcessVisibility();
+  }
+  
+
 
   cerr << "Preprocessor main finished...\n";
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp	(revision 863)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp	(revision 878)
@@ -60,6 +60,16 @@
     cout<<"+";
     for (x = 0; x < mWidth; x++) {
-      SetupRay(ray, x, mHeight - (y + 1));
-      if (tree->CastRay(ray))
+      SetupRay(ray, mWidth - (x + 1), mHeight - (y + 1));
+
+	  bool debug = false;
+	  //	  (y == mHeight/2) && (x== mWidth/3);
+	  //	  MeshDebug = debug;
+	  
+	  if (debug) 
+		ray.mFlags = (Ray::STORE_TESTED_OBJECTS | Ray::STORE_KDLEAVES);
+	  else 
+		ray.mFlags &= ~(Ray::STORE_TESTED_OBJECTS|Ray::STORE_KDLEAVES);
+	  
+	  if (tree->CastRay(ray))
 		if (ray.intersections.size()) {
 		  sort(ray.intersections.begin(), ray.intersections.end());
@@ -79,5 +89,7 @@
 	  //      if (exportRays && ( 1||(x==222) && (y==97))) {
 	  //	  if (exportRays && ((x%4==0) && (y%4==0))) {
-	  if (exportRays && ray.intersections.empty()) {
+
+	  //	  if (exportRays && ray.intersections.empty()) {
+	  if (debug) {
 		Ray *nray = new Ray(ray);
 		rays.push_back(nray);
@@ -104,6 +116,9 @@
   if (1) {
     exporter = Exporter::GetExporter(filename + "-rays" + ".x3d");
-    exporter->SetFilled();
-	if (sceneGraph)
+    //exporter->SetFilled();
+
+	exporter->SetWireframe();
+
+	if (sceneGraph) 
 	  exporter->ExportScene(sceneGraph->mRoot);
 	
@@ -111,5 +126,4 @@
 	//exporter->ExportBspTree(*bsptree);
     exporter->ExportRays(rays, 2000);
-    exporter->SetFilled();
     int k =0;
     for (int j=0; j < rays.size(); j++)
@@ -117,11 +131,15 @@
 		Ray *ray = rays[j];
 		int i;
-		if (0)
+		exporter->SetWireframe();
+
+		if (1)
 		  for (i= 0; i < ray->kdLeaves.size(); i++)
 			exporter->ExportBox(tree->GetBox(ray->kdLeaves[i]));
-		if (0)
+
+		exporter->SetFilled();
+		
+		if (1)
 		  for (i= 0; i < ray->testedObjects.size(); i++)
 			exporter->ExportIntersectable(ray->testedObjects[i]);
-		
       }
 	
@@ -142,5 +160,5 @@
   ray.Clear();
   ray.Init(mPosition, target, Ray::LOCAL_RAY);
-  
+  ray.mFlags &= ~Ray::CULL_BACKFACES;
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 878)
@@ -4915,5 +4915,4 @@
 
   pvs.Merge(nPvs);
-
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 871)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 878)
@@ -55,4 +55,7 @@
   mViewPoint = mSceneGraph->GetBox().Center();
   mViewDirection = Vector3(0,0,1);
+
+  mViewPoint = Vector3(991.7, 187.8, -271);
+  mViewDirection = Vector3(0.9, 0, -0.4);
 
   //  timerId = startTimer(10);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 873)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 878)
@@ -6,4 +6,5 @@
 namespace GtpVisibilityPreprocessor {
 
+bool MeshDebug = false;
 
 int Intersectable::sMailId = 21843194198;
@@ -158,10 +159,10 @@
 int
 Mesh::CastRayToFace(
-										const int faceIndex,
-										Ray &ray,
-										float &nearestT,
-										int &nearestFace,
-										Intersectable *instance
-										)
+					const int faceIndex,
+					Ray &ray,
+					float &nearestT,
+					int &nearestFace,
+					Intersectable *instance
+					)
 {
   float t;
@@ -180,6 +181,6 @@
     case Ray::LINE_SEGMENT:
       if (t <= 1.0f) {
-				ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex));
-				hit++;
+		ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex));
+		hit++;
       }
       break;
@@ -243,6 +244,6 @@
 
   for ( fi = faces.begin();
-				fi != faces.end();
-				fi++) {
+		fi != faces.end();
+		fi++) {
     hits += CastRayToFace(*fi, ray, nearestT, nearestFace, instance);
     if (mIsConvex && nearestFace != -1)
@@ -296,8 +297,9 @@
 
   double thresh;
+
   if (ydiff < 0.0f)
-	thresh = -1e20;
+	thresh = -1e-20;
   else
-	thresh = 1e20;
+	thresh = 1e-20;
 
   
@@ -319,5 +321,12 @@
   Plane3 plane = GetFacePlane(faceIndex);
   float dot = DotProd(plane.mNormal, ray.GetDir());
-  
+
+  if (MeshDebug) {
+	cout<<endl<<endl;
+	cout<<"normal="<<plane.mNormal<<endl;
+	cout<<"dot="<<dot<<endl;
+  }
+  
+	
   // Watch for near-zero denominator
   // ONLY single sided polygons!!!!!
@@ -332,5 +341,8 @@
   
   t = (-plane.mD - DotProd(plane.mNormal, ray.GetLoc())) / dot;
-  
+
+  if (MeshDebug)
+	cout<<"t="<<t<<endl;
+
   if (t <= Limits::Small)
     return Ray::INTERSECTION_OUT_OF_LIMITS;
@@ -346,4 +358,5 @@
   int paxis = plane.mNormal.DrivingAxis();
 
+  
   // Project the intersection point onto the coordinate plane
   // specified by which.
@@ -353,4 +366,7 @@
   int size = (int)face->mVertexIndices.size();
 
+  if (MeshDebug)
+	cout<<"size="<<size<<endl;
+  
   mVertices[face->mVertexIndices[size - 1]].
     ExtractVerts(&u1, &v1, paxis );
@@ -362,6 +378,9 @@
       mVertices[face->mVertexIndices[i]].ExtractVerts(&u2, &v2, paxis);
       // line u1, v1, u2, v2
-      if ((v1 - v2)*(u - u1) + (u2 - u1)*(v - v1) > 0)
+      if ((v1 - v2)*(u - u1) + (u2 - u1)*(v - v1) > 0) {
+		if (MeshDebug)
+		  cout<<"exit on "<<i<<endl;
 		return Ray::NO_INTERSECTION;
+	  }
       u1 = u2;
       v1 = v2;
@@ -381,4 +400,7 @@
     v1 = v2;
   }
+
+  if (MeshDebug)
+	cout<<"count="<<count<<endl;
 
   // We hit polygon if number of intersections is odd.
