Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1633)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1634)
@@ -822,21 +822,11 @@
 {
 	// always try to load the kd tree
-	bool loadKdTree = true;
-	//Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree);
-		
-	if (!loadKdTree)
-	{	
+	cout << "loading kd tree file " << internKdTree << " ... ";
+
+	if (!LoadKdTree(internKdTree))
+	{
+		cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl;
 		// build new kd tree from scene geometry
 		BuildKdTree();
-	}
-	else
-	{
-		cout << "loading kd tree file " << internKdTree << " ... ";
-
-		if (!LoadKdTree(internKdTree))
-		{
-			cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl;
-			BuildKdTree();
-		}
 
 		// export kd tree?
@@ -866,17 +856,5 @@
 			delete exporter;
 		}
-
-		/*ofstream objstr("objects.txt");
-
-		vector<KdLeaf *> leaves;
-		mKdTree->CollectLeaves(leaves);
-
-		vector<KdLeaf *>::const_iterator lit, lit_end = leaves.end();
-		for (lit = leaves.begin(); lit != lit_end; ++ lit)
-		{
-			objstr << "objects: " << (*lit)->mObjects.size() << " bb " << mKdTree->GetBox(*lit) << endl;
-		}*/
-	}
-
+	}
 
 	int rayCastMethod;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1633)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1634)
@@ -263,5 +263,5 @@
 						SubdivisionCandidateContainer &chosenCandidates,
 						const float minRenderCostDecr,
-						const int maxSteps);
+						const int minSteps);
 
 	/** Default subdivision method.
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1633)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1634)
@@ -581,9 +581,8 @@
 inline bool BvHierarchy::LocalTerminationCriteriaMet(const BvhTraversalData &data) const
 {
-	// matt: TODO
 	return ( 0
-		|| ((int)data.mNode->mObjects.size() <= mTermMinObjects)
-		//|| (data.mProbability <= mTermMinProbability)
-		//|| (data.mNumRays <= mTermMinRays)
+			|| ((int)data.mNode->mObjects.size() <= mTermMinObjects)
+			//|| (data.mProbability <= mTermMinProbability)
+			//|| (data.mNumRays <= mTermMinRays)
 		 );
 }
@@ -1229,4 +1228,5 @@
 					HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV)
 				{
+					///////////
 					//-- heuristics using objects weighted by view cells volume
 					nCostRatio[axis] =
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/common.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 1557)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 1634)
@@ -499,4 +499,6 @@
 GetPath(const char *s);
 
+char *
+StripPath(const char *s);
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1633)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1634)
@@ -20,5 +20,5 @@
 #include "MeshKdTree.h"
 #include "Preprocessor.h"
-
+#include "common.h"
 
 #include "PreprocessorThread.h"
@@ -73,36 +73,80 @@
 
 
-static string GetInternKdTreeName(string &filename)
-{
-	//Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
-	string suffix;
-
-	if (preprocessor->mLoadMeshes)
-	{
-		suffix = ".kdm";	
-	}
-	else
-	{
-		suffix = ".kdt";
-	}
-
-	// hack! should take any extension
-    if (strstr(filename.c_str(), ".x3d")) 
-	{
-		return ReplaceSuffix(filename, ".x3d", suffix);
-	} 
-	else if (strstr(filename.c_str(), ".dat"))
-	{
-		return ReplaceSuffix(filename, ".dat", suffix);
-	} 
-	else if (strstr(filename.c_str(), ".obj"))
-	{
-		return ReplaceSuffix(filename, ".dat", suffix);
-	}
-
-	cerr << "Error: Currently unsupported format for kd, filename " << filename << endl;
-
-	// return empty string
-	return string();
+static int SplitFilenames(const string str, vector<string> &filenames)
+{
+	int pos = 0;
+
+	while(1) {
+		int npos = (int)str.find(';', pos);
+		
+		if (npos < 0 || npos - pos < 1)
+			break;
+		filenames.push_back(string(str, pos, npos - pos));
+		pos = npos + 1;
+	}
+	
+	filenames.push_back(string(str, pos, str.size() - pos));
+	return (int)filenames.size();
+}
+
+
+static string GetInternKdTreeName(const string &filename)
+{
+	vector<string> filenames;
+	const int files = SplitFilenames(filename, filenames);
+
+	vector<string>::const_iterator sit, sit_end = filenames.end();
+	string kdFilename;
+
+	int i = 0;
+	for (sit = filenames.begin(); sit != sit_end; ++ sit, ++ i)
+	{
+		string currentFile = *sit;
+		//cout << "here6 " << currentFile << endl;
+		string strippedFilename;
+
+		if (i == 0)
+		{	
+			strippedFilename = currentFile;
+		}
+		else
+		{
+			strippedFilename = string(StripPath(currentFile.c_str()));
+		}
+		
+		string suffix("_");
+
+		if (i == (int)filenames.size() - 1)
+		{
+			if (preprocessor->mLoadMeshes)
+			{
+				suffix = ".kdm";	
+			}
+			else
+			{
+				suffix = ".kdt";
+			}
+		}
+
+		if (strstr(strippedFilename.c_str(), ".x3d")) 
+		{
+			kdFilename += ReplaceSuffix(strippedFilename, ".x3d", suffix);
+		}
+        else if (strstr(strippedFilename.c_str(), ".dat"))
+		{
+			kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix);
+		} 
+		else if (strstr(strippedFilename.c_str(), ".obj"))
+		{
+			kdFilename += ReplaceSuffix(strippedFilename, ".dat", suffix);
+		}
+		else
+		{
+			cerr << "Error: Currently unsupported format for kd, filename " << currentFile << endl;
+		}
+	}
+
+	//cout << "kdfilename: " << kdFilename << endl;
+	return kdFilename;
 }
 
@@ -150,4 +194,5 @@
 	Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
 	string filename(buff);
+	const string dummyname = GetInternKdTreeName(filename);
 
 	if (!preprocessor->LoadScene(filename))
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp	(revision 863)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp	(revision 1634)
@@ -218,4 +218,25 @@
 
 char *
+StripPath(const char *s)
+{
+	const int len = strlen(s);
+
+	int i = len;
+	for (; i>0; i--) {
+		if (s[i]=='/' || s[i]=='\\')
+			break;
+	}
+
+	char *filename = new char[len - i];
+	int j = 0;
+
+	for (; j < len - i; ++ j)
+		filename[j] = s[i + j + 1];
+	//filename[j] = 0;
+
+	return filename;
+}
+
+char *
 strdup(char *a)
 {
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1633)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1634)
@@ -330,6 +330,6 @@
 
 	// number of initial splits
-	int maxSteps = 200;
-	float renderCostDecr = 0;
+	int minSteps = 200;
+	float renderCostDecr = Limits::Infinity;
 
 	SubdivisionCandidate *osc = 
@@ -347,5 +347,5 @@
 	// has started, use render cost heuristics instead
 	const int ospSteps = 
-		RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, maxSteps);
+		RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps);
 
 	cout << ospSteps << " object space partition steps taken" << endl;
@@ -376,5 +376,9 @@
 		{
 			// use splits of one kind until rendercost slope is reached
-			renderCostDecr = mHierarchyStats.mRenderCostDecrease;
+			//renderCostDecr = mHierarchyStats.mRenderCostDecrease;
+			
+			// lower number of minsteps: this should be solved 
+			// with render cost decrease from now
+			//minSteps = 5; 
 
 			// dirtied view space candidates
@@ -385,5 +389,5 @@
 			// has started, use render cost heuristics instead
 			const int ospSteps = 
-				RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, maxSteps);
+				RunConstruction(objectSpaceQueue, dirtyVspList, renderCostDecr, minSteps);
 
 			cout << ospSteps << " object space partition steps taken" << endl;
@@ -400,5 +404,5 @@
 		{
 			// use splits of one kind until rendercost slope is reached
-			renderCostDecr = mHierarchyStats.mRenderCostDecrease;
+		//	renderCostDecr = mHierarchyStats.mRenderCostDecrease;
 
 			/////////////////
@@ -409,5 +413,5 @@
 			// process view space candidates
 			const int vspSteps = 
-				RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, maxSteps);
+				RunConstruction(viewSpaceQueue, dirtyOspList, renderCostDecr, minSteps);
 
 			cout << vspSteps << " view space partition steps taken" << endl;
@@ -480,5 +484,9 @@
 
 	// begin subdivision
-	RunConstruction(mRepairQueue, sampleRays, objects, forcedViewSpace);
+	RunConstruction(mRepairQueue, 
+					sampleRays, 
+					objects, 
+					forcedViewSpace//, 
+					/*vspSc*/);
 	
 	cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
@@ -760,5 +768,5 @@
 									  SubdivisionCandidateContainer &dirtyCandidates,
 									  const float minRenderCostDecr,
-									  const int maxSteps)
+									  const int minSteps)
 {
 	int steps = 0;
@@ -766,10 +774,12 @@
 
 	// main loop
-	while (!splitQueue.Empty() && (steps < maxSteps))
+	while (!splitQueue.Empty())
 	{
 		SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue); 
 		
 		// minimum slope reached
-		//if (sc->GetRenderCostDecrease() < minRenderCostDecr)	break;
+		if ((sc->GetRenderCostDecrease() < minRenderCostDecr) &&
+			!(steps < minSteps))
+			break;
 
 		////////
