Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1737)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1738)
@@ -2475,5 +2475,5 @@
   Intersectable::NewMail();
   
-  ObjectPvsMap::const_iterator oi;
+  ObjectPvsEntries::const_iterator oi;
   
   for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi) 
@@ -2527,5 +2527,5 @@
 
   Intersectable::NewMail();
-  ObjectPvsMap::const_iterator oi;
+  ObjectPvsEntries::const_iterator oi;
   // first mark all object from this pvs
   for (oi = pvs.mEntries.begin(); oi != pvs.mEntries.end(); ++ oi) {
@@ -2537,5 +2537,5 @@
   int pvsSize = 0;
   int nPvsSize = 0;
-  float samples = pvs.mSamples;
+  float samples = (float)pvs.mSamples;
   cout<<"Samples = "<<samples<<endl;
   //  cout<<"Filter size = "<<filterSize<<endl;
@@ -2595,5 +2595,5 @@
 
 	// update samples and globalC
-	samples = pvs.mSamples;
+	samples = (float)pvs.mSamples;
 	globalC = 2.0f*filterSize/sqrt(samples);
 	cout<<"neighboring viewcells = "<<i-1<<endl;
@@ -2780,5 +2780,5 @@
 	for (vit = interior->mChildren.begin(); vit != vit_end; ++ vit, ++ oit)
 	{
-	    ObjectPvsMap::iterator pit, pit_end = (*oit).mEntries.end();
+	    ObjectPvsEntries::iterator pit, pit_end = (*oit).mEntries.end();
 	
 		for (pit = (*oit).mEntries.begin(); pit != pit_end; ++ pit)
@@ -3268,5 +3268,5 @@
 		{
 			Intersectable::NewMail();
-			ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
+			ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end();
 			
 			// output PVS of view cell
@@ -3769,5 +3769,5 @@
 			exporter->SetFilled();
 
-			ObjectPvsMap::iterator it, it_end = vc->GetPvs().mEntries.end();
+			ObjectPvsEntries::iterator it, it_end = vc->GetPvs().mEntries.end();
 			// -- output PVS of view cell
 			for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)
@@ -4617,5 +4617,5 @@
 			Intersectable::NewMail();
 
-			ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
+			ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end();
 			cout << endl;
 			// output PVS of view cell
@@ -5448,5 +5448,5 @@
 
 			Intersectable::NewMail();
-			ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
+			ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end();
 			
 			// output PVS of view cell
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1713)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1738)
@@ -61,5 +61,5 @@
 	int count = 0;
 
-	ObjectPvsMap::const_iterator it, it_end = vc->GetPvs().mEntries.end();
+	ObjectPvsEntries::const_iterator it, it_end = vc->GetPvs().mEntries.end();
 	for (it = vc->GetPvs().mEntries.begin(); it != it_end; ++ it)
 	{
@@ -81,5 +81,5 @@
 	float pvs = (float)pvs1.GetSize();
 
-	ObjectPvsMap::const_iterator it, it_end =  pvs1.mEntries.end();
+	ObjectPvsEntries::const_iterator it, it_end = pvs1.mEntries.end();
 
 	Intersectable::NewMail();
@@ -830,5 +830,5 @@
 
 	// compute new pvs size
-	ObjectPvsMap::const_iterator it, it_end =  pvs1.mEntries.end();
+	ObjectPvsEntries::const_iterator it, it_end =  pvs1.mEntries.end();
 
 	Intersectable::NewMail();
@@ -1638,5 +1638,5 @@
 	ViewCellContainer::const_iterator cit, cit_end = interior->mChildren.end();
 
-	ObjectPvsMap::const_iterator oit;
+	ObjectPvsEntries::const_iterator oit;
 
 	// mail all objects in the leaf sets
@@ -1647,5 +1647,5 @@
 		ViewCell *vc = *cit;
 
-		ObjectPvsMap::const_iterator oit_end = vc->GetPvs().mEntries.end();
+		ObjectPvsEntries::const_iterator oit_end = vc->GetPvs().mEntries.end();
 
 		for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -1669,5 +1669,5 @@
 		ViewCell *vc = *cit;
 
-		ObjectPvsMap::const_iterator oit_end = vc->GetPvs().mEntries.end();
+		ObjectPvsEntries::const_iterator oit_end = vc->GetPvs().mEntries.end();
 
 		for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -1682,5 +1682,5 @@
 
 	// delete all the objects from the leaf sets which were moved to parent pvs
-	ObjectPvsMap::const_iterator oit_end = interior->GetPvs().mEntries.end();
+	ObjectPvsEntries::const_iterator oit_end = interior->GetPvs().mEntries.end();
 
 	for (oit = interior->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -1775,5 +1775,5 @@
 	for (it = leaves.begin(); it != it_end; ++ it)
 	{
-		ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end();
+		ObjectPvsEntries::iterator oit, oit_end = (*it)->GetPvs().mEntries.end();
 
 		for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -1825,5 +1825,5 @@
 	for (it = leaves.begin(); it != it_end; ++ it)
 	{
-		ObjectPvsMap::iterator oit, oit_end = (*it)->GetPvs().mEntries.end();
+		ObjectPvsEntries::iterator oit, oit_end = (*it)->GetPvs().mEntries.end();
 
 		for (oit = (*it)->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -2339,5 +2339,5 @@
 void ViewCellsTree::ExportPvs(ViewCell *viewCell, OUT_STREAM &stream)
 {
-	ObjectPvsMap::iterator it, it_end = viewCell->GetPvs().mEntries.end();
+	ObjectPvsEntries::iterator it, it_end = viewCell->GetPvs().mEntries.end();
 
 	for (it = viewCell->GetPvs().mEntries.begin(); it != it_end; ++ it)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1737)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 1738)
@@ -89,5 +89,4 @@
 };
 
-
 /** Template class representing the Potentially Visible Set (PVS) 
 	mainly from a view cell, but also e.g., from objects.
@@ -97,4 +96,23 @@
 {
 public:
+//vector<pair<T, S> >::iterator mItEnd;
+	template<typename T, typename S>
+	class Iterator
+	{
+		//template<typename T, typename S> friend Pvs<T, S>;
+	private:
+		//std::vector<std::pair<T, S> >::iterator mIt;
+		//vector<pair<T, S> >::iterator mItEnd;
+	};
+
+	template<typename T, typename S>
+	class ConstIterator
+	{
+	//	template<typename T, typename S> friend Pvs<T, S>;
+	private:
+		//vector<pair<T, S> >::const_iterator mIt;
+		//vector<pair<T, S> >::const_iteator mItEnd;
+	};
+
   Pvs(): mSamples(0), mEntries() {}
   
@@ -185,7 +203,5 @@
 	/** Compute continuous PVS difference */
 	float GetPvsHomogenity(Pvs<T, S> &pvs) {
-		float 
-			pvsReduction,
-			pvsEnlargement;
+		float pvsReduction, pvsEnlargement;
 
 		ComputeContinuousPvsDifference(pvs,
@@ -198,7 +214,11 @@
 	int Size() { return mEntries.size(); }
 
-	/// Map of PVS entries
-	std::map<T, S, LtSample<T> > mEntries;
-	//vector<pair<T, S> > mEntries; 
+	//vector<pair<T, S> >::const_iterator &GetConstIterator() const { return mEntries.begin(); }
+	//vector<pair<T, S> >::iterator &GetIterator() { return mEntries.begin(); }
+
+//protected:
+
+	/// vector of PVS entries
+	vector<pair<T, S> > mEntries; 
 	
 	/// Number of samples used to create the PVS
@@ -221,62 +241,63 @@
 	pvsReduction = 0.0f;
 	pvsEnlargement = 0.0f;
-  // Uses sum of log differences, which corresponds to entropy
-  std::map<T, S, LtSample<T> >::iterator it;
-  
-  for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
-  {
-	float bSumPdf = (*it).second.mSumPdf;
-	float aSumPdf = 0.0f;
-	S *data = Find((*it).first);		
-	
-	if (data) 
-	{
-		aSumPdf = data->mSumPdf;
-		// mark this entry as processed to avoid double counting
-		data->mSumPdf = -aSumPdf;
-	}
+	// Uses sum of log differences, which corresponds to entropy
+	std::vector<pair<T, S> >::iterator it;
+
+	for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it) 
+	{
+		float bSumPdf = (*it).second.mSumPdf;
+		float aSumPdf = 0.0f;
+		S *data = Find((*it).first);		
+
+		if (data) 
+		{
+			aSumPdf = data->mSumPdf;
+			// mark this entry as processed to avoid double counting
+			data->mSumPdf = -aSumPdf;
+		}
 
 #if 0
-	float diff = bSumPdf - aSumPdf;
-	
-	if (diff > 0.0f) {
-	  pvsEnlargement += diff;
-	} else {
-	  pvsReduction += -diff;
-	}
+		float diff = bSumPdf - aSumPdf;
+
+		if (diff > 0.0f) {
+			pvsEnlargement += diff;
+		} else {
+			pvsReduction += -diff;
+		}
 #else
-	if (!data)
-	  pvsEnlargement += 1.0f;
-#endif
-  }
-  
-  for (it = mEntries.begin(); it != mEntries.end(); ++ it) {
-	float aSumPdf = (*it).second.mSumPdf;
-	float bSumPdf = 0.0f;
-	if (aSumPdf < 0.0f) {
-	  // this entry was already accounted for!
-	  // just revert it back
-	  (*it).second.mSumPdf = -aSumPdf;
-	} else {
-	  S *data = b.Find((*it).first);
-	  if (data) {
-		bSumPdf = data->mSumPdf;
-	  }
+		if (!data)
+			pvsEnlargement += 1.0f;
+#endif
+	}
+
+	for (it = mEntries.begin(); it != mEntries.end(); ++ it) {
+		float aSumPdf = (*it).second.mSumPdf;
+		float bSumPdf = 0.0f;
+		if (aSumPdf < 0.0f) {
+			// this entry was already accounted for!
+			// just revert it back
+			(*it).second.mSumPdf = -aSumPdf;
+		} else {
+			S *data = b.Find((*it).first);
+			if (data) {
+				bSumPdf = data->mSumPdf;
+			}
 #if 0
-	  float diff = bSumPdf - aSumPdf;
-	  
-	  if (diff > 0.0f) {
-		pvsEnlargement += diff;
-	  } else {
-		pvsReduction += -diff;
-	  }
+			float diff = bSumPdf - aSumPdf;
+
+			if (diff > 0.0f) {
+				pvsEnlargement += diff;
+			} else {
+				pvsReduction += -diff;
+			}
 
 #else
-	  if (!data) 
-		pvsReduction += 1.0f;
-#endif
-	}
-  }
-}
+			if (!data) 
+				pvsReduction += 1.0f;
+#endif
+		}
+	}
+}
+
 
 template <typename T, typename S>
@@ -285,5 +306,5 @@
 	int dif = 0;
 
-	std::map<T, S, LtSample<T> >::const_iterator it;
+	std::vector<pair<T, S> >::const_iterator it;
 
 	for (it = b.mEntries.begin(); it != b.mEntries.end(); ++ it)
@@ -298,13 +319,16 @@
 template <typename T, typename S> void Pvs<T, S>::Merge(const Pvs<T, S> &a)
 {
-  
-  std::map<T, S, LtSample<T> >::const_iterator it;
-  int samples = mSamples + a.mSamples;
-
-  for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it)
-	{
-	  AddSample((*it).first, (*it).second.mSumPdf);
-	}
-  mSamples = samples;
+#if TODO
+	const int samples = mSamples + a.mSamples;
+
+	std::vector<pair<T, S>> >::const_iterator it;
+
+	for (it = a.mEntries.begin(); it != a.mEntries.end(); ++ it)
+	{
+		AddSample((*it).first, (*it).second.mSumPdf);
+	}
+
+	mSamples = samples;
+#endif
 }
 
@@ -319,5 +343,6 @@
 S *Pvs<T, S>::Find(T sample)
 {
-  std::map<T, S, LtSample<T> >::iterator i = mEntries.find(sample);
+#if TODO
+  std::vector<pair<T, S>, LtSample<T> >::iterator i = mEntries.find(sample);
 
   if (i != mEntries.end()) 
@@ -329,4 +354,7 @@
 	  return NULL;
   }
+#else
+return NULL;
+#endif
 }
 
@@ -336,11 +364,11 @@
 					 S &data)
 {
-  std::map<T, S, LtSample<T> >::iterator i = mEntries.begin();
-  for (int k = 0; k != index && i != mEntries.end(); i++, k++);
-
-  entry = (*i).first;
-  data = (*i).second;
-  
-}
+	std::vector<pair<T, S> >::iterator i = mEntries.begin();
+	for (int k = 0; k != index && i != mEntries.end(); ++ i, ++ k);
+
+	entry = (*i).first;
+	data = (*i).second;
+}
+
 
 template <typename T, typename S>
@@ -348,17 +376,21 @@
 Pvs<T, S>::AddSample(T sample, const float pdf)
 {
-  mSamples++;
-  S *data = Find(sample);
-  
-  if (data)  
-	{
-	  data->mSumPdf += pdf;
-	  return data->mSumPdf;
-	}
-  else 
-	{
-	  mEntries[sample] = S(pdf);
-	  return pdf;
-	}
+#if TODO
+	++ mSamples;
+	S *data = Find(sample);
+
+	if (data)  
+	{
+		data->mSumPdf += pdf;
+		return data->mSumPdf;
+	}
+	else 
+	{
+		mEntries[sample] = S(pdf);
+		return pdf;
+	}
+#else
+return 0;
+#endif
 }
 
@@ -388,18 +420,21 @@
 				  float &contribution)
 {
-  mSamples++;
-  S *data = Find(sample);
-  
-  if (data)  
-  {
-	data->mSumPdf += pdf;
-	contribution = pdf / data->mSumPdf;
-	return false;
-  }
-  else {
-	mEntries[sample] = S(pdf);
-	contribution = 1.0f;
+	++ mSamples;
+    S *data = Find(sample);
+#if TODO
+	if (data)  
+	{
+		data->mSumPdf += pdf;
+		contribution = pdf / data->mSumPdf;
+		return false;
+	}
+	else {
+		mEntries[sample] = S(pdf);
+		contribution = 1.0f;
+		return true;
+	}
+#else
 	return true;
-  }
+#endif
 }
 
@@ -424,10 +459,9 @@
 template <typename T, typename S>
 bool Pvs<T, S>::RemoveSample(T sample,
-						  const float pdf)
+							 const float pdf)
 {
   -- mSamples;
-  
-  std::map<T, S, LtSample<T> >::
-	iterator it = mEntries.find(sample);
+#if TODO
+  std::vector<pair<T, S> >::iterator it = mEntries.find(sample);
   
   if (it == mEntries.end())
@@ -442,5 +476,5 @@
 	  mEntries.erase(it);
   }
-
+#endif
   return true;
 }
@@ -450,5 +484,5 @@
 {
   int samples = mSamples + pvs.mSamples;
-  std::map<T, S, LtSample<T> >::
+  std::vector<pair<T, S> >::
 	const_iterator it, it_end = pvs.mEntries.end();
   
@@ -468,15 +502,16 @@
 int Pvs<T, S>::SubtractPvs(const Pvs<T, S> &pvs)
 {
-  
-  int samples = mSamples - pvs.mSamples;
-  std::map<T, S, LtSample<T> >::
-	const_iterator it, it_end = pvs.mEntries.end();
-  
-  // output PVS of view cell
-  for (it = pvs.mEntries.begin(); it != it_end; ++ it) 
-	RemoveSample((*it).first, (*it).second.mSumPdf);
-
-  mSamples = samples;
-  return GetSize();
+	const int samples = mSamples - pvs.mSamples;
+#if TODO
+	std::vector<pair<T, S> >::
+		const_iterator it, it_end = pvs.mEntries.end();
+
+	// output PVS of view cell
+	for (it = pvs.mEntries.begin(); it != it_end; ++ it) 
+		RemoveSample((*it).first, (*it).second.mSumPdf);
+
+	mSamples = samples;
+#endif
+	return GetSize();
 }
 
@@ -484,5 +519,5 @@
 void Pvs<T, S>::CollectEntries(std::vector<T> &entries)
 {
-	std::map<T, S, LtSample<T> >::
+	std::vector<pair<T, S> >::
 		const_iterator it, it_end = mEntries.end();
 
@@ -495,5 +530,5 @@
 void Pvs<T, S>::NormalizeMaximum()
 {
-  std::map<T, S, LtSample<T> >::
+  std::vector<pair<T, S> >::
 	const_iterator it, it_end = mEntries.end();
 
@@ -555,8 +590,10 @@
 //-- typedefs
 
-typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap;
-typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsMap;
-typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsMap;
-
+//typedef std::map<KdNode *, PvsData, LtSample<KdNode *> > KdPvsMap;
+//typedef std::map<Intersectable *, PvsData, LtSample<Intersectable *> > ObjectPvsEntries;
+//typedef std::map<ViewCell *, MailablePvsData, LtSample<ViewCell *> > ViewCellPvsEntries;
+
+
+typedef std::vector<pair<Intersectable *, PvsData> > ObjectPvsEntries;
 
 typedef Pvs<ViewCell *, MailablePvsData> ViewCellPvs;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1737)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1738)
@@ -85,5 +85,5 @@
 
 	// remove the parents from the object pvss
-	ObjectPvsMap::const_iterator oit, oit_end = parent->GetPvs().mEntries.end();
+	ObjectPvsEntries::const_iterator oit, oit_end = parent->GetPvs().mEntries.end();
 
 	for (oit = parent->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -104,5 +104,5 @@
 
 	// Add front view cell to the object pvsss
-	ObjectPvsMap::const_iterator oit, oit_end = vc->GetPvs().mEntries.end();
+	ObjectPvsEntries::const_iterator oit, oit_end = vc->GetPvs().mEntries.end();
 
 	for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
@@ -2914,5 +2914,5 @@
 #if WORK_WITH_VIEWCELL_PVS
 	// add first view cell to all the objects view cell pvs
-	ObjectPvsMap::const_iterator oit, 
+	ObjectPvsEntries::const_iterator oit, 
 		oit_end = leaf->GetViewCell()->GetPvs().mEntries.end();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1707)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.cpp	(revision 1738)
@@ -131,5 +131,4 @@
 
 
-
 float ObjectPvs::EvalPvsCost() const
 {
@@ -140,5 +139,5 @@
 	BvhLeaf::NewMail();
 
-	ObjectPvsMap::const_iterator it, it_end = mEntries.end();
+	ObjectPvsEntries::const_iterator it, it_end = mEntries.end();
 
 	for (it = mEntries.begin(); it != it_end; ++ it)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1736)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1738)
@@ -266,4 +266,8 @@
 {
 	SubdivisionCandidate *splitCandidate = splitQueue.Top();
+
+	if (splitCandidate->IsDirty())
+		splitCandidate->EvalCandidate();
+
 	splitQueue.Pop();
 
@@ -1837,5 +1841,5 @@
 
 		// hack: should not be done here
-		ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
+		ObjectPvsEntries::const_iterator oit, oit_end = pvs.mEntries.end();
 
 		for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit)
@@ -1937,5 +1941,5 @@
 		{
 			subStats.mTotalRenderCost -= subStats.mRenderCostDecrease;
-			subStats.mEntriesInPvs += entriesIncr;
+			//subStats.mEntriesInPvs += entriesIncr;
 
 			// if (rcDecr <= 0)
