Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env	(revision 1277)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.env	(revision 1404)
@@ -9,6 +9,7 @@
 #	filename ../data/vienna/vienna-simple.x3d
 #	filename ../data/vienna/vienna-buildings.x3d
-	filename ../data/vienna/city1500_flat_1.x3d
-#	filename ../data/vienna/vienna-buildings.x3d;../data/vienna-roads.x3d;../data/vienna/vienna-roofs.x3d
+#	filename ../data/vienna/city1500_flat_1.x3d
+#	filename ../data/vienna/vienna-roads.x3d
+#	filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roads.x3d;../data/vienna/vienna-roofs.x3d
 #filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
 filename ../data/vienna/city1500_flat_1.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
@@ -29,5 +30,5 @@
 #	type rss
 	detectEmptyViewSpace true
-	loadPolygonsAsMeshes false
+	loadMeshes true
 	applyVisibilityFilter true
 	applyVisibilitySpatialFilter true
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells	(revision 1277)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells	(revision 1404)
@@ -1,4 +1,6 @@
 #!/bin/sh
+
 PROGRAM=../bin/release/Preprocessor.exe
+#PROGRAM=../bin/Debug/Preprocessor.exe
 
 
@@ -29,5 +31,5 @@
 -vsp_bsp_subdivision_stats=$LOG_PREFIX-$METHOD-subdivisionStats.log \
 -view_cells_post_process_merge=false \
--view_cells_active=400 \
+-view_cells_active=1000 \
 -view_cells_filename=$LOG_PREFIX-visibility.xml.zip \
 -view_cells_export_pvs=true \
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna.env	(revision 1052)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vienna.env	(revision 1404)
@@ -8,8 +8,8 @@
 #	filename vienna.x3d
 #	filename ../data/vienna/vienna-simple.x3d
-#	filename ../data/vienna/vienna-buildings.x3d
-	filename ../data/vienna/city1500_flat_1.x3d
+	filename ../data/vienna/vienna-buildings.x3d
+#	filename ../data/vienna/city1500_flat_1.x3d
 #	filename ../data/vienna/vienna-buildings.x3d;../data/vienna-roads.x3d;../data/vienna/vienna-roofs.x3d
-filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
+#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d
 #filename ../data/vienna/city1500_flat_1.x3d;../data/vienna/vienna-roofs.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
@@ -29,5 +29,5 @@
 #	type rss
 	detectEmptyViewSpace true
-	loadPolygonsAsMeshes false
+	loadMeshes false
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 1404)
@@ -1108,50 +1108,4 @@
 
 
-void VrmlExporter::ExportGeometry(const ObjectContainer &objects)
-{
-	ObjectContainer::const_iterator oit, oit_end = objects.end();
-
-	if (1)
-	{
-		// export using native or random material
-		for (oit = objects.begin(); oit != oit_end; ++ oit)
-		{
-			if (0)
-			{
-				mUseForcedMaterial = true;
-				SetForcedMaterial(RandomMaterial());
-			}
-			ExportIntersectable(*oit);
-		}
-		return;
-	}
-
-	///////////////////////////////////
-	// method 2 (hacky)
-	// all object exported as one mesh
-	PolygonContainer polys;
-
-	for (oit = objects.begin(); oit != oit_end; ++ oit)
-	{
-		MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit);
-		polys.push_back(new Polygon3(mi->GetMesh()->mVertices));
-	}
-
-	Mesh dummyMesh;
-	PolygonContainer::const_iterator pit, pit_end = polys.end();
-
-	for (pit = polys.begin(); pit != pit_end; ++ pit)
-	{
-		Polygon3 *poly = (*pit);
-		IncludePolyInMesh(*poly, dummyMesh);
-	}
-	
-	ExportMesh(&dummyMesh);
-
-	CLEAR_CONTAINER(polys);
-}
-
-
-
 bool VrmlExporter::ExportRssTree2(const RssTree &tree,
 								  const Vector3 direction)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1379)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1404)
@@ -250,5 +250,5 @@
 			 for (tit = triangles.begin(); tit != tit_end; ++ tit)
 			 {
-				 cout << "triangle: " << *tit << endl;
+				 //cout << "triangle: " << *tit << endl;
 				 TriangleIntersectable *ti = new TriangleIntersectable(*tit);
 				 mCurrentNode->mGeometry.push_back(ti);
@@ -292,9 +292,8 @@
 				 mCurrentNode->mGeometry.push_back(mi);
 
-				 if (mCurrentMaterial)
+				 if (mCurrentMaterial && !mCurrentMesh->mMaterial)
 				 {
 					 // HACK: add the material to the mesh directly if no material yet
-					 if (!mCurrentMesh->mMaterial)
-						 mCurrentMesh->mMaterial = mCurrentMaterial;
+					 mCurrentMesh->mMaterial = mCurrentMaterial;
 				 }
 			 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h	(revision 1404)
@@ -123,5 +123,5 @@
 
   virtual void
-  ExportGeometry(const ObjectContainer &objects) = 0;
+  ExportGeometry(const ObjectContainer &objects, const bool exportSingleMesh = false);
 
   virtual void
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1381)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1404)
@@ -233,5 +233,5 @@
 	Parser *parser;
 	vector<string> filenames;
-	int files = SplitFilenames(filename, filenames);
+	const int files = SplitFilenames(filename, filenames);
 	cout << "number of input files: " << files << endl;
 	bool result = false;
@@ -239,4 +239,8 @@
 	// root for different files
 	mSceneGraph->SetRoot(new SceneGraphNode());
+
+	// intel ray caster can only trace triangles
+	vector<FaceParentInfo> *fi = (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) ?
+		&mFaceParents : NULL;
 
 	if (files == 1) {
@@ -253,51 +257,41 @@
 
 		cout << filename << endl;
-
-		if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER)
-		{ 
-			result = parser->ParseFile(
+		
+		result = parser->ParseFile(
 				filename, 
 				mSceneGraph->GetRoot(),
 				mLoadMeshes,
-				&mFaceParents);
-		}
-		else
-		{ 
-			result = parser->ParseFile(filename, mSceneGraph->GetRoot(), mLoadMeshes);
-		}
-		
+				fi);
+			
 		delete parser;
 
-	} else {
-		
-		for (int i= 0; i < filenames.size(); i++) {
-		  if (strstr(filenames[i].c_str(), ".x3d"))
-			parser = new X3dParser;
-		  else 
-			parser = new UnigraphicsParser;
-		  
-		  SceneGraphNode *node = new SceneGraphNode();
-		  bool success;
-		  
-		  if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER)
-		  { 
-			  success = parser->ParseFile(
-				  filename, 
-				  node,
-				  mLoadMeshes,
-				  &mFaceParents);
-		  }
-		  else
-		  {
-			  success = parser->ParseFile(filename, node, mLoadMeshes);
-		  }
-
-		  if (success) 
-		  { 
-			  mSceneGraph->GetRoot()->mChildren.push_back(node);
-			  result = true; // at least one file parsed
-		  }
-		  
-		  delete parser;
+	} 
+	else {
+		vector<string>::const_iterator fit, fit_end = filenames.end();
+		
+		for (fit = filenames.begin(); fit != fit_end; ++ fit) 
+		{
+			const string filename = *fit;
+
+			cout << "parsing file " << filename.c_str() << endl;
+			if (strstr(filename.c_str(), ".x3d"))
+				parser = new X3dParser;
+			else 
+				parser = new UnigraphicsParser;
+
+			SceneGraphNode *node = new SceneGraphNode();
+			const bool success = parser->ParseFile(
+				filename, 
+				node,
+				mLoadMeshes,
+				fi);
+
+			if (success) 
+			{ 
+				mSceneGraph->GetRoot()->mChildren.push_back(node);
+				result = true; // at least one file parsed
+			}
+
+			delete parser;
 		}
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h	(revision 1404)
@@ -86,7 +86,4 @@
   ExportViewCell(ViewCell *viewCell);
 
-  virtual void
-  ExportGeometry(const ObjectContainer &objects);
-
   bool
   ExportRays(const RayContainer &rays,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1328)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1404)
@@ -466,26 +466,28 @@
   mSceneGraph->CollectObjects(&mObjects);
 
-  //-- load view cells from file or reconstruct them
   if (!mLoadViewCells)
   {
+	  //-- generate new view cells or reconstruct them
+	  //-- for construction the manager uses it's own set of samples
 	  mViewCellsManager->SetViewSpaceBox(vbox);
-	  // construct view cells using it's own set of samples
 	  mViewCellsManager->Construct(this);
 
-	  //-- several visualizations and statistics
+	  // output visualizations and statistics
 	  Debug << "view cells construction finished: " << endl;
 	  mViewCellsManager->PrintStatistics(Debug);
   }
-#if 1 // test successful view cells loading by exporting them again
+#if 1 
   else 
   {	 
-	  VssRayContainer dummies;
+	  //-- load view cells from file
+	  //-- test successful view cells loading by exporting them again
+      VssRayContainer dummies;
 	  mViewCellsManager->Visualize(mObjects, dummies);
 	  mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects);
   }
 #endif
+
   VssTree *vssTree = NULL; 
-
-  long initialTime = GetTime();
+  const long initialTime = GetTime();
 
   if (mLoadInitialSamples)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 1404)
@@ -1047,44 +1047,4 @@
 
 
-void X3dExporter::ExportGeometry(const ObjectContainer &objects)
-{
-	ObjectContainer::const_iterator oit, oit_end = objects.end();
-
-	if (1)
-	{
-		for (oit = objects.begin(); oit != oit_end; ++ oit)
-		{
-			if (0)
-				SetForcedMaterial(RandomMaterial());
-			
-			ExportIntersectable(*oit);
-		}
-
-		return;
-	}
-
-	// hack: all object exported as one mesh
-	PolygonContainer polys;
-
-	for (oit = objects.begin(); oit != oit_end; ++ oit)
-	{
-		polys.push_back(new Polygon3(dynamic_cast<MeshInstance *>(*oit)->GetMesh()->mVertices));
-	}
-
-	Mesh dummyMesh;
-	PolygonContainer::const_iterator pit, pit_end = polys.end();
-
-	for (pit = polys.begin(); pit != pit_end; ++ pit)
-	{
-		Polygon3 *poly = (*pit);
-		IncludePolyInMesh(*poly, dummyMesh);
-	}
-	
-	ExportMesh(&dummyMesh);
-
-	CLEAR_CONTAINER(polys);
-}
-
-
 bool
 X3dExporter::ExportRssTree2(const RssTree &tree,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1379)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1404)
@@ -1616,4 +1616,19 @@
 }
 
+/*
+Mesh *BvHierarchy::MergeLeafToMesh()
+void BvHierarchy::MergeLeavesToMeshes()
+{
+	vector<BvhLeaf *> leaves;
+	CollectLeaves(leaves);
+
+	vector<BvhLeaf *>::const_iterator lit, lit_end = leaves.end();
+
+	for (lit = leaves.begin(); lit != lit_end; ++ lit)
+	{
+		Mesh *mesh = MergeLeafToMesh(*lit);
+	}
+}*/
+
 
 SubdivisionCandidate *BvHierarchy::PrepareConstruction(const VssRayContainer &sampleRays,
@@ -1621,5 +1636,7 @@
 {
 	///////////////////////////////////////////////////////////////
-	// note matt: we assume that we have objects sorted by their id
+	//-- note matt: we assume that we have objects sorted by their id => 
+	//-- we don't have to sort them here and an binary search 
+	//-- for identifying if a object is in a leaf.
 
 	mBvhStats.Reset();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.cpp	(revision 1404)
@@ -52,4 +52,18 @@
 
 	mMaterial = parentMesh->mMaterial;
+}
+
+
+Polygon3::Polygon3(const Triangle3 &tri):
+mMaterial(NULL), 
+mParent(NULL), 
+mPiercingRays(0), 
+mPlane(NULL)
+{	
+	mVertices.reserve(3);
+	
+	mVertices.push_back(tri.mVertices[0]);
+	mVertices.push_back(tri.mVertices[1]);
+	mVertices.push_back(tri.mVertices[2]);
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.h	(revision 1404)
@@ -89,7 +89,4 @@
   ExportViewCell(ViewCell *viewCell);
 
-  virtual void
-  ExportGeometry(const ObjectContainer &objects);
-
   bool
   ExportRays(const RayContainer &rays,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BoostPreprocessorThread.cpp	(revision 1404)
@@ -75,5 +75,6 @@
 void BoostPreprocessorThread::RunThread()
 {
-  mThread->join();
+	Main();
+  //mThread->join();
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1381)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1404)
@@ -2625,4 +2625,5 @@
 	}
 
+	///////////////////////////////////////
 	//-- post processing of bsp view cells
 
@@ -3755,5 +3756,5 @@
 	}
 
-	if (0) 
+	if (1) 
 	{
 		mColorCode = 1; // export merged view cells using pvs coding
@@ -5127,5 +5128,5 @@
 			if (mExportGeometry)
 			{
-				exporter->ExportGeometry(objects);
+				exporter->ExportGeometry(objects, true);
 			}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1344)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1404)
@@ -146,5 +146,5 @@
 		{
 			SetFilled();
-			ExportGeometry(leaf->mObjects);
+			ExportGeometry(leaf->mObjects, true);
 		}
 	}
@@ -221,4 +221,55 @@
 
 
-
-}
+void Exporter::ExportGeometry(const ObjectContainer &objects, 
+							  const bool exportSingleMesh)
+{
+	ObjectContainer::const_iterator oit, oit_end = objects.end();
+
+	if (!exportSingleMesh)
+	{
+		for (oit = objects.begin(); oit != oit_end; ++ oit)
+		{
+			if (0) SetForcedMaterial(RandomMaterial());
+			ExportIntersectable(*oit);
+		}
+
+		return;
+	}
+
+	//-- all objects exported as one mesh
+	//-- hack: currently it works only for triangles
+	PolygonContainer polys;
+
+	for (oit = objects.begin(); oit != oit_end; ++ oit)
+	{
+		Intersectable *obj = *oit;
+		switch (obj->Type())
+		{
+		case Intersectable::TRIANGLE_INTERSECTABLE:
+			{
+				TriangleIntersectable *ti = dynamic_cast<TriangleIntersectable *>(obj);
+				polys.push_back(new Polygon3(ti->GetItem()));
+                break;
+			}
+		default:
+			cout << "merging of object type " << obj->Type() << " not implemented yet" << endl;
+			break;
+		}
+	}
+
+	Mesh dummyMesh;
+	PolygonContainer::const_iterator pit, pit_end = polys.end();
+
+	for (pit = polys.begin(); pit != pit_end; ++ pit)
+	{
+		Polygon3 *poly = (*pit);
+		IncludePolyInMesh(*poly, dummyMesh);
+	}
+	
+	ExportMesh(&dummyMesh);
+	CLEAR_CONTAINER(polys);
+}
+
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h	(revision 1328)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h	(revision 1404)
@@ -37,4 +37,7 @@
 	*/
 	Polygon3(MeshInstance *parent);
+	/** A Triangle is converted to a polygon.
+	*/
+	Polygon3(const Triangle3 &tri);
 
 	~Polygon3() {DEL_PTR(mPlane);}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1387)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1404)
@@ -2,5 +2,5 @@
 //#define USE_QT 0
 #endif
-
+//#define USE_QT 0
 #define USE_THREADS 1
 
@@ -180,28 +180,4 @@
 	preprocessor->KdTreeStatistics(cout);
 
-	/*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
-	MeshManager::GetSingleton()->ExportEntries("meshes.bin");
-
-	KdTree *kdTree2 = new KdTree;
-
-	cout << "loading kd tree ... ";
-	long startTime = GetTime();
-	kdTree2->LoadBinTree("kd.bin.gz", preprocessor->mObjects);
-  		
-	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-
-	Exporter *exporter = Exporter::GetExporter("testkd.x3d");
-	MeshManager::GetSingleton()->ExportEntries("meshes.bin");
-
-	if (exporter) 
-	{
-		exporter->SetWireframe();
-		exporter->ExportKdTree(*kdTree2, true);
-
-		delete exporter;
-	}
-
-	DEL_PTR(kdTree2);
-*/
 	// parse view cells related options
 	preprocessor->PrepareViewCells();
@@ -256,11 +232,8 @@
 
 		  rendererWidget->Show();
-		  guiSupported = true;
-
-		  
+		  guiSupported = true; 
 		}
 
-		qApp->exec();
-		
+		qApp->exec();	
 #endif
 	  }
