Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2601)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2603)
@@ -156,20 +156,4 @@
 
 
-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();
-}
 
 
@@ -331,14 +315,4 @@
 }
 
-static string ReplaceSuffix(const 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;
-}
 
 
@@ -1071,5 +1045,5 @@
 	//	return true;
   }
-
+  
   
   if (!mUseKdTree) {
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/common.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2588)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2603)
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <fstream>
+#include <string>
 #include <limits.h>
-
+#include <vector>
 
 
@@ -489,4 +490,11 @@
 strdup(char *a);
 
+std::string
+ReplaceSuffix(const std::string &filename, const std::string &a, const std::string &b);
+
+
+int
+SplitFilenames(const std::string &str, std::vector<std::string> &filenames);
+
 bool
 FileExists(char *filename);
@@ -511,4 +519,5 @@
 StripPath(const char *s);
 }
+
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2602)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2603)
@@ -10,4 +10,5 @@
 #include "Preprocessor.h"
 #include "IntersectableWrapper.h"
+#include "Environment.h"
 
 #ifdef USE_HAVRAN_RAYCASTER
@@ -32,4 +33,5 @@
 
 
+
 #ifdef USE_HAVRAN_RAYCASTER 
 #ifdef _USE_HAVRAN_SSE
@@ -62,15 +64,23 @@
 {
 #ifdef USE_HAVRAN_RAYCASTER 
-
-  CTimer timer;
-
-  cout << "\nBuilding up kd-tree for Havran ray caster ..."<<endl<<flush;
-
-  timer.Start();
-  mKtbtree->BuildUp(objlist);
-  timer.Stop();
-  cout << "\nBuilding up kd-tree is finished, user time = "
-       << timer.UserTime() << " real time = " << timer.RealTime() <<
-	endl <<flush;
+  char buff[256];
+  Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
+  string filename(buff);
+  const string kdfile = ReplaceSuffix(filename, ".obj", ".kdh");
+
+  if (!ImportBinTree(kdfile, objlist)) {
+	cout << "\nKd-tree for Havran ray caster imported."<<endl<<flush;
+  } else {
+	CTimer timer;
+	cout << "\nBuilding up kd-tree for Havran ray caster ..."<<endl<<flush;
+	
+	timer.Start();
+	mKtbtree->BuildUp(objlist);
+	timer.Stop();
+	cout << "\nBuilding up kd-tree is finished, user time = "
+		 << timer.UserTime() << " real time = " << timer.RealTime() <<
+	  endl <<flush;
+	ExportBinTree(kdfile);
+  }
 #endif
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2602)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2603)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: st 16. I 21:20:04 2008
+# Generated by qmake (2.00a) (Qt 4.1.2) on: st 16. I 22:10:45 2008
 # Project:  preprocessor.pro
 # Template: app
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2598)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2603)
@@ -72,34 +72,4 @@
 
 
-static string ReplaceSuffix(const string &filename, const string &a, const 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 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();
-}
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp	(revision 2187)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp	(revision 2603)
@@ -81,4 +81,38 @@
 {
   srand(seed);
+}
+
+
+string
+ReplaceSuffix(const string &filename, const string &a, const 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;
+}
+
+
+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();
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp	(revision 2602)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp	(revision 2603)
@@ -11,4 +11,5 @@
 
 // GOLEM library
+#include "ktbconf.h"
 #include "ktb.h"
 #include "ktbai.h"
@@ -925,5 +926,5 @@
 
   if (!stream.is_open()) {
-    cerr << "Kd-tree description file (.kbt) cannot be opened for reading\n";
+    cerr << "Kd-tree description file (.kdh) cannot be opened for reading\n";
     return true; // error
   }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h	(revision 2602)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbconf.h	(revision 2603)
@@ -24,5 +24,5 @@
 
 // If we support the use of SSE instructions for ray shooting
-//#define _USE_HAVRAN_SSE
+// #define _USE_HAVRAN_SSE
 
 namespace GtpVisibilityPreprocessor {
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp	(revision 2575)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Camera.cpp	(revision 2603)
@@ -19,4 +19,5 @@
 #ifdef USE_HAVRAN_RAYCASTER 
 //#include "timer.h"
+#include "ktbconf.h"
 #include "raypack.h"
 #endif
@@ -290,5 +291,5 @@
 			)
 {
-#ifdef USE_HAVRAN_RAYCASTER 
+#if defined(USE_HAVRAN_RAYCASTER) && defined(_USE_HAVRAN_SSE)
   
   int x;
@@ -314,5 +315,5 @@
   //CTimer timer;
   //timer.Start();
-
+  
   RayPacket2x2 rp;
   for (y = 0; y < mHeight-1; y+=2) {
