Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreMeshInstance.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreMeshInstance.h	(revision 2069)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreMeshInstance.h	(revision 2115)
@@ -49,4 +49,7 @@
 									 const int maxTries);
   
+	int GetRandomEdgePoint(GtpVisibilityPreprocessor::Vector3 &point,
+						   GtpVisibilityPreprocessor::Vector3 &normal);
+
 	ostream &Describe(ostream &s);
 	
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 2113)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 2115)
@@ -39,4 +39,5 @@
 };
 
+
 /**	Class which converts preprocessor types to OGRE types
 */
@@ -121,4 +122,5 @@
 
 	list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end();
+
 	// find the bbox which is closest to the current bbox
 	for (sit = sceneNodeList.begin(); sit != sit_end; ++ sit)
@@ -247,23 +249,43 @@
 	for (iit = iboxes.begin(); iit != iit_end; ++ iit)
 	{
+		const GtpVisibilityPreprocessor::AxisAlignedBox3 pbox = (*iit).second;
+		const int id = (*iit).first;
+
 		const AxisAlignedBox box = 
-			OgreTypeConverter::ConvertToOgre((*iit).second);
-		
-		EntityContainer *entryObjects = new EntityContainer();
+			OgreTypeConverter::ConvertToOgre(pbox);
+		
+		EntityContainer entryObjects;
 
 		// find all objects that intersect the bounding box
-		FindIntersectingObjects(box, *entryObjects);
-
+		FindIntersectingObjects(box, entryObjects);
+
+		// TODO: can actually just put single objects into pvs with same id, 
+		// this can be sorted out later!!
+#if 1
+		EntityContainer::const_iterator eit, eit_end = entryObjects.end();
+
+		for (eit = entryObjects.begin(); eit != eit_end; ++ eit)
+		{
+			Entity *ent = *eit;
+
+            // warning: multiple ids possible
+			OgreMeshInstance *omi = new OgreMeshInstance(ent);
+			omi->SetId(id);
+			objects.push_back(omi);
+		}
+#else
 		EngineIntersectable *entry = 
 			new EngineIntersectable(entryObjects);
 
-		entry->SetId((*iit).first);
-
+		entry->SetId(id);
 		objects.push_back(entry);
+#endif
 	}
 
 	return true;
 }
+
 #else
+
 //-------------------------------------------------------------------------
 template<typename T>
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 2114)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 2115)
@@ -1325,9 +1325,9 @@
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
 	KdTreeBoundingBoxConverter bconverter(this);
-GtpVisibilityPreprocessor::ObjectContainer dummys;
+
 	// load the view cells assigning the found objects to the pvss
 	mViewCellsManager = 
 		GtpVisibilityPreprocessor::ViewCellsManager::
-			LoadViewCells(filename, mObjects, dummys, false, &bconverter);
+			LoadViewCells(filename, mObjects, false, &bconverter);
 
 	return (mViewCellsManager != NULL);
@@ -1344,4 +1344,5 @@
 		// representing unbounded space then
 		SetObjectsVisible(true);
+
 		return;
 	}
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp	(revision 2114)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp	(revision 2115)
@@ -1325,10 +1325,10 @@
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
 	BvhBoundingBoxConverter bconverter(this);
-GtpVisibilityPreprocessor::ObjectContainer dummys;
+
 	// 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, dummys, false, &bconverter);
+		LoadViewCells(filename, mObjects, false, &bconverter);
 
 	return (mViewCellsManager != NULL);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreMeshInstance.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreMeshInstance.cpp	(revision 2066)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreMeshInstance.cpp	(revision 2115)
@@ -55,9 +55,15 @@
 
 	int OgreMeshInstance::GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
-		GtpVisibilityPreprocessor::Vector3 &normal)
+												GtpVisibilityPreprocessor::Vector3 &normal)
 	{
 		return 0;
 	}
 
+	int OgreMeshInstance::GetRandomEdgePoint(GtpVisibilityPreprocessor::Vector3 &point,
+											 GtpVisibilityPreprocessor::Vector3 &normal)
+	{
+		return 0;
+	}
+  
 	int OgreMeshInstance::GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
 													   GtpVisibilityPreprocessor::Vector3 &normal,
@@ -67,5 +73,5 @@
 		return 0;
 	}
-  
+
 	ostream &OgreMeshInstance::Describe(ostream &s)
 	{
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2114)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2115)
@@ -403,5 +403,5 @@
 	// show current view cell geometry
     if (mCurrentViewCell && mCurrentViewCell->GetMesh())
-	{
+	{/*
 		//const bool showSingleViewCell = true;
 		if (mViewCellsGeometryLoaded)
@@ -427,11 +427,9 @@
 			}
 		}
-		
-
+		*/
 		//////////
 		//-- set PVS of view cell visible
 
-		GtpVisibilityPreprocessor::ObjectPvsIterator pit = 
-			mCurrentViewCell->GetPvs().GetIterator();
+		GtpVisibilityPreprocessor::ObjectPvsIterator pit = mCurrentViewCell->GetPvs().GetIterator();
 
 		while (pit.HasMoreEntries())
@@ -440,63 +438,8 @@
 			GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject;
 
-			if (obj->Type() != 
-				GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE)
-				continue;
-			
-			EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
-
-			EntityContainer *entries = oi->GetItem();
-			EntityContainer::const_iterator eit, eit_end = entries->end();
-
-			for (eit = entries->begin(); eit != eit_end; ++ eit)
-			{
-				(*eit)->setUserAny(Any((int)0));
-			}
-		}
-
-		pit = mCurrentViewCell->GetPvs().GetIterator();
-
-		while (pit.HasMoreEntries())
-		{		
-			GtpVisibilityPreprocessor::ObjectPvsEntry entry = pit.Next();
-			GtpVisibilityPreprocessor::Intersectable *obj = entry.mObject;
-
-			switch (obj->Type())
-			{	
-			case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
-				{
-					OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
-					omi->GetEntity()->_updateRenderQueue(getRenderQueue());
-				}
-				break;
-
-			case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
-				{
-					EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
-
-					EntityContainer *entries = oi->GetItem();
-					EntityContainer::const_iterator eit, eit_end = entries->end();
-
-					for (eit = entries->begin(); eit != eit_end; ++ eit)
-					{
-					
-						Entity *ent = *eit;
-						Any newAny = ent->getUserAny();
-
-						int flt = any_cast<int>(newAny);
-					
-						if (any_cast<int>(newAny) == 0)
-						{
-							ent->setUserAny(Any((int)1));
-							ent->_updateRenderQueue(getRenderQueue());
-						}
-
-					}
-				}
-				break;
-			default:
-				break;
-			}
-		}	
+			OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
+			omi->GetEntity()->_updateRenderQueue(getRenderQueue());
+		}
+		
 	}
 /*
@@ -1414,30 +1357,7 @@
 		GtpVisibilityPreprocessor::Intersectable *entry = *it;
 
-		switch (entry->Type())
-		{
-			case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
-				{
-					OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(entry);
-					omi->GetEntity()->setVisible(visible);
-					//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
-				}
-				break;
-			case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
-				{
-					EngineIntersectable *oi = static_cast<EngineIntersectable *>(entry);
-
-					EntityContainer *entries = oi->GetItem();
-					EntityContainer::const_iterator eit,
-						eit_end = entries->end();
-					for (eit = entries->begin(); eit != eit_end; ++ eit)
-					{
-						Entity *ent = *eit;
-						ent->setVisible(visible);
-					}
-				}
-				break;
-			default:
-				break;
-		}
+		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(entry);
+		omi->GetEntity()->setVisible(visible);
+		//GtpVisibilityPreprocessor::Debug << "assigned id " << omi->GetId() << endl;
 	}
 }
@@ -1459,9 +1379,8 @@
 	const bool finalizeViewCells = false;
 
-	GtpVisibilityPreprocessor::ObjectContainer dummys;
 	// load the view cells assigning the found objects to the pvss
 	mViewCellsManager = 
 		GtpVisibilityPreprocessor::ViewCellsManager::
-			LoadViewCells(filename, mObjects, dummys, false, &bconverter);
+			LoadViewCells(filename, mObjects, false, &bconverter);
 	
 	Ogre::LogManager::getSingleton().logMessage("******** view cells loaded *********");
@@ -1508,31 +1427,6 @@
 		if (!obj) continue;
 	
-		switch (obj->Type())
-		{
-			case GtpVisibilityPreprocessor::Intersectable::OGRE_MESH_INSTANCE:
-				{
-					OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
-					omi->GetEntity()->setVisible(load);
-				}				
-				break;
-			case GtpVisibilityPreprocessor::Intersectable::ENGINE_INTERSECTABLE:
-				{
-					EngineIntersectable *oi = static_cast<EngineIntersectable *>(obj);
-
-					EntityContainer *entries = oi->GetItem();
-
-					EntityContainer::const_iterator eit, eit_end = entries->end();
-
-					for (eit = entries->begin(); eit != eit_end; ++ eit)
-					{
-						Entity *ent = *eit;
-						ent->setVisible(load);					
-					}
-				}
-				break;
-			default:
-				LogManager::getSingleton().logMessage("error: should not come here");
-				break;
-		}
+		OgreMeshInstance *omi = static_cast<OgreMeshInstance *>(obj);
+		omi->GetEntity()->setVisible(load);
 	}
 }
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2112)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/include/ObjReader.h	(revision 2115)
@@ -31,4 +31,6 @@
 	
 	const std::vector<Ogre::Entity *> &GetObjects() const;
+	
+	Ogre::Entity *CreateEntity(const std::string &name);
 
 protected:
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2112)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.cpp	(revision 2115)
@@ -57,49 +57,82 @@
 
 
-#if TODO
-
-Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, 
-									 std::string name, 
-									 ObjMeshData *mData, 
-									 Ogre::Vector3 *translation)
+Ogre::Entity *ObjReader::CreateEntity(const std::string &name)
+//									  ObjMeshData *mData, 
+//									  Ogre::Vector3 *translation)
 {
 	using namespace Ogre;
+	Entity *entity;
 
+	
 	std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh";
 	std::string entityName = name + "/Entity";
 
-	Mesh* pMesh = NULL;
-	if ((pMesh = (Mesh *) MeshManager::getSingleton().getByName(meshName).getPointer()) == NULL)
+	MeshPtr mesh = MeshManager::getSingleton().createManual(meshName, "ObjGroup");
+	SubMesh* submesh = mesh->createSubMesh();
+int nbVertices = 99992;
+	// We must create the vertex data, indicating how many vertices there will be
+	submesh->useSharedVertices = false;
+	submesh->vertexData = new VertexData();
+	submesh->vertexData->vertexStart = 0;
+	submesh->vertexData->vertexCount = nbVertices;
+
+	static const unsigned short source = 0;
+	size_t offset = 0;
+
+	VertexDeclaration* declaration = HardwareBufferManager::getSingleton().createVertexDeclaration();
+
+	offset += declaration->addElement(source,offset,VET_FLOAT3,VES_POSITION).getSize();
+	//	offset += declaration->addElement(source,offset,VET_FLOAT3,VES_NORMAL).getSize();
+	//	offset += declaration->addElement(source,offset,VET_FLOAT2,VES_TEXTURE_COORDINATES).getSize();
+
+
+	int numVertices = 0;
+
+	HardwareVertexBufferSharedPtr vbuffer = 
+		HardwareBufferManager::getSingleton().createVertexBuffer(declaration->getVertexSize(source), // size of one whole vertex
+		submesh->vertexData->vertexCount, // number of vertices
+		HardwareBuffer::HBU_STATIC_WRITE_ONLY, // usage
+		false); // no shadow buffer
+
+
+	// No we get access to the buffer to fill it.  During so we record the bounding box.
+	AxisAlignedBox aabox;
+
+	float* vdata = static_cast<float*>(vbuffer->lock(HardwareBuffer::HBL_DISCARD));
+
+	for (size_t i = 0; i < nbVertices; ++ i)
 	{
+		// Position
+		Vector3 position;// = 20.0f*positions[i];
+		*vdata++ = position.x;
+		*vdata++ = position.y;
+		*vdata++ = position.z;
+		aabox.merge(position);
+		// Normal
+		Vector3 normal = position.normalisedCopy();
+		*vdata++ = normal.x;
+		*vdata++ = normal.y;
+		*vdata++ = normal.z;
 
-		ObjMeshData *data = mData->expand();
+		// Texture coordinate
+		Vector2 tcoordinate;// = tcoordinates[i];
+		*vdata ++ = tcoordinate.x;
 
-		ObjManualMeshLoader *loader	= new ObjManualMeshLoader(data);
+		*vdata ++ = tcoordinate.y;
 
-		if (translation != NULL) *translation = data->boundingBox->getCenter();
-
-		addMeshToList(meshName, loader);
-
-		Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "IVGroup", loader).getPointer(); 
-
-		pMesh->load(); 
-		pMesh->touch();
-	}
-	else
-	{
-		if (translation != NULL)
-		{
-			*translation = meshList->getManualMeshLoader(meshName)->getBoundingBox()->getCenter();
-		}
 	}
 
-	Entity *pEntity = sceneMgr->createEntity(entityName, meshName);
+	vbuffer->unlock();
 
+	// We must indicate the bounding box
+	//mesh->_setBounds(aabox); 
 
-	if (0) pEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_MAIN);
+	//mesh->_setBoundingSphereRadius((aabox.getMaximum()-aabox.getMinimum()).length()/2.0); 
 
-	return pEntity;
+	mesh->load();
+	
+	// Create an entity with the mesh
+	//entity = mSceneManager->createEntity(meshName, entityName);
+
+	return entity;
 }
-
-
-#endif
