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;
+}
+
+}
