Index: GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj.UNKNOWN.matt.user
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj.UNKNOWN.matt.user	(revision 2563)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj.UNKNOWN.matt.user	(revision 2722)
@@ -62,4 +62,32 @@
 			/>
 		</Configuration>
+		<Configuration
+			Name="Engine|Win32"
+			>
+			<DebugSettings
+				Command=""
+				WorkingDirectory=""
+				CommandArguments=""
+				Attach="false"
+				DebuggerType="3"
+				Remote="1"
+				RemoteMachine="UNKNOWN"
+				RemoteCommand=""
+				HttpUrl=""
+				PDBPath=""
+				SQLDebugging=""
+				Environment=""
+				EnvironmentMerge="true"
+				DebuggerFlavor=""
+				MPIRunCommand=""
+				MPIRunArguments=""
+				MPIRunWorkingDirectory=""
+				ApplicationCommand=""
+				ApplicationArguments=""
+				ShimCommand=""
+				MPIAcceptMode=""
+				MPIAcceptFilter=""
+			/>
+		</Configuration>
 	</Configurations>
 </VisualStudioUserFile>
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2720)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2722)
@@ -1698,19 +1698,16 @@
 float Preprocessor::_HackComputeRenderCost(ViewCell *vc)
 {
-	ObjectPvs basePvs;
-	
-	basePvs = vc->CopyPvs();
-	ObjectPvsIterator pit = basePvs.GetIterator();
+	ObjectPvsIterator pit = vc->GetPvs().GetIterator();
 
 	float renderCost = 0;
-
+	int i = 0;
+	cout<<"size: " << vc->GetPvs().GetSize() << endl;
 	// first mark all objects from this pvs
 	while (pit.HasMoreEntries()) 	
 	{
 		Intersectable *obj = pit.Next();
-
 		if (obj->Type() == Intersectable::KD_INTERSECTABLE)
 		{
-			KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
+			KdIntersectable *kdObj = static_cast<KdIntersectable *>(obj);
 
 			/*if (mShowDistanceWeightedPvs)
@@ -1756,11 +1753,22 @@
   int maxPlanes = 0;
   int allEntries = 0;
+
+  int viewCells = 0;
+
   // now search for pvss which contained any mailed node
-  for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) {
+  for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) 
+  {
 	  ObjectPvs &pvs = (*vit)->GetPvs();
-	  if (Overlap(box, (*vit)->GetBox())) {
+
+	  bool pvsChanged = false;
+
+	  if (Overlap(box, (*vit)->GetBox())) 
+	  {
 		  pvs.Clear();
 		  removedEntries += pvs.GetSize();
-	  } else {
+		  pvsChanged = true;
+	  } 
+	  else 
+	  {
 		  //	cout<<(*vit)->GetBox()<<" "<<box<<endl;
 		  shadowVolume.Init((*vit)->GetBox(), box);
@@ -1769,24 +1777,35 @@
 
 		  int j = 0;
-		  for (int i=0; i < pvs.mEntries.size(); i++) {
+		  for (int i=0; i < pvs.mEntries.size(); i++) 
+		  {
 			  allEntries++;
 			  Intersectable *o = pvs.mEntries[i].mObject;
-			  if (o == inter) {
+			  if (o == inter) 
+			  {
 				  removedSelfEntries++;
-			  } else {
-				  if (!shadowVolume.TestIsInsideShaft(o->GetBox())) {
+				  pvsChanged = true;
+			  } 
+			  else 
+			  {
+				  if (!shadowVolume.TestIsInsideShaft(o->GetBox())) 
+				  {
 					  if (j != i)
 						  pvs.mEntries[j] = pvs.mEntries[i];
 					  j++;
-				  } else {
+				  } 
+				  else 
+				  {
 					  removedEntries++;
+					  pvsChanged = true;
 				  }
 			  }
 		  }
+
 		  // now the pvs has to be resorted
 		  pvs.mLastSorted = 0;
 		  if (j==0)
 			  pvs.mEntries.clear();
-		  else {
+		  else 
+		  {
 			  pvs.mEntries.resize(j);
 			  if (j>1)
@@ -1795,11 +1814,14 @@
 	  }
 
-	  ViewCell *vc = *vit;
-
-	  // recompute render cost
-	  float renderCost = _HackComputeRenderCost(vc);
-	  vc->GetPvs().mStats.mWeightedTriangles = renderCost;
+	  if (pvsChanged)
+	  {
+		  ViewCell *vc = *vit;
+
+		  // recompute render cost
+		  float renderCost = _HackComputeRenderCost(vc);
+		  vc->GetPvs().mStats.mWeightedTriangles = renderCost;
+	  }
   }
-  
+
   cerr<<"Number of removed pvs entries = "<<removedEntries<<" ("<<
 	100.0f*removedEntries/(float)allEntries<<"%)"<<endl;
