Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1551)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1623)
@@ -95,6 +95,7 @@
   ViewCell *mViewCellRoot;
 
-  typedef map<int, ViewCell *> ViewCellsMap;
-  ViewCellsMap mViewCells;
+ // typedef map<int, ViewCell *> ViewCellsMap;
+  //ViewCellsMap mViewCells;
+ViewCellContainer mViewCells;
 
   ViewCellsManager *mViewCellsManager;
@@ -118,5 +119,5 @@
   int mViewSpaceHierarchyType;
   int mObjectSpaceHierarchyType;
-
+int nViewCells;
   ////////////////////////////////
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1622)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1623)
@@ -94,4 +94,5 @@
   , mBoundingBoxConverter(bconverter)
   , mHierarchyManager(NULL)
+  , nViewCells(0)
 {
 	std::stable_sort(mObjects->begin(), mObjects->end(), ilt);
@@ -205,5 +206,5 @@
 	// go one up in the tree
 	if (mCurrentBspNode->GetParent())
-	{	cout << "]";
+	{	Debug << "]";
 		mCurrentBspNode = mCurrentBspNode->GetParent();
 	}
@@ -215,5 +216,5 @@
 	// go one up in the tree
 	if (mCurrentBvhNode->GetParent())
-	{	cout << "]";
+	{	Debug << "]";
 		mCurrentBvhNode = mCurrentBvhNode->GetParent();
 	}
@@ -225,5 +226,5 @@
 	// go one up in the tree
 	if (mCurrentOspNode->mParent)
-	{	cout << "]";
+	{	Debug << "]";
 		mCurrentOspNode = mCurrentOspNode->mParent;
 	}
@@ -235,5 +236,5 @@
 	// go one up in the tree
 	if (mCurrentVspNode->GetParent())
-	{	cout << "]";
+	{	Debug << "]";
 		mCurrentVspNode = mCurrentVspNode->GetParent();
 	}
@@ -245,5 +246,5 @@
 	// go one up in the tree
 	if (mCurrentViewCell->GetParent())
-	{	cout << "]";
+	{	Debug << "]";
 		mCurrentViewCell = mCurrentViewCell->GetParent();
 	}
@@ -260,5 +261,5 @@
 {
 	// sort view cells to help associating view cells according to their id
-	//stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
+	stable_sort(mViewCells.begin(), mViewCells.end(), vlt);
 
 	// not parsing view cells anymore
@@ -288,5 +289,5 @@
 	if (element == "Interior") 
 	{
-		cout << "[";
+		Debug << "[";
 		StartBspInterior(attributes);
 	}
@@ -294,5 +295,5 @@
 	if (element == "Leaf") 
 	{
-		cout << "l";
+		Debug << "l";
 		StartBspLeaf(attributes);
 	}
@@ -305,10 +306,10 @@
 	if (element == "Interior") 
 	{
-		cout << "[";
+		Debug << "[";
 		StartVspInterior(attributes);
 	}
 	if (element == "Leaf") 
 	{
-		cout << "l";
+		Debug << "l";
 		StartVspLeaf(attributes);
 	}
@@ -321,5 +322,5 @@
 	if (element == "Interior") 
 	{
-		cout << "[";
+		Debug << "[";
 		StartOspInterior(attributes);
 	}
@@ -327,5 +328,5 @@
 	if (element == "Leaf") 
 	{
-		cout << "l";
+		Debug << "l";
 		StartOspLeaf(attributes);
 	}
@@ -338,5 +339,5 @@
 	if (element == "Interior") 
 	{
-		cout << "[";
+		Debug << "[";
 		StartBvhInterior(attributes);
 	}
@@ -344,5 +345,5 @@
 	if (element == "Leaf") 
 	{
-		cout << "l";
+		Debug << "l";
 		StartBvhLeaf(attributes);
 	}
@@ -391,8 +392,10 @@
 														   AttributeList& attributes)
 {
+	if (((nViewCells ++) % 1000) == 0)
+		Debug << "\n " << nViewCells << " view cells parsed" << endl;
 	// interiors + leaves interpreted view cells else
 	if (element == "Interior") 
 	{
-		cout << "[";
+		Debug << "[";
 		StartViewCell(attributes, false);
 	}
@@ -400,5 +403,5 @@
 	if (element == "Leaf") 
 	{
-		cout << "l";
+		Debug << "l";
 		StartViewCell(attributes, true);
 	}
@@ -414,5 +417,5 @@
 	if (element == "ViewCells")
 	{
-		cout << "\nparsing view cells" << endl;
+		Debug << "\nparsing view cells" << endl;
 		
 		mCurrentState = PARSE_VIEWCELLS;
@@ -425,5 +428,5 @@
 	if (element == "ViewSpaceHierarchy")
 	{		
-		cout << "\nparsing view space hierarchy" << endl;
+		Debug << "\nparsing view space hierarchy" << endl;
 		mCurrentState = PARSE_VIEWSPACE_HIERARCHY;
 		StartViewSpaceHierarchy(attributes);
@@ -433,5 +436,5 @@
 	if (element == "ObjectSpaceHierarchy")
 	{
-		cout << "\nparsing object space hierarchy" << endl;
+		Debug << "\nparsing object space hierarchy" << endl;
 		mCurrentState = PARSE_OBJECTSPACE_HIERARCHY;
 		StartObjectSpaceHierarchy(attributes);
@@ -441,5 +444,5 @@
 	if (element == "BoundingBox")
 	{
-	  //		cout << "b";
+	  //		Debug << "b";
 		StartBoundingBox(attributes);
 	}
@@ -506,5 +509,5 @@
 		else
 		{
-			cout << "error: object with id " << objId << " does not exist" << endl;
+			Debug << "error: object with id " << objId << " does not exist" << endl;
 		}
 	}
@@ -529,10 +532,10 @@
 			if (strcmp(ptr, "bsp") == 0)
 			{
-				cout << "\nview space hierarchy: Bsp" << endl;
+				Debug << "\nview space hierarchy: Bsp" << endl;
 				mViewSpaceHierarchyType = BSP;
 			}
 			else if (strcmp(ptr, "vsp") == 0)
 			{
-				cout << "\nview space hierarchy: Vsp" << endl;
+				Debug << "\nview space hierarchy: Vsp" << endl;
 				mViewSpaceHierarchyType = VSP;
 			}
@@ -573,5 +576,5 @@
 			if (strcmp(ptr, "osp") == 0)
 			{
-				cout << "\nobject space hierarchy: Osp" << endl;
+				Debug << "\nobject space hierarchy: Osp" << endl;
 
 				mHierarchyManager = 
@@ -597,5 +600,5 @@
 			else if (strcmp(ptr, "bvh") == 0)
 			{
-				cout << "\nobject space hierarchy: Bvh" << endl;
+				Debug << "\nobject space hierarchy: Bvh" << endl;
 				mObjectSpaceHierarchyType = BVH;
 				mHierarchyManager = 
@@ -639,5 +642,5 @@
 	AxisAlignedBox3 box(bmin, bmax);
 	mIBoundingBoxes.push_back(IndexedBoundingBox(id, box));
-	//cout << "bbox: " << box << endl;
+	//Debug << "bbox: " << box << endl;
 }
 
@@ -683,7 +686,13 @@
 	{
 		// TODO: get view cell with specified id
-		ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
-		BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second);
-	
+		ViewCellInterior dummyVc;
+		dummyVc.SetId(viewCellId);
+
+		ViewCellContainer::iterator vit =
+			lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
+		
+		//ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
+//		BspViewCell *viewCell = dynamic_cast<BspViewCell *>((*vit).second);
+		BspViewCell *viewCell = dynamic_cast<BspViewCell *>(*vit);
 		if (viewCell->GetId() == viewCellId)
 		{
@@ -694,5 +703,5 @@
 		else
 		{
-			cout << "error: view cell does not exist" << endl;
+			Debug << "error: view cell does not exist" << endl;
 		}
 	}
@@ -744,5 +753,5 @@
 
 ViewCell *ViewCellsParseHandlers::GetOrCreateViewCell(const int id, const bool isLeaf)
-{
+{/*
 	ViewCellsMap::iterator vit = mViewCells.find(id);
 
@@ -766,5 +775,6 @@
 		mViewCells[id] = vc;
 		return vc;
-	}
+	}*/
+	return NULL;
 }
 
@@ -776,5 +786,16 @@
 	const int len = attributes.getLength();
 	float mergeCost;
-	ObjectPvs pvs;
+	//ObjectPvs pvs;
+
+	//viewCell = GetOrCreateViewCell(id, isLeaf);
+	
+		if (isLeaf)
+		{
+			viewCell = new ViewCellLeaf();
+		}
+		else
+		{
+			viewCell = new ViewCellInterior();
+		}
 
 	for (int i = 0; i < len; ++ i) 
@@ -790,6 +811,7 @@
 
 			// create new view cell, otherwise use reference.
-			viewCell = GetOrCreateViewCell(id, isLeaf);
-			
+			//viewCell = GetOrCreateViewCell(id, isLeaf);
+			viewCell->SetId(id);
+
 			if (mCurrentViewCell) // replace front or (if not NULL) back child
 			{	
@@ -815,5 +837,7 @@
 			// note: id must come before pvs! 
 			// otherwise view cell is undefined
-			StartViewCellPvs(pvs, ptr);
+
+			StartViewCellPvs(viewCell->GetPvs(), ptr); // assume that view cell comes before pvs
+			//StartViewCellPvs(pvs, ptr);
 		}
 		else if (attrName == "active")
@@ -840,5 +864,6 @@
 
 	viewCell->SetMergeCost(mergeCost);
-	viewCell->SetPvs(pvs);
+	//viewCell->SetPvs(pvs);
+	mViewCells.push_back(viewCell);
 }
 
@@ -848,5 +873,5 @@
 	if (mViewSpaceHierarchyType == BSP)
 	{
-		cout << "hierarchy type: Bsp" << endl;
+		Debug << "hierarchy type: Bsp" << endl;
 		mVspBspTree = new VspBspTree();
 
@@ -854,11 +879,16 @@
 		mVspBspTree->mBoundingBox = mViewSpaceBox;
 
-		ViewCellsMap::iterator vit, vit_end = mViewCells.end();
-
+		//ViewCellsMap::iterator vit, vit_end = mViewCells.end();
+		ViewCellContainer::iterator vit, vit_end = mViewCells.end();
+
+		Debug << "exchanging boxes" << endl;
+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)
-		{
-			ViewCell *vc = (*vit).second;
+		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
@@ -868,4 +898,5 @@
 
 			bspVc->SetId(vc->GetId());
+			//bspVc->GetPvs().reserve(vc->GetPvs().size());
 			bspVc->SetPvs(vc->GetPvs());
 
@@ -880,10 +911,12 @@
 
 			DEL_PTR(vc);
-			(*vit).second = bspVc;
-		}
+//			(*vit).second = bspVc;
+			(*vit) = bspVc;
+		}
+		Debug << "finished" << endl;
 	}
 	else if (mViewSpaceHierarchyType == VSP) 
 	{
-		cout << "hierarchy type: Vsp" << endl;
+		Debug << "hierarchy type: Vsp" << endl;
 		mVspTree = new VspTree();
 
@@ -891,11 +924,11 @@
 		mVspTree->mBoundingBox = mViewSpaceBox;
 
-		ViewCellsMap::iterator vit, vit_end = mViewCells.end();
-
+//		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).second;
+	ViewCell *vc = (*vit);
 			VspViewCell *vspVc = new VspViewCell();
 			vspVc->SetPvs(vc->GetPvs());
@@ -914,6 +947,7 @@
 			}
 			
-			DEL_PTR(vc);
-			(*vit).second = vspVc;
+			//DEL_PTR(vc);
+			//(*vit).second = vspVc;
+			(*vit) = vspVc;
 		}
 
@@ -1007,15 +1041,16 @@
 	{
 		// TODO: get view cell with specified id
-		/*ViewCellInterior dummyVc;
+		ViewCellInterior dummyVc;
 		dummyVc.SetId(viewCellId);
 
 		ViewCellContainer::iterator vit =
 			lower_bound(mViewCells.begin(), mViewCells.end(), &dummyVc, vlt);
-		*/
-		ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
+		
+		//ViewCellsMap::iterator vit = mViewCells.find(viewCellId);
 		if (vit == mViewCells.end())
-			cout << "error: view cell " << viewCellId << " not found" << endl;
+			Debug << "error: view cell " << viewCellId << " not found" << endl;
 	
-		VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second);
+		//VspViewCell *viewCell = dynamic_cast<VspViewCell *>((*vit).second);
+		VspViewCell *viewCell = dynamic_cast<VspViewCell *>(*vit);
 		
 		if (viewCell->GetId() == viewCellId)
@@ -1026,5 +1061,5 @@
 		else
 		{
-			cout << "error: view cell does not exist" << endl;
+			Debug << "error: view cell does not exist" << endl;
 		}
 	}
@@ -1237,5 +1272,5 @@
 		else
 		{
-			cout << "error: object with id " << objId << " does not exist" << endl;
+			Debug << "error: object with id " << objId << " does not exist" << endl;
 		}
 	}
