Index: GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 2635)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 2636)
@@ -4,5 +4,5 @@
 
 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+"
-COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=1000000 -total_samples=20000000 -mutation_use_pass_importance- -mutation_silhouette_search_steps=3 -preprocessor_ray_cast_method=1 -preprocessor_detect_empty_viewspace+"
+COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=20000000 -mutation_use_pass_importance- -mutation_silhouette_search_steps=3 -preprocessor_ray_cast_method=3 -preprocessor_detect_empty_viewspace+"
 
 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2621)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2636)
@@ -78,5 +78,5 @@
 	/// used as actual pvs entry
 	ObjectContainer mGeometry;
-
+  const Matrix4x4 &GetTransformation() const { return mTrafo; }
 protected:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2634)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2636)
@@ -1235,5 +1235,8 @@
 			pruneInvalidRays);
 
-#if DYNAMIC_OBJECTS_HACK
+		//#if DYNAMIC_OBJECTS_HACK
+		// disabled not neccessary
+		UpdateDynamicObjects();
+#if 0
 		static Ray hRay;
 		VssRayContainer::iterator vit, vit_end = vssRays.end();
@@ -1722,4 +1725,5 @@
 
 		mDynamicObjects.push_back(tmi);
+		
 		return true;
 	}
@@ -1733,4 +1737,9 @@
 		leaf->RebuildKtbTree();
 		mSceneGraph->GetRoot()->mChildren.push_back(leaf);
+
+		if (mRayCaster)
+		  mRayCaster->AddDynamicObjecs(leaf->mGeometry, leaf->GetTransformation());
+
+
 		return true;
 	}
@@ -1741,3 +1750,50 @@
 }
 
-}
+
+void
+Preprocessor::ObjectMoved(SceneGraphLeaf *object)
+{
+  // first invalidate all PVS from which this object is visible
+  ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
+  
+  AxisAlignedBox3 box = object->GetBox();
+
+  KdNode::NewMail();
+
+  ObjectContainer objects;
+  // first mail all kDObjects which are intersected by the object
+  preprocessor->mKdTree->CollectKdObjects(box,
+										  objects);
+  
+  // now search for pvss which contained any mailed node
+  for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) {
+	ObjectPvs &pvs = (*vit)->GetPvs();
+	for (int i=0; i < objects.size(); i++) {
+	  vector<PvsEntry<Intersectable *,PvsData> >::iterator v;
+	  //	  ObjectPvsIterator it;
+	  if (pvs.Find(objects[i], v)) {
+		// clear the pvs
+		pvs.Clear();
+		break;
+	  }
+	}
+  }
+  
+}
+
+void
+Preprocessor::UpdateDynamicObjects()
+{
+  if (mUpdateDynamicObjects) {
+	preprocessor->mRayCaster->DeleteDynamicObjects();
+	
+	for (int i=0; i < mDynamicObjects.size(); i++) {
+	  SceneGraphLeaf *l = mDynamicObjects[i];
+	  mRayCaster->AddDynamicObjecs(l->mGeometry, l->GetTransformation());
+	  preprocessor->ObjectMoved(l);
+	}
+	mUpdateDynamicObjects = false;
+  }
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2635)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2636)
@@ -17,5 +17,5 @@
 #include "IntersectableWrapper.h"
 #include "LogWriter.h"
-
+#include "RayCaster.h"
 
 
@@ -664,4 +664,13 @@
 }
 
+void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *e)
+{
+
+  if (e->modifiers() & Qt::AltModifier) 
+	if (mCurrentDynamicObjectIdx >= 0) {
+	  //	  preprocessor->ScheduleUpdateDynamicObjects();
+	}
+}
+
 void
 QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
@@ -722,6 +731,8 @@
 			tmi->ApplyWorldTransform(tm);
 #else
-			SceneGraphLeaf *l = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
+			SceneGraphLeaf *l =
+			  mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
 			l->ApplyTransform(tm);
+			
 #endif
 			updateGL();
@@ -744,8 +755,4 @@
 }
 
-void
-QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *)
-{
-}
 
 void
@@ -1021,5 +1028,7 @@
 	connect(mControlWidget, SIGNAL(SetRotation(bool)), this, SLOT(SetRotation(bool)));
 	connect(mControlWidget, SIGNAL(SetScale(bool)), this, SLOT(SetScale(bool)));
-	
+
+	connect(mControlWidget, SIGNAL(UpdateDynamicObjects()), this, SLOT(UpdateDynamicObjects()));
+
 	setWindowTitle("PVS Visualization");
 
@@ -1091,9 +1100,10 @@
 	++ mCurrentDynamicObjectIdx;
 
-	if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename))
-		cout << "Loading finished" << endl;
-	else
-		cerr << "Loading failed" << endl;
-
+	if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename)) {
+	  
+	  cout << "Loading finished" << endl;
+	} else
+	  cerr << "Loading failed" << endl;
+	
     updateGL();
 }
@@ -1742,9 +1752,15 @@
 
 	vbox2->addStretch(1);
+
+
+	QPushButton *button = new QPushButton("Update", groupBox);
+	vbox2->addWidget(button);
+	connect(button, SIGNAL(clicked()), SIGNAL(UpdateDynamicObjects()));
+	
+	
 	groupBox->setLayout(vbox2);
-
+	
 	return groupBox;
 }
-
 
 
@@ -2373,3 +2389,10 @@
 }
 
-}
+void
+QtGlRendererWidget::UpdateDynamicObjects()
+{
+  preprocessor->ScheduleUpdateDynamicObjects();
+  
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2633)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2636)
@@ -108,5 +108,5 @@
 
   signals:
-
+  void UpdateDynamicObjects();
   void ComputeVisibility();
   void StopComputation();
@@ -310,5 +310,5 @@
 
 public slots:
-
+void UpdateDynamicObjects();
 	void UpdateAllPvs();
 	void ComputeVisibility();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2633)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2636)
@@ -273,5 +273,11 @@
 
 
-	int mGenericStats;
+  int mGenericStats;
+
+  void ScheduleUpdateDynamicObjects() {
+	mUpdateDynamicObjects = true;
+  }
+
+  void UpdateDynamicObjects();
 
 protected:
@@ -291,5 +297,5 @@
 	virtual void EvalViewCellHistogram();
 
-
+  virtual void ObjectMoved(SceneGraphLeaf *object);
 	/////////////////////////
 
@@ -309,4 +315,6 @@
 
 	PreprocessorThread *mThread;
+
+  bool mUpdateDynamicObjects;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 2582)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Pvs.h	(revision 2636)
@@ -446,5 +446,4 @@
 bool VerbosePvs<T, S>::RemoveSample(T sample, const float pdf)
 {
-	-- mSamples;
 	
 	typename vector<PvsEntry<T, S> >::iterator it;
@@ -453,4 +452,7 @@
 	if (!entryFound)
 		return false;
+
+	// $$JB decrement only if the sample found
+	-- mSamples;
 
 	S &data = (*it).mData;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2634)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2636)
@@ -152,5 +152,5 @@
   tStack.push(tdata);
   AxisAlignedBox3 backBox, frontBox;
-
+  
   while (!tStack.empty()) {
 	//	cout<<mStat.Nodes()<<" "<<mTermMaxNodes<<endl;
