Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1545)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1627)
@@ -265,49 +265,4 @@
 				}
 			}
-#if 0
-			// we create a new mesh for each face from the current mesh
-			Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
-
-				
-			// dummy vertex indices container
-			VertexIndexContainer vcIndices;
-			VertexIndexContainer::const_iterator vit, vit_end = face->mVertexIndices.end();
-			int i = 0;
-
-			for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit, ++ i)
-			{
-				cout << "i";
-				const int index = (*vit);
-				// add vertices
-				mesh->mVertices.push_back(mCurrentMesh->mVertices[index]);
-				// indices don't make much sense if mesh == face, but we need them anyway ...
-				vcIndices.push_back(i);
-			}
-
-			mesh->mFaces.push_back(new Face(vcIndices));
-
-			// write transformations directly into the mesh
-			// note: could be transformed in parent mesh, save some transformations
-			ApplyTransformations(mTransformations, mesh);
-
-			mesh->Preprocess();
-
-			if (mesh->mFaces.empty())
-			{
-				cout << "error: empy mesh" << endl;
-			}
-			else
-			{
-				// make an instance of this mesh
-				MeshInstance *mi = new MeshInstance(mesh);
-				mCurrentNode->mGeometry.push_back(mi);
-
-				if (mCurrentMaterial && !mCurrentMesh->mMaterial)
-				{
-					// HACK: add the material to the mesh directly if no material yet
-					mCurrentMesh->mMaterial = mCurrentMaterial;
-				}
-			}
-#endif
 		}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1626)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1627)
@@ -470,14 +470,17 @@
 		Environment::GetSingleton()->GetStringValue("ViewCells.geometryFilename", vcGeomFilename);
 		
-		if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
-		{
-			if (!mViewCellsManager->LoadViewCellsGeometry(vcGeomFilename, extrudeBaseTriangles))
+		if (loadVcGeometry)
+		{
+			if (mViewCellsManager->GetType() == ViewCellsManager::BSP)
 			{
-				cerr << "loading view cells geometry failed" << endl;
+				if (!mViewCellsManager->LoadViewCellsGeometry(vcGeomFilename, extrudeBaseTriangles))
+				{
+					cerr << "loading view cells geometry failed" << endl;
+				}
 			}
-		}
-		else
-		{
-			cerr << "loading view cells geometry is not implemented for this manager" << endl;
+			else
+			{
+				cerr << "loading view cells geometry is not implemented for this manager" << endl;
+			}
 		}
 	}
@@ -513,12 +516,12 @@
 bool Preprocessor::ConstructViewCells()
 {
-  // construct view cells using it's own set of samples
-  mViewCellsManager->Construct(this);
-  
-  // visualizations and statistics
-  Debug << "finished view cells:" << endl;
-  mViewCellsManager->PrintStatistics(Debug);
-  
-  return true;
+	// construct view cells using it's own set of samples
+	mViewCellsManager->Construct(this);
+
+	// visualizations and statistics
+	Debug << "finished view cells:" << endl;
+	mViewCellsManager->PrintStatistics(Debug);
+
+	return true;
 }
 
@@ -815,5 +818,5 @@
 
 
-bool Preprocessor::InitRayCast(const string externKdTree, const string internkdtree)
+bool Preprocessor::InitRayCast(const string externKdTree, const string internKdTree)
 {
 	bool loadKdTree = true;
@@ -830,10 +833,10 @@
 	else
 	{
-		const long startTime = GetTime();
-		cout << "loading kd tree file " << internkdtree << " ... ";
-
-		if (!LoadKdTree(internkdtree))
-		{
-			cout << "error loading kd tree with filename " << internkdtree << ", rebuilding it instead ..." << endl;
+		long startTime = GetTime();
+		cout << "loading kd tree file " << internKdTree << " ... ";
+
+		if (!LoadKdTree(internKdTree))
+		{
+			cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ..." << endl;
 
 			BuildKdTree();
@@ -852,4 +855,17 @@
 				delete exporter;
 			}
+		}
+
+		// export kd tree?
+		startTime = GetTime();
+		cout << "exporting kd tree ... ";
+
+		if (!ExportKdTree(internKdTree))
+		{
+			cout << " error exporting kd tree with filename " << internKdTree << endl;
+		}
+		else
+		{
+			cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 		}
 	}
@@ -909,5 +925,5 @@
 		  }
 		if (i % 10000 == 0)
-		  cout<<"\r"<<i<<"/"<<rays.size()<<"\r";
+		  cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r";
 	}
 	cout<<endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1626)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1627)
@@ -419,5 +419,12 @@
 protected:
 
-	enum {SEQUENTIAL, INTERLEAVED};
+	/** construction types
+		sequential: construct first view space, then object space
+		interleaved: construct view space and object space fully interleaved
+		gradient: construct view space / object space until a threshold is reached
+		multilevel: iterate until subdivisions converge to the optimum.
+	*/
+	enum {SEQUENTIAL, INTERLEAVED, GRADIENT, MULTILEVEL};
+
 	/// type of hierarchy construction
 	int mConstructionType;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1621)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1627)
@@ -30,5 +30,5 @@
 
 // $$JB HACK
-#define USE_KD_PVS 1
+#define USE_KD_PVS 0
 #define KD_PVS_AREA 1e-3f
 
@@ -5636,12 +5636,11 @@
 	const bool startFromZero = true;
 
-	// reset pvs and start over from zero
 	if (startFromZero)
 	{
+		// reset pvs and start over from zero
 		mViewCellsTree->ResetPvs();
 	}
 	else 
 	{
-		// start from current sampless
 		// statistics before casting more samples
 		cout << "compute new statistics ... ";
Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1577)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1627)
@@ -13,4 +13,7 @@
 #include "Environment.h"
 #include "ResourceManager.h"
+#include "Triangle3.h"
+#include "IntersectableWrapper.h"
+#include "Polygon3.h"
 
 
@@ -60,9 +63,9 @@
     return false;
 
-  Mesh *currentMesh = MeshManager::GetSingleton()->CreateResource();
-
   int meshGrouping;
   Environment::GetSingleton()->GetIntValue("Unigraphics.meshGrouping",
 			   meshGrouping);
+
+  Mesh *currentMesh = MeshManager::GetSingleton()->CreateResource();
 
   while(fscanf(file,"%s",str)!=EOF) 
@@ -83,5 +86,4 @@
 		  break;
 
-
 	  case 'v':            // is it v ?
 		  cout<<".";
@@ -98,5 +100,5 @@
 		  {
 			  cout << "+";
-			  vector<Vector3> vertices;
+			  VertexContainer vertices;
 			  VertexIndexContainer vertexIndices;
 
@@ -151,17 +153,19 @@
 					Material *mat = MaterialManager::GetSingleton()->CreateResource();
 					if (c != cht.end()) 
-			  {
-				  mat->mDiffuseColor = RgbColor((*c).second.x, (*c).second.y, (*c).second.z);
-				  currentMesh->mMaterial = mat;
-			  }
+					{
+						mat->mDiffuseColor = RgbColor((*c).second.x, (*c).second.y, (*c).second.z);
+						currentMesh->mMaterial = mat;
+					}
 					else
-			  {
-				  currentMesh->AssignRandomMaterial();
-			  }
+					{
+						currentMesh->AssignRandomMaterial();
+					}
 				}
 			}
 
 			currentMesh->AddFace(face);
-			if (meshGrouping != 0 && currentMesh->mFaces.size() >=  meshGrouping) 
+
+			if (loadMeshes &&
+				(meshGrouping != 0 && currentMesh->mFaces.size() >=  meshGrouping)) 
 			{
 				if (ROTATE_SCENE)
@@ -176,5 +180,5 @@
 				currentMesh = MeshManager::GetSingleton()->CreateResource();
 			}
-		}
+		  }
 		break;
 	}      /* end face */
@@ -191,7 +195,45 @@
 	  }
 
-	  currentMesh->Preprocess();
-	  MeshInstance *mi = new MeshInstance(currentMesh);
-	  root->mGeometry.push_back(mi);
+	  if (!loadMeshes)
+	  {
+		  // hack: just triangulate current mesh
+		  FaceContainer::const_iterator fit, fit_begin = currentMesh->mFaces.begin(), 
+			  fit_end = currentMesh->mFaces.end();
+
+		  for (fit = fit_begin; fit != fit_end; ++ fit)
+		  {
+			  // triangulate the faces
+			  Face *face = *fit;
+			  vector<Triangle3> triangles;
+
+			  Polygon3 poly(face, currentMesh);
+			  poly.Triangulate(triangles);
+
+			  vector<Triangle3>::const_iterator tit, tit_end = triangles.end();
+
+			  for (tit = triangles.begin(); tit != tit_end; ++ tit)
+			  {
+				  if ((*tit).CheckValidity())
+				  {
+					  // create new triangle intersectable
+					  TriangleIntersectable *ti = new TriangleIntersectable(*tit);
+					  //cout << "t: " << (*tit) << endl;
+					  root->mGeometry.push_back(ti);
+				  }
+				  else
+				  {
+					  cout << "error tri:\n" << (*tit) << endl;
+				  }
+			  }
+		  }
+		  // not needed anymore
+		  MeshManager::GetSingleton()->DestroyEntry(currentMesh->GetId());
+	  }
+	  else
+	  {
+		  currentMesh->Preprocess();
+		  MeshInstance *mi = new MeshInstance(currentMesh);
+		  root->mGeometry.push_back(mi);
+	  }
   }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1626)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1627)
@@ -161,22 +161,4 @@
 		Cleanup();
 		exit(1);
-	}
-
-	// export kd tree?
-	bool exportKdTree;
-	Environment::GetSingleton()->GetBoolValue("Preprocessor.exportKdTree", exportKdTree);
-	if (exportKdTree)
-	{
-		const long startTime = GetTime();
-		cout << "exporting kd tree ... ";
-
-		if (!preprocessor->ExportKdTree(internKdTree))
-		{
-			cout << " error exporting kd tree with filename " << internKdTree << endl;
-		}
-		else
-		{
-			cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-		}
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1626)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1627)
@@ -262,11 +262,18 @@
 								 AxisAlignedBox3 *forcedViewSpace)
 {
-	if (mUseMultiLevelConstruction)
-	{
+	switch (mConstructionType)
+	{
+	case MULTILEVEL:
 		ConstructMultiLevel(sampleRays, objects, forcedViewSpace);
-	}
-	else
-	{
+		break;
+	case INTERLEAVED:
+	case SEQUENTIAL:
 		ConstructInterleaved(sampleRays, objects, forcedViewSpace);
+		break;
+	case GRADIENT:
+		ConstructInterleavedWithGradient(sampleRays, objects, forcedViewSpace);
+		break;
+	default:
+		break;
 	}
 }
@@ -424,5 +431,5 @@
 		PrepareObjectSpaceSubdivision(sampleRays, objects);
 	}
-
+cout << "****************555555555555555555555555" << endl;
 	// begin subdivision
 	RunConstruction(mRepairQueue, sampleRays, objects, forcedViewSpace);
