Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2718)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2720)
@@ -42,5 +42,5 @@
 -gvs_initial_samples=16 \
 -gvs_max_viewcells=5000 \
--gvs_min_contribution=500 \
+-gvs_min_contribution=2000 \
 -gvs_per_viewcell=true \
 -preprocessor_detect_empty_viewspace+ \
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2716)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2720)
@@ -1608,4 +1608,20 @@
 
 
+SceneGraphLeaf *Preprocessor::GenerateBoxGeometry(const AxisAlignedBox3 &box)
+{
+	float offs = box.Min().y;
+	AxisAlignedBox3 newBox = box;
+	newBox.Translate(Vector3(0.0f, -offs, 0.0f));
+
+	const bool dynamic = true;
+	SceneGraphLeaf *leaf = new SceneGraphLeaf(dynamic);
+	newBox.Triangulate(leaf->mGeometry);
+
+	leaf->UpdateBox();
+
+	return leaf;
+}
+
+
 SceneGraphLeaf *Preprocessor::LoadDynamicGeometry(const string &filename)
 {
@@ -1678,4 +1694,50 @@
 	return NULL;
 }
+
+
+float Preprocessor::_HackComputeRenderCost(ViewCell *vc)
+{
+	ObjectPvs basePvs;
+	
+	basePvs = vc->CopyPvs();
+	ObjectPvsIterator pit = basePvs.GetIterator();
+
+	float renderCost = 0;
+
+	// 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());
+
+			/*if (mShowDistanceWeightedPvs)
+			{
+			const AxisAlignedBox3 box = kdObj->GetBox();
+
+			const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
+			renderCost += 1.0f / dist;
+			}
+			else if (mShowDistanceWeightedTriangles)
+			{
+			const AxisAlignedBox3 box = kdObj->GetBox();
+
+			const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
+			renderCost += kdObj->ComputeNumTriangles() / dist;
+			}
+			else //if (mShowWeightedTriangles)
+			{
+			*/
+			renderCost += kdObj->ComputeNumTriangles();
+			//}
+		}
+	}
+
+	return renderCost;
+}
+
+
 
 
@@ -1696,40 +1758,46 @@
   // now search for pvss which contained any mailed node
   for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) {
-	ObjectPvs &pvs = (*vit)->GetPvs();
-	if (Overlap(box, (*vit)->GetBox())) {
-	  pvs.Clear();
-	  removedEntries += pvs.GetSize();
-	} else {
-	  //	cout<<(*vit)->GetBox()<<" "<<box<<endl;
-	  shadowVolume.Init((*vit)->GetBox(), box);
-	  if (shadowVolume.CntPlanes() > maxPlanes)
-		maxPlanes = shadowVolume.CntPlanes();
-	  
-	  int j = 0;
-	  for (int i=0; i < pvs.mEntries.size(); i++) {
-		allEntries++;
-		Intersectable *o = pvs.mEntries[i].mObject;
-		if (o == inter) {
-		  removedSelfEntries++;
-		} else {
-		  if (!shadowVolume.TestIsInsideShaft(o->GetBox())) {
-			if (j != i)
-			  pvs.mEntries[j] = pvs.mEntries[i];
-			j++;
-		  } else {
-			removedEntries++;
+	  ObjectPvs &pvs = (*vit)->GetPvs();
+	  if (Overlap(box, (*vit)->GetBox())) {
+		  pvs.Clear();
+		  removedEntries += pvs.GetSize();
+	  } else {
+		  //	cout<<(*vit)->GetBox()<<" "<<box<<endl;
+		  shadowVolume.Init((*vit)->GetBox(), box);
+		  if (shadowVolume.CntPlanes() > maxPlanes)
+			  maxPlanes = shadowVolume.CntPlanes();
+
+		  int j = 0;
+		  for (int i=0; i < pvs.mEntries.size(); i++) {
+			  allEntries++;
+			  Intersectable *o = pvs.mEntries[i].mObject;
+			  if (o == inter) {
+				  removedSelfEntries++;
+			  } else {
+				  if (!shadowVolume.TestIsInsideShaft(o->GetBox())) {
+					  if (j != i)
+						  pvs.mEntries[j] = pvs.mEntries[i];
+					  j++;
+				  } else {
+					  removedEntries++;
+				  }
+			  }
 		  }
-		}
+		  // now the pvs has to be resorted
+		  pvs.mLastSorted = 0;
+		  if (j==0)
+			  pvs.mEntries.clear();
+		  else {
+			  pvs.mEntries.resize(j);
+			  if (j>1)
+				  pvs.SimpleSort();
+		  }
 	  }
-	  // now the pvs has to be resorted
-	  pvs.mLastSorted = 0;
-	  if (j==0)
-		pvs.mEntries.clear();
-	  else {
-		pvs.mEntries.resize(j);
-		if (j>1)
-		  pvs.SimpleSort();
-	  }
-	}
+
+	  ViewCell *vc = *vit;
+
+	  // recompute render cost
+	  float renderCost = _HackComputeRenderCost(vc);
+	  vc->GetPvs().mStats.mWeightedTriangles = renderCost;
   }
   
@@ -1754,13 +1822,11 @@
 	if (mUpdateDynamicObjects) 
 	{
-
 		// delete ALL dynamic stuff and rebuild using the new trafos
 		preprocessor->mRayCaster->DeleteDynamicObjects();
 
-#define MULTIPLE_OBJECTS 1
+#define MULTIPLE_OBJECTS 0
 
 #if MULTIPLE_OBJECTS 
 		static ObjectContainer objects;
-
 		CLEAR_CONTAINER(objects);
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2719)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2720)
@@ -589,11 +589,11 @@
 
 	//cout << "dynamic objects in pvs " << mDynamicPvsObjects.size() << endl;;
-
+#if 0
 	for (dit = mDynamicPvsObjects.begin(); dit != dit_end; ++ dit)
 	{
 		_RenderDynamicObject(*dit);
 	}
-
-	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+#endif
+	//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 
 	// show placed dynamic objects as wireframe
@@ -789,5 +789,5 @@
 
 	int pixelCount = query->GetQueryResult();
-	pErrorPixels = ((float)pixelCount) / (GetWidth() * GetHeight());
+	pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight());
 	
 	if (0) cout << "error pixels=" << pixelCount << endl;
@@ -1347,4 +1347,19 @@
 void QtGlRendererWidget::LoadObjects()
 {
+	AxisAlignedBox3 sceneBox = mViewCellsManager->GetViewSpaceBox();
+	
+	float x = 1.0f;
+	float y = 20.0f;
+	float z = 80.0f;
+
+	AxisAlignedBox3 box(Vector3(0.5f * x, 0, -0.5f * z), Vector3(-0.5f * x, y, 0.5f * z));
+
+//	box.Scale(Vector3(0.02f, 0.1f, 0.1f));
+
+	box.Translate(-box.Min());
+
+	SceneGraphLeaf *leaf = GetPreprocessor()->GenerateBoxGeometry(box);
+	mPlacer->AddObject(leaf);
+	
 	LoadObject("../data/teapot.bn");
 	LoadObject("../data/bunny.bn");
@@ -1625,45 +1640,4 @@
 }
 
-#if 0
-float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
-{
-	ObjectPvs basePvs;
-	
-	basePvs = vc->CopyPvs();
-	ObjectPvsIterator pit = basePvs.GetIterator();
-
-	float renderCost = 0;
-
-	//cout << "cost vis: " << mShowDistanceWeightedPvs << " " << " " << mShowDistanceWeightedTriangles << " " << mShowWeightedTriangles << endl;
-	
-	// first mark all objects from this pvs
-	while (pit.HasMoreEntries()) 	
-	{
-		KdIntersectable *kdObj = static_cast<KdIntersectable *>(pit.Next());
-
-		if (mShowDistanceWeightedPvs)
-		{
-			const AxisAlignedBox3 box = kdObj->GetBox();
-
-			const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
-			renderCost += 1.0f / dist;
-		}
-		else if (mShowDistanceWeightedTriangles)
-		{
-			const AxisAlignedBox3 box = kdObj->GetBox();
-
-			const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
-			renderCost += kdObj->ComputeNumTriangles() / dist;
-		}
-		else //if (mShowWeightedTriangles)
-		{
-			renderCost += kdObj->ComputeNumTriangles();
-		}
-		//if (pit.Next()->Mail();
-	}
-
-	return renderCost;
-}
-#else
 
 float QtGlRendererWidget::ComputeRenderCost(ViewCell *vc)
@@ -1688,6 +1662,4 @@
 #endif
 }
-#endif
-
 
 
@@ -1946,5 +1918,6 @@
 		if (0 && (i < 20))
 		{
-			cout << "pvs1: " << vc->GetPvs().GetSize() << " pvs2: " << compareInfo[i].mPvsSize << " importance: " << importance << endl;
+			cout << "pvs1: " << vc->GetPvs().GetSize() << " pvs2: " 
+				 << compareInfo[i].mPvsSize << " importance: " << importance << endl;
 		}
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.cpp	(revision 2710)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.cpp	(revision 2720)
@@ -63,5 +63,5 @@
 	AxisAlignedBox3 box = leaf->GetBox();
 
-	Vector3 p = box.Center() - pt;;
+	Vector3 p = box.Center() - pt;
 
 	// set pivot to ground of object
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2715)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2720)
@@ -208,5 +208,7 @@
 	virtual void ObjectRemoved(SceneGraphLeaf *object);
 
-
+	SceneGraphLeaf *GenerateBoxGeometry(const AxisAlignedBox3 &box);
+
+	float _HackComputeRenderCost(ViewCell *vc);
 
 	/////////////////////////
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2710)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2720)
@@ -368,8 +368,13 @@
 												  const bool isTermination) const
 {
+	//if (!ray.mTerminationObject) return NULL;
+	
 	// dynamic objects are scene graph leaves
 	const int index = ray.mTerminationObject->GetId();
+
 	if (index >= mPreprocessor->mObjects.size())
 	{
+		// Do nothing
+		return NULL;
 		for (size_t i = 0; i < mPreprocessor->mDynamicObjects.size(); ++ i)
 		{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj	(revision 2709)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj	(revision 2720)
@@ -529,4 +529,8 @@
 			>
 			<File
+				RelativePath=".\AxisAlignedBox3.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\AxisAlignedBox3.h"
 				>
@@ -952,8 +956,4 @@
 				>
 				<File
-					RelativePath=".\AxisAlignedBox3.cpp"
-					>
-				</File>
-				<File
 					RelativePath=".\Beam.cpp"
 					>
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h	(revision 2176)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Polygon3.h	(revision 2720)
@@ -105,7 +105,5 @@
 	*/
 	void Triangulate(vector<Triangle3> &triangles) const;
-
-	/** 
-		Triangle strip indices are created from this polgon.
+	/** Triangle strip indices are created from this polgon.
 	*/
 	void Triangulate(VertexIndexContainer &indices) const;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 2720)
@@ -165,7 +165,6 @@
   void
   GetSqrDistances(const Vector3 &point,
-		  float &minDistance,
-		  float &maxDistance
-		  ) const;
+				  float &minDistance,
+				  float &maxDistance) const;
 
   // returns true, when the sphere specified by the origin and radius
@@ -377,5 +376,7 @@
   */
   void ExtractPolys(PolygonContainer &polys) const;
-
+  /** Triangulate the box.
+  */
+  void Triangulate(ObjectContainer &triangles) const;
   /** Returns true if the mesh intersects the bounding box.
   */
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 2720)
@@ -8,5 +8,5 @@
 #include "Triangle3.h"
 #include "VssRay.h"
-
+#include "IntersectableWrapper.h"
 
 
@@ -2135,5 +2135,117 @@
     face6->mVertices.push_back(Vector3(mMax.x, mMax.y, mMax.z));
     face6->mVertices.push_back(Vector3(mMin.x, mMax.y, mMax.z));
-
+}
+ /* 
+   xxxxxx
+  x    xx
+ x    x x
+xxxxxx  x         
+x    x x 
+x    xx
+xxxxxx
+   */
+
+void AxisAlignedBox3::Triangulate(ObjectContainer &triangles) const
+{
+	/*PolygonContainer polys;
+	TriangleContainer tris;
+
+	ExtractPolys(polys);
+
+	for (size_t i = 0; i < polys.size(); ++ i)
+	{
+		Triangle tri;
+		polys[i].Trianulage(tris);
+	}*/
+
+	TriangleIntersectable *triObj;
+	Triangle3 tri;
+
+	tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z);
+	tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z);
+	tri.mVertices[2] = Vector3(mMin.x, mMax.y ,mMin.z);
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+	tri.mVertices[0] = Vector3(mMin.x, mMax.y ,mMin.z);
+	tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z);
+    tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z);
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+	tri.mVertices[0] = Vector3(mMax.x, mMin.y, mMin.z);
+    tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z);
+    tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z);
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+    tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z);
+	tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z);
+	tri.mVertices[2] = Vector3(mMax.x, mMin.y, mMin.z);
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+    tri.mVertices[0] = Vector3(mMax.x, mMin.y ,mMin.z);
+	tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z);
+	tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z);
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+	tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z);	
+	tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z);
+    tri.mVertices[2] = Vector3(mMax.x, mMin.y ,mMin.z);
+
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+	tri.mVertices[0] = Vector3(mMin.x, mMax.y, mMin.z);
+	tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z);
+	tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z);
+
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+	tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z);
+	tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z);
+	tri.mVertices[2] = Vector3(mMin.x, mMax.y, mMin.z);
+    
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+	tri.mVertices[0] = Vector3(mMin.x, mMax.y, mMin.z);
+	tri.mVertices[1] = Vector3(mMax.x, mMax.y, mMin.z);
+    tri.mVertices[2] = Vector3(mMax.x, mMin.y, mMin.z);
+
+	   
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+    tri.mVertices[0] = Vector3(mMax.x, mMin.y, mMin.z);
+	tri.mVertices[1] = Vector3(mMin.x, mMin.y, mMin.z);
+	tri.mVertices[2] = Vector3(mMin.x, mMax.y, mMin.z);
+	   
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+    tri.mVertices[0] = Vector3(mMin.x, mMin.y, mMax.z);
+	tri.mVertices[1] = Vector3(mMax.x, mMin.y, mMax.z);
+    tri.mVertices[2] = Vector3(mMax.x, mMax.y, mMax.z);
+
+	   
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
+
+    tri.mVertices[0] = Vector3(mMax.x, mMax.y, mMax.z);
+    tri.mVertices[1] = Vector3(mMin.x, mMax.y, mMax.z);
+    tri.mVertices[2] = Vector3(mMin.x, mMin.y, mMax.z);
+	   
+	triObj = new TriangleIntersectable(tri);
+	triangles.push_back(triObj);
 }
 
