Index: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 1166)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 1194)
@@ -155,6 +155,7 @@
 void SceneGraph::ExportScene(const string filename)
 {
-	// export binary version of mesh
+	
 }
+
 
 void SceneGraph::LoadScene(const string filename)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1174)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1194)
@@ -609,4 +609,5 @@
 #endif
 	samplesOut.close();
+
 	return true;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 1184)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 1194)
@@ -1125,3 +1125,141 @@
 
 
-}
+#define INTERIOR_START_ID -2
+#define LEAF_START_ID -3
+#define LEAF_END_ID -4
+
+
+void KdTree::ExportBinLeaf(ofstream &stream, KdLeaf *leaf)
+{
+	ObjectContainer::const_iterator it, it_end = leaf->mObjects.end();
+	
+	int leafStartId = LEAF_START_ID;
+	stream.write(reinterpret_cast<char *>(&leafStartId), sizeof(int));
+	for (it = leaf->mObjects.begin(); it != it_end; ++ it)
+	{	
+		Intersectable *obj = *it;
+				
+		int id = obj->mId;		
+		
+		//stream.write(reinterpret_cast<char *>(&origin), sizeof(Vector3));
+		stream.write(reinterpret_cast<char *>(&id), sizeof(int));
+    }
+	
+	// end leaf
+	int leafEndId = LEAF_END_ID;
+	stream.write(reinterpret_cast<char *>(&leafEndId), sizeof(int));
+}
+
+
+void KdTree::ImportBinLeaf(ifstream &stream, KdLeaf *leaf)
+{
+	ObjectContainer::const_iterator it, it_end = leaf->mObjects.end();
+	
+	int leafId = LEAF_START_ID;
+	int objId = leafId;
+	
+	while (objId != LEAF_END_ID)
+	{	
+		stream.read(reinterpret_cast<char *>(&objId), sizeof(int));
+		 //if (samplesIn.eof()) break;
+    }
+}
+
+
+void KdTree::ExportBinInterior(ofstream &stream, KdInterior *interior)
+{
+	int interiorid = INTERIOR_START_ID;
+	stream.write(reinterpret_cast<char *>(&interiorid), sizeof(int));
+
+	int axis = interior->mAxis;
+	Vector3 pos = interior->mPosition;
+
+	stream.write(reinterpret_cast<char *>(&axis), sizeof(int));
+	stream.write(reinterpret_cast<char *>(&pos), sizeof(Vector3));
+}
+
+
+void KdTree::ImportBinInterior(ifstream &stream, KdInterior *interior)
+{
+	int interiorid = -2;
+	stream.read(reinterpret_cast<char *>(&interiorid), sizeof(int));
+
+	int axis = interior->mAxis;
+	Vector3 pos = interior->mPosition;
+
+	stream.read(reinterpret_cast<char *>(&axis), sizeof(int));
+	stream.read(reinterpret_cast<char *>(&pos), sizeof(Vector3));
+}
+
+
+bool KdTree::ExportBinTree(const string &filename)
+{
+	ofstream stream(filename.c_str(), ios::binary);
+	
+	if (!stream.is_open())
+		return false;
+
+	// export binary version of mesh
+	stack<KdNode *> tStack;
+
+	tStack.push(mRoot);
+
+	while(!tStack.empty())
+	{
+		KdNode *node = tStack.top();
+
+		if (node->IsLeaf())
+		{
+			ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node));
+		}
+		else
+		{
+			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+
+			ExportBinInterior(stream, interior);
+			
+			tStack.push(interior->mFront);
+			tStack.push(interior->mBack);
+		}
+	}
+
+	return true;
+}
+
+
+bool KdTree::LoadBinTree(const string &filename)
+{
+	ofstream stream(filename.c_str(), ios::binary);
+	
+	if (!stream.is_open())
+		return false;
+
+	// export binary version of mesh
+	stack<KdNode *> tStack;
+
+	tStack.push(mRoot);
+
+	while(!tStack.empty())
+	{
+		KdNode *node = tStack.top();
+
+		if (node->IsLeaf())
+		{
+			ExportBinLeaf(stream, dynamic_cast<KdLeaf *>(node));
+		}
+		else
+		{
+			KdInterior *interior = dynamic_cast<KdInterior *>(node);
+
+			ExportBinInterior(stream, interior);
+			
+			tStack.push(interior->mFront);
+			tStack.push(interior->mBack);
+		}
+	}
+
+	return true;
+}
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1184)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1194)
@@ -391,4 +391,7 @@
   CollectLeafPvs();
 
+  bool ExportBinTree(const string &filename);
+  bool LoadBinTree(const string &filename);
+
 protected:
 
@@ -553,4 +556,9 @@
 	*/
 	void ProcessMultipleRefs(KdLeaf *leaf) const;
+
+	void ExportBinLeaf(ofstream &stream, KdLeaf *leaf);
+	void ExportBinInterior(ofstream &stream, KdInterior *interior);
+void ImportBinLeaf(ifstream &stream, KdLeaf *leaf);
+	void ImportBinInterior(ifstream &stream, KdInterior *interior);
 
   int mTermMaxNodes;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1181)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1194)
@@ -161,5 +161,5 @@
 	preprocessor->BuildKdTree();
 	preprocessor->KdTreeStatistics(cout);
-
+	preprocessor->mKdTree->ExportBinTree("kd.bin");
 	// parse view cells related options
 	preprocessor->PrepareViewCells();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1143)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1194)
@@ -289,5 +289,6 @@
 
 
-void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, AttributeList&  attributes)
+void ViewCellsParseHandlers::StartViewCell(ViewCell *viewCell, 
+										   AttributeList&  attributes)
 {
 	int len = attributes.getLength();
