Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1613)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1626)
@@ -817,10 +817,12 @@
 bool Preprocessor::InitRayCast(const string externKdTree, const string internkdtree)
 {
-	bool loadKdTree;
-	Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree);
+	bool loadKdTree = true;
+	//Environment::GetSingleton()->GetBoolValue("Preprocessor.loadKdTree", loadKdTree);
+	
 	
 	if (!loadKdTree)
-	{	
+	{	/////////
 		//-- build new kd tree from scene geometry
+
 		BuildKdTree();
 		KdTreeStatistics(cout);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1625)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1626)
@@ -216,15 +216,16 @@
 	/** Exports object space hierarchy for visualization.
 	*/
-	void ExportObjectSpaceHierarchy(
-		Exporter *exporter, 
-		const ObjectContainer &objects,
-		const AxisAlignedBox3 *bbox,
-		const bool exportBounds = true) const;
+	void ExportObjectSpaceHierarchy(Exporter *exporter, 
+									const ObjectContainer &objects,
+									const AxisAlignedBox3 *bbox,
+									const bool exportBounds = true) const;
 
 	/** Returns intersectable pierced by this ray.
 	*/
-	Intersectable *GetIntersectable(
-		const VssRay &ray, 
-		const bool isTermination) const;
+	Intersectable *GetIntersectable(const VssRay &ray, const bool isTermination) const;
+
+	/** Export object space partition bounding boxes.
+	*/
+	void ExportBoundingBoxes(OUT_STREAM &stream, const ObjectContainer &objects);
 
 	friend ostream &operator<<(ostream &s, const HierarchyManager &hm) 
@@ -233,7 +234,4 @@
 		return s;
 	} 
-
-	void ExportBoundingBoxes(OUT_STREAM &stream, const ObjectContainer &objects);
-
 
 protected:
@@ -386,8 +384,7 @@
 		for the next split.
 	*/
-	void ConstructInterleaved(
-		const VssRayContainer &sampleRays,
-		const ObjectContainer &objects,
-		AxisAlignedBox3 *forcedViewSpace);
+	void ConstructInterleaved(const VssRayContainer &sampleRays,
+							  const ObjectContainer &objects,
+							  AxisAlignedBox3 *forcedViewSpace);
 
 	/** Construct object space partition interleaved with view space partition.
@@ -399,15 +396,13 @@
 		next number of split.
 	*/
-	void ConstructInterleaved2(
-		const VssRayContainer &sampleRays,
-		const ObjectContainer &objects,
-		AxisAlignedBox3 *forcedViewSpace);
+	void ConstructInterleavedWithGradient(const VssRayContainer &sampleRays,
+										  const ObjectContainer &objects,
+										  AxisAlignedBox3 *forcedViewSpace);
 
 	/** Use iteration to construct the object space hierarchy.
 	*/
-	void ConstructMultiLevel(
-		const VssRayContainer &sampleRays,
-		const ObjectContainer &objects,
-		AxisAlignedBox3 *forcedViewSpace);
+	void ConstructMultiLevel(const VssRayContainer &sampleRays,
+							 const ObjectContainer &objects,
+							 AxisAlignedBox3 *forcedViewSpace);
 
 	/** Reset the object space subdivision. 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1613)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1626)
@@ -61,18 +61,40 @@
 
 
-
-
-string ReplaceSuffix(string filename,
-					 string a,
-					 string b)
-{
-  string result = filename;
-
-  int pos = (int)filename.rfind(a, (int)filename.size() - 1);
-  if (pos == filename.size() - a.size()) {
-	result.replace(pos, a.size(), b);
-  }
-  return result;
-}
+static string ReplaceSuffix(string filename, string a, string b)
+{
+	string result = filename;
+
+	int pos = (int)filename.rfind(a, (int)filename.size() - 1);
+	if (pos == filename.size() - a.size()) {
+		result.replace(pos, a.size(), b);
+	}
+	return result;
+}
+
+
+static string GetInternKdTreeName(string &filename)
+{
+	//Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
+	
+	// hack! should take any extension
+    if (strstr(filename.c_str(), ".x3d")) 
+	{
+		return ReplaceSuffix(filename, ".x3d", ".kd");
+	} 
+	else if (strstr(filename.c_str(), ".dat"))
+	{
+		return ReplaceSuffix(filename, ".dat", ".kd");
+	} 
+	else if (strstr(filename.c_str(), ".obj"))
+	{
+		return ReplaceSuffix(filename, ".dat", ".kd");
+	}
+
+	cerr << "Error: Currently unsupported format for kd, filename " << filename << endl;
+
+	// return empty string
+	return string();
+}
+
 
 int
@@ -126,8 +148,6 @@
 	}
 
-	string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
-	char internKdTree[100];
-	Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
-	//const string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd");
+	const string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
+	const string internKdTree = GetInternKdTreeName(filename);
 
 	//-- initialize external ray casters
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1625)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1626)
@@ -273,7 +273,7 @@
 
 
-void HierarchyManager::ConstructInterleaved2(const VssRayContainer &sampleRays,											 
-											 const ObjectContainer &objects,
-											 AxisAlignedBox3 *forcedViewSpace)
+void HierarchyManager::ConstructInterleavedWithGradient(const VssRayContainer &sampleRays,											 
+														const ObjectContainer &objects,
+														AxisAlignedBox3 *forcedViewSpace)
 {
 	mHierarchyStats.Reset();
