Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.h	(revision 1139)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.h	(revision 1233)
@@ -10,21 +10,22 @@
 struct VssRayContainer;
 class KdNode;
+class BvhNode;
 
 /**
-	Wrapper for Kd nodes for use in a PVS.
+	Wrapper used for creating a PVS compliant intersectable.
 */
-class KdIntersectable: public Intersectable
+template<typename T>
+class IntersectableWrapper: public Intersectable
 {
 public:
-	KdIntersectable(KdNode *node);
+	IntersectableWrapper(T *item);
 
-	/** Returns 'mesh' associated with this instance. 
+	/** Returns node associated with this instance. 
 	*/
-	KdNode *GetNode() const;
+	T *GetItem() const;
 
 	/** See get.
 	*/
-	void SetNode(KdNode *node);
-
+	void SetItem(T *item);
 
 	//-- inherited functions from Intersectable
@@ -39,5 +40,5 @@
   
 	int NumberOfFaces() const;
-	int Type() const;
+	//int Type() const;
 
 	int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 
@@ -52,13 +53,111 @@
 	
 
-	/** Pointer to kd leaf object that was hit during ray casting.
-	*/
-	Intersectable *mHitObject;
-
 protected:
 	
-	KdNode *mNode;
+	T *mItem;
 };
 
+template<typename T>
+IntersectableWrapper<T>::IntersectableWrapper(T *item):
+Intersectable(), mItem(item)
+{
+}
+
+template<typename T>
+void IntersectableWrapper<T>::SetItem(T *item)
+{
+	mItem = item;
+}
+
+template<typename T>
+T *IntersectableWrapper<T>::GetItem() const
+{ 
+	return mItem; 
+}
+	
+template<typename T>
+AxisAlignedBox3 IntersectableWrapper<T>::GetBox() const
+{	// TODO matt
+	return AxisAlignedBox3();
+}
+
+template<typename T>
+int IntersectableWrapper<T>::CastRay(Ray &ray)
+{	// TODO matt
+	return 0;
+}
+	
+template<typename T>
+bool IntersectableWrapper<T>::IsConvex() const
+{
+	return true;
+}
+
+template<typename T>
+bool IntersectableWrapper<T>::IsWatertight() const
+{
+	return true;
+}
+
+template<typename T>
+float IntersectableWrapper<T>::IntersectionComplexity()
+{
+	return 1.0f;
+}
+
+template<typename T>
+int IntersectableWrapper<T>::NumberOfFaces() const
+{
+	return 0;
+}
+
+template<typename T>
+int IntersectableWrapper<T>::GetRandomSurfacePoint(Vector3 &point,
+												Vector3 &normal)
+{
+	return 0;
+}
+
+template<typename T>
+int IntersectableWrapper<T>::GetRandomVisibleSurfacePoint(Vector3 &point,
+													   Vector3 &normal,
+													   const Vector3 &viewpoint,
+													   const int maxTries)
+{
+	return 0;
+}
+  
+template<typename T>
+ostream &IntersectableWrapper<T>::Describe(ostream &s)
+{
+	s << mItem;
+	return s;
+}
+
+
+class KdIntersectable: public IntersectableWrapper<KdNode>
+{
+public:
+	KdIntersectable(KdNode *item):
+	IntersectableWrapper<KdNode>(item) {}
+
+	int Type() const
+	{
+		return Intersectable::KD_INTERSECTABLE;
+	}
+};
+
+
+class BvhIntersectable: public IntersectableWrapper<BvhNode>
+{
+public:
+	BvhIntersectable(BvhNode *item):
+	IntersectableWrapper<BvhNode>(item) {}
+
+	int Type() const
+	{
+		return Intersectable::BVH_INTERSECTABLE;
+	}
+};
 
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 1197)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VrmlExporter.cpp	(revision 1233)
@@ -11,5 +11,5 @@
 #include "VssTree.h"
 #include "VspBspTree.h"
-#include "VspOspTree.h"
+#include "HierarchyManager.h"
 #include "RssTree.h"
 #include "Beam.h"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 1121)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 1233)
@@ -890,5 +890,5 @@
 		@param splitCandidates returns sorted list of split candidates
 	*/
-	void SortSplitCandidates(const PolygonContainer &polys, 
+	void SortSubdivisionCandidates(const PolygonContainer &polys, 
 							 const int axis, 
 							 vector<SortableEntry> &splitCandidates) const;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 1233)
@@ -196,5 +196,5 @@
 
 
-	mLocalSplitCandidates = new vector<SortableEntry>;
+	mLocalSubdivisionCandidates = new vector<SortableEntry>;
 
 	Debug << endl;
@@ -230,5 +230,5 @@
 {
 	DEL_PTR(mRoot);
-	DEL_PTR(mLocalSplitCandidates);
+	DEL_PTR(mLocalSubdivisionCandidates);
 }
 
@@ -639,8 +639,8 @@
 
 	// compute first split candidate
-	VspBspSplitCandidate splitCandidate;
+	VspBspSubdivisionCandidate splitCandidate;
 	splitCandidate.mParentData = tData;
 
-	EvalSplitCandidate(splitCandidate);
+	EvalSubdivisionCandidate(splitCandidate);
 
 	tQueue.push(splitCandidate);
@@ -742,5 +742,5 @@
 			<< "#ViewCells\n" << viewCells << endl
 			<< "#RenderCostDecrease\n" << renderCostDecr << endl 
-			<< "#SplitCandidateCost\n" << splitCandidateCost << endl
+			<< "#SubdivisionCandidateCost\n" << splitCandidateCost << endl
 			<< "#TotalRenderCost\n" << totalRenderCost << endl
 			<< "#AvgRenderCost\n" << avgRenderCost << endl;
@@ -895,5 +895,5 @@
 // subdivide node using a split plane queue
 BspNode *VspBspTree::Subdivide(VspBspSplitQueue &tQueue,
-							   VspBspSplitCandidate &splitCandidate)
+							   VspBspSubdivisionCandidate &splitCandidate)
 {
 	VspBspTraversalData &tData = splitCandidate.mParentData;
@@ -953,12 +953,12 @@
 	
 		//-- push the new split candidates on the stack
-		VspBspSplitCandidate frontCandidate;
+		VspBspSubdivisionCandidate frontCandidate;
 		frontCandidate.mParentData = tFrontData;
 
-		VspBspSplitCandidate backCandidate;
+		VspBspSubdivisionCandidate backCandidate;
 		backCandidate.mParentData = tBackData;
 
-		EvalSplitCandidate(frontCandidate);
-		EvalSplitCandidate(backCandidate);
+		EvalSubdivisionCandidate(frontCandidate);
+		EvalSubdivisionCandidate(backCandidate);
 	
 		tQueue.push(frontCandidate);
@@ -1042,6 +1042,6 @@
 
 /*
-void VspBspTree::EvalSplitCandidate(VspBspTraversalData &tData,
-									VspBspSplitCandidate &splitData)
+void VspBspTree::EvalSubdivisionCandidate(VspBspTraversalData &tData,
+									VspBspSubdivisionCandidate &splitData)
 {
 	VspBspTraversalData frontData;
@@ -1065,5 +1065,5 @@
 */
 
-void VspBspTree::EvalSplitCandidate(VspBspSplitCandidate &splitCandidate)
+void VspBspTree::EvalSubdivisionCandidate(VspBspSubdivisionCandidate &splitCandidate)
 {
 	VspBspTraversalData frontData;
@@ -1306,21 +1306,21 @@
 
 
-void VspBspTree::SortSplitCandidates(const RayInfoContainer &rays, 
+void VspBspTree::SortSubdivisionCandidates(const RayInfoContainer &rays, 
 									 const int axis, 
 									 float minBand, 
 									 float maxBand)
 {
-	mLocalSplitCandidates->clear();
+	mLocalSubdivisionCandidates->clear();
 
 	int requestedSize = 2 * (int)(rays.size());
 	// creates a sorted split candidates array
-	if (mLocalSplitCandidates->capacity() > 500000 &&
-		requestedSize < (int)(mLocalSplitCandidates->capacity() / 10) )
-	{
-    	delete mLocalSplitCandidates;
-   		mLocalSplitCandidates = new vector<SortableEntry>;
-	}
-
-	mLocalSplitCandidates->reserve(requestedSize);
+	if (mLocalSubdivisionCandidates->capacity() > 500000 &&
+		requestedSize < (int)(mLocalSubdivisionCandidates->capacity() / 10) )
+	{
+    	delete mLocalSubdivisionCandidates;
+   		mLocalSubdivisionCandidates = new vector<SortableEntry>;
+	}
+
+	mLocalSubdivisionCandidates->reserve(requestedSize);
 
 	if (0)
@@ -1339,5 +1339,5 @@
 		if (0) ClipValue(pos, minBand, maxBand);
 		
-		mLocalSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 
+		mLocalSubdivisionCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 
 									pos, (*ri).mRay));
 
@@ -1347,9 +1347,9 @@
 		if (0) ClipValue(pos, minBand, maxBand);
 
-		mLocalSplitCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 
+		mLocalSubdivisionCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 
 									pos, (*ri).mRay));
 	}
 
-	stable_sort(mLocalSplitCandidates->begin(), mLocalSplitCandidates->end());
+	stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end());
 }
 
@@ -1380,5 +1380,5 @@
 	const float maxBand = minBox + mMaxBand * sizeBox;
 
-	SortSplitCandidates(usedRays, axis, minBand, maxBand);
+	SortSubdivisionCandidates(usedRays, axis, minBand, maxBand);
 
 	// go through the lists, count the number of objects left and right
@@ -1442,7 +1442,7 @@
 	Intersectable::NewMail();
 
-	vector<SortableEntry>::const_iterator ci, ci_end = mLocalSplitCandidates->end();
-
-	for (ci = mLocalSplitCandidates->begin(); ci != ci_end; ++ ci)
+	vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end();
+
+	for (ci = mLocalSubdivisionCandidates->begin(); ci != ci_end; ++ ci)
 	{
 		VssRay *ray;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.cpp	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.cpp	(revision 1233)
@@ -5,85 +5,5 @@
 
 
-KdIntersectable::KdIntersectable(KdNode *node):
-Intersectable(), mNode(node)
-{
-}
 
-
-void KdIntersectable::SetNode(KdNode *node)
-{
-	mNode = node;
-}
-
-
-KdNode *KdIntersectable::GetNode() const
-{ 
-	return mNode; 
-}
-	
-
-AxisAlignedBox3 KdIntersectable::GetBox() const
-{	// TODO matt
-	return AxisAlignedBox3();
-}
-
-
-int KdIntersectable::CastRay(Ray &ray)
-{	// TODO matt
-	return 0;
-}
-	
-
-bool KdIntersectable::IsConvex() const
-{
-	return true;
-}
-
-
-bool KdIntersectable::IsWatertight() const
-{
-	return true;
-}
-
-
-float KdIntersectable::IntersectionComplexity()
-{
-	return 1.0f;
-}
-
-
-int KdIntersectable::NumberOfFaces() const
-{
-	return 0;
-}
-
-
-int KdIntersectable::Type() const
-{
-	return Intersectable::KD_INTERSECTABLE;
-}
-
-
-int KdIntersectable::GetRandomSurfacePoint(Vector3 &point,
-										   Vector3 &normal)
-{
-	return 0;
-}
-
-
-int KdIntersectable::GetRandomVisibleSurfacePoint(Vector3 &point,
-												  Vector3 &normal,
-												  const Vector3 &viewpoint,
-												  const int maxTries)
-{
-	return 0;
-}
-  
-
-ostream &KdIntersectable::Describe(ostream &s)
-{
-	s << mNode;
-	return s;
-}
 	
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 1168)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 1233)
@@ -1170,5 +1170,5 @@
 
 
-void BspTree::SortSplitCandidates(const PolygonContainer &polys, 
+void BspTree::SortSubdivisionCandidates(const PolygonContainer &polys, 
 								  const int axis, 
 								  vector<SortableEntry> &splitCandidates) const
@@ -1207,5 +1207,5 @@
 	vector<SortableEntry> splitCandidates;
 
-	SortSplitCandidates(polys, axis, splitCandidates);
+	SortSubdivisionCandidates(polys, axis, splitCandidates);
 	
 	// go through the lists, count the number of objects left and right
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1232)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1233)
@@ -13,5 +13,6 @@
 #include "PlyParser.h"
 #include "SamplingStrategy.h"
-#include "VspOspTree.h"
+#include "VspTree.h"
+#include "OspTree.h"
 #include "ObjParser.h"
 #ifdef INTEL_COMPILER
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1233)
@@ -13,5 +13,5 @@
 #include "Beam.h"
 #include "GlRenderer.h"
-#include "ArchModeler2MLRT.hxx"
+//#include "ArchModeler2MLRT.hxx"
 #include "Intersectable.h"
 
@@ -191,5 +191,5 @@
 
 	float dist = 0;
-	const int hittriangle = mlrtaIntersectAS(pforg, pfdir, pfnorm, dist);
+	const int hittriangle = -1//mlrtaIntersectAS(pforg, pfdir, pfnorm, dist);
 
 	if (hittriangle == -1)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 1197)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.cpp	(revision 1233)
@@ -9,5 +9,5 @@
 #include "Polygon3.h"
 #include "VssRay.h"
-#include "VspOspTree.h"
+#include "HierarchyManager.h"
 #include "VssTree.h"
 #include "VspBspTree.h"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1233)
@@ -2881,5 +2881,5 @@
 		{
 			leaf->Mail();
-			dirtyList.push_back(leaf->mSplitCandidate);
+			dirtyList.push_back(leaf->mSubdivisionCandidate);
 		}
 		
@@ -2889,5 +2889,5 @@
 		{
 			leaf->Mail();
-			dirtyList.push_back(leaf->mSplitCandidate);
+			dirtyList.push_back(leaf->mSubdivisionCandidate);
 		}
 	}
@@ -5972,5 +5972,5 @@
 	
 	//-- reevaluate the dirty list
-	vector<SplitCandidate *>::const_iterator sit, sit_end = dirtyList.end();
+	vector<SubdivisionCandidate *>::const_iterator sit, sit_end = dirtyList.end();
 
 	for (sit = dirtyList.begin(); sit != sit_end; ++ sit)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1233)
@@ -8,5 +8,5 @@
 #include "ViewCellBsp.h"
 #include "KdTree.h"
-#include "VspOspTree.h"
+#include "HierarchyManager.h"
 #include "Exporter.h"
 #include "VspBspTree.h"
@@ -19,4 +19,7 @@
 #include "ResourceManager.h"
 #include "KdIntersectable.h"
+#include "VspTree.h"
+#include "OspTree.h"
+
 
 // should not count origin object for sampling because it disturbs heuristics
@@ -3472,5 +3475,5 @@
 			exporter->SetWireframe();
 
-			KdPvsMap::iterator i = object->mKdPvs.mEntries.begin();
+			KdPvsMap::iterator kit = object->mKdPvs.mEntries.begin();
 			Intersectable::NewMail();
 
@@ -3479,7 +3482,7 @@
 			ObjectContainer visibleObjects;
 
-			for (; i != object->mKdPvs.mEntries.end(); i++)
+			for (; kit != object->mKdPvs.mEntries.end(); i++)
 			{
-				KdNode *node = (*i).first;
+				KdNode *node = (*kit).first;
 				exporter->ExportBox(mKdTree->GetBox(node));
 
@@ -5410,5 +5413,5 @@
 					// export bounding box of node
 					KdIntersectable *kdObj  = dynamic_cast<KdIntersectable *>(obj);
-					AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetNode());
+					AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetItem());
 					
 					exporter->SetWireframe();
@@ -5509,5 +5512,5 @@
 	
 	// the type of the view space partition
-	stream << "<ViewSpacePartition>" << endl;
+	stream << "<ViewSpaceHierarchy>" << endl;
 	mVspTree->Export(stream);
 	stream << endl << "</ViewSpacePartitioin>" << endl;
@@ -5517,7 +5520,7 @@
 	
 	// the type of the view cells hierarchy
-	stream << "<ObjectSpacePartition>" << endl;
+	stream << "<ObjectSpaceHierarchy>" << endl;
 	mOspTree->Export(stream);
-	stream << endl << "</ObjectSpacePartition>" << endl;
+	stream << endl << "</ObjectSpaceHierarchy>" << endl;
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 1233)
@@ -156,5 +156,5 @@
 	
 	
-	struct VspBspSplitCandidate
+	struct VspBspSubdivisionCandidate
 	{  
 		/// the current split plane
@@ -172,8 +172,8 @@
 		float mRenderCostDecr;
 
-		VspBspSplitCandidate(): mPriority(0), mRenderCostDecr(0) 
+		VspBspSubdivisionCandidate(): mPriority(0), mRenderCostDecr(0) 
 		{};
 
-		VspBspSplitCandidate(const Plane3 &plane, const VspBspTraversalData &tData): 
+		VspBspSubdivisionCandidate(const Plane3 &plane, const VspBspTraversalData &tData): 
 		mSplitPlane(plane), mParentData(tData), mPriority(0), mRenderCostDecr(0) 
 		{}
@@ -190,5 +190,5 @@
 		}
 
-		friend bool operator<(const VspBspSplitCandidate &a, const VspBspSplitCandidate &b)
+		friend bool operator<(const VspBspSubdivisionCandidate &a, const VspBspSubdivisionCandidate &b)
 		{
 			return a.GetPriority() < b.GetPriority();
@@ -196,5 +196,5 @@
     };
 
-	typedef std::priority_queue<VspBspSplitCandidate> VspBspSplitQueue;
+	typedef std::priority_queue<VspBspSubdivisionCandidate> VspBspSplitQueue;
 
 	/** Default constructor creating an empty tree.
@@ -402,5 +402,5 @@
 	/** Evaluates candidate for splitting.
 	*/
-	void EvalSplitCandidate(VspBspSplitCandidate &splitData);
+	void EvalSubdivisionCandidate(VspBspSubdivisionCandidate &splitData);
 
 	/** Computes priority of the traversal data and stores it in tData.
@@ -461,5 +461,5 @@
 	*/
 	BspNode *Subdivide(VspBspSplitQueue &tQueue,
-					   VspBspSplitCandidate &splitCandidate);
+					   VspBspSubdivisionCandidate &splitCandidate);
 
 	/** Constructs the tree from the given traversal data.
@@ -563,5 +563,5 @@
 		@param splitCandidates returns sorted list of split candidates
 	*/
-	void SortSplitCandidates(const RayInfoContainer &rays, 
+	void SortSubdivisionCandidates(const RayInfoContainer &rays, 
 							 const int axis, 
 							 float minBand, 
@@ -732,5 +732,5 @@
 
 	/// sorted split candidates used for sweep-heuristics
-	vector<SortableEntry> *mLocalSplitCandidates;
+	vector<SortableEntry> *mLocalSubdivisionCandidates;
 
 	/// box around the whole view domain
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1181)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1233)
@@ -1,5 +1,5 @@
 #include "X3dExporter.h"
 #include "VrmlExporter.h"
-#include "VspOspTree.h"
+#include "OspTree.h"
 #include "KdTree.h"
 #include "KdIntersectable.h"
@@ -76,5 +76,5 @@
 void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
 {
-	KdNode *node = kdObj.GetNode();
+	KdNode *node = kdObj.GetItem();
 	
 	Intersectable::NewMail();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1233)
@@ -36,7 +36,4 @@
 
 
-//int upperPvsLimit = 120;
-//int lowerPvsLimit = 5;
-
 float MergeCandidate::sRenderCostWeight = 0;
 
@@ -73,4 +70,5 @@
 	return count;
 }
+
 
 /// Fast computation of merged pvs size
@@ -418,7 +416,11 @@
 		{
 			ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc);
+
 			ViewCellContainer::const_iterator it, it_end = interior->mChildren.end();
+			
 			for (it = interior->mChildren.begin(); it != it_end; ++ it)
+			{
 				tstack.push(*it);
+			}
 			
 		}
@@ -1833,16 +1835,4 @@
 	while (root->GetParent())
 	{
-// <<<<<<< .mine
-// 	case PVS_IN_LEAVES: //-- store pvs only in leaves
-// 		{			
-// 			// pvs is always stored directly in leaves
-// 			if (vc->IsLeaf())
-// 			{
-// 				if (!countKdPvs)
-// 					pvsSize = vc->GetPvs().GetSize();
-// 				else
-// 					pvsSize = CountKdPvs(dynamic_cast<ViewCellLeaf *>(vc));
-// 				break;
-// 			}
 		root = root->GetParent();
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1233)
@@ -16,5 +16,4 @@
 
 class ViewCellLeaf;
-//class VspViewCell;
 class Plane3;
 class AxisAlignedBox3;
@@ -48,49 +47,4 @@
 		return c1->GetPriority() < c2->GetPriority();
 	}
-};
-
-
-/** Candidate for a view space / object space split.
-*/
-class SplitCandidate: public Heapable
-{  
-public:
-
-	enum {OBJECT_SPACE, VIEW_SPACE};
-
-	/// the current split plane
-	AxisAlignedPlane mSplitPlane;
-	/// split axis of this plane (0, 1, 2, or 3 if non-axis-aligned)
-	int mSplitAxis;
-	/// the number of misses of max cost ratio until this split
-	int mMaxCostMisses;
-
-	SplitCandidate(): mRenderCostDecrease(0)
-	{};
-
-	SplitCandidate(const AxisAlignedPlane &plane): mSplitPlane(plane), mRenderCostDecrease(0)
-	{}
-
-	virtual void EvalPriority() = 0;
-	virtual int Type() const = 0;
-	virtual bool GlobalTerminationCriteriaMet() const = 0;
-
-	/** Set render cost decrease achieved through this split.
-	*/
-	void SetRenderCostDecrease(const float renderCostDecr)
-	{
-		mRenderCostDecrease = renderCostDecr;
-	}
-	
-	float GetRenderCostDecrease() const
-	{
-		return mRenderCostDecrease;
-	}
-
-protected:
-
-	/// render cost decrease achieved through this split
-	float mRenderCostDecrease;
-	
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.h	(revision 1233)
@@ -761,5 +761,5 @@
 
   void
-  SortSplitCandidates(
+  SortSubdivisionCandidates(
 					  RssTreeLeaf *node,
 					  const int axis
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.h	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.h	(revision 1233)
@@ -727,5 +727,5 @@
 
   void
-  SortSplitCandidates(
+  SortSubdivisionCandidates(
 					  VssTreeLeaf *node,
 					  const int axis
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 1233)
@@ -435,5 +435,5 @@
 
 void
-KdTree::SortSplitCandidates(
+KdTree::SortSubdivisionCandidates(
 			    KdLeaf *node,
 			    const int axis
@@ -485,5 +485,5 @@
 {
 
-  SortSplitCandidates(node, axis);
+  SortSubdivisionCandidates(node, axis);
   
   // go through the lists, count the number of objects left and right
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1233)
@@ -938,5 +938,5 @@
   }
 	
-  SortSplitCandidates(leaf, info.axis);
+  SortSubdivisionCandidates(leaf, info.axis);
   
   // go through the lists, count the number of objects left and right
@@ -1111,5 +1111,5 @@
 
 void
-RssTree::SortSplitCandidates(
+RssTree::SortSubdivisionCandidates(
 							 RssTreeLeaf *node,
 							 const int axis
@@ -2642,5 +2642,5 @@
   else 
 	switch (passDiff) {
-	  //	case 0:
+	  case 0:
 	  //	  weight = 1.0f;
 	  //	  break;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp	(revision 1004)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssTree.cpp	(revision 1233)
@@ -794,5 +794,5 @@
   }
 	
-  SortSplitCandidates(leaf, axis);
+  SortSubdivisionCandidates(leaf, axis);
   
   // go through the lists, count the number of objects left and right
@@ -892,5 +892,5 @@
 
 void
-VssTree::SortSplitCandidates(
+VssTree::SortSubdivisionCandidates(
 							 VssTreeLeaf *node,
 							 const int axis
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1233)
@@ -20,5 +20,4 @@
   class KdInterior;
   class Intersectable;
-  //class KdViewCell;
   class Beam;
 
@@ -174,5 +173,5 @@
 };
   
-class SplitCandidate;
+class SubdivisionCandidate;
   
 /** Implementation of the kd-tree leaf node */
@@ -213,5 +212,5 @@
 
   /// pvs of view cells seeing this node.
-  SplitCandidate *mSplitCandidate;
+  SubdivisionCandidate *mSubdivisionCandidate;
 
   /// pointer to view cell.
@@ -227,5 +226,4 @@
 };
 
-  
 
 /** KdTree for indexing scene entities - occluders/occludees/viewcells */
@@ -528,5 +526,5 @@
 
   void
-  SortSplitCandidates(
+  SortSubdivisionCandidates(
 		      KdLeaf *node,
 		      const int axis
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1233)
@@ -1,3 +1,3 @@
-#include  <stdlib.h>
+#include <stdlib.h>
 #include <iostream>
 #include <list>
@@ -155,7 +155,4 @@
 	char str[100];
 	
-	float x,y,z;
-	int i;
-
 	SceneGraphNode *root = new SceneGraphNode;
 	
@@ -168,13 +165,14 @@
 		{
 		case 'v':
-			cout << "v";
-
-			// vertex 
-			sscanf(str + 1, "%f %f %f", &x, &y, &z);
-			vertices.push_back(Vector3(x,y,z));
-			
-			//Debug << "vertex: " << vertices.back() << endl;
-			break;
-
+			{
+				float x,y,z;
+				cout << "v";
+
+				// vertex 
+				sscanf(str + 1, "%f %f %f", &x, &y, &z);
+				vertices.push_back(Vector3(x,y,z));
+				//Debug << "vertex: " << vertices.back() << endl;
+				break;
+			}
 		case 'f': 
 			{
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 1193)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 1233)
@@ -11,4 +11,6 @@
 struct VssRayContainer;
 class KdLeaf;
+class BvhLeaf;
+
 
 class Intersectable {
@@ -32,9 +34,10 @@
   ViewCellPvs mViewCellPvs;
 
-  /// kd leaves that this intersectable belongs to
-  //set<KdLeaf *> mKdLeaves;
+  /// pointer to the container bvh leaf
+  BvhLeaf *mBvhLeaf;
+
   VssRayContainer mVssRays;
 
-  /// # of object references
+  /// # of references to this instance
   int mReferences;
 
@@ -44,5 +47,6 @@
 		 VIEW_CELL, 
 		 OGRE_MESH_INSTANCE,
-		 KD_INTERSECTABLE
+		 KD_INTERSECTABLE,
+		 BVH_INTERSECTABLE
 		};
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1233)
@@ -121,6 +121,6 @@
   void EndViewCellInterior();
 
-  void StartViewSpacePartitionElement(const std::string &element, AttributeList& attributes);
-  void StartObjectSpacePartitionElement(const std::string &element, AttributeList& attributes);
+  void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
+  void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
   void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h	(revision 1106)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/FlexibleHeap.h	(revision 1233)
@@ -226,5 +226,4 @@
 }
 
-
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.h	(revision 1233)
@@ -134,6 +134,6 @@
   MeshKdTree(Mesh *mesh);
   ~MeshKdTree() {
-    if (mSplitCandidates)
-      delete mSplitCandidates;
+    if (mSubdivisionCandidates)
+      delete mSubdivisionCandidates;
     
     if (mRoot)
@@ -220,5 +220,5 @@
 
   void
-  SortSplitCandidates(
+  SortSubdivisionCandidates(
 		      MeshKdLeaf *node,
 		      const int axis
@@ -251,5 +251,5 @@
   
   /// reusable array of split candidates
-  vector<SortableEntry> *mSplitCandidates;
+  vector<SortableEntry> *mSubdivisionCandidates;
 
 public:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1189)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1233)
@@ -6,4 +6,5 @@
 #include "KdTree.h"
 #include "common.h"
+#include "BvHierarchy.h"
 
 
@@ -19,4 +20,119 @@
 }
 
+/** the pvs is the number of different objects in the node leaves
+	We eliminate already accounted kd nodes and objects using mailboxing. 
+*/
+static int CountNewObjectsInKdNode(KdIntersectable *kdobj)
+{
+	int pvs = 0;
+	stack<KdNode *> tStack;
+
+	tStack.push(kdobj->GetItem());
+
+	while (!tStack.empty())
+	{
+		KdNode *node = tStack.top();
+		tStack.pop();
+
+		// already processed node (=> objects already in pvs)?
+		if (!node->Mailed())
+		{
+			node->Mail();
+
+			if (node->IsLeaf())
+			{
+				KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
+                       
+				// add #objects exclusivly in this node
+				pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size());
+
+				// Objects already accounted for can only be found among those
+				// which are referenced in more than one leaf
+				ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end();
+						
+				for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit)
+				{
+					Intersectable *object = *oit;						
+                            
+					if (!object->Mailed())
+					{
+						object->Mail();
+						++ pvs;
+					}
+				}
+			}
+			else // traverse tree
+			{
+				KdInterior *interior = dynamic_cast<KdInterior *>(node);
+
+				tStack.push(interior->mFront);
+				tStack.push(interior->mBack);
+			}
+		}
+	}
+
+	return pvs;
+}
+
+
+/** the pvs is the number of different objects in the node leaves
+	We eliminate already accounted kd nodes and objects using mailboxing. 
+*/
+static int CountNewObjectsInBvhNode(BvhIntersectable *bvhobj)
+{
+	BvhNode *node= bvhobj->GetItem();
+
+	// early exit
+	if (node->IsLeaf())	
+	{
+		if (!node->Mailed())
+		{
+			node->Mail();
+			return (int)(((BvhLeaf *)node)->mObjects.size());
+		}
+		else
+		{
+			return 0;
+		}
+	}
+				 
+
+	// compute leaf pvs
+	int pvs = 0;
+
+	stack<BvhNode *> tStack;
+
+	tStack.push(bvhobj->GetItem());
+
+	while (!tStack.empty())
+	{
+		BvhNode *node = tStack.top();
+		tStack.pop();
+
+		// already processed node (=> objects already in pvs)?
+		if (!node->Mailed())
+		{
+			node->Mail();
+
+			if (node->IsLeaf())
+			{
+				BvhLeaf *leaf = dynamic_cast<BvhLeaf *>(node);
+                       
+				// add #objects exclusivly in this node
+				pvs += leaf->mObjects.size();
+			}
+			else // traverse tree
+			{
+				BvhInterior *interior = dynamic_cast<BvhInterior *>(node);
+
+				tStack.push(interior->GetFront());
+				tStack.push(interior->GetBack());
+			}
+		}
+	}
+	return pvs;
+}
+
+
 
 int ObjectPvs::CountObjectsInPvs() const
@@ -26,4 +142,5 @@
 	Intersectable::NewMail();
 	KdLeaf::NewMail();
+	BvhLeaf::NewMail();
 
 	ObjectPvsMap::const_iterator it, it_end = mEntries.end();
@@ -33,74 +150,22 @@
 		Intersectable *obj = (*it).first;
 
-		// found kd node
-		// the pvs is the number od different objects in the node leaves
-		// We eliminate already accounted kd nodes and objects using mailboxing. 
-		if (obj->Type() == Intersectable::KD_INTERSECTABLE)
+		switch (obj->Type())
 		{
-			KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj);
-
-			stack<KdNode *> tStack;
-
-			tStack.push(kdObj->GetNode());
-
-			while (!tStack.empty())
-			{
-				KdNode *node = tStack.top();
-				tStack.pop();
-
-				// already processed node (= objects in pvs)?
-				if (0 ||!node->Mailed())
+			case Intersectable::KD_INTERSECTABLE:
 				{
-					node->Mail();
-
-					if (node->IsLeaf())
-					{
-						KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
-#if 1                        
-						// add #objects exclusivly in this node
-						pvs += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size());
-
-						// Objects already accounted for can only be found among those
-						// which are referenced in more than one leaf
-						ObjectContainer::const_iterator oit, oit_end = leaf->mMultipleObjects.end();
-						
-						for (oit = leaf->mMultipleObjects.begin(); oit != oit_end; ++ oit)
-						{
-							Intersectable *object = *oit;						
-                            
-							if (!object->Mailed())
-							{
-								object->Mail();
-								++ pvs;
-							}
-						}
-#else	
-						ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
-						
-						for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
-						{
-							Intersectable *object = *oit;						
-                            
-							if (!object->Mailed())
-							{
-								object->Mail();
-								++ pvs;
-							}
-						}
-#endif
-					}
-					else // traverse tree
-					{
-						KdInterior *interior = dynamic_cast<KdInterior *>(node);
-
-						tStack.push(interior->mFront);
-						tStack.push(interior->mBack);
-					}
+					// found kd node
+					KdIntersectable *kdObj = dynamic_cast<KdIntersectable *>(obj);
+					pvs += CountNewObjectsInKdNode(kdObj);	
+					break;
 				}
-			}
-		}
-		else
-		{
-			++ pvs;
+			case Intersectable::BVH_INTERSECTABLE:
+				{
+					BvhIntersectable *bvhObj = dynamic_cast<BvhIntersectable *>(obj);
+					pvs += CountNewObjectsInBvhNode(bvhObj);
+					break;
+				}
+			default:
+				++ pvs;
+				break;
 		}
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1233)
@@ -30,5 +30,6 @@
 #include "ViewCellsManager.h"
 #include "GzFileInputSource.h"
-#include "VspOspTree.h"
+#include "OspTree.h"
+#include "VspTree.h"
 #include "KdTree.h"
 
@@ -260,5 +261,5 @@
 }
 
-void ViewCellsParseHandlers::StartViewSpacePartitionElement(const std::string &element,
+void ViewCellsParseHandlers::StartViewSpaceHierarchyElement(const std::string &element,
 															AttributeList& attributes)
 {
@@ -283,5 +284,5 @@
 
 
-void ViewCellsParseHandlers::StartObjectSpacePartitionElement(const std::string &element,
+void ViewCellsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element,
 															  AttributeList& attributes)
 {
@@ -340,7 +341,7 @@
 
 	// decides about the view cell hierarchy
-	if (element == "ViewSpacePartition")
-	{
-		//StartViewSpacePartition(attributes);
+	if (element == "ViewSpaceHierarchy")
+	{
+		//StartViewSpaceHierarchy(attributes);
 		cout << "parsing view space partition" << endl;
 		mCurrentTask = PARSE_VSP;
@@ -348,7 +349,7 @@
 
 	// decides about the view cell hierarchy
-	if (element == "ObjectSpacePartition")
-	{
-		//StartObjectSpacePartition(attributes);
+	if (element == "ObjectSpaceHierarchy")
+	{
+		//StartObjectSpaceHierarchy(attributes);
 		cout << "parsing object space partition" << endl;
 		mCurrentTask = PARSE_OSP;
@@ -373,8 +374,8 @@
 	{
 	case PARSE_VSP:
-		StartViewSpacePartitionElement(element, attributes);
+		StartViewSpaceHierarchyElement(element, attributes);
 		break;
 	case PARSE_OSP:
-		StartObjectSpacePartitionElement(element, attributes);
+		StartObjectSpaceHierarchyElement(element, attributes);
 		break;
 	case PARSE_VIEWCELLS:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp	(revision 1004)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp	(revision 1233)
@@ -19,5 +19,5 @@
 {
   mRoot = new MeshKdLeaf;
-  mSplitCandidates = NULL;
+  mSubdivisionCandidates = NULL;
 }
 
@@ -177,20 +177,20 @@
 
 void
-MeshKdTree::SortSplitCandidates(
+MeshKdTree::SortSubdivisionCandidates(
 			    MeshKdLeaf *node,
 			    const int axis
 			    )
 {
-  mSplitCandidates->clear();
+  mSubdivisionCandidates->clear();
   
   int requestedSize = 2*(int)node->mFaces.size();
   // creates a sorted split candidates array
-  if (mSplitCandidates->capacity() > 500000 &&
-      requestedSize < (int)(mSplitCandidates->capacity()/10) ) {
-    delete mSplitCandidates;
-    mSplitCandidates = new vector<SortableEntry>;
-  }
-  
-  mSplitCandidates->reserve(requestedSize);
+  if (mSubdivisionCandidates->capacity() > 500000 &&
+      requestedSize < (int)(mSubdivisionCandidates->capacity()/10) ) {
+    delete mSubdivisionCandidates;
+    mSubdivisionCandidates = new vector<SortableEntry>;
+  }
+  
+  mSubdivisionCandidates->reserve(requestedSize);
   
   vector<int>::const_iterator fi;
@@ -202,5 +202,5 @@
     AxisAlignedBox3 box = mMesh->GetFaceBox(*fi);
     
-    mSplitCandidates->push_back(SortableEntry(SortableEntry::FACE_MIN,
+    mSubdivisionCandidates->push_back(SortableEntry(SortableEntry::FACE_MIN,
 					     box.Min(axis),
 					     *fi)
@@ -208,5 +208,5 @@
     
     
-    mSplitCandidates->push_back(SortableEntry(SortableEntry::FACE_MAX,
+    mSubdivisionCandidates->push_back(SortableEntry(SortableEntry::FACE_MAX,
 					     box.Max(axis),
 					     *fi)
@@ -214,5 +214,5 @@
   }
   
-  stable_sort(mSplitCandidates->begin(), mSplitCandidates->end());
+  stable_sort(mSubdivisionCandidates->begin(), mSubdivisionCandidates->end());
 }
 
@@ -229,5 +229,5 @@
 {
 
-  SortSplitCandidates(node, axis);
+  SortSubdivisionCandidates(node, axis);
   
   // go through the lists, count the number of objects left and right
@@ -247,6 +247,6 @@
   vector<SortableEntry>::const_iterator ci;
 
-  for(ci = mSplitCandidates->begin();
-      ci != mSplitCandidates->end();
+  for(ci = mSubdivisionCandidates->begin();
+      ci != mSubdivisionCandidates->end();
       ci++) {
     switch ((*ci).type) {
@@ -409,6 +409,6 @@
 MeshKdTree::Construct()
 {
-  if (!mSplitCandidates)
-    mSplitCandidates = new vector<SortableEntry>;
+  if (!mSubdivisionCandidates)
+    mSubdivisionCandidates = new vector<SortableEntry>;
   
   // first construct a leaf that will get subdivide
@@ -418,6 +418,6 @@
   
   // remove the allocated array
-  delete mSplitCandidates;
-  mSplitCandidates = NULL;
+  delete mSubdivisionCandidates;
+  mSubdivisionCandidates = NULL;
   
   return true;
