Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1676)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 2066)
@@ -21,14 +21,13 @@
 typedef vector<Entity *> EntityContainer;
 
-class ObjectsIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *>
+class EngineIntersectable: public GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *>
 {
 public:
-	ObjectsIntersectable(EntityContainer *item):
+	EngineIntersectable(EntityContainer *item):
 	GtpVisibilityPreprocessor::IntersectableWrapper<EntityContainer *>(item) {}
 
 	// hack
-	ObjectsIntersectable::~ObjectsIntersectable() 
-	{
-		//CLEAR_CONTAINER(*mItem);
+	EngineIntersectable::~EngineIntersectable() 
+	{
 		delete mItem;
 	}
@@ -36,5 +35,5 @@
 	int Type() const
 	{
-		return Intersectable::OBJECTS_INTERSECTABLE;
+		return Intersectable::ENGINE_INTERSECTABLE;
 	}
 };
@@ -90,4 +89,5 @@
 								 vector<Entity *> &objects) const;
 
+	/// this can be any scene manager
 	T *mSceneMgr;
 };
@@ -108,4 +108,5 @@
 		
 	// get intersecting scene nodes
+	// note: this function must be provided by scene manager
 	mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
 		
@@ -169,22 +170,34 @@
 	return bestFittingObj;
 }
-//-----------------------------------------------------------------------
-/*template<typename T>
+
+
+#define ENLARGE_OBJECT_BBOX 0
+#define ENLRAGE_NODE_BBOX 0 
+template<typename T>
 void PlatFormBoundingBoxConverter<T>::FindIntersectingObjects(const AxisAlignedBox &box,
 															  EntityContainer &objects) const
-{//return;
+{
 	list<SceneNode *> sceneNodeList;
 			
-	// get intersecting scene nodes (= candidates)
+	// find intersecting scene nodes to get candidates for intersection
+    // note: this function has to be provided by scene manager
+#if ENLARGE_NODE_BBOX
+	// make search radius larger
 	AxisAlignedBox mybox = EnlargeBox(box);
 	mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
-	//mSceneMgr->findNodesIn(box, sceneNodeList, NULL);
 
 	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
 
-	GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(mybox);
-	//GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box);
-
-	// find really intersecting objects
+	GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = 
+		OgreTypeConverter::ConvertFromOgre(mybox);
+#else
+
+	mSceneMgr->findNodesIn(box, sceneNodeList, NULL);
+
+	GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = 
+		OgreTypeConverter::ConvertFromOgre(box);
+#endif
+	
+	// loop through the intersected scene nodes
 	for (sit = sceneNodeList.begin(); sit != sceneNodeList.end(); ++ sit)
 	{
@@ -192,4 +205,5 @@
 		SceneNode::ObjectIterator oit = sn->getAttachedObjectIterator();
 
+		// find the objects that intersect the box
         while (oit.hasMoreElements())
 		{
@@ -198,125 +212,23 @@
 			// we are only interested in scene entities
 			if (mo->getMovableType() != "Entity")
+				continue;
+			
+			// get the bounding box of the objects
+#if ENLARGE_OBJECT_BBOX)
+			// compare with enlarged entitiy box
+			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
+#else
+			const AxisAlignedBox bbox = mo->getWorldBoundingBox();
+#endif
+
+			// test for intersection (note: function provided of preprocessor)
+			if (Overlap(nodeBox, OgreTypeConverter::ConvertFromOgre(bbox)))
 			{
-				continue;
+				objects.push_back(static_cast<Entity *>(mo));
 			}
-			 
-			//const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
-			const AxisAlignedBox bbox = mo->getWorldBoundingBox();
-
-			const bool overlaps = Overlap(nodeBox,
-										  OgreTypeConverter::ConvertFromOgre(bbox)
-										  );
-										  //,0.00001);
-	
-			 if (overlaps)
-			 {
-				 objects.push_back(static_cast<Entity *>(mo));
-			 }
 		}
 	}
 }
-*/
-template<typename T>
-void PlatFormBoundingBoxConverter<T>::FindIntersectingObjects(const AxisAlignedBox &box,
-															  EntityContainer &objects) const
-{//return;
-	list<SceneNode *> sceneNodeList;
-			
-	// get intersecting scene nodes (= candidates)
-	//AxisAlignedBox mybox = EnlargeBox(box);
-	//mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
-	mSceneMgr->findNodesIn(box, sceneNodeList, NULL);
-
-	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
-
-	//GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(mybox);
-	GtpVisibilityPreprocessor::AxisAlignedBox3 nodeBox = OgreTypeConverter::ConvertFromOgre(box);
-
-	// find really intersecting objects
-	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());
-			const AxisAlignedBox bbox = mo->getWorldBoundingBox();
-
-			const bool overlaps = 
-				Overlap(nodeBox, OgreTypeConverter::ConvertFromOgre(bbox));
-										
-	
-			 if (overlaps)
-			 {
-				 objects.push_back(static_cast<Entity *>(mo));
-			 }
-		}
-	}
-}
 #if USE_KD_PVS
-//-------------------------------------------------------------------------
-template<typename T>
-bool PlatFormBoundingBoxConverter<T>::IdentifyObjects(
-	const GtpVisibilityPreprocessor::IndexedBoundingBoxContainer &iboxes,
-	GtpVisibilityPreprocessor::ObjectContainer &objects) const
-{
-	//Ogre::LogManager().logMessage("pvs: intersecting objects");
-	const long startTime = GtpVisibilityPreprocessor::GetTime();
-
-	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer::
-		const_iterator iit, iit_end = iboxes.end();
-  
-	int i = 0;
-
-	for (iit = iboxes.begin(); iit != iit_end; ++ iit, ++ i)
-	{
-		if (0 && ((i % 1000) == 0))
-		{
-			std::stringstream d; d << "found " << i << " objects";
-			Ogre::LogManager().getSingleton().logMessage(d.str());
-		}
-
-		const AxisAlignedBox box = OgreTypeConverter::ConvertToOgre((*iit).second);
-		
-		//GtpVisibilityPreprocessor::ObjectContainer *entryObjects = new EntityContainer();
-		EntityContainer *entryObjects = new EntityContainer();
-
-		// find all objects that intersect the bounding box
-		FindIntersectingObjects(box, *entryObjects);
-
-		/*vector<Entity *>::const_iterator mit, mit_end = sceneObjects.end();
-		
-		for (mit = sceneObjects.begin(); mit != mit_end; ++ mit)
-		{
-			Entity *ent = *mit;
-			// create new mesh instance
-			OgreMeshInstance *omi = new OgreGetOrCreateOgreMeshInstance(ent);
-			//omi->SetId((*iit).first);
-			entryObjects->push_back(omi);
-		}*/
-
-		ObjectsIntersectable *entry = 
-			new ObjectsIntersectable(entryObjects);
-		entry->SetId((*iit).first);
-		//kdObj->mBbox = (*iit).second;
-		objects.push_back(entry);
-	}
-
-	//std::stringstream d; d << "finished object intersection in " << GtpVisibilityPreprocessor::TimeDiff(startTime, GtpVisibilityPreprocessor::GetTime()) * 1e-3 << "secs";
-	//Ogre::LogManager().logMessage(d.str());
-
-	return true;
-}
-#else
 //-------------------------------------------------------------------------
 template<typename T>
@@ -330,16 +242,43 @@
 	for (iit = iboxes.begin(); iit != iit_end; ++ iit)
 	{
+		const AxisAlignedBox box = 
+			OgreTypeConverter::ConvertToOgre((*iit).second);
+		
+		EntityContainer *entryObjects = new EntityContainer();
+
+		// find all objects that intersect the bounding box
+		FindIntersectingObjects(box, *entryObjects);
+
+		EngineIntersectable *entry = 
+			new EngineIntersectable(entryObjects);
+		entry->SetId((*iit).first);
+
+		objects.push_back(entry);
+	}
+
+	return true;
+}
+#else
+//-------------------------------------------------------------------------
+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);
-
-		if (ent)
-		{
-			// create new mesh instance
-			OgreMeshInstance *omi = new OgreMeshInstance(ent);
-			omi->SetId((*iit).first);
-			objects.push_back(omi);
-		}
+		if (!ent) continue;
+		
+		// create new mesh instance
+		OgreMeshInstance *omi = new OgreMeshInstance(ent);
+		omi->SetId((*iit).first);
+		objects.push_back(omi);
 	}
 
