Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2073)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2094)
@@ -42,4 +42,6 @@
 class Exporter;
 class ViewCellsParseHandlers;
+class TraversalTree;
+
 
 
@@ -305,4 +307,14 @@
 
 
+	/** Casts line segment into the view cells tree.
+		@param origin the origin of the line segment
+		@param termination the end point of the line segment
+		@returns view cells intersecting the line segment.
+	*/
+    int CastLineSegment(const Vector3 &origin,
+						const Vector3 &termination,
+						ViewCellContainer &viewcells,
+						const bool useMailboxing = true);
+	
 protected:
 
@@ -351,5 +363,6 @@
 	*/
 	void RunConstruction(const bool repairQueue);
-		
+	
+	
 	////////////////////////////////////////////////
 
@@ -651,4 +664,6 @@
 	bool mConsiderMemory;
 
+	TraversalTree *mTraversalTree;
+
 	int mMaxRepairs;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2093)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2094)
@@ -1063,11 +1063,8 @@
 		{
 			// create the meshes and compute volumes
-			vm->FinalizeViewCells(false);
-			// vm->mViewCellsTree->AssignRandomColors();
-		}
-
-		if (0)
-		{
-			cout << "=============== " << vm->GetViewCellById(5318)->GetPvs().GetSize() << "========" << endl;
+			const bool createMeshes = true;
+			//const bool createMeshes = false;
+
+			vm->FinalizeViewCells(createMeshes);
 		}
 
@@ -2778,9 +2775,11 @@
 	if (lastVssRay == NULL ||
 		!(ray.mOrigin == lastVssRay->mTermination) ||
-		!(ray.mTermination == lastVssRay->mOrigin)) {
-	  viewCells.clear();
-	  // traverse the view space subdivision
-	  CastLineSegment(origin, termination, viewCells);
-	  lastVssRay = &ray;
+		!(ray.mTermination == lastVssRay->mOrigin)) 
+	{
+		viewCells.clear();
+		
+		// traverse the view space subdivision
+		CastLineSegment(origin, termination, viewCells);
+		lastVssRay = &ray;
 	}
 	
@@ -6556,6 +6555,5 @@
 											ViewCellContainer &viewcells)
 {
-	return mHierarchyManager->
-		GetVspTree()->CastLineSegment(origin, termination, viewcells);
+	return mHierarchyManager->CastLineSegment(origin, termination, viewcells);
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TraversalTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TraversalTree.cpp	(revision 2093)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TraversalTree.cpp	(revision 2094)
@@ -152,8 +152,8 @@
 
 	mBox.Initialize();
+
 	ObjectContainer::const_iterator mi;
 	for ( mi = leaf->mObjects.begin(); mi != leaf->mObjects.end(); ++ mi) 
 	{
-		//	cout<<(*mi)->GetBox()<<endl;
 		mBox.Include((*mi)->GetBox());
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2093)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2094)
@@ -22,4 +22,5 @@
 #include "BvHierarchy.h"
 #include "ViewCell.h"
+#include "TraversalTree.h"
 
 
@@ -28,5 +29,4 @@
 
 #define USE_FIXEDPOINT_T 0
-
 #define STUPID_METHOD 0
 
@@ -41,5 +41,6 @@
 mObjectSpaceSubdivisionType(objectSpaceSubdivisionType),
 mOspTree(NULL), 
-mBvHierarchy(NULL)
+mBvHierarchy(NULL),
+mTraversalTree(NULL)
 {
 	switch(mObjectSpaceSubdivisionType)
@@ -396,4 +397,6 @@
 		mBvHierarchy->SetUniqueNodeIds();
 	}
+
+	if (0) CreateTraversalTree();
 }
 
@@ -2483,6 +2486,34 @@
 void HierarchyManager::CreateTraversalTree()
 {
-}
-
-
-}
+	mTraversalTree = new TraversalTree;
+
+	ViewCellContainer viewCells;
+
+	// add mesh instances of the scene graph to the root of the tree
+	TraversalLeaf *root = (TraversalLeaf *)mTraversalTree->GetRoot();
+
+	//mVspTree->CollectViewCells(root->mViewCells, false);
+	
+  	const long startTime = GetTime();
+	cout << "building traversal tree ... " << endl;
+
+	mTraversalTree->Construct();
+
+	cout << "finished kd tree construction in " << TimeDiff(startTime, GetTime()) * 1e-3 
+		 << " secs " << endl;
+}
+
+
+int HierarchyManager::CastLineSegment(const Vector3 &origin,
+									  const Vector3 &termination,
+									  ViewCellContainer &viewcells,
+									  const bool useMailboxing)
+{
+	if (!mTraversalTree)
+		return mVspTree->CastLineSegment(origin,termination, viewcells, useMailboxing);
+	else
+		return mTraversalTree->CastLineSegment(origin,termination, viewcells, useMailboxing);
+}
+
+
+}
