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
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.h	(revision 2113)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.h	(revision 2115)
@@ -1,4 +1,4 @@
-#ifndef __VIEWCELLSDPARSER_H
-#define __VIEWCELLSDPARSER_H
+#ifndef __OBJECTSPARSER_H
+#define __OBJECTSPARSER_H
 
 #include "Parser.h"
@@ -12,14 +12,12 @@
 class Environment;
 
-class ViewCellsParser : public Parser
+class ObjectsParser: public Parser
 {
 public:
-  ViewCellsParser():Parser() {}
+  ObjectsParser(): Parser() {}
   
-  bool ParseViewCellsFile(const string &filename, 
-						  ViewCellsManager **viewCells,
-						  ObjectContainer &pvsObjects,
-						  ObjectContainer &preprocessorObjects,
-						  BoundingBoxConverter *bconverter);
+  bool ParseObjects(const string &filename, 
+					ObjectContainer &pvsObjects,
+					const ObjectContainer &preprocessorObjects);
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2113)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2115)
@@ -562,5 +562,5 @@
 		@param filename the filename of the view cells
 		@param objects the scene objects
-		@param finalizeViewCells if the view cells should be post processed, i.e.
+		@param finalizeViewCells if the view cells should be post processed, i.e.,
 			   a mesh is created representing the geometry
 		@param bconverter a conversion routine working with the similarities of bounding
@@ -576,4 +576,8 @@
 										   BoundingBoxConverter *bconverter = NULL);
 
+	static ViewCellsManager *LoadViewCells(const string &filename, 
+										   ObjectContainer &pvsObjects,
+										   bool finalizeViewCells = false,
+										   BoundingBoxConverter *bconverter = NULL);
 
 	///////////////////////
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2113)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2115)
@@ -22,4 +22,5 @@
 #include "InternalRayCaster.h"
 #include "GlobalLinesRenderer.h"
+#include "ObjectsParser.h"
 
 
@@ -730,9 +731,17 @@
 	if (mLoadViewCells)
 	{	
-		Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
-		cout << "loading view cells from " << buf << endl<<flush;
+        Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf);
+		
+		cout << "loading objects from " << buf << endl;
+
+		// load objects which will be used as pvs entries
+		ObjectContainer pvsObjects;
+
+		LoadObjects(buf, pvsObjects, mObjects);
+
+		cout << "loading view cells from " << buf << endl;
 
 		mViewCellsManager = ViewCellsManager::LoadViewCells(buf, 
-															mObjects, 
+															pvsObjects,
 															mObjects, 
 															true, 
@@ -1626,3 +1635,28 @@
 
 
-}
+bool Preprocessor::LoadObjects(const string &filename,
+							   ObjectContainer &pvsObjects, 
+							   const ObjectContainer &preprocessorObjects)
+{
+	ObjectsParser parser;
+
+	const bool success = parser.ParseObjects(filename, 
+											 pvsObjects, 
+											 preprocessorObjects);
+
+	if (!success)
+	{
+		Debug << "Error: loading objects failed!" << endl;
+	}
+
+	// hack: no bvh object could be found => take preprocessor objects
+	if (!pvsObjects.empty())
+	{
+		pvsObjects = preprocessorObjects;
+	}
+
+	return success;
+}
+
+
+}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2113)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2115)
@@ -581,4 +581,13 @@
 			</File>
 			<File
+				RelativePath=".\ObjectsParser.cpp">
+			</File>
+			<File
+				RelativePath=".\ObjectsParser.h">
+			</File>
+			<File
+				RelativePath=".\ObjectsParserXerces.h">
+			</File>
+			<File
 				RelativePath=".\ObjExporter.cpp">
 			</File>
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2111)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2115)
@@ -191,4 +191,7 @@
 	virtual void DeterminePvsObjects(VssRayContainer &rays);
 
+	static bool LoadObjects(const string &filename,
+							ObjectContainer &pvsObjects, 
+							const ObjectContainer &preprocessorObject);
 
 	////////////////////////////////////////////////
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2113)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2115)
@@ -27,7 +27,4 @@
 #include "PerfTimer.h"
 
-//#include "HashPvs.h"
-
-
 
 #define USE_RAY_LENGTH_AS_CONTRIBUTION 0
@@ -173,5 +170,6 @@
 	}
 		
-    Debug << "casting strategies: ";
+    Debug << "casting initial strategies: ";
+
 	for (int i = 0; i < (int)mStrategies.size(); ++ i)
 		Debug << mStrategies[i] << " ";
@@ -1020,4 +1018,18 @@
 
 
+ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename, 
+												  ObjectContainer &pvsObjects,
+												  bool finalizeViewCells,
+												  BoundingBoxConverter *bconverter)
+												 
+{
+	ObjectContainer dummys;
+
+	return LoadViewCells(filename, 
+						 pvsObjects,
+						 dummys,
+						 finalizeViewCells,
+						 bconverter);
+}
 
 
@@ -1047,6 +1059,4 @@
 	}
 	
-	//cout << "viewcells parsed " <<endl;
-
 	if (0)
 	{
@@ -1117,5 +1127,6 @@
 		if (mUseKdPvs)
 		{
-			vector<KdIntersectable *>::iterator kit, kit_end = GetPreprocessor()->mKdTree->mKdIntersectables.end();
+			vector<KdIntersectable *>::iterator kit, kit_end = 
+				GetPreprocessor()->mKdTree->mKdIntersectables.end();
 
 			int id = 0;
@@ -1127,7 +1138,7 @@
 				obj->SetId(id);
 	
-				stream << "<BoundingBox" << " id=\"" << id << "\""
-					   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""
-					   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;
+				stream << "<BoundingBox" << " id=\""    << id  << "\""
+					   << " min=\""      << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""
+					   << " max=\""      << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;
 			}
 		}
@@ -1143,7 +1154,7 @@
 				//-- the bounding boxes
 
-				stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\""
-					   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""
-					   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;
+				stream << "<BoundingBox" << " id=\""    << (*oit)->GetId()    << "\""
+					   << " min=\""      << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""
+					   << " max=\""      << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;
 			}
 		}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2093)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2115)
@@ -201,6 +201,5 @@
 	float GetMergeCost() {return (float)-mTimeStamp; }
 
-	virtual int GetRandomEdgePoint(Vector3 &point,
-								 Vector3 &normal);
+	virtual int GetRandomEdgePoint(Vector3 &point, Vector3 &normal);
 
 	inline int GetTimeStamp() const { return mTimeStamp; }
@@ -221,5 +220,5 @@
 	int NumberOfFaces() const { return 6; };
 	
-  int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 
+	int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 
 							  GtpVisibilityPreprocessor::Vector3 &normal)
 	{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2053)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2115)
@@ -345,5 +345,4 @@
 
 	bool guiSupported = false;
-
 	bool useRendererBuffer = true;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h	(revision 2114)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h	(revision 2115)
@@ -1,4 +1,4 @@
-#ifndef _X3D_PARSER_XERCES__H
-#define _X3D_PARSER_XERCES__H
+#ifndef _OBJECTS_PARSER_XERCES__H
+#define _OBJECTS_PARSER_XERCES__H
 
 // ---------------------------------------------------------------------------
@@ -17,14 +17,7 @@
 XERCES_CPP_NAMESPACE_END
 
-class VspBspTree;
-class BspTree;
-class ViewCellsManager;
-class ViewCellsTree;
-class VspTree;
-class OspTree;
-class VspNode;
+
 class BvhNode;
 class BvHierarchy;
-class HierarchyManager;
 
 
@@ -32,109 +25,101 @@
 {
 public:
-  // -----------------------------------------------------------------------
-  //  Constructors and Destructor
-  // -----------------------------------------------------------------------
-  ObjectsParseHandlers(ObjectContainer &pvsObjects, 
-						 ObjectContainer &preprocessorObjects, 
-						 BoundingBoxConverter *bconverter);
-  ~ObjectsParseHandlers();
-  
-  
-  // -----------------------------------------------------------------------
-  //  Getter methods
-  // -----------------------------------------------------------------------
-  unsigned int GetElementCount()
-  {
-    return mElementCount;
-  }
-  
-  unsigned int GetAttrCount()
-  {
-    return mAttrCount;
-  }
-  
-  unsigned int GetCharacterCount()
-  {
-    return mCharacterCount;
-  }
-  
-  unsigned int GetSpaceCount()
-  {
-    return mSpaceCount;
-  }
+
+	// -----------------------------------------------------------------------
+	//  Constructors and Destructor
+	// -----------------------------------------------------------------------
+
+	ObjectsParseHandlers(ObjectContainer &pvsObjects, 
+						 const ObjectContainer &preprocessorObjects);
+
+	~ObjectsParseHandlers();
 
 
-  // -----------------------------------------------------------------------
-  //  Handlers for the SAX DocumentHandler interface
-  // -----------------------------------------------------------------------
-  void endElement(const XMLCh* const name);
-  void startElement(const XMLCh* const name, AttributeList& attributes);
-  void characters(const XMLCh* const chars, const unsigned int length);
-  void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
-  void resetDocument();
+	// -----------------------------------------------------------------------
+	//  Getter methods
+	// -----------------------------------------------------------------------
 
-  /////////////////////////
+	unsigned int GetElementCount()
+	{
+		return mElementCount;
+	}
 
-  int mUniqueObjectId;
-  vector<BvhLeaf *> mBvhLeaves;
-  ObjectContainer &mPreprocessorObjects;
+	unsigned int GetAttrCount()
+	{
+		return mAttrCount;
+	}
 
-  /// current state of the parser
-  int mCurrentState;
-  
-  enum {, BVH};
+	unsigned int GetCharacterCount()
+	{
+		return mCharacterCount;
+	}
 
-  int mViewSpaceHierarchyType;
-  int mObjectSpaceHierarchyType;
-  int nViewCells;
-  int nObjects;
-  
-  
-  ////////////////////////////////
+	unsigned int GetSpaceCount()
+	{
+		return mSpaceCount;
+	}
 
 
-  // Handlers for X3D
-  
-  void StartObjectSpaceHierarchy(AttributeList& attributes);
+	// -----------------------------------------------------------------------
+	//  Handlers for the SAX DocumentHandler interface
+	// -----------------------------------------------------------------------
 
-  void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
+	void endElement(const XMLCh* const name);
+	void startElement(const XMLCh* const name, AttributeList& attributes);
+	void characters(const XMLCh* const chars, const unsigned int length);
+	void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
+	void resetDocument();
 
-  void StartBvhLeaf(AttributeList& attributes);
-  void StartBvhInterior(AttributeList& attributes);
-  void StartBvhElement(string element, AttributeList& attributes);
+	void StartObjectSpaceHierarchyElement(const std::string &element, 
+										  AttributeList& attributes);
 
-  void EndObjectSpaceHierarchyInterior();
+	/////////////////////////
 
-  void EndBvhInterior();
-  void EndOspInterior();
+	int mUniqueObjectId;
 
-  void EndObjectSpaceHierarchy();
+	vector<BvhLeaf *> mBvhLeaves;
 
-  void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
+	const ObjectContainer &mPreprocessorObjects;
+	ObjectContainer &mPvsObjects;
 
-  // -----------------------------------------------------------------------
-  //  Handlers for the SAX ErrorHandler interface
-  // -----------------------------------------------------------------------
+	/// current state of the parser
+	bool mIsObjectSpaceHierarchy;
 
-  void warning(const SAXParseException& exc);
-  void error(const SAXParseException& exc);
-  void fatalError(const SAXParseException& exc);
-  
-  
+	enum {BVH};
+
+	////////////
+	//-- Handlers for X3D
+
+	void StartBvhLeaf(AttributeList& attributes);
+	void StartBvhElement(string element, AttributeList& attributes);
+
+	void EndObjectSpaceHierarchy();
+
+	void StartBvhLeafObjects(ObjectContainer &objects, const char *ptr);
+
+	// -----------------------------------------------------------------------
+	//  Handlers for the SAX ErrorHandler interface
+	// -----------------------------------------------------------------------
+
+	void warning(const SAXParseException& exc);
+	void error(const SAXParseException& exc);
+	void fatalError(const SAXParseException& exc);
+
+
 private:
-  // -----------------------------------------------------------------------
-  //  Private data members
-  //
-  //  fAttrCount
-  //  fCharacterCount
-  //  fElementCount
-  //  fSpaceCount
-  //      These are just counters that are run upwards based on the input
-  //      from the document handlers.
-  // -----------------------------------------------------------------------
-  unsigned int    mAttrCount;
-  unsigned int    mCharacterCount;
-  unsigned int    mElementCount;
-  unsigned int    mSpaceCount;
+	// -----------------------------------------------------------------------
+	//  Private data members
+	//
+	//  fAttrCount
+	//  fCharacterCount
+	//  fElementCount
+	//  fSpaceCount
+	//      These are just counters that are run upwards based on the input
+	//      from the document handlers.
+	// -----------------------------------------------------------------------
+	unsigned int    mAttrCount;
+	unsigned int    mCharacterCount;
+	unsigned int    mElementCount;
+	unsigned int    mSpaceCount;
 };
 
@@ -146,34 +131,34 @@
 {
 public :
-  // -----------------------------------------------------------------------
-  //  Constructors and Destructor
-  // -----------------------------------------------------------------------
-  StrX(const XMLCh* const toTranscode)
-  {
-	  // Call the private transcoding method
-	  mLocalForm = XMLString::transcode(toTranscode);
-  }
-  
-  ~StrX()
-  {
-	  XMLString::release(&mLocalForm);
-  }
-  
-  // -----------------------------------------------------------------------
-  //  Getter methods
-  // -----------------------------------------------------------------------
-  const char* LocalForm() const
-  {
-    return mLocalForm;
-  }
-  
+	// -----------------------------------------------------------------------
+	//  Constructors and Destructor
+	// -----------------------------------------------------------------------
+	StrX(const XMLCh* const toTranscode)
+	{
+		// Call the private transcoding method
+		mLocalForm = XMLString::transcode(toTranscode);
+	}
+
+	~StrX()
+	{
+		XMLString::release(&mLocalForm);
+	}
+
+	// -----------------------------------------------------------------------
+	//  Getter methods
+	// -----------------------------------------------------------------------
+	const char* LocalForm() const
+	{
+		return mLocalForm;
+	}
+
 private :
-  // -----------------------------------------------------------------------
-  //  Private data members
-  //
-  //  fLocalForm
-  //      This is the local code page form of the string.
-  // -----------------------------------------------------------------------
-  char*   mLocalForm;
+	// -----------------------------------------------------------------------
+	//  Private data members
+	//
+	//  fLocalForm
+	//      This is the local code page form of the string.
+	// -----------------------------------------------------------------------
+	char*   mLocalForm;
 };
 
@@ -181,6 +166,6 @@
 operator<<(XERCES_STD_QUALIFIER ostream& target, const StrX& toDump)
 {
-  target << toDump.LocalForm();
-  return target;
+	target << toDump.LocalForm();
+	return target;
 }
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 2114)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 2115)
@@ -1,4 +1,4 @@
-#ifndef _X3D_PARSER_XERCES__H
-#define _X3D_PARSER_XERCES__H
+#ifndef _VIEWCELLS_PARSER_XERCES__H
+#define _VIEWCELLS_PARSER_XERCES__H
 
 // ---------------------------------------------------------------------------
@@ -74,8 +74,5 @@
   void resetDocument();
 
-  void CreateViewCellsManager(/*const char *name*/);
-
-  void ReplacePvs();
-  void ReplaceBvhPvs(ViewCell *vc);
+  void CreateViewCellsManager();
 
 
@@ -109,7 +106,5 @@
 
   ObjectContainer &mPvsObjects;
-  ObjectContainer &mPreprocessorObjects;
-
-  bool mCreatePvsObjects;
+  const ObjectContainer &mPreprocessorObjects;
 
   BoundingBoxConverter *mBoundingBoxConverter;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp	(revision 2114)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp	(revision 2115)
@@ -13,4 +13,5 @@
 //  Includes
 // ---------------------------------------------------------------------------
+
 #include <xercesc/framework/StdInInputSource.hpp>
 #include <xercesc/parsers/SAXParser.hpp>
@@ -20,21 +21,16 @@
 //  Includes
 // ---------------------------------------------------------------------------
+
 #include <xercesc/sax/AttributeList.hpp>
 #include <xercesc/sax/SAXParseException.hpp>
 #include <xercesc/sax/SAXException.hpp>
 
-#include "ViewCellsParser.h"
-
-#include "ViewCellsParserXerces.h"
+#include "ObjectsParser.h"
+
+#include "ObjectsParserXerces.h"
 #include "Mesh.h"
-#include "VspBspTree.h"
-#include "ViewCellBsp.h"
 #include "ViewCellsManager.h"
 #include "GzFileInputSource.h"
-#include "OspTree.h"
-#include "VspTree.h"
-#include "KdTree.h"
 #include "BvHierarchy.h"
-#include "HierarchyManager.h"
 
 
@@ -61,4 +57,5 @@
 //      can be set via the -v= command.
 // ---------------------------------------------------------------------------
+
 static bool     doNamespaces       = false;
 static bool     doSchema           = false;
@@ -66,6 +63,4 @@
 static SAXParser::ValSchemes    valScheme       = SAXParser::Val_Auto;
 
-// hack for loading bvh nodes
-#define PVS_HACK 0
 
 inline static bool ilt(Intersectable *obj1, Intersectable *obj2)
@@ -78,31 +73,16 @@
 //  StdInParseHandlers: Constructors and Destructor
 // ---------------------------------------------------------------------------
-ViewCellsParseHandlers::ViewCellsParseHandlers(ObjectContainer &pvsObjects, 
-											   ObjectContainer &preprocessorObjects,
-											   BoundingBoxConverter *bconverter
-											   ):
+
+ObjectsParseHandlers::ObjectsParseHandlers(ObjectContainer &pvsObjects, 
+										   const ObjectContainer &preprocessorObjects
+										   ):
   mElementCount(0)
   , mAttrCount(0)
   , mCharacterCount(0)
   , mSpaceCount(0)
-  , mViewCellsManager(NULL)
-  , mVspBspTree(NULL)
-  , mBspTree(NULL)
-  , mViewCellsTree(NULL)
-  , mCurrentState(PARSE_OPTIONS)
-  , mCurrentViewCell(NULL)
-  , mCurrentBspNode(NULL)
-  , mCurrentVspNode(NULL)
-  , mCurrentOspNode(NULL)
-  , mCurrentBvhNode(NULL)
   , mPvsObjects(pvsObjects)
   , mPreprocessorObjects(preprocessorObjects)
-  , mBoundingBoxConverter(bconverter)
-  , mHierarchyManager(NULL)
-  , nViewCells(0)
-  , nObjects(0)
-{
-	mCreatePvsObjects = mPvsObjects.empty();
-
+  , mIsObjectSpaceHierarchy(false)
+{
 	// sort objects so we can search in them
 	//if (!is_sorted(mPvsObjects.begin(), mPvsObjects.end(), ilt))
@@ -110,9 +90,9 @@
 
 	//if (!is_sorted(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt))
-		sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt);
-}
-
-
-ViewCellsParseHandlers::~ViewCellsParseHandlers()
+		//sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt);
+}
+
+
+ObjectsParseHandlers::~ObjectsParseHandlers()
 {
 }
@@ -124,146 +104,19 @@
 
 
-void ViewCellsParseHandlers::endElement(const XMLCh* const name)
+void ObjectsParseHandlers::endElement(const XMLCh* const name)
 {
 	StrX lname(name);
 	string element(lname.LocalForm());
 
-	if (element == "BoundingBoxes")
-	{
-		EndBoundingBoxes();
-	}
-
-	if (element == "ViewCells")
-	{	
-		EndViewCells();
-	}
-
 	if (element == "ObjectSpaceHierarchy")
 	{
 		EndObjectSpaceHierarchy();
 	}
-
-	// finished, create view cells manager
-	if (element == "VisibilitySolution")
-	{
-		CreateViewCellsManager();
-	}
-
-	if (element == "Interior")
-	{
-		switch (mCurrentState)
-		{
-		case PARSE_VIEWCELLS:
-			EndViewCellInterior();
-			break;
-		case PARSE_OBJECTSPACE_HIERARCHY:
-			EndObjectSpaceHierarchyInterior();
-			break;
-		case PARSE_VIEWSPACE_HIERARCHY:	
-			EndViewSpaceHierarchyInterior();
-			break;
-		default:
-			break;
-		}
-	}
-}
-
-
-void ViewCellsParseHandlers::EndObjectSpaceHierarchy()
-{
-	if (mObjectSpaceHierarchyType == OSP)
-	{
-		// for a spatial subdivision, it is not necessary to store
-		// the objects with the leaves, they can be classified geometrically
-		mHierarchyManager->mOspTree->
-			InsertObjects(mHierarchyManager->mOspTree->mRoot, mPvsObjects);
-	}
-}
-
-
-void ViewCellsParseHandlers::EndViewSpaceHierarchyInterior()
-{
-	switch (mViewSpaceHierarchyType)
-	{
-	case BSP:
-		EndBspInterior();
-		break;
-	case VSP:
-		EndVspInterior();
-		break;	
-	default:
-		Debug << "not implemented view space hierarchy type " << mViewSpaceHierarchyType << endl;
-		break;
-	}
-}
-
-
-void ViewCellsParseHandlers::EndObjectSpaceHierarchyInterior()
-{
-	switch (mObjectSpaceHierarchyType)
-	{
-	case OSP:
-		EndOspInterior();
-		break;
-	case BVH:
-		EndBvhInterior();
-		break;	
-	default:
-		Debug << "not implemented object space hierarchy type " << mViewSpaceHierarchyType << endl;
-		break;
-	}
-}
-
-
-void ViewCellsParseHandlers::EndBspInterior()
-{
-	// go one up in the tree
-	if (mCurrentBspNode->GetParent())
-	{	//cout << "]";
-		mCurrentBspNode = mCurrentBspNode->GetParent();
-	}
-}
-
-
-void ViewCellsParseHandlers::EndBvhInterior()
-{
-	// go one up in the tree
-	if (mCurrentBvhNode->GetParent())
-	{	//cout << "]";
-		mCurrentBvhNode = mCurrentBvhNode->GetParent();
-	}
-}
-
-
-void ViewCellsParseHandlers::EndOspInterior()
-{
-	// go one up in the tree
-	if (mCurrentOspNode->mParent)
-	{	
-		//cout << "]";
-		mCurrentOspNode = mCurrentOspNode->mParent;
-	}
-}
-
-
-void ViewCellsParseHandlers::EndVspInterior()
-{
-	// go one up in the tree
-	if (mCurrentVspNode->GetParent())
-	{	
-		//cout << "]";
-		mCurrentVspNode = mCurrentVspNode->GetParent();
-	}
-}
-
-
-void ViewCellsParseHandlers::EndViewCellInterior()
-{
-	// go one up in the tree
-	if (mCurrentViewCell->GetParent())
-	{	
-		//cout << "]";
-		mCurrentViewCell = mCurrentViewCell->GetParent();
-	}
+}
+
+
+void ObjectsParseHandlers::EndObjectSpaceHierarchy()
+{
+	mIsObjectSpaceHierarchy = false;
 }
 
@@ -275,89 +128,7 @@
 
 
-void ViewCellsParseHandlers::EndViewCells()
-{
-	// sort view cells to help associating view cells according to their id
-	stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
-
-	// not parsing view cells anymore
-	mCurrentState = PARSE_OPTIONS;
-}
-
-
-void ViewCellsParseHandlers::EndBoundingBoxes()
-{
-	// all bounding boxes gathered in this step => 
-	// associate object ids with bounding boxes
-	const long startTime = GetTime();
-	
-	if (mBoundingBoxConverter)
-	{
-		mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, mPvsObjects);
-	}
-
-	Debug << "\nconverted bounding boxes to objects in "
-		  << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-}
-
-
-void ViewCellsParseHandlers::StartBspElement(string element,
-											 AttributeList& attributes)
-{
-	if (element == "Interior") 
-	{
-		//cout << "[";
-		StartBspInterior(attributes);
-	}
-
-	if (element == "Leaf") 
-	{
-		//cout << "l";
-		StartBspLeaf(attributes);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartVspElement(string element,
-											 AttributeList& attributes)
-{
-	if (element == "Interior") 
-	{
-		//cout << "[";
-		StartVspInterior(attributes);
-	}
-	if (element == "Leaf") 
-	{
-		//cout << "l";
-		StartVspLeaf(attributes);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartOspElement(string element,
-											 AttributeList& attributes)
-{
-	if (element == "Interior") 
-	{
-		//cout << "[";
-		StartOspInterior(attributes);
-	}
-
-	if (element == "Leaf") 
-	{
-		//cout << "l";
-		StartOspLeaf(attributes);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartBvhElement(string element,
-											 AttributeList& attributes)
-{
-	if (element == "Interior") 
-	{
-		//cout << "[";
-		StartBvhInterior(attributes);
-	}
-
+void ObjectsParseHandlers::StartBvhElement(string element,
+										   AttributeList& attributes)
+{
 	if (element == "Leaf") 
 	{
@@ -368,152 +139,18 @@
 
 
-void ViewCellsParseHandlers::StartViewSpaceHierarchyElement(const std::string &element,
+void ObjectsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element,
 															AttributeList& attributes)
 {
 	//-- use cell type according to the chosen method
-	switch (mViewSpaceHierarchyType)
-	{
-	case BSP:
-		StartBspElement(element, attributes);
-		break;
-	case VSP:
-		StartVspElement(element, attributes);
-		break;
-	default:
-		Debug << "not implemented" << endl;
-		break;
-	}
-}
-
-
-void ViewCellsParseHandlers::StartObjectSpaceHierarchyElement(const std::string &element,
-															  AttributeList& attributes)
-{
-	//-- use cell type according to the chosen method
-	switch (mObjectSpaceHierarchyType)
-	{
-		case OSP:
-			StartOspElement(element, attributes);
-			break;
-		case BVH:
-			StartBvhElement(element, attributes);
-			break;
-		default:
-			Debug << "not implemented" << endl;
-			break;
-	}
-}
-
-
-void ViewCellsParseHandlers::ReplaceBvhPvs(ViewCell *vc)
-{
-	//cout << "exchanging pvs" << endl;
-	ObjectPvs newPvs;
-
-	ObjectPvsIterator pit = vc->GetPvs().GetIterator();
-
-	BvhLeaf *dummyInst = new BvhLeaf(AxisAlignedBox3());
-
-	ObjectContainer oldIntersectables;
-
-	// output PVS of view cell
-	while (pit.HasMoreEntries())
-	{		
-		ObjectPvsEntry entry = pit.Next();
-
-		Intersectable *intersect = entry.mObject;
-		oldIntersectables.push_back(intersect);
-
-		DummyIntersectable *dummyIntersect = static_cast<DummyIntersectable *>(intersect);
-
-		const int objId = dummyIntersect->GetItem();	
-		dummyInst->SetId(objId);
-
-		vector<BvhLeaf *>::iterator oit =
-			lower_bound(mBvhLeaves.begin(), 
-						mBvhLeaves.end(), 
-						dummyInst, ilt);	
-
-		if ((oit != mBvhLeaves.end()) && ((*oit)->GetId() == objId))
-		{
-			// $$JB we should store a float a per object which corresponds
-			// to sumof pdfs, i.e. its relative visibility
-			// temporarily set to 1.0f
-			//cout << (*oit)->GetId() << " ";
-			
-			newPvs.AddSample(*oit, 1.0f);
-		}
-		else
-		{
-			Debug << "exchangePvs error: object with id " << objId << " does not exist" << endl;
-		}
-	}
-
-	//newPvs.SimpleSort();
-	delete dummyInst;
-	vc->SetPvs(newPvs);
-
-	CLEAR_CONTAINER(oldIntersectables);
-}
-
-
-void ViewCellsParseHandlers::ReplacePvs()
-{
-	ViewCellContainer::const_iterator vit, vit_end = mViewCells.end();
-	
-	sort(mBvhLeaves.begin(), mBvhLeaves.end(), ilt);
-
-	//cout << "viewcells : " << mViewCells.size() << endl;
-	for (vit = mViewCells.begin(); vit != vit_end; ++ vit)
-	{
-		ReplaceBvhPvs(*vit);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element,
-														   AttributeList& attributes)
-{
-	// interiors + leaves interpreted view cells else
-	if (element == "Interior") 
-	{
-		//cout << "[";
-		StartViewCell(attributes, false);
-	}
-
-	if (element == "Leaf") 
-	{
-		//cout << "l";
-		StartViewCell(attributes, true);
-	}
-}
-
-
-void ViewCellsParseHandlers::startElement(const XMLCh* const name,
-										  AttributeList& attributes)
+	StartBvhElement(element, attributes);
+}
+
+
+void ObjectsParseHandlers::startElement(const XMLCh* const name,
+										AttributeList& attributes)
 {
 	StrX lname(name);
 	string element(lname.LocalForm());
 
-	if (element == "ViewCells")
-	{
-		cout << "\nparsing view cells" << endl;
-		Debug << "\nparsing view cells" << endl;
-		
-		mCurrentState = PARSE_VIEWCELLS;
-
-		// create new view cells hierarchy
-		mViewCellsTree = new ViewCellsTree();
-	}
-
-	// decides about the view cell hierarchy
-	if (element == "ViewSpaceHierarchy")
-	{		
-		Debug << "\nparsing view space hierarchy" << endl;
-		cout << "\nparsing view space hierarchy" << endl;
-		mCurrentState = PARSE_VIEWSPACE_HIERARCHY;
-		StartViewSpaceHierarchy(attributes);
-	}
-
 	// decides about the view cell hierarchy
 	if (element == "ObjectSpaceHierarchy")
@@ -522,37 +159,13 @@
 		Debug << "\nparsing object space hierarchy" << endl;
 
-		mCurrentState = PARSE_OBJECTSPACE_HIERARCHY;
-		StartObjectSpaceHierarchy(attributes);
+		mIsObjectSpaceHierarchy = true;
 	}
 	
-	// decides the used view cell hierarchy
-	if (element == "BoundingBox")
-	{
-		// cout << "b";
-		StartBoundingBox(attributes);
-	}
-
 	// parse view space hierarchy
-	switch (mCurrentState)
-	{
-	case PARSE_VIEWSPACE_HIERARCHY:
-		if ((++ nViewCells % 1000) == 0)
-			cout<<"\r"<<nViewCells<<" view cells parsed\r";
-		
-		StartViewSpaceHierarchyElement(element, attributes);
-		break;
-	case PARSE_OBJECTSPACE_HIERARCHY:
-		if ((++ nObjects % 1000) == 0)
-		 cout<<"\r"<< nObjects <<" objects parsed\r";
-		
+	if (mIsObjectSpaceHierarchy)
+	{
 		StartObjectSpaceHierarchyElement(element, attributes);
-		break;
-	case PARSE_VIEWCELLS:
-		StartViewCellHierarchyElement(element, attributes);
-		break;
-	default:
-		break;
-	}
-	
+	}
+
 	++ mElementCount;
 	mAttrCount += attributes.getLength();
@@ -560,791 +173,97 @@
 
 
-void ViewCellsParseHandlers::StartViewCellPvs(ObjectPvs &pvs, const char *ptr)
-{
-	// handle obect indices
+
+void ObjectsParseHandlers::characters(const XMLCh* const chars,
+										const unsigned int length)
+{
+	mCharacterCount += length;
+}
+
+
+void ObjectsParseHandlers::ignorableWhitespace(const XMLCh* const chars,
+												 const unsigned int length)
+{
+	mSpaceCount += length;
+}
+
+
+void ObjectsParseHandlers::resetDocument()
+{
+	mAttrCount = 0;
+	mCharacterCount = 0;
+	mElementCount = 0;
+	mSpaceCount = 0;
+}
+
+void ObjectsParseHandlers::StartBvhLeaf(AttributeList& attributes)
+{
+	const int len = attributes.getLength();
+	Vector3 minBox, maxBox;
+
+	ObjectContainer objects;
+
+	for (int i = 0; i < len; ++ i) 
+	{
+		string attrName(StrX(attributes.getName(i)).LocalForm());
+		StrX attrValue(attributes.getValue(i));
+		const char *ptr = attrValue.LocalForm();
+
+		if (attrName == "min") 
+		{
+			sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z);
+		}
+		if (attrName == "max") 
+		{
+			sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z);
+		}
+		/*if (attrName == "objects")
+		{
+			StartBvhLeafObjects(objects, ptr);
+		}*/
+	}
+
+	AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox);
+
+	BvhLeaf *leaf = new BvhLeaf(box, NULL, (int)objects.size());
+
+	//leaf->mObjects = objects;
+	//BvHierarchy::AssociateObjectsWithLeaf(leaf);
+
+	// new pvs object
+	mPvsObjects.push_back(leaf);
+}
+
+
+void ObjectsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects,
+											   const char *ptr)
+{
 	vector<int> objIndices;
 	char *endptr;
 			
 	while (1)
-	{	// read object ids
+	{
 		const int index = strtol(ptr, &endptr, 10);
-		if (ptr == endptr) 
-			break;
+		if (ptr == endptr) break;
+
 		objIndices.push_back(index);
 		ptr = endptr;
 	}
 
-	// TODO: 
-	// 1) find objects and add them to pvs
-	// 2) get view cell with specified id
 	MeshInstance dummyInst(NULL);
 
 	vector<int>::const_iterator it, it_end = objIndices.end();
+
 	for (it = objIndices.begin(); it != it_end; ++ it)
 	{
-#if PVS_HACK
-		//cout << "u";
-		pvs.AddSample(new DummyIntersectable(*it), 1);
-#else
 		const int objId = *it;	
 		dummyInst.SetId(objId);
 
-		ObjectContainer::iterator oit =	
-								lower_bound(mPvsObjects.begin(), 
-											mPvsObjects.end(), 
-											(Intersectable *)&dummyInst, ilt);	
-
-		if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId))
-		{
-			// $$JB we should store a float a per object which corresponds
-			// to sumof pdfs, i.e. its relative visibility
-			// temporarily set to 1.0f
-			pvs.AddSample(*oit, 1.0f);
-			//Debug << "y";
-		}
-		else
-		{
-			Debug << "x";
-			//Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl;
-		}
-#endif
-	}
-}
-
-
-void ViewCellsParseHandlers::StartViewSpaceHierarchy(AttributeList& attributes)
-{
-	int len = attributes.getLength();
-
-	Vector3 bmin, bmax;
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		// hierarchy type
-		if (attrName == "type")
-		{
-			if (strcmp(ptr, "bsp") == 0)
-			{
-				Debug << "\nview space hierarchy: Bsp" << endl;
-				mViewSpaceHierarchyType = BSP;
-			}
-			else if (strcmp(ptr, "vsp") == 0)
-			{
-				Debug << "\nview space hierarchy: Vsp" << endl;
-				mViewSpaceHierarchyType = VSP;
-			}
-		}
-		else if (attrName == "min") // the view space extent
-		{
-			sscanf(ptr, "%f %f %f",
-				   &bmin.x, &bmin.y, &bmin.z);
-		}
-		else if (attrName == "max") 
-		{
-			sscanf(ptr, "%f %f %f",
-				   &bmax.x, &bmax.y, &bmax.z);
-		}
-	}
-
-	mViewSpaceBox = AxisAlignedBox3(bmin, bmax);
-
-	// create the hierarchy based on this information
-	CreateViewSpaceHierarchy();
-}
-
-
-void ViewCellsParseHandlers::StartObjectSpaceHierarchy(AttributeList& attributes)
-{
-	const int len = attributes.getLength();
-	Vector3 bmin, bmax;
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		// hierarchy type
-		if (attrName == "type")
-		{
-			if (strcmp(ptr, "osp") == 0)
-			{
-				Debug << "\nobject space hierarchy: Osp" << endl;
-
-				mHierarchyManager = 
-					new HierarchyManager(HierarchyManager::KD_BASED_OBJ_SUBDIV);
-
-				DEL_PTR(mHierarchyManager->mVspTree);
-				mHierarchyManager->mVspTree = mVspTree;
-
-				mObjectSpaceHierarchyType = OSP;
-
-				//std::stable_sort(objects.begin(), objects.end(), ilt);
-				mHierarchyManager->mOspTree->mBoundingBox.Initialize();
-				ObjectContainer::const_iterator oit, oit_end = mPvsObjects.end();
-				
-				//-- compute bounding box
-				for (oit = mPvsObjects.begin(); oit != oit_end; ++ oit)
-				{
-					Intersectable *obj = *oit;
-					// compute bounding box of view space
-					mHierarchyManager->mOspTree->mBoundingBox.Include(obj->GetBox());
-				}
-			}
-			else if (strcmp(ptr, "bvh") == 0)
-			{
-				Debug << "\nobject space hierarchy: Bvh" << endl;
-				mObjectSpaceHierarchyType = BVH;
-				mHierarchyManager = 
-					new HierarchyManager(HierarchyManager::BV_BASED_OBJ_SUBDIV);
-
-				DEL_PTR(mHierarchyManager->mVspTree);
-				mHierarchyManager->mVspTree = mVspTree;
-			}
-		}
-	}
-}
-
-
-void ViewCellsParseHandlers::StartBoundingBox(AttributeList& attributes)
-{
-	int len = attributes.getLength();
-
-	Vector3 bmin, bmax;
-	int id;
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		if (attrName == "id")
-		{
-			sscanf(ptr, "%d", &id);
-		}
-		if (attrName == "min") 
-		{
-			sscanf(ptr, "%f %f %f", &bmin.x, &bmin.y, &bmin.z);
-		}
-		else if (attrName == "max") 
-		{
-			sscanf(ptr, "%f %f %f", &bmax.x, &bmax.y, &bmax.z);
-		}
-	}
-
-	AxisAlignedBox3 box(bmin, bmax);
-	mIBoundingBoxes.push_back(IndexedBoundingBox(id, box));
-	//Debug << "bbox: " << box << endl;
-}
-
-
-void ViewCellsParseHandlers::StartBspLeaf(AttributeList& attributes)
-{
-	BspLeaf * leaf;
-
-	if (mCurrentBspNode) // replace front or (if not NULL) back child
-	{
-		BspInterior *interior = static_cast<BspInterior *>(mCurrentBspNode);
-
-		leaf = new BspLeaf(interior);
-		interior->ReplaceChildLink(NULL, leaf);
-	}
-	else
-	{
-		leaf = new BspLeaf();
-		mVspBspTree->mRoot = leaf;
-	}
-
-	///////////
-	//-- find associated view cell
-
-	int viewCellId;
-	const int len = attributes.getLength();
-	  
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-
-		const char *ptr = attrValue.LocalForm();
-		char *endptr = NULL;
-
-		if (attrName == "viewCellId") 
-		{
-			viewCellId = strtol(ptr, &endptr, 10);
-		}
-	}
-	
-	if (viewCellId >= 0) // valid view cell found
-	{
-		// TODO: get view cell with specified id
-		ViewCellInterior dummyVc;
-		dummyVc.SetId(viewCellId);
-
-		ViewCellContainer::iterator vit =
-			lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
-		
-		//ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
-//		BspViewCell *viewCell = static_cast<BspViewCell *>((*vit).second);
-
-		BspViewCell *viewCell = static_cast<BspViewCell *>(*vit);
-		if (viewCell->GetId() == viewCellId)
-		{
-			// create new view cell for bsp nodes
-			leaf->SetViewCell(viewCell);
-			viewCell->mLeaves.push_back(leaf);
-		}
-		else
-		{
-			cerr << "error: view cell does not exist" << endl;
-		}
-	}
-	else
-	{
-		// add to invalid view space
-		leaf->SetViewCell(mVspBspTree->GetOrCreateOutOfBoundsCell());
-		leaf->SetTreeValid(false);
-		mVspBspTree->PropagateUpValidity(leaf);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartBspInterior(AttributeList& attributes)
-{
-	Plane3 plane;
-	int len = attributes.getLength();
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		if (attrName == "plane") 
-		{
-			sscanf(ptr, "%f %f %f %f",
-				   &plane.mNormal.x, &plane.mNormal.y, &plane.mNormal.z, &plane.mD);
-		}
-	}
-
-	BspInterior* interior = new BspInterior(plane);
-	
-	if (mCurrentBspNode) // replace NULL child of parent with current node
-	{
-		BspInterior *parent = static_cast<BspInterior *>(mCurrentBspNode);
-
-		parent->ReplaceChildLink(NULL, interior);
-		interior->SetParent(parent);
-	}
-	else
-	{
-		mVspBspTree->mRoot = interior;
-	}
-
-	mCurrentBspNode = interior;
-}
-
-
-void ViewCellsParseHandlers::StartViewCell(AttributeList& attributes, const bool isLeaf)
-{
-	ViewCell *viewCell = NULL;
-	
-	const int len = attributes.getLength();
-	float mergeCost;
-	
-	if (isLeaf)
-	{
-		viewCell = new ViewCellLeaf();
-	}
-	else
-	{
-		viewCell = new ViewCellInterior();
-	}
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		const string attrName(StrX(attributes.getName(i)).LocalForm());
-	
-		if (attrName == "id") 
-		{
-			const StrX attrValue(attributes.getValue(i));
-			const char *ptr = attrValue.LocalForm();
-			char *endptr = NULL;
-			const int id = strtol(ptr, &endptr, 10);
-
-			// create new view cell, otherwise use reference.
-			viewCell->SetId(id);
-
-			if (mCurrentViewCell) // replace front or (if not NULL) back child
-			{	
-				ViewCellInterior *interior = 
-					static_cast<ViewCellInterior *>(mCurrentViewCell);
-				interior->SetupChildLink(viewCell);
-			}
-			else 
-			{	// set the new root
-				mViewCellsTree->SetRoot(viewCell);
-			}
-			
-			if (!isLeaf)
-			{
-				mCurrentViewCell = viewCell;
-			}
-		}
-		if (attrName == "pvs") 
-		{
-			StrX attrValue(attributes.getValue(i));
-			const char *ptr = attrValue.LocalForm();
-
-			// note: id must come before pvs! 
-			// otherwise view cell is undefined
-
-			// hack: assume that view cell comes before pvs
-			StartViewCellPvs(viewCell->GetPvs(), ptr); 
-			//StartViewCellPvs(pvs, ptr);
-		}
-		else if (attrName == "active")
-		{
-			StrX attrValue(attributes.getValue(i));
-			const char *ptr = attrValue.LocalForm();
-			char *endptr = NULL;
-			const bool isActive = (bool)strtol(ptr, &endptr, 10);
-
-			if (isActive)
-			{
-				// TODO
-			}
-		}
-		else if (attrName == "mergecost")
-		{
-			StrX attrValue(attributes.getValue(i));
-			
-			const char *ptr = attrValue.LocalForm();
-			char *endptr = NULL;
-			mergeCost = (float)strtod(ptr, &endptr);
-		}
-	}
-
-	viewCell->SetMergeCost(mergeCost);
-	//viewCell->SetPvs(pvs);
-	mViewCells.push_back(viewCell);
-}
-
-
-void ViewCellsParseHandlers::CreateViewSpaceHierarchy()
-{
-	if (mViewSpaceHierarchyType == BSP)
-	{
-		Debug << "hierarchy type: Bsp" << endl;
-		mVspBspTree = new VspBspTree();
-
-		// set view space box
-		mVspBspTree->mBoundingBox = mViewSpaceBox;
-
-		//ViewCellsMap::iterator vit, vit_end = mViewCells.end();
-		ViewCellContainer::iterator vit, vit_end = mViewCells.end();
-
-		int i = 0;
-		// remove view cells and exchange them with the 
-		// view cells specialized for the current hierarchy node type
-		for (vit = mViewCells.begin(); vit != vit_end; ++ vit, ++ i)
-		{
-			//if ((i % 1000) == 0)
-			//	Debug << "\n exchanged " << i << " boxes" << endl;
-			ViewCell *vc = (*vit);
-
-			if (!vc->IsLeaf()) // exchange only leaves
-				continue;
-		
-			BspViewCell *bspVc = new BspViewCell();
-
-			bspVc->SetId(vc->GetId());
-			//bspVc->GetPvs().reserve(vc->GetPvs().size());
-			bspVc->SetPvs(vc->GetPvs());
-
-			if (vc->IsRoot())
-			{
-				mViewCellsTree->mRoot = bspVc;
-			}
-			else
-			{
-                vc->GetParent()->ReplaceChildLink(vc, bspVc);
-			}
-
-			// delete old view cell
-			DEL_PTR(vc);
-
-//			(*vit).second = bspVc;
-			(*vit) = bspVc;
-		}
-		cout << "finished creating view space hierarchy" << endl;
-	}
-	else if (mViewSpaceHierarchyType == VSP) 
-	{
-		Debug << "hierarchy type: Vsp" << endl;
-		mVspTree = new VspTree();
-
-		// set view space box
-		mVspTree->mBoundingBox = mViewSpaceBox;
-
-		// ViewCellsMap::iterator vit, vit_end = mViewCells.end();
-		ViewCellContainer::iterator vit, vit_end = mViewCells.end();
-
-		// reset view cells using the current node type
-		for (vit = mViewCells.begin(); vit != vit_end; ++ vit)
-		{
-			//ViewCell *vc = (*vit).second;
-			ViewCell *vc = (*vit);
-			
-			if (!vc->IsLeaf()) // exchange only leaves
-				continue;
-
-			VspViewCell *vspVc = new VspViewCell();
-
-			vspVc->SetPvs(vc->GetPvs());
-			vspVc->SetId(vc->GetId());
-
-			if (vc->IsRoot())
-			{
-				mViewCellsTree->mRoot = vspVc;
-			}
-			else
-			{
-				vc->GetParent()->ReplaceChildLink(vc, vspVc);
-			}
-			
-			// exchange view cell with new one
-			DEL_PTR(vc);
-
-			//(*vit).second = vspVc;
-			(*vit) = vspVc;
-		}
-
-		if (mHierarchyManager)
-		{
-			// come here only if object space hierarchy already constructed
-			mHierarchyManager->mVspTree = mVspTree;
-			mVspTree->mHierarchyManager = mHierarchyManager;
-		}
-	}
-}
-
-
-void ViewCellsParseHandlers::CreateViewCellsManager()
-{
-	if (mViewSpaceHierarchyType == BSP)
-	{
-		Debug << "\ncreating view cells manager: VspBsp" << endl;
-		mViewCellsManager = new VspBspViewCellsManager(mViewCellsTree, mVspBspTree);
-	}
-	else if (mViewSpaceHierarchyType == VSP) 
-	{
-		Debug << "\ncreating view cells manager: VspOsp" << endl;
-		mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager);
-	}
-
-	mViewCellsManager->SetViewSpaceBox(mViewSpaceBox);
-}
-
-
-void ViewCellsParseHandlers::characters(const XMLCh* const chars,
-										const unsigned int length)
-{
-	mCharacterCount += length;
-}
-
-
-void ViewCellsParseHandlers::ignorableWhitespace(const XMLCh* const chars,
-												 const unsigned int length)
-{
-	mSpaceCount += length;
-}
-
-
-void ViewCellsParseHandlers::resetDocument()
-{
-	mAttrCount = 0;
-	mCharacterCount = 0;
-	mElementCount = 0;
-	mSpaceCount = 0;
-}
-
-
-void ViewCellsParseHandlers::StartVspLeaf(AttributeList& attributes)
-{
-	VspLeaf * leaf;
-		
-	if (mCurrentVspNode) // replace front or (if not NULL) back child
-	{
-		VspInterior *interior = static_cast<VspInterior *>(mCurrentVspNode);
-		leaf = new VspLeaf(interior);
-		interior->ReplaceChildLink(NULL, leaf);
-	}
-	else
-	{
-		leaf = new VspLeaf();
-		mVspTree->mRoot = leaf;
-	}
-
-	/////////////
-	//-- find view cell associated with the id
-
-	int viewCellId;
-	const int len = attributes.getLength();
-	  
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-
-		const char *ptr = attrValue.LocalForm();
-		char *endptr = NULL;
-
-		if (attrName == "viewCellId") 
-		{
-			viewCellId = strtol(ptr, &endptr, 10);
-		}
-	}
-	
-	if (viewCellId >= 0) // valid view cell found
-	{
-		// TODO: get view cell with specified id
-		ViewCellInterior dummyVc;
-		dummyVc.SetId(viewCellId);
-
-		ViewCellContainer::iterator vit =
-			lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
-		
-		//ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
-		if (vit == mViewCells.end())
-			Debug << "error: view cell " << viewCellId << " not found" << endl;
-	
-		//VspViewCell *viewCell = static_cast<VspViewCell *>((*vit).second);
-		VspViewCell *viewCell = static_cast<VspViewCell *>(*vit);
-		
-		if (viewCell->GetId() == viewCellId)
-		{
-			leaf->SetViewCell(viewCell);
-			viewCell->mLeaves.push_back(leaf);
-		}
-		else
-		{
-			Debug << "error: view cell does not exist" << endl;
-		}
-	}
-	else
-	{	
-		// add to invalid view space
-		leaf->SetViewCell(mVspTree->GetOrCreateOutOfBoundsCell());
-		leaf->SetTreeValid(false);
-		mVspTree->PropagateUpValidity(leaf);
-	}
-}
-
-
-void ViewCellsParseHandlers::StartVspInterior(AttributeList& attributes)
-{
-	AxisAlignedPlane plane;
-	const int len = attributes.getLength();
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		if (attrName == "plane") 
-		{
-			sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis);
-		}
-	}
-
-	VspInterior* interior = new VspInterior(plane);
-	
-	if (mCurrentVspNode) // replace NULL child of parent with current node
-	{
-		VspInterior *parent = static_cast<VspInterior *>(mCurrentVspNode);
-
-		parent->ReplaceChildLink(NULL, interior);
-		interior->SetParent(parent);
-		
-		AxisAlignedBox3 frontBox, backBox;
-
-		parent->GetBoundingBox().Split(
-			parent->GetPlane().mAxis, 
-			parent->GetPlane().mPosition, 
-			frontBox, 
-			backBox);
-
-		if (parent->GetFront() == interior)
-			interior->SetBoundingBox(frontBox);
-		else
-			interior->SetBoundingBox(backBox);
-	}
-	else
-	{
-		mVspTree->mRoot = interior;
-		interior->SetBoundingBox(mVspTree->GetBoundingBox());
-	}
-
-	mCurrentVspNode = interior;
-}
-
-
-void ViewCellsParseHandlers::StartOspInterior(AttributeList& attributes)
-{
-	AxisAlignedPlane plane;
-	int len = attributes.getLength();
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		if (attrName == "plane") 
-		{
-			sscanf(ptr, "%f %d", &plane.mPosition, &plane.mAxis);
-		}
-	}
-
-	KdInterior* interior = new KdInterior(NULL);
-	
-	interior->mAxis = plane.mAxis;
-	interior->mPosition = plane.mPosition;
-
-	if (mCurrentOspNode) // replace NULL child of parent with current node
-	{
-		KdInterior *parent = static_cast<KdInterior *>(mCurrentOspNode);
-		parent->ReplaceChildLink(NULL, interior);
-		interior->mParent = parent;
-
-		AxisAlignedBox3 frontBox, backBox;
-
-		parent->mBox.Split(parent->mAxis, parent->mPosition, frontBox, backBox);
-
-		if (parent->mFront == interior)
-			interior->mBox = frontBox;
-		else
-			interior->mBox = backBox;
-	}
-	else
-	{
-		mHierarchyManager->mOspTree->mRoot = interior;
-		interior->mBox = mHierarchyManager->mOspTree->mBoundingBox;
-	}
-
-	mCurrentOspNode = interior;
-}
-
-
-void ViewCellsParseHandlers::StartOspLeaf(AttributeList& attributes)
-{
-	KdLeaf * leaf = new KdLeaf(static_cast<KdInterior *>(mCurrentOspNode), NULL);
-
-	if (mCurrentOspNode)
-	{
-		 // replace front or (if not NULL) back child
-		static_cast<KdInterior *>(mCurrentOspNode)->ReplaceChildLink(NULL, leaf);
-	}
-	else
-	{
-		mHierarchyManager->mOspTree->mRoot = leaf;
-	}
-}
-
-
-void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes)
-{
-	const int len = attributes.getLength();
-	Vector3 minBox, maxBox;
-
-	ObjectContainer objects;
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		if (attrName == "min") 
-		{
-			sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z);
-		}
-		if (attrName == "max") 
-		{
-			sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z);
-		}
-		if (attrName == "objects")
-		{
-			StartBvhLeafObjects(objects, ptr);
-		}
-	}
-
-	AxisAlignedBox3 box = AxisAlignedBox3(minBox, maxBox);
-
-	BvhLeaf *leaf;
-
-	if (mCurrentBvhNode) // replace front or (if not NULL) back child
-	{
-		BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode);
-		leaf = new BvhLeaf(box, interior, (int)objects.size());
-		interior->ReplaceChildLink(NULL, leaf);
-	}
-	else
-	{
-		leaf = new BvhLeaf(box, NULL, (int)objects.size());
-		mHierarchyManager->mBvHierarchy->mRoot = leaf;
-	}
-
-	leaf->mObjects = objects;
-	BvHierarchy::AssociateObjectsWithLeaf(leaf);
-	
-	if (PVS_HACK)
-	{
-		if (0) // Temp matt: should already have right id
-			leaf->SetId((int)mBvhLeaves.size());
-		
-		mBvhLeaves.push_back(leaf);	
-	}
-}
-
-
-void ViewCellsParseHandlers::StartBvhLeafObjects(ObjectContainer &objects, 
-												 const char *ptr)
-{
-	vector<int> objIndices;
-	char *endptr;
-			
-	while (1)
-	{
-		const int index = strtol(ptr, &endptr, 10);
-		if (ptr == endptr) break;
-
-		objIndices.push_back(index);
-		ptr = endptr;
-	}
-
-	MeshInstance dummyInst(NULL);
-
-	vector<int>::const_iterator it, it_end = objIndices.end();
-
-	for (it = objIndices.begin(); it != it_end; ++ it)
-	{
-		const int objId = *it;	
-		dummyInst.SetId(objId);
-
-		ObjectContainer::iterator oit =
-			lower_bound(mPvsObjects.begin(), 
-						mPvsObjects.end(), 
+		ObjectContainer::const_iterator oit =
+			lower_bound(mPreprocessorObjects.begin(), 
+						mPreprocessorObjects.end(), 
 						(Intersectable *)&dummyInst, 
 						ilt);	
 							
-		if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId))
+		if ((oit != mPreprocessorObjects.end()) && ((*oit)->GetId() == objId))
 		{
 			objects.push_back(*oit);
@@ -1360,41 +279,4 @@
 
 
-void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes)
-{
-	const int len = attributes.getLength();
-	Vector3 minBox, maxBox;
-
-	for (int i = 0; i < len; ++ i) 
-	{
-		string attrName(StrX(attributes.getName(i)).LocalForm());
-		StrX attrValue(attributes.getValue(i));
-		const char *ptr = attrValue.LocalForm();
-
-		if (attrName == "min") 
-		{
-			sscanf(ptr, "%f %f %f", &minBox.x, &minBox.y, &minBox.z);
-		}
-		if (attrName == "max") 
-		{
-			sscanf(ptr, "%f %f %f", &maxBox.x, &maxBox.y, &maxBox.z);
-		}
-	}
-
-	BvhInterior* interior = new BvhInterior(AxisAlignedBox3(minBox, maxBox));
-
-	if (mCurrentBvhNode) // replace NULL child of parent with current node
-	{
-		BvhInterior *parent = static_cast<BvhInterior *>(mCurrentBvhNode);
-		parent->ReplaceChildLink(NULL, interior);
-		interior->SetParent(parent);
-	}
-	else
-	{
-		mHierarchyManager->mBvHierarchy->mRoot = interior;
-	}
-
-	mCurrentBvhNode = interior;
-}
-
 
 // ---------------------------------------------------------------------------
@@ -1404,5 +286,5 @@
 
 void
-ViewCellsParseHandlers::error(const SAXParseException& e)
+ObjectsParseHandlers::error(const SAXParseException& e)
 {
   XERCES_STD_QUALIFIER cerr << "\nError at (file " << StrX(e.getSystemId())
@@ -1413,5 +295,5 @@
 
 void
-ViewCellsParseHandlers::fatalError(const SAXParseException& e)
+ObjectsParseHandlers::fatalError(const SAXParseException& e)
 {
   XERCES_STD_QUALIFIER cerr << "\nFatal Error at (file " << StrX(e.getSystemId())
@@ -1422,5 +304,5 @@
 
 void
-ViewCellsParseHandlers::warning(const SAXParseException& e)
+ObjectsParseHandlers::warning(const SAXParseException& e)
 {
   XERCES_STD_QUALIFIER cerr << "\nWarning at (file " << StrX(e.getSystemId())
@@ -1431,118 +313,114 @@
 
 
-bool ViewCellsParser::ParseViewCellsFile(const string &filename, 
-										 ViewCellsManager **viewCells,
-										 ObjectContainer &pvsObjects,
-										 ObjectContainer &preprocessorObjects,
-										 BoundingBoxConverter *bconverter)
-{
-  // Initialize the XML4C system
-  try {
-    XMLPlatformUtils::Initialize();
-  }
-  
-  catch (const XMLException& toCatch)
-    {
-      XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
-				<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
-      return false;
-    }
-
-  //  cout<<"parsing started"<<endl<<flush;
-
-  //
-  //  Create a SAX parser object. Then, according to what we were told on
-  //  the command line, set the options.
-  //
-  SAXParser* parser = new SAXParser;
-  parser->setValidationScheme(valScheme);
-  parser->setDoNamespaces(doNamespaces);
-  parser->setDoSchema(doSchema);
-  parser->setValidationSchemaFullChecking(schemaFullChecking);
-  
-
-  //
-  //  Create our SAX handler object and install it on the parser, as the
-  //  document and error handler. We are responsible for cleaning them
-  //  up, but since its just stack based here, there's nothing special
-  //  to do.
-  //
-  ViewCellsParseHandlers handler(pvsObjects, preprocessorObjects, bconverter);
-  parser->setDocumentHandler(&handler);
-  parser->setErrorHandler(&handler);
-  
-  unsigned long duration;
-  int errorCount = 0;
-  // create a faux scope so that 'src' destructor is called before
-  // XMLPlatformUtils::Terminate
-  {
-    //
-    //  Kick off the parse and catch any exceptions. Create a standard
-    //  input input source and tell the parser to parse from that.
-    //
-    //    StdInInputSource src;
-    try
-	{
-	const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
+bool ObjectsParser::ParseObjects(const string &filename, 
+								 ObjectContainer &pvsObjects,
+								 const ObjectContainer &preprocessorObjects)
+{
+	// Initialize the XML4C system
+	try {
+		XMLPlatformUtils::Initialize();
+	}
+
+	catch (const XMLException& toCatch)
+	{
+		XERCES_STD_QUALIFIER cerr << "Error during initialization! Message:\n"
+			<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
+		return false;
+	}
+
+	//  cout<<"parsing started"<<endl<<flush;
+
+	//
+	//  Create a SAX parser object. Then, according to what we were told on
+	//  the command line, set the options.
+	//
+	SAXParser* parser = new SAXParser;
+	parser->setValidationScheme(valScheme);
+	parser->setDoNamespaces(doNamespaces);
+	parser->setDoSchema(doSchema);
+	parser->setValidationSchemaFullChecking(schemaFullChecking);
+
+
+	//
+	//  Create our SAX handler object and install it on the parser, as the
+	//  document and error handler. We are responsible for cleaning them
+	//  up, but since its just stack based here, there's nothing special
+	//  to do.
+	//
+	ObjectsParseHandlers handler(pvsObjects, preprocessorObjects);
+	parser->setDocumentHandler(&handler);
+	parser->setErrorHandler(&handler);
+
+	unsigned long duration;
+	int errorCount = 0;
+	// create a faux scope so that 'src' destructor is called before
+	// XMLPlatformUtils::Terminate
+	{
+		//
+		//  Kick off the parse and catch any exceptions. Create a standard
+		//  input input source and tell the parser to parse from that.
+		//
+		//    StdInInputSource src;
+		try
+		{
+			const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
 
 #if USE_GZLIB
-	XMLCh *myFilePath = XMLString::transcode(filename.c_str());
-	
-	GzFileInputSource isource(myFilePath);
-	parser->parse(isource);
+			XMLCh *myFilePath = XMLString::transcode(filename.c_str());
+
+			GzFileInputSource isource(myFilePath);
+			parser->parse(isource);
 #else
-	parser->parse(filename.c_str());
+			parser->parse(filename.c_str());
 
 #endif
 
-	if (1 && PVS_HACK)
-		handler.ReplacePvs();
-
-	const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
-	duration = endMillis - startMillis;
-	errorCount = parser->getErrorCount();
-      }
-    catch (const OutOfMemoryException&)
-      {
-	XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
-	errorCount = 2;
-	return false;
-      }
-    catch (const XMLException& e)
-      {
+			const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
+			duration = endMillis - startMillis;
+			errorCount = parser->getErrorCount();
+		}
+		catch (const OutOfMemoryException&)
+		{
+			XERCES_STD_QUALIFIER cerr << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
+			errorCount = 2;
+			return false;
+		}
+		catch (const XMLException& e)
+		{
 			XERCES_STD_QUALIFIER cerr << "\nError during parsing: \n"
-				  << StrX(e.getMessage())
-				  << "\n" << XERCES_STD_QUALIFIER endl;
+				<< StrX(e.getMessage())
+				<< "\n" << XERCES_STD_QUALIFIER endl;
 			errorCount = 1;
 			return false;
-      }
-
-    
-    // Print out the stats that we collected and time taken
-    if (!errorCount) {
-		XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms ("
+		}
+
+
+		// Print out the stats that we collected and time taken
+		if (!errorCount) 
+		{
+			XERCES_STD_QUALIFIER cerr << filename << ": " << duration << " ms ("
 				<< handler.GetElementCount() << " elems, "
 				<< handler.GetAttrCount() << " attrs, "
 				<< handler.GetSpaceCount() << " spaces, "
 				<< handler.GetCharacterCount() << " chars)" << XERCES_STD_QUALIFIER endl;
-    }
-  }
-
-  cout<<"parsed - will delete the parser"<<endl<<flush;
-  //
-  //  Delete the parser itself.  Must be done prior to calling Terminate, below.
-  //
-  delete parser;
-  
-  XMLPlatformUtils::Terminate();
-  
-  //-- assign new view cells manager
-  *viewCells = handler.mViewCellsManager;
-  
-  if (errorCount > 0)
-    return false;
-  else
-    return true;
-}
-
-}
+		}
+	}
+
+	cout << "parsed - will delete the parser" << endl << flush;
+	//
+	//  Delete the parser itself.  Must be done prior to calling Terminate, below.
+	//
+	delete parser;
+
+	XMLPlatformUtils::Terminate();
+
+	//-- assign new view cells manager
+	//*viewCells = handler.mViewCellsManager;
+
+	if (errorCount > 0)
+		return false;
+	else
+		return true;
+}
+
+}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2114)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2115)
@@ -103,7 +103,6 @@
   , nObjects(0)
 {
-	// pvs objects empty => have to create new ones
-	mCreatePvsObjects = mPvsObjects.empty();
-
+	// q: can we assume that the objects are sorted?
+	
 	// sort objects so we can search in them
 	//if (!is_sorted(mPvsObjects.begin(), mPvsObjects.end(), ilt))
@@ -111,5 +110,5 @@
 
 	//if (!is_sorted(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt))
-		sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt);
+	//	sort(mPreprocessorObjects.begin(), mPreprocessorObjects.end(), ilt);
 }
 
@@ -407,71 +406,4 @@
 
 
-void ViewCellsParseHandlers::ReplaceBvhPvs(ViewCell *vc)
-{
-	//cout << "exchanging pvs" << endl;
-	ObjectPvs newPvs;
-
-	ObjectPvsIterator pit = vc->GetPvs().GetIterator();
-
-	BvhLeaf *dummyInst = new BvhLeaf(AxisAlignedBox3());
-
-	ObjectContainer oldIntersectables;
-
-	// output PVS of view cell
-	while (pit.HasMoreEntries())
-	{		
-		ObjectPvsEntry entry = pit.Next();
-
-		Intersectable *intersect = entry.mObject;
-		oldIntersectables.push_back(intersect);
-
-		DummyIntersectable *dummyIntersect = static_cast<DummyIntersectable *>(intersect);
-
-		const int objId = dummyIntersect->GetItem();	
-		dummyInst->SetId(objId);
-
-		vector<BvhLeaf *>::iterator oit =
-			lower_bound(mBvhLeaves.begin(), 
-						mBvhLeaves.end(), 
-						dummyInst, ilt);	
-
-		if ((oit != mBvhLeaves.end()) && ((*oit)->GetId() == objId))
-		{
-			// $$JB we should store a float a per object which corresponds
-			// to sumof pdfs, i.e. its relative visibility
-			// temporarily set to 1.0f
-			//cout << (*oit)->GetId() << " ";
-			
-			newPvs.AddSample(*oit, 1.0f);
-		}
-		else
-		{
-			Debug << "exchangePvs error: object with id " << objId << " does not exist" << endl;
-		}
-	}
-
-	//newPvs.SimpleSort();
-	delete dummyInst;
-	vc->SetPvs(newPvs);
-
-	CLEAR_CONTAINER(oldIntersectables);
-}
-
-
-void ViewCellsParseHandlers::ReplacePvs()
-{
-	// sort the pvs entries
-	sort(mPvsObjects.begin(), mPvsObjects.end(), ilt);
-
-	ViewCellContainer::const_iterator vit, vit_end = mViewCells.end();
-	
-	//cout << "viewcells : " << mViewCells.size() << endl;
-	for (vit = mViewCells.begin(); vit != vit_end; ++ vit)
-	{
-		ReplaceBvhPvs(*vit);
-	}
-}
-
-
 void ViewCellsParseHandlers::StartViewCellHierarchyElement(const std::string &element,
 														   AttributeList& attributes)
@@ -513,5 +445,6 @@
 	{		
 		Debug << "\nparsing view space hierarchy" << endl;
-		cout << "\nparsing view space hierarchy" << endl;
+		cout  << "\nparsing view space hierarchy" << endl;
+
 		mCurrentState = PARSE_VIEWSPACE_HIERARCHY;
 		StartViewSpaceHierarchy(attributes);
@@ -521,5 +454,5 @@
 	if (element == "ObjectSpaceHierarchy")
 	{
-		cout << "\nparsing object space hierarchy" << endl;
+		cout  << "\nparsing object space hierarchy" << endl;
 		Debug << "\nparsing object space hierarchy" << endl;
 
@@ -540,5 +473,5 @@
 	case PARSE_VIEWSPACE_HIERARCHY:
 		if ((++ nViewCells % 1000) == 0)
-			cout<<"\r"<<nViewCells<<" view cells parsed\r";
+			cout << "\r" << nViewCells << " view cells parsed\r";
 		
 		StartViewSpaceHierarchyElement(element, attributes);
@@ -546,5 +479,5 @@
 	case PARSE_OBJECTSPACE_HIERARCHY:
 		if ((++ nObjects % 1000) == 0)
-		 cout<<"\r"<< nObjects <<" objects parsed\r";
+			cout <<"\r" << nObjects << " objects parsed\r";
 		
 		StartObjectSpaceHierarchyElement(element, attributes);
@@ -577,4 +510,5 @@
 	}
 
+#if 1
 	// TODO: 
 	// 1) find objects and add them to pvs
@@ -583,35 +517,58 @@
 
 	vector<int>::const_iterator it, it_end = objIndices.end();
+	
+	pair<ObjectContainer::const_iterator, ObjectContainer::const_iterator> result;
+
 	for (it = objIndices.begin(); it != it_end; ++ it)
 	{
-		if (mCreatePvsObjects)
-		{
-			// pvs entries will be created => just use dummy proxy
-			pvs.AddSample(new DummyIntersectable(*it), 1);
+		const int objId = *it;	
+		dummyInst.SetId(objId);
+
+		// equal indeces possible!
+		result = equal_range(mPvsObjects.begin(), 
+							 mPvsObjects.end(), 
+							 (Intersectable *)&dummyInst, 
+							 ilt);	
+
+		ObjectContainer::const_iterator eit = result.first;
+
+		for (; eit != result.second; ++ eit)
+		{
+			pvs.AddSample(*eit, 1.0f);
+		}
+	}
+
+#else
+
+	// TODO: 
+	// 1) find objects and add them to pvs
+	// 2) get view cell with specified id
+	MeshInstance dummyInst(NULL);
+
+	vector<int>::const_iterator it, it_end = objIndices.end();
+	for (it = objIndices.begin(); it != it_end; ++ it)
+	{
+		const int objId = *it;	
+		dummyInst.SetId(objId);
+
+		ObjectContainer::iterator oit =	
+							lower_bound(mPvsObjects.begin(), 
+										mPvsObjects.end(), 
+										(Intersectable *)&dummyInst, ilt);	
+
+		if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId))
+		{
+			// $$JB we should store a float a per object which corresponds
+			// to sumof pdfs, i.e. its relative visibility
+			// temporarily set to 1.0f
+			pvs.AddSample(*oit, 1.0f);
 		}
 		else
 		{
-			const int objId = *it;	
-			dummyInst.SetId(objId);
-
-			ObjectContainer::iterator oit =	
-								lower_bound(mPvsObjects.begin(), 
-											mPvsObjects.end(), 
-											(Intersectable *)&dummyInst, ilt);	
-
-			if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId))
-			{
-				// $$JB we should store a float a per object which corresponds
-				// to sumof pdfs, i.e. its relative visibility
-				// temporarily set to 1.0f
-				pvs.AddSample(*oit, 1.0f);
-			}
-			else
-			{
-				//Debug << "x";
-				//Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl;
-			}
-		}
-	}
+			Debug << "x";
+			//Debug << "StartViewCellPvs error: object with id " << objId << " does not exist" << endl;
+		}
+	}
+#endif
 }
 
@@ -1287,5 +1244,6 @@
 		if (attrName == "objects")
 		{
-			StartBvhLeafObjects(objects, ptr);
+			if (!mPreprocessorObjects.empty())
+				StartBvhLeafObjects(objects, ptr);
 		}
 	}
@@ -1298,4 +1256,5 @@
 	{
 		BvhInterior *interior = static_cast<BvhInterior *>(mCurrentBvhNode);
+
 		leaf = new BvhLeaf(box, interior, (int)objects.size());
 		interior->ReplaceChildLink(NULL, leaf);
@@ -1309,12 +1268,4 @@
 	leaf->mObjects = objects;
 	BvHierarchy::AssociateObjectsWithLeaf(leaf);
-	
-	if (mCreatePvsObjects)
-	{
-		// Temp matt: leaves should already have right id
-		if (0) leaf->SetId((int)mBvhLeaves.size());
-		
-		mPvsObjects.push_back(leaf);	
-	}
 }
 
@@ -1336,5 +1287,4 @@
 
 	MeshInstance dummyInst(NULL);
-
 	vector<int>::const_iterator it, it_end = objIndices.end();
 
@@ -1344,11 +1294,11 @@
 		dummyInst.SetId(objId);
 
-		ObjectContainer::iterator oit =
-			lower_bound(mPvsObjects.begin(), 
-						mPvsObjects.end(), 
+		ObjectContainer::const_iterator oit =
+			lower_bound(mPreprocessorObjects.begin(), 
+						mPreprocessorObjects.end(), 
 						(Intersectable *)&dummyInst, 
 						ilt);	
 							
-		if ((oit != mPvsObjects.end()) && ((*oit)->GetId() == objId))
+		if ((oit != mPreprocessorObjects.end()) && ((*oit)->GetId() == objId))
 		{
 			objects.push_back(*oit);
