Index: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2615)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2621)
@@ -10,4 +10,6 @@
 
 class SceneGraphLeafIntersectable;
+class CKTB;
+
 
 /** Basic scene graph node, we are interested only in bounding boxes and topology
@@ -68,14 +70,22 @@
 	virtual bool IsLeaf() const { return true; }
 	virtual void UpdateBox();
-#if DYNAMIC_OBJECT_HACK
-	SceneGraphLeafIntersectable *GetIntersectable() { return mIntersectable;}
+
+#if DYNAMIC_OBJECTS_HACK
+	void RebuildKtbTree();
+	SceneGraphLeafIntersectable *GetIntersectable() { return mIntersectable; }
 #endif
+
 	/// used as actual pvs entry
 	ObjectContainer mGeometry;
 
 protected:
-#if DYNAMIC_OBJECT_HACK
+
+#if DYNAMIC_OBJECTS_HACK
+	
 	SceneGraphLeafIntersectable *mIntersectable;
+	CKTB *mKtbTree;
+
 #endif
+
 	bool mIsDynamic;
 	Matrix4x4 mTrafo;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2583)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2621)
@@ -25,4 +25,5 @@
 struct SimpleRay;
 class RayPacket2x2;
+class Matrix4x4;
 
 /** This class provides an interface for ray casting.
@@ -104,4 +105,8 @@
 
 
+  virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m) = 0;
+  virtual void UpdateDynamicObjects(const Matrix4x4 &m) = 0;
+  virtual void DeleteDynamicObjects() = 0;
+
   // pool of vss rays to be used in one pass of the sampling
   struct VssRayPool 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 2615)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 2621)
@@ -6,4 +6,5 @@
 #include "Intersectable.h"
 #include "IntersectableWrapper.h"
+#include "ktball.h"
 
 
@@ -234,5 +235,4 @@
 void SceneGraph::ExportScene(const string filename)
 {
-	
 }
 
@@ -279,6 +279,10 @@
 
 SceneGraphLeaf::SceneGraphLeaf(): mIsDynamic(false)
+#if DYNAMIC_OBJECTS_HACK
+, mKtbTree(NULL)
+#endif
 {
 	mTrafo = IdentityMatrix();
+
 #if DYNAMIC_OBJECTS_HACK
 	mIntersectable = new SceneGraphLeafIntersectable(this, mBox);
@@ -288,6 +292,9 @@
 
 SceneGraphLeaf::SceneGraphLeaf(bool isDynamic): mIsDynamic(isDynamic)
-{
-	mTrafo = IdentityMatrix();
+#if DYNAMIC_OBJECTS_HACK
+, mKtbTree(NULL)
+#endif
+{
+    mTrafo = IdentityMatrix();
 }
 
@@ -316,3 +323,19 @@
 }
 
-}
+
+#if DYNAMIC_OBJECTS_HACK
+
+
+void SceneGraphLeaf::RebuildKtbTree()
+{
+	if (mKtbTree)
+		delete mKtbTree;
+
+	mKtbTree = new CKTB();
+	mKtbTree->BuildUp(mGeometry);
+}
+
+#endif
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2615)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2621)
@@ -173,5 +173,6 @@
 bool Preprocessor::LoadBinaryObj(const string &filename,
 								 SceneGraphLeaf *root,
-								 vector<FaceParentInfo> *parents)
+								 vector<FaceParentInfo> *parents,
+								 float scale)
 {
 	//ifstream inStream(filename, ios::binary);
@@ -202,4 +203,11 @@
 		inStream.read(reinterpret_cast<char *>(tri.mVertices + 1), sizeof(Vector3));
 		inStream.read(reinterpret_cast<char *>(tri.mVertices + 2), sizeof(Vector3));
+
+		if (scale > 0.0f)
+		{
+			tri.mVertices[0] *= scale;
+			tri.mVertices[1] *= scale;
+			tri.mVertices[2] *= scale;
+		}
 
 		// end of file reached
@@ -1227,5 +1235,6 @@
 
 				float maxT, minT;
-					// test with bounding box
+				
+				// test with bounding box
 				if (tmi->GetBox().GetMinMaxT(hRay, &minT, &maxT))
 				{
@@ -1700,9 +1709,10 @@
 	SceneGraphLeaf *leaf = new SceneGraphLeaf(dynamic);
 
-	if (LoadBinaryObj(filename, leaf, NULL))
+	if (LoadBinaryObj(filename, leaf, NULL, 100))
 	{
 		mDynamicObjects.push_back(leaf);
+		leaf->RebuildKtbTree();
 		mSceneGraph->GetRoot()->mChildren.push_back(leaf);
-		return true
+		return true;
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2598)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2621)
@@ -777,4 +777,7 @@
 			</File>
 			<File
+				RelativePath=".\SimpleRay.h">
+			</File>
+			<File
 				RelativePath="..\src\Statistics.h">
 			</File>
@@ -1071,8 +1074,8 @@
 			</File>
 			<File
+				RelativePath=".\sparsehash\src\windows\hash_fun.h">
+			</File>
+			<File
 				RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h">
-			</File>
-			<File
-				RelativePath=".\sparsehash\src\windows\hash_fun.h">
 			</File>
 			<File
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2620)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2621)
@@ -423,5 +423,5 @@
 		RenderIntersectable(*dit);
 #else
-		RenderDynamicObject(*dit);
+		_RenderDynamicObject(*dit);
 #endif
 	}
@@ -679,6 +679,4 @@
 		{
 			Matrix4x4 tm;
-			TransformedMeshInstance *tmi;
-#if USE_TRANSFORMED_MESH_INSTANCE_HACK
 
 			switch (mTrafoType)
@@ -687,5 +685,5 @@
 				{
 					const Vector3 transl(diffx, 0, diffy);
-					tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
+					
 					tm = TranslationMatrix(transl);
 				}
@@ -696,5 +694,4 @@
 					if (scalef < 0.9) scalef = 0.9f;
 					else if (scalef > 1.1f) scalef = 1.1f;
-					tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
 					tm = ScaleMatrix(scalef, scalef, scalef);
 				}
@@ -702,5 +699,4 @@
 			case 2:
 				{
-					tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
 					tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
 				}
@@ -710,5 +706,10 @@
 			}
 
+#if USE_TRANSFORMED_MESH_INSTANCE_HACK
+			TransformedMeshInstance *tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
 			tmi->ApplyWorldTransform(tm);
+#else
+			SceneGraphLeaf *l = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
+			l->ApplyTransform(tm);
 #endif
 			updateGL();
@@ -1457,5 +1458,5 @@
 	ComputeMaxValues(viewcells, maxPvs, maxPiercingRays, maxRelativeRays, maxRcCost);
 	// matt: temp hack
-	//maxRcCost = 200.0f;
+	maxRcCost = 200.0f;
 	//cout << "maxRcCost: " << maxRcCost << endl;
 	int i;
@@ -2119,4 +2120,7 @@
 	vbox->layout()->addWidget(button);
 	connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics()));
+#endif
+
+#if DYNAMIC_OBJECTS_HACK
 
 	button = new QPushButton("Load object", vbox);
@@ -2124,4 +2128,5 @@
 	connect(button, SIGNAL(clicked()), SIGNAL(LoadObject()));
 #endif
+
 	/*cb = new QCheckBox("Stats", vbox);
 	vbox->layout()->addWidget(cb);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2620)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2621)
@@ -15,5 +15,5 @@
 #include "LogReader.h"
 #include "Material.h"
-
+#include "common.h"
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2615)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2621)
@@ -275,5 +275,6 @@
 	bool LoadBinaryObj(const std::string &filename,
                        SceneGraphLeaf *root,
-					   std::vector<FaceParentInfo> *parents);
+					   std::vector<FaceParentInfo> *parents,
+					   float scale = -1.0f);
 
 	bool ExportBinaryObj(const std::string &filename, SceneGraphLeaf *root);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/common.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2615)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2621)
@@ -23,6 +23,6 @@
 #include <vector>
 
-#define DYNAMIC_OBJECTS_HACK 0
-#define USE_TRANSFORMED_MESH_INSTANCE_HACK 1
+#define DYNAMIC_OBJECTS_HACK 1
+#define USE_TRANSFORMED_MESH_INSTANCE_HACK 0
 #define USE_HAVRAN_RAYCASTER
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2603)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2621)
@@ -516,3 +516,8 @@
 
 
+    /*
+  virtual void HavranRayCaster::AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m);
+  virtual void UpdateDynamicObjects(const Matrix4x4 &m);
+  virtual void DeleteDynamicObjects);
+*/
 } // the namespace
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h	(revision 2602)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h	(revision 2621)
@@ -37,5 +37,9 @@
   
   int Type() const { return HAVRAN_RAYCASTER; }
-  
+    
+  virtual void AddDynamicObjecs(const ObjectContainer &objects, const Matrix4x4 &m);
+  virtual void UpdateDynamicObjects(const Matrix4x4 &m);
+  virtual void DeleteDynamicObjects);
+
   virtual int CastRay(
 		      const SimpleRay &simpleRay,
