Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 2097)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 2114)
@@ -1325,8 +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, false, &bconverter);
+		GtpVisibilityPreprocessor::ViewCellsManager::
+			LoadViewCells(filename, mObjects, dummys, false, &bconverter);
 
 	return (mViewCellsManager != NULL);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp	(revision 2067)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBvHierarchySceneManager.cpp	(revision 2114)
@@ -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, false, &bconverter);
+		LoadViewCells(filename, mObjects, dummys, false, &bconverter);
 
 	return (mViewCellsManager != NULL);
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2108)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 2114)
@@ -1459,9 +1459,9 @@
 	const bool finalizeViewCells = false;
 
-	mViewCellsManager = GtpVisibilityPreprocessor::
-		ViewCellsManager::LoadViewCells(filename, 
-										&mObjects, 
-										true, 
-										&bconverter);
+	GtpVisibilityPreprocessor::ObjectContainer dummys;
+	// load the view cells assigning the found objects to the pvss
+	mViewCellsManager = 
+		GtpVisibilityPreprocessor::ViewCellsManager::
+			LoadViewCells(filename, mObjects, dummys, false, &bconverter);
 	
 	Ogre::LogManager::getSingleton().logMessage("******** view cells loaded *********");
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h	(revision 2113)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h	(revision 2114)
@@ -12,8 +12,8 @@
 class Environment;
 
-class ViewCellsParser : public Parser
+class ViewCellsParser: public Parser
 {
 public:
-  ViewCellsParser():Parser() {}
+  ViewCellsParser(): Parser() {}
   
   bool ParseViewCellsFile(const string &filename, 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h	(revision 2113)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParserXerces.h	(revision 2114)
@@ -29,5 +29,5 @@
 
 
-class ViewCellsParseHandlers: public HandlerBase
+class ObjectsParseHandlers: public HandlerBase
 {
 public:
@@ -35,8 +35,8 @@
   //  Constructors and Destructor
   // -----------------------------------------------------------------------
-  ViewCellsParseHandlers(ObjectContainer &pvsObjects, 
+  ObjectsParseHandlers(ObjectContainer &pvsObjects, 
 						 ObjectContainer &preprocessorObjects, 
 						 BoundingBoxConverter *bconverter);
-  ~ViewCellsParseHandlers();
+  ~ObjectsParseHandlers();
   
   
@@ -74,58 +74,14 @@
   void resetDocument();
 
-  void CreateViewCellsManager(/*const char *name*/);
-
-  void ReplacePvs();
-  void ReplaceBvhPvs(ViewCell *vc);
-
-
   /////////////////////////
 
-  VspBspTree *mVspBspTree;
-  HierarchyManager *mHierarchyManager;
- 
-  BspTree *mBspTree;
-  ViewCellsTree *mViewCellsTree;
-  VspTree *mVspTree;
-
-  BspNode *mCurrentBspNode;
-  BvhNode *mCurrentBvhNode;
-  KdNode *mCurrentOspNode;
-  VspNode *mCurrentVspNode;
- 
-  ViewCell *mCurrentViewCell;
-    
-  BspNode *mBspRoot;
-  VspNode *mVspRoot;
-  ViewCell *mViewCellRoot;
-  
   int mUniqueObjectId;
   vector<BvhLeaf *> mBvhLeaves;
-  //typedef map<int, ViewCell *> ViewCellsMap;
-  //ViewCellsMap mViewCells;
-  ViewCellContainer mViewCells;
-
-  ViewCellsManager *mViewCellsManager;
-
-  ObjectContainer &mPvsObjects;
   ObjectContainer &mPreprocessorObjects;
 
-  bool mCreatePvsObjects;
-
-  BoundingBoxConverter *mBoundingBoxConverter;
-  AxisAlignedBox3 mViewSpaceBox;
-  IndexedBoundingBoxContainer mIBoundingBoxes;
- 
   /// current state of the parser
   int mCurrentState;
   
-  enum {
-	  PARSE_OPTIONS, 
-	  PARSE_VIEWCELLS, 
-	  PARSE_VIEWSPACE_HIERARCHY, 
-	  PARSE_OBJECTSPACE_HIERARCHY};
-
-  /// view space / object space hierarchy types
-  enum {BSP, VSP, OSP, BVH};
+  enum {, BVH};
 
   int mViewSpaceHierarchyType;
@@ -140,37 +96,7 @@
   // Handlers for X3D
   
-  void StartBspLeaf(AttributeList& attributes);
-  void StartBspInterior(AttributeList& attributes);
-  void EndBspInterior();
-
-  void StartVspLeaf(AttributeList& attributes);
-  void StartVspInterior(AttributeList& attributes);
-  void EndVspInterior();
-
-  void StartViewCellPvs(ObjectPvs &pvs, const char *ptr);
-
-  void EndViewCells();
-  void EndBoundingBoxes();
-
-  void StartBspElement(string element, AttributeList& attributes);
-  void StartVspElement(string element, AttributeList& attributes);
-
-  void StartViewSpaceHierarchy(AttributeList& attributes);
   void StartObjectSpaceHierarchy(AttributeList& attributes);
 
-  void StartBoundingBox(AttributeList& attributes);
-  void StartViewCell(AttributeList& attributes, const bool isLeaf);
-  void EndViewCellInterior();
-
-  void StartViewSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
   void StartObjectSpaceHierarchyElement(const std::string &element, AttributeList& attributes);
-  void StartViewCellHierarchyElement(const std::string &element, AttributeList& attributes);
-
-  void StartOspElement(string element, AttributeList& attributes);
-
-  void StartOspLeaf(AttributeList& attributes);
-  void StartOspInterior(AttributeList& attributes);
-
-  void CreateViewSpaceHierarchy();
 
   void StartBvhLeaf(AttributeList& attributes);
@@ -178,5 +104,4 @@
   void StartBvhElement(string element, AttributeList& attributes);
 
-  void EndViewSpaceHierarchyInterior();
   void EndObjectSpaceHierarchyInterior();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 2113)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 2114)
@@ -124,5 +124,6 @@
 	  PARSE_VIEWCELLS, 
 	  PARSE_VIEWSPACE_HIERARCHY, 
-	  PARSE_OBJECTSPACE_HIERARCHY};
+	  PARSE_OBJECTSPACE_HIERARCHY
+  };
 
   /// view space / object space hierarchy types
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp	(revision 2113)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjectsParser.cpp	(revision 2114)
@@ -458,5 +458,5 @@
 
 
-void ViewCellsParseHandlers::ExchangeElements()
+void ViewCellsParseHandlers::ReplacePvs()
 {
 	ViewCellContainer::const_iterator vit, vit_end = mViewCells.end();
@@ -1497,5 +1497,5 @@
 
 	if (1 && PVS_HACK)
-		handler.ExchangeElements();
+		handler.ReplacePvs();
 
 	const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2113)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 2114)
@@ -103,4 +103,5 @@
   , nObjects(0)
 {
+	// pvs objects empty => have to create new ones
 	mCreatePvsObjects = mPvsObjects.empty();
 
@@ -278,5 +279,5 @@
 {
 	// sort view cells to help associating view cells according to their id
-	stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
+	sort(mViewCells.begin(), mViewCells.end(), vlt);
 
 	// not parsing view cells anymore
@@ -287,10 +288,10 @@
 void ViewCellsParseHandlers::EndBoundingBoxes()
 {
-	// all bounding boxes gathered in this step => 
-	// associate object ids with bounding boxes
 	const long startTime = GetTime();
 	
 	if (mBoundingBoxConverter)
 	{
+		// all bounding boxes gathered in this step => 
+		// associate object ids with bounding boxes
 		mBoundingBoxConverter->IdentifyObjects(mIBoundingBoxes, mPvsObjects);
 	}
@@ -458,10 +459,11 @@
 
 
-void ViewCellsParseHandlers::ExchangeElements()
-{
+void ViewCellsParseHandlers::ReplacePvs()
+{
+	// sort the pvs entries
+	sort(mPvsObjects.begin(), mPvsObjects.end(), ilt);
+
 	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)
@@ -583,30 +585,32 @@
 	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 =	
+		if (mCreatePvsObjects)
+		{
+			// pvs entries will be created => just use dummy proxy
+			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
+			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;
+			}
+		}
 	}
 }
@@ -1306,10 +1310,10 @@
 	BvHierarchy::AssociateObjectsWithLeaf(leaf);
 	
-	if (PVS_HACK)
-	{
-		if (0) // Temp matt: should already have right id
-			leaf->SetId((int)mBvhLeaves.size());
+	if (mCreatePvsObjects)
+	{
+		// Temp matt: leaves should already have right id
+		if (0) leaf->SetId((int)mBvhLeaves.size());
 		
-		mBvhLeaves.push_back(leaf);	
+		mPvsObjects.push_back(leaf);	
 	}
 }
@@ -1437,112 +1441,113 @@
 										 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();
+	// 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();
 
 #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.ExchangeElements();
-
-	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)
-      {
+			//if (mCreatePvsObjects)
+			//	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)
+		{
 			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;
+}
+
+}
