Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneManager.h	(revision 1320)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBvHierarchySceneManager.h	(revision 1595)
@@ -271,11 +271,13 @@
 	bool mDeleteQueueAfterRendering;
 
-
 	// remember visited scene nodes for viz
 	BvHierarchy::NodeList mVisibleNodes;
 
-	/************************************************************************/
-	/* Kd-Tree specific options & members                                   */
-	/************************************************************************/
+
+	/************************************************************************/
+	/* Bvh specific options & members                                   */
+	/************************************************************************/
+
+
 	// maximum depth of the BvHierarchy
 	int mMaxDepth;
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1296)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1595)
@@ -1,4 +1,4 @@
-#ifndef _OgreBoundingBoxConverter_H__
-#define _OgreBoundingBoxConverter_H__
+#ifndef _PlatFormBoundingBoxConverter_H__
+#define _PlatFormBoundingBoxConverter_H__
  
 #include "OgreAxisAlignedBox.h"
@@ -13,13 +13,15 @@
 class OctreeSceneManager;
 class KdTreeSceneManager;
+class BvHierarchySceneManager;
+
 
 /**	Class which converts preprocessor types to OGRE types
 */
-class __declspec(dllexport) OgreBoundingBoxConverter: public GtpVisibilityPreprocessor::BoundingBoxConverter
+template<typename T>
+class __declspec(dllexport) PlatFormBoundingBoxConverter: public GtpVisibilityPreprocessor::BoundingBoxConverter
 {
 public:
-	OgreBoundingBoxConverter(OctreeSceneManager *sm);
-	OgreBoundingBoxConverter(KdTreeSceneManager *sm);
-
+	PlatFormBoundingBoxConverter(T *sm);
+	
 	bool IdentifyObjects(const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes,
 						 GtpVisibilityPreprocessor::ObjectContainer &objects) const;
@@ -28,11 +30,130 @@
 protected:
 
-	Entity *FindCorrespondingObject(const AxisAlignedBox &box) const;
+	//-------------------------------------------------------------------------
+	inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box)
+	{
+		const float eps = 1e-3f;
+		const Vector3 veps(eps, eps, eps);
+		
+		Vector3 max = box.getMaximum();
+        Vector3 min = box.getMinimum();
 
-	OctreeSceneManager *mOctSceneMgr;
-	KdTreeSceneManager *mKdSceneMgr;
+		return AxisAlignedBox(min - veps, max + veps);
+	}
+	
+	Entity *FindBestFittingObject(const AxisAlignedBox &box) const;
+
+	T *mSceneMgr;
 };
+
+//-------------------------------------------------------------------------
+template<typename T>
+PlatFormBoundingBoxConverter<T>::PlatFormBoundingBoxConverter(T *sm):
+mSceneMgr(sm)
+{
+}
+//-----------------------------------------------------------------------
+template<typename T>
+Entity *PlatFormBoundingBoxConverter<T>::FindBestFittingObject(const AxisAlignedBox &box) const
+{
+	list<SceneNode *> sceneNodeList;
+	AxisAlignedBox mybox = EnlargeBox(box);
+		
+	// get intersecting scene nodes
+	mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
+		
+	// minimal overlap
+	float overlap = 0;//1e-6;
+
+	Entity *bestFittingObj = NULL;
+	float bestFit = overlap;
+
+	// perfect fit threshold
+	const float thresh = 1.0 - GtpVisibilityPreprocessor::Limits::Small;
+
+	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
+	// find the bbox which is closest to the current bbox
+	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
+	{
+		SceneNode *sn = *sit;
+		SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator();
+
+        while (oit.hasMoreElements())
+		{
+			MovableObject *mo = oit.getNext();
+
+			// we are only interested in scene entities
+			if (mo->getMovableType() != "Entity")
+			{
+				continue;
+			}
+			 
+			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
+					
+			// compute measure how much aabbs overlap
+			overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox),
+									 OgreTypeConverter::ConvertFromOgre(bbox));
+	
+			 if (overlap > bestFit)
+			 {
+				 bestFit = overlap;
+				 bestFittingObj = static_cast<Entity *>(mo);
+
+				 // perfect fit => object found, early exit
+				 if (overlap >= thresh)
+				 {
+					 return bestFittingObj;	
+				 }
+			 }
+		}
+	}
+
+	if (0)
+	{
+		std::stringstream d; 
+		if (bestFittingObj)
+			d << "best fit: " << bestFit;     
+		else
+			d << "warning, no best fitting object\n" << box;
+	
+		Ogre::LogManager::getSingleton().logMessage(d.str());
+	}
+
+	return bestFittingObj;
+}
+//-------------------------------------------------------------------------
+template<typename T>
+bool PlatFormBoundingBoxConverter<T>::IdentifyObjects(
+	const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes,
+	GtpVisibilityPreprocessor::ObjectContainer &objects) const
+{
+	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer::
+		const_iterator iit, iit_end = iboxes.end();
+  
+	for (iit = iboxes.begin(); iit != iit_end; ++ iit)
+	{
+		const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second;
+		const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box);
+   
+		Entity *ent = FindBestFittingObject(currentBox);
+
+		// create new mesh instance
+		if (ent)
+		{
+			OgreMeshInstance *omi = new OgreMeshInstance(ent);
+			omi->SetId((*iit).first);
+			objects.push_back(omi);
+		}
+	}
+
+	return true;
+}
+
+
+typedef PlatFormBoundingBoxConverter<OctreeSceneManager> OctreeBoundingBoxConverter;
+typedef PlatFormBoundingBoxConverter<BvHierarchySceneManager> BvhBoundingBoxConverter;
+typedef PlatFormBoundingBoxConverter<KdTreeSceneManager> KdTreeBoundingBoxConverter;
 
 } // namespace Ogre
 
-#endif // OgreBoundingBoxConverter
+#endif // PlatFormBoundingBoxConverter
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1593)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1595)
@@ -1322,5 +1322,5 @@
 	// converter between view cell ids and Ogre entites 
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
-	OgreBoundingBoxConverter bconverter(this);
+	KdTreeBoundingBoxConverter bconverter(this);
 
 	// load the view cells assigning the found objects to the pvss
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp	(revision 1296)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp	(revision 1595)
@@ -9,125 +9,6 @@
 namespace Ogre
 {
-//-------------------------------------------------------------------------
-OgreBoundingBoxConverter::OgreBoundingBoxConverter(OctreeSceneManager *sm):
-mOctSceneMgr(sm), mKdSceneMgr(0)
-{
-}
-//-------------------------------------------------------------------------
-OgreBoundingBoxConverter::OgreBoundingBoxConverter(KdTreeSceneManager *sm):
-mOctSceneMgr(0), mKdSceneMgr(sm)
-{
-}
-//-------------------------------------------------------------------------
-bool OgreBoundingBoxConverter::IdentifyObjects(const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes,
-											   GtpVisibilityPreprocessor::ObjectContainer &objects) const
-{
-	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer::
-		const_iterator iit, iit_end = iboxes.end();
-  
-	for (iit = iboxes.begin(); iit != iit_end; ++ iit)
-	{
-		const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second;
-		const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box);
-   
-		Entity *ent = FindCorrespondingObject(currentBox);
-
-		// create new mesh instance
-		OgreMeshInstance *omi = new OgreMeshInstance(ent);
-		omi->SetId((*iit).first);
-		objects.push_back(omi);
-	}
-
-	return true;
-}
-//-------------------------------------------------------------------------
-inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box)
-{
-	const float eps = 1e-3f;
-	const Vector3 veps(eps, eps, eps);
-
-	Vector3 max = box.getMaximum();
-	Vector3 min = box.getMinimum();
-
-	return AxisAlignedBox(min - veps, max + veps);
-}
-//-----------------------------------------------------------------------
-Entity *OgreBoundingBoxConverter::FindCorrespondingObject(const AxisAlignedBox &box) const
-{
-	list<SceneNode *> sceneNodeList;
-	AxisAlignedBox mybox = EnlargeBox(box);
-	//AxisAlignedBox dummy(Vector3(-50000, -50000, -50000), Vector3(50000, 50000, 50000));
-	
-	// get intersecting scene nodes
-	if (mOctSceneMgr)
-		mOctSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
-	else if (mKdSceneMgr)
-		mKdSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
-	else
-		OGRE_EXCEPT(Exception::ERR_INTERNAL_ERROR, "Bounding Box Converter cannot "
-		"find appropriate scene manager.", "OgreBoundingBoxConverter::FindCorrespondingObject");
-	
-
-	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
-
-	// minimal overlap
-	float overlap = 0;//1e-6;
-
-	Entity *bestFittingObj = NULL;
-	float bestFit = overlap;
-
-	// perfect fit threshold
-	const float thresh = 1.0 - GtpVisibilityPreprocessor::Limits::Small;
 
 
-	// find the bbox which is closest to the current bbox
-	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
-	{
-		SceneNode *sn = *sit;
-		SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator();
-
-        while (oit.hasMoreElements())
-		{
-			MovableObject *mo = oit.getNext();
-
-			// we are only interested in scene entities
-			if (mo->getMovableType() != "Entity")
-			{
-				continue;
-			}
-			 
-			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
-					
-
-			// compute measure how much aabbs overlap
-			overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox),
-									 OgreTypeConverter::ConvertFromOgre(bbox));
-	
-			 if (overlap > bestFit)
-			 {
-				 bestFit = overlap;
-			
-				 bestFittingObj = static_cast<Entity *>(mo);
-
-				 // perfect fit => object found, early exit
-				 if (overlap >= thresh)
-					 return bestFittingObj;				
-			 }
-		}
-	}
-
-	if (0)
-	{
-		std::stringstream d; 
-		if (bestFittingObj)
-			d << "best fit: " << bestFit;     
-		else
-			d << "warning, objects do not fit\n" << box;
-	
-		Ogre::LogManager::getSingleton().logMessage(d.str());
-	}
-
-	return bestFittingObj;
-}
 
 }
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp	(revision 1593)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp	(revision 1595)
@@ -27,5 +27,6 @@
 {
 
-BvHierarchySceneManager::BvHierarchySceneManager(const String& name, GtpVisibility::VisibilityManager *vm):
+BvHierarchySceneManager::BvHierarchySceneManager(const String& name, 
+												 GtpVisibility::VisibilityManager *vm):
 SceneManager(name), 
 mVisibilityManager(vm), 
@@ -1323,23 +1324,21 @@
 	// converter between view cell ids and Ogre entites 
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
-#if 0
-	OgreBoundingBoxConverter bconverter(this);
-
-	// load the view cells assigning the found objects to the pvss
+	BvhBoundingBoxConverter bconverter(this);
+
+	// load the view cells and assigns the objects in the pvs to 
+	// the scene objects using the bounding boxes
 	mViewCellsManager = 
 		GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &mObjects, false, &bconverter);
 
 	return (mViewCellsManager != NULL);
-#endif
 }
 //-------------------------------------------------------------------------
 void BvHierarchySceneManager::applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, 
 													const bool load)
-{	// NOTE: should not happen, rather apply view cell representing unbounded space then
+{	// NOTE: should not happen, rather apply view cell 
+	// representing unbounded space then
 	if (!vc) 
-	{	
-		// set everything visible for savety
+	{	// set everything visible for savety
 		SetObjectsVisible(true);
-
 		return;
 	}
@@ -1348,4 +1347,5 @@
 		oit_end = vc->GetPvs().mEntries.end();
 
+	//////////////
 	//-- PVS of view cell
 	for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1593)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1595)
@@ -593,5 +593,5 @@
 			// reset view cell
 			OGRE_DELETE(mCurrentViewCell);
-
+			
 			if (mUseViewCells)
 			{
@@ -601,5 +601,5 @@
 			mElementaryViewCell = NULL;
 
-			// if using view cells, all objects are set to false initially
+			// if we use view cells, all objects are set to false initially
 			SetObjectsVisible(!mUseViewCells);
 		}
@@ -1060,5 +1060,5 @@
 	// converter between view cell ids and Ogre entites 
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
-	OgreBoundingBoxConverter bconverter(this);
+	OctreeBoundingBoxConverter bconverter(this);
 
 	// load the view cells assigning the found objects to the pvss
Index: /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 1495)
+++ /GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgrePlatformHierarchyInterface.cpp	(revision 1595)
@@ -125,12 +125,12 @@
 {
 	// create new query if there is no query left
-	if (mCurrentTestIdx == mOcclusionQueries.size())
+	if (mCurrentTestIdx == (int)mOcclusionQueries.size())
 	{
 		mOcclusionQueries.push_back(new PlatformOcclusionQuery(mRenderSystem));
-	}
-
-	std::stringstream d;
-	d << "resizing queries: " << (int)mOcclusionQueries.size() << std::endl;
-	LogManager::getSingleton().logMessage(d.str());
+
+		std::stringstream d;
+		d << "resizing queries: " << (int)mOcclusionQueries.size() << std::endl;
+		LogManager::getSingleton().logMessage(d.str());
+	}
 	
 	return mOcclusionQueries[mCurrentTestIdx ++];
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1581)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1595)
@@ -129,5 +129,5 @@
 	char internKdTree[100];
 	Environment::GetSingleton()->GetStringValue("Preprocessor.kdTreeFilename", internKdTree);
-	//string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd");
+	//const string internKdTree = ReplaceSuffic(filename, ".x3d", ".kd");
 
 	//-- initialize external ray casters
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1580)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1595)
@@ -270,8 +270,8 @@
 	VssRayContainer::const_iterator rit, rit_end = vssRays.end();
 	for (rit = vssRays.begin(); rit != rit_end; ++ rit)
-	{cout << "z";
+	{
 		(*rit)->mFlags |= VssRay::BorderSample;
-		//(*rit)->mOriginObject = currentRay.mTerminationObject;
-	}
+	}
+
 	// add to ray queue
 	EnqueueRays(vssRays);
@@ -280,8 +280,6 @@
 	int castRays = (int)vssRays.size();
 
-
-#if 0
     // recursivly subdivide each edge
-	for (int i = 0; i < n; ++ i)
+	for (int i = 0; 1 && (i < n); ++ i)
 	{
 		castRays += SubdivideEdge(
@@ -293,5 +291,4 @@
 			currentRay);
 	}
-#endif
 
 	mBorderSamples += castRays;
@@ -348,5 +345,5 @@
 {	
 	const long startTime = GetTime();
-//cout << "here8"<<endl;
+
 	// generate simple rays
 	SimpleRayContainer simpleRays;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1586)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1595)
@@ -274,5 +274,7 @@
 	
 	if (mBoundingBoxConverter)
+	{
 		mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, *mObjects);
+	}
 
 	Debug << "\nconverted bounding boxes to objects in "
