Index: GTP/trunk/Lib/Vis/Preprocessing/include/Mesh.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/include/Mesh.h	(revision 68)
+++ GTP/trunk/Lib/Vis/Preprocessing/include/Mesh.h	(revision 2609)
@@ -16,5 +16,6 @@
   };
 
-  /** Mesh containing polygonal patches */
+  /** Mesh containing polygonal patches 
+  */
   class Mesh {
   public:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 2600)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 2609)
@@ -234,5 +234,5 @@
 	{
 		///////////////////
-		//-- load data as single triangles instead of whole meshes
+		//-- load data as triangle soup instead of whole meshes
 
 		cout << "m";	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2606)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2609)
@@ -5,5 +5,5 @@
 #include "Containers.h"
 #include "AxisAlignedBox3.h"
-
+#include "Matrix4x4.h"
 
 namespace GtpVisibilityPreprocessor {
@@ -37,6 +37,4 @@
 	virtual void UpdateBox();
 
-	~SceneGraphInterior();
-
 //protected:
 
@@ -51,19 +49,27 @@
 public:
 
+	SceneGraphLeaf(bool isDynamic = false): 
+	  mIsDynamic(isDynamic){}
+	~SceneGraphLeaf();
+
+	virtual void Transform(const Matrix4x4 &trafo);
+	virtual bool IsDynamic() const { return mIsDynamic;}
 	virtual bool IsLeaf() const { return true; }
 	virtual void UpdateBox();
 
-	~SceneGraphLeaf();
+	ObjectContainer mGeometry;
 
-//protected:
+protected:
 
-	//MeshContainer mGeometry;
-	ObjectContainer mGeometry;
+	bool mIsDynamic;
+	Matrix4x4 mTrafo;
 };
 
 
 
-/** Scene graph class */
-class SceneGraph {
+/** Scene graph class 
+*/
+class SceneGraph 
+{
 
 public:
@@ -81,9 +87,7 @@
 
 	AxisAlignedBox3 GetBox() const { return mRoot->mBox; }
-  
 	/** Exports binary version of the scene.
 	*/
 	void ExportScene(const std::string filename);
-
 	/** Loads binary version of the scene.
 	*/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 2575)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp	(revision 2609)
@@ -3854,5 +3854,6 @@
 	{  
 		VssRay *ray = rays[i];
-	
+
+#if VSS_STORE_VIEWCELLS
 		// traverse leaves stored in the rays and compare and 
 		// merge consecutive leaves (i.e., the neighbors in the tree)
@@ -3913,4 +3914,5 @@
 			}
         }
+#endif
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h	(revision 2575)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Ray.h	(revision 2609)
@@ -38,16 +38,4 @@
   struct Intersection 
   {
-	  /// the point of intersection
-	  float mT;
-
-	  /// the normal of the intersection
-	  Vector3 mNormal;
-
-	  /// can be either mesh or a viewcell
-	  Intersectable *mObject;
-
-	/// the face of the intersectable
-	  int mFace;
-
 	  Intersection(const float t,
 								 const Vector3 &normal,
@@ -59,5 +47,16 @@
 	  Intersection(): mT(0), mNormal(0,0,0), mObject(NULL), mFace(0) 
 	  {}
-		
+
+
+  	  /// the point of intersection
+	  float mT;
+	  /// the normal of the intersection
+	  Vector3 mNormal;
+	  /// can be either mesh or a viewcell
+	  Intersectable *mObject;
+	  /// the face of the intersectable
+	  int mFace;
+
+
 	  bool operator<(const Intersection &b) const 
 	  {
@@ -69,9 +68,9 @@
   // I should have some abstract cell data type !!! here
   // corresponds to the spatial elementary cell
-  /** intersection with the source object if any */
+  
+  /// intersection with the source object if any
   Intersection sourceObject;
   
   std::vector<Intersection> intersections;
- // std::vector<BspIntersection> bspIntersections;
   std::vector<KdLeaf *> kdLeaves;
   std::vector<Intersectable *> testedObjects;
@@ -84,15 +83,17 @@
   // constructors
   Ray(const Vector3 &wherefrom,
-      const Vector3 &whichdir,
-      const int _type):mFlags(CULL_BACKFACES) {
-    loc = wherefrom;
-    if (_type == LINE_SEGMENT)
-      dir = whichdir;
-    else
-      dir = Normalize(whichdir);
-    mType = _type;
-    depth = 0;
-	Init();
-  }
+	  const Vector3 &whichdir,
+	  const int _type): mFlags(CULL_BACKFACES) 
+  {
+	  loc = wherefrom;
+	  if (_type == LINE_SEGMENT)
+		  dir = whichdir;
+	  else
+		  dir = Normalize(whichdir);
+	  mType = _type;
+	  depth = 0;
+	  Init();
+  }
+
   // dummy constructor
   Ray() {}
@@ -100,7 +101,8 @@
   /** Construct ray from a vss ray.
   */
-  Ray(const VssRay &vssRay) {
-	Init(vssRay);
-	mFlags |= CULL_BACKFACES;
+  Ray(const VssRay &vssRay) 
+  {
+	  Init(vssRay);
+	  mFlags |= CULL_BACKFACES;
   }
 
@@ -130,11 +132,12 @@
 	    const Vector3 &whichdir,
 	    const int _type, 
-	    bool dirNormalized = false) {
-    loc = wherefrom;
-    dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ;
-    mType = _type;
-    depth = 0;
-    Init();
-	Precompute();
+	    bool dirNormalized = false) 
+  {
+	  loc = wherefrom;
+	  dir = (dirNormalized || _type == LINE_SEGMENT) ? whichdir: Normalize(whichdir) ;
+	  mType = _type;
+	  depth = 0;
+	  Init();
+	  Precompute();
   }
 
@@ -253,5 +256,4 @@
   int mType;
  
-  
   // unique ID of a ray for the use in the mailboxes
   int ID;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 2601)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 2609)
@@ -276,3 +276,9 @@
 }
 
-}
+
+void SceneGraphLeaf::Transform(const Matrix4x4 &trafo)
+{
+	mTrafo *= trafo;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 2017)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp	(revision 2609)
@@ -2822,4 +2822,5 @@
 	{  
 		VssRay *ray = rays[i];
+#if VSS_STORE_VIEWCELLS
 	
 		// traverse leaves stored in the rays and compare and 
@@ -2875,5 +2876,5 @@
 				candidates.push_back(mc);
 
-				if (((int)candidates.size() % 1000) == 0)
+				if ((candidates.size() % 1000) == 0)
 				{
 					cout << "collected " << (int)candidates.size() << " merge candidates" << endl;
@@ -2881,4 +2882,5 @@
 			}
         }
+#endif
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2606)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2609)
@@ -115,5 +115,4 @@
 	DEL_PTR(mViewCellsManager);
 	cout << "done.\n";
-
 	
 	cout << "Deleting bsp tree ... \n";
@@ -136,7 +135,9 @@
 	DEL_PTR(mRenderSimulator);
 	mRenderSimulator = NULL;
+
 	cout << "deleting renderer ... \n";
 	DEL_PTR(renderer);
 	renderer = NULL;
+
 	cout << "deleting ray caster ... \n";
 	DEL_PTR(mRayCaster);
@@ -1093,34 +1094,4 @@
 			       const string &internKdTree)
 {
-	// always try to load the kd tree
-/*	cout << "loading kd tree file " << internKdTree << " ... " << endl;
-
-	if (!LoadKdTree(internKdTree))
-	{
-		cout << "error loading kd tree with filename " 
-			 << internKdTree << ", rebuilding it instead ... " << endl;
-		// build new kd tree from scene geometry
-		BuildKdTree();
-
-		// export kd tree?
-		const long startTime = GetTime();
-		cout << "exporting kd tree ... ";
-
-		if (!ExportKdTree(internKdTree))
-		{
-			cout << " error exporting kd tree with filename " 
-				 << internKdTree << endl;
-		}
-		else
-		{
-			cout << "finished in " 
-				 << TimeDiff(startTime, GetTime()) * 1e-3 
-				 << " secs" << endl;
-		}
-	}
-	
-	KdTreeStatistics(cout);
-	cout << mKdTree->GetBox() << endl;
-*/
 	int rayCastMethod;
 	Environment::GetSingleton()->
@@ -1204,5 +1175,4 @@
 					   )
 {
-
 	const long t1 = GetTime();
 
@@ -1234,4 +1204,42 @@
 			castDoubleRays,
 			pruneInvalidRays);
+
+#if DYNAMIC_OBJECTS_HACK
+
+		static Ray hRay;
+
+		VssRayContainer::iterator vit, vit_end = vssRays.end();
+
+		for (vit = vssRays.begin(); vit != vit_end; ++ vit)
+		{
+			VssRay *vssRay = *vit;
+			hRay.Init(*vssRay);
+
+			DynamicObjectsContainer::const_iterator tit, tit_end = mDynamicObjects.end();
+
+			bool foundIntersect = false;
+			for (tit = mDynamicObjects.begin(); tit != tit_end; ++ tit)
+			{
+				TransformedMeshInstance *tmi = *tit;
+				if (tmi->CastRay(hRay)) //cout << "z"; else cout<< "r";
+				{
+					cout << "i: " << Intersectable::GetTypeName(hRay.intersections[0].mObject);
+					foundIntersect = true;
+				}
+			}
+
+			if (foundIntersect)
+				cout << "x: " << Intersectable::GetTypeName(hRay.intersections[0].mObject);
+
+			if (foundIntersect)
+				// write new results back into vssRay
+				vssRay->Init(hRay);
+
+			if (foundIntersect)
+				cout << "y : " << Intersectable::GetTypeName(vssRay->mTerminationObject);
+
+			hRay.intersections.clear();
+		}
+#endif
 	}
 
@@ -1595,16 +1603,91 @@
 
 
-bool Preprocessor::AddGeometry(const string &filename,
-							   ObjectContainer &pvsObjects, 
-							   const ObjectContainer &preprocessorObjects)
-{
-//	bool success = LoadBinaryObj(filename, mSceneGraph->GetRoot(), &mFaceParents);
-	SceneGraphLeaf *leaf = new SceneGraphLeaf();
-	if (LoadBinaryObj(filename, leaf, NULL))
-	{
+Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename)
+{
+	igzstream inStream(filename.c_str());
+	
+	if (!inStream.is_open())
+		return NULL;
+
+	cout << "binary obj dump available, loading " << filename.c_str() << endl;
+	
+	// read in triangle size
+	int numTriangles;
+
+	inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int));
+	
+	cout << "loading " << numTriangles << " triangles into mesh" << endl;
+
+	int i = 0, j = 0;
+
+	Mesh *mesh = new Mesh(numTriangles * 3, numTriangles);
+
+	const int t = 500000;
+	while (1)
+	{
+		Triangle3 tri;
+		
+		inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i]), sizeof(Vector3));
+		inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 1]), sizeof(Vector3));
+		inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 2]), sizeof(Vector3));
+
+		
+		mesh->mVertices[i].x += 20;
+		mesh->mVertices[i + 1].x += 20;
+		mesh->mVertices[i + 2].x += 20;
+
+		mesh->mVertices[i].z -= 10;
+		mesh->mVertices[i + 1].z -= 10;
+		mesh->mVertices[i + 2].z -= 10;
+
+		mesh->mVertices[i] *= 50;
+		mesh->mVertices[i + 1] *= 50;
+		mesh->mVertices[i + 2] *= 50;
+
+		mesh->AddFace(new Face(i + 0, i + 1, i + 2));
+
+		// end of file reached
+		if (inStream.eof())
+			break;
+
+		i += 3;
+		if (((j ++) % t) == (t - 1))
+			 cout<<"\r"<<i<<"/"<<numTriangles<<"\r";
+	}
+	
+	if (j != numTriangles)
+	{
+		cout << "warning: triangle size does not match with loaded triangle size" << endl;
+		return false;
+	}
+
+	mesh->Preprocess();
+	cout << "loaded " << numTriangles << " triangles" << endl;
+
+	return mesh;
+}
+
+
+bool Preprocessor::LoadDynamicGeometry(const string &filename)
+{
+	const bool dynamic = true;
+
+	Mesh *mesh = LoadBinaryObjIntoMesh(filename);
+    
+	if (mesh)
+	{
+		SceneGraphLeaf *leaf = new SceneGraphLeaf(dynamic);
+
+		TransformedMeshInstance *tmi = new TransformedMeshInstance(mesh);
+		leaf->mGeometry.push_back(tmi);
+
 		mSceneGraph->GetRoot()->mChildren.push_back(leaf);
+		//mDynamicObjects.push_back(leaf);
+		mDynamicObjects.push_back(tmi);
+
 		return true;
 	}
 
+
 	return false;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Ray.cpp	(revision 2609)
@@ -227,25 +227,25 @@
 }
 
-void
-Ray::Init(const VssRay &vssRay)
-{
-  loc = vssRay.mOrigin;
-  sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0);
-  mType = LOCAL_RAY;
-  
-  float len = vssRay.Length();
-  
-  if (!len)
-	len = Limits::Small;
-  
-  dir = vssRay.GetDir() / len;
-  
-  intersections.clear();
-  if (vssRay.mTerminationObject)
-	intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0));
-
-  
-  Precompute();
-}
-
-}
+
+void Ray::Init(const VssRay &vssRay)
+{
+	loc = vssRay.mOrigin;
+	sourceObject = Intersection(0, vssRay.GetDir(), vssRay.mOriginObject, 0);
+	mType = LOCAL_RAY;
+
+	float len = vssRay.Length();
+
+	if (!len)
+		len = Limits::Small;
+
+	dir = vssRay.GetDir() / len;
+
+	intersections.clear();
+
+	if (vssRay.mTerminationObject)
+		intersections.push_back(Intersection(len, -vssRay.GetDir(), vssRay.mTerminationObject, 0));
+
+	Precompute();
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2604)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2609)
@@ -369,8 +369,16 @@
 	glNormalPointer(GL_FLOAT, 0, (char *)arrayPtr + offset * sizeof(Vector3));
 	glDrawElements(GL_TRIANGLES, mIndexBufferSize, GL_UNSIGNED_INT, mIndices);
-}
-
-
-void QtGlRendererWidget::_UpdatePvsIndices()
+
+	// handle dynamic objects
+	DynamicObjectsContainer::const_iterator dit, dit_end = mDynamicObjects.end();
+
+	for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit)
+	{
+		RenderIntersectable(*dit);
+	}
+}
+
+
+void QtGlRendererWidget::PreparePvs()
 {
 	int indexBufferSize = 0;
@@ -381,4 +389,6 @@
 	mPvsSize = mPvsCache.mPvs.GetSize();
 
+	mDynamicObjects.clear();
+
 	ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
 
@@ -386,7 +396,18 @@
 	{
 		Intersectable *obj = it.Next();
-		KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
-
-		_UpdatePvsIndices(node, indexBufferSize);
+		switch (obj->Type())
+		{
+		case Intersectable::KD_INTERSECTABLE:
+			{
+				KdNode *node = static_cast<KdIntersectable *>(obj)->GetItem();
+				_UpdatePvsIndices(node, indexBufferSize);
+			}
+			break;
+		case Intersectable::TRANSFORMED_MESH_INSTANCE:
+			mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj));
+			break;
+		default:
+			cerr << "PreparePvs: type " << Intersectable::GetTypeName(obj) << " not handled yet" << endl;
+		}
 	}
 
@@ -421,15 +442,4 @@
 				static_cast<TriangleIntersectable *>(leaf->mObjects[i]);
 
-			// check if already rendered
-			/*if (!obj->Mailed())
-			{
-				obj->Mail();
-
-				mIndices[indexBufferSize + 0] = (obj->GetId() - 1) * 3 + 0;
-				mIndices[indexBufferSize + 1] = (obj->GetId() - 1) * 3 + 1;
-				mIndices[indexBufferSize + 2] = (obj->GetId() - 1) * 3 + 2;
-
-				indexBufferSize += 3;
-			}*/
 			if (obj->mRenderedFrame != mCurrentFrame)
 			{
@@ -481,6 +491,4 @@
 			if (mUseSpatialFilter) 
 			{
-				//ObjectPvs pvs;
-
 				//mMutex.lock();
 				// mSpatialFilter size is in range 0.001 - 0.1
@@ -500,11 +508,9 @@
 
 			/// update the indices for rendering
-			_UpdatePvsIndices();
+			PreparePvs();
 
 			emit PvsUpdated();
 		}
 
-		//Intersectable::NewMail();
-		PvsData pvsData;
 
 		// Render PVS
@@ -519,45 +525,7 @@
 		{
 			if (!mRenderVisibilityEstimates && !mUseRandomColorPerPvsObject)
-			{
 				_RenderPvs();
-			}
 			else
-			{
-				mPvsSize = mPvsCache.mPvs.GetSize();
-
-				ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
-
-				while (it.HasMoreEntries())
-				{
-					Intersectable *object = it.Next(pvsData);
-
-					RgbColor color;
-
-					//float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
-					// glColor3f(visibility, 0.0f, 0.0f);
-					//cerr << "sumpdf: " << pvsData.mSumPdf << endl;
-					if (mUseRandomColorPerPvsObject)
-					{
-						KdIntersectable *kdint = static_cast<KdIntersectable *>(object);
-
-						if (kdint->mGenericIdx == -1)
-						{
-							kdint->mGenericIdx = (int)mColors.size();
-							mColors.push_back(RandomColor());
-						}
-						color = mColors[kdint->mGenericIdx];
-					} 
-					else
-					{
-						color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1));
-					}
-
-					glColor3f(color.r, color.g, color.b);
-
-					mUseForcedColors = true;
-					RenderIntersectable(object);
-					mUseForcedColors = false;
-				}
-			}
+				_RenderColoredPvs();
 		}
 
@@ -587,7 +555,4 @@
 		RenderScene();
 	}
-
-	//DisableDrawArrays();
-	//glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
 }
 
@@ -673,7 +638,7 @@
 {
 	float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
-	float TURN_SENSITIVITY=0.1f;
-	float TILT_SENSITIVITY=32.0 ;
-	float TURN_ANGLE= M_PI/36.0 ;
+	float TURN_SENSITIVITY = 0.1f;
+	float TILT_SENSITIVITY = 32.0 ;
+	float TURN_ANGLE= M_PI  /36.0 ;
 
 	int x = e->pos().x();
@@ -685,6 +650,6 @@
 	if (e->modifiers() & Qt::ControlModifier) 
 	{
-		mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY/2.0;
-		mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY/2.0;
+		mViewPoint.y += (y-mousePoint.y)*MOVE_SENSITIVITY / 2.0;
+		mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0;
 	} 
 	else 
@@ -930,4 +895,5 @@
 	connect(mControlWidget, SIGNAL(SetRandomViewPoint()), this,	SLOT(SetRandomViewPoint()));
 	connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void)));
+	connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void)));
 
 	connect(mControlWidget, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int)));
@@ -1029,4 +995,19 @@
 }
 
+
+void QtGlRendererWidget::LoadObject()
+{
+	string filename("../data/bunny.bn");
+	
+	cout << "Loading model << " << filename << endl;
+
+	if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename))
+		cout << "Loading finished" << endl;
+	else
+		cerr << "Loading failed" << endl;
+
+    updateGL();
+}
+
 void
 QtGlRendererWidget::RenderRenderCost()
@@ -1176,5 +1157,5 @@
 	
 	QFont font40; font40.setPointSize(30);
-	s.sprintf("pvs:%04d", mPvsSize);
+	s.sprintf("PVS: %04d", mPvsSize);
 	renderText(20, 40, s, font40);
 }
@@ -1862,5 +1843,4 @@
 	QGroupBox *groupBox2 = CreateRenderCostPanel(hbox);
 	vh->addWidget(groupBox2, 0, 0);
-
 	
 	QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox);
@@ -1877,5 +1857,4 @@
 
 	vbox->resize(800,150);
-
 
 	vbox = new QGroupBox("Rendering", this);
@@ -2034,9 +2013,12 @@
 	connect(button, SIGNAL(clicked()), SIGNAL(StoreStatistics()));
 
+	button = new QPushButton("Load object", vbox);
+	vbox->layout()->addWidget(button);
+	connect(button, SIGNAL(clicked()), SIGNAL(LoadObject()));
+
 	/*cb = new QCheckBox("Stats", vbox);
 	vbox->layout()->addWidget(cb);
 	cb->setChecked(false);
-	connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));
-*/
+	connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/
 	if (0) 
 	{
@@ -2207,3 +2189,45 @@
 
 
-}
+void QtGlRendererWidget::_RenderColoredPvs()
+{
+	// note: could be done more efficiently using color buffers
+	mPvsSize = mPvsCache.mPvs.GetSize();
+
+	ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
+
+	PvsData pvsData;
+
+	while (it.HasMoreEntries())
+	{
+		Intersectable *object = it.Next(pvsData);
+
+		RgbColor color;
+
+		//float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
+		// glColor3f(visibility, 0.0f, 0.0f);
+		//cerr << "sumpdf: " << pvsData.mSumPdf << endl;
+		if (mUseRandomColorPerPvsObject)
+		{
+			KdIntersectable *kdint = static_cast<KdIntersectable *>(object);
+
+			if (kdint->mGenericIdx == -1)
+			{
+				kdint->mGenericIdx = (int)mColors.size();
+				mColors.push_back(RandomColor());
+			}
+			color = mColors[kdint->mGenericIdx];
+		} 
+		else
+		{
+			color = RainbowColorMapping(mTransferFunction * log10(pvsData.mSumPdf + 1));
+		}
+
+		glColor3f(color.r, color.g, color.b);
+
+		mUseForcedColors = true;
+		RenderIntersectable(object);
+		mUseForcedColors = false;
+	}
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2604)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2609)
@@ -109,4 +109,5 @@
   void SetRandomViewPoint();
   void StoreStatistics();
+  void LoadObject();
   void UpdateAllPvs();
   void SetViewCellGranularity(int);
@@ -224,4 +225,6 @@
 	bool mUseRandomColorPerPvsObject;
 
+	DynamicObjectsContainer mDynamicObjects;
+
 	QtGlRendererWidget(SceneGraph *sceneGraph,
 		               ViewCellsManager *viewcells,
@@ -270,11 +273,7 @@
 		SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
 
-	void
-		RenderViewCells();
-
-
-	virtual void Show() {
-		show();
-	}
+	void RenderViewCells();
+
+	virtual void Show() { show(); }
 
 	bool PvsChanged(ViewCell *viewcell) const;
@@ -300,5 +299,4 @@
 
 	/////////
-
 	//QMutex mMutex;
 
@@ -311,4 +309,5 @@
 	void SetRandomViewPoint();
 	void StoreStatistics();
+	void LoadObject();
 
 	void SetRenderErrors(bool b) {
@@ -517,7 +516,10 @@
 	}
 
+	void PreparePvs();
+
 	void _RenderPvs();
-
-	void _UpdatePvsIndices();
+	/** Render pvs using false colors.
+	*/
+	void _RenderColoredPvs();
 
 	void _UpdatePvsIndices(KdNode *node, int &indexBufferSize);
@@ -569,3 +571,2 @@
 
 #endif
-
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2605)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2609)
@@ -177,5 +177,5 @@
 
 	glLoadIdentity();
-	gluLookAt(0.0f, 0.0f, 10.0f,  // eye is at (0,0,30) 
+	gluLookAt(0.0f, 0.0f, 15.0f,  // eye is at (0,0,30) 
 		      0.0f, 0.0f, 0.0f,  // center is at (0,0,0) 
 		      0.0f, 1.0f, 0.0f); // up is in positive Y direction 
@@ -191,9 +191,8 @@
 	glTranslatef(t.x, t.y, t.z);
 
-	/*mDummyViewPoint = -t;
-	mDummyViewPoint /= s;
-
+	//mDummyViewPoint = -t;
+	//mDummyViewPoint /= s;
 	//glGetFloatv(GL_MODELVIEW_MATRIX, m1);
-*/
+
 	m.Invert();
 
@@ -243,6 +242,6 @@
 QtGlViewer::mouseMoveEvent(QMouseEvent *event)
 {
-  int dx = event->x() + lastPos.x();
-  int dy = event->y() + lastPos.y();  
+  int dx = event->x() - lastPos.x();
+  int dy = event->y() - lastPos.y();  
   
   if (event->modifiers() & Qt::CTRL)
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2600)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2609)
@@ -58,5 +58,4 @@
 
 	virtual ~Preprocessor();
-
 	/** Load the input scene. 
 		@param filename file to load
@@ -64,5 +63,4 @@
 	*/
 	virtual bool LoadScene(const string &filename);
-
 	/** Export all preprocessed data in a XML format understandable by the
 		PreprocessingInterface of the GtpVisibilityPreprocessor Module. 
@@ -71,5 +69,4 @@
 	*/
 	virtual bool ExportPreprocessedData(const string &filename);
-
 	/** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
 		is driven by the environment settings, which also sais which of the three types of
@@ -77,5 +74,4 @@
 	*/
 	virtual bool BuildKdTree();
-
 	/** Compute visibility method. This method has to be reimplemented by the actual
 		Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
@@ -83,10 +79,8 @@
 	*/
 	virtual bool ComputeVisibility() = 0;
-
 	/** Post Process the computed visibility. By default applys the visibility filter
 		(if specified in the environment and export the preprocessed data 
-		*/
+	*/
 	virtual bool PostProcessVisibility();
-
 	/** View cells are either loaded or prepared for generation, according to the chosen environment
 		object. Important evironment options are, e.g, the view cell type.
@@ -94,13 +88,10 @@
 	*/
 	bool PrepareViewCells();
-
 	/** Construct viewcells from the scratch 
 	*/
 	bool ConstructViewCells();
-
 	/** Returns the specified sample strategy, NULL if no valid strategy.
 	*/
 	SamplingStrategy *GenerateSamplingStrategy(const int strategyId);
-
 	/** Export preprocessor data.
 	*/
@@ -198,7 +189,10 @@
 							const ObjectContainer &preprocessorObject);
 
-	/** Adds new geometry to the existing one.
-	*/
-	bool AddGeometry(const string &filename, ObjectContainer &pvsObjects, const ObjectContainer &prepObjects);
+	/** Adds dynamic geometry
+	*/
+	bool LoadDynamicGeometry(const string &filename);
+
+	Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename);
+
 
 	/////////////////////////
@@ -212,5 +206,6 @@
 	/// kD-tree organizing the scene graph (occluders + occludees) + viewcells
 	KdTree *mKdTree;
-  AxisAlignedBox3 sceneBox;
+	AxisAlignedBox3 sceneBox;
+
 	/// View space partition bsp tree
 	VspBspTree *mVspBspTree;
@@ -222,7 +217,9 @@
 	/// list of all loaded occludees
 	ObjectContainer mOccludees;
-
-
+	/// the view cells manager
 	ViewCellsManager *mViewCellsManager;
+
+	//SceneGraphNodeContainer mDynamicObjects;
+	DynamicObjectsContainer mDynamicObjects;
 
 	/// greedy optimized hierarchy for both objects and view cells
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Containers.h	(revision 2609)
@@ -10,4 +10,5 @@
 namespace GtpVisibilityPreprocessor {
 
+class TransformedMeshInstance;
 class ViewCell;
 class HierarchyNode;
@@ -71,4 +72,8 @@
 typedef std::vector<int> VertexIndexContainer;
 
+/// a container for dynamic objects
+typedef std::vector<TransformedMeshInstance *> DynamicObjectsContainer;
+
+
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2606)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2609)
@@ -368,4 +368,8 @@
 												  const bool isTermination) const
 {
+#if DYNAMIC_OBJECTS_HACK
+	if (ray.mTerminationObject->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+		return ray.mTerminationObject;
+#endif
 	if (mUseKdPvs)
 	{
@@ -2483,17 +2487,15 @@
 									  const bool useHitObjects)
 {
-  if (!useHitObjects) 
-	{
-	  // store higher order object (e.g., bvh node) instead of object itself
-	  VssRayContainer::const_iterator it, it_end = rays.end();
-	  
-	  for (it = rays.begin(); it != it_end; ++ it) 
-		{
-		  VssRay *vssRay = *it;
-		  
-		  // set only the termination object
-		  //		  if (vssRay->mTerminationObject == NULL) 
-		  //			cerr<<"Error NULL termination object!"<<endl;
-		  vssRay->mTerminationObject = GetIntersectable(*vssRay, true);
+	if (!useHitObjects) 
+	{
+		// store higher order object (e.g., bvh node) instead of object itself
+		VssRayContainer::const_iterator it, it_end = rays.end();
+
+		for (it = rays.begin(); it != it_end; ++ it) 
+		{
+			VssRay *vssRay = *it;
+
+			// set only the termination object
+			vssRay->mTerminationObject = GetIntersectable(*vssRay, true);
 #if 0
 		  if (vssRay->mTerminationObject == NULL) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2604)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2609)
@@ -133,5 +133,5 @@
 void GlRenderer::RenderTriangle(TriangleIntersectable *object)
 {
-  Triangle3 *t = &(object->GetItem());
+	Triangle3 *t = &(object->GetItem());
 
 	glBegin(GL_TRIANGLES);
@@ -317,5 +317,4 @@
 
 	glPushMatrix();
-
 	glMultMatrixf((float *)m.x);
 
@@ -494,6 +493,14 @@
 	Intersectable::NewMail();
 
+	Preprocessor *p = mViewCellsManager->GetPreprocessor();
+	// handle dynamic objects
+	DynamicObjectsContainer::const_iterator dit, dit_end = p->mDynamicObjects.end();
+
+	for (dit = p->mDynamicObjects.begin(); dit != dit_end; ++ dit)
+	{
+		RenderIntersectable(*dit);
+	}
+
 #if 1
-
 	_RenderSceneTrianglesWithDrawArrays();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/common.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2603)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2609)
@@ -23,5 +23,5 @@
 #include <vector>
 
-
+#define DYNAMIC_OBJECTS_HACK 1
 #define USE_HAVRAN_RAYCASTER
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2588)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2609)
@@ -215,6 +215,6 @@
 	
 	int CastRay(Ray &ray) { return 0; }
-        int CastSimpleRay(const SimpleRay &ray) { return 0;}
-        int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;}
+	int CastSimpleRay(const SimpleRay &ray) { return 0;}
+	int CastSimpleRay(const SimpleRay &ray, int IndexRay) { return 0;}
 	
 	bool IsConvex() const { return true; }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 2575)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 2609)
@@ -62,37 +62,23 @@
 
 /** Mesh containing polygonal patches */
-class Mesh {
+class Mesh 
+{
 
 public:
 
   /// Default constructor
-  Mesh():mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {}
+  Mesh(): mVertices(), mFaces(), mMaterial(NULL), mKdTree(NULL), mId(0) {}
 
   /// Constructor with container preallocation
-  Mesh(const int vertices, const int faces):
-    mFaces(),
-    mMaterial(NULL),
-    mKdTree(NULL),
-    mVertices(),
-    mIsConvex(false),
-    mIsWatertight(false),
-	mId(0)
-  {
-    mVertices.reserve(vertices);
-    mFaces.reserve(faces);
-  }
-
+  Mesh(const int vertices, const int faces);
   /** Constructor setting a unqiue mesh id.
   */
   Mesh(const int id);
-
   /** Setting unique mesh id and using preallocation.
   */
   Mesh(const int id, const int vertices, const int faces);
-
   /** Copy constructor making a deep copy of the faces.
   */
   Mesh(const Mesh &rhs);
-
   /** Assignement operator.
 	@note does not copy id
@@ -116,9 +102,8 @@
   void AddFace(Face *face) 
   {
-    mFaces.push_back(face);
+	  mFaces.push_back(face);
   }
 
   void ComputeBoundingBox();
-
   /** This function must be called after creating the mesh
 	because it creates the local kd tree and the bounding box.
@@ -132,26 +117,15 @@
   void ApplyTransformation(const Matrix4x4 &m);
 
-  /** Axis aligned bounding box of the mesh in local mesh coordinates.
-  */
-  AxisAlignedBox3 mBox;
-  
-  /** Vertices forming the mesh.
-  */
+  /// Axis aligned bounding box of the mesh in local mesh coordinates.
+  AxisAlignedBox3 mBox; 
+  /// Vertices forming the mesh.
   VertexContainer mVertices;
-  
-  /** Patches forming the mesh.
-  */
+  /// Patches forming the mesh.
   FaceContainer mFaces;
-  
-  /** Global mesh material.
-  */
+  /// Global mesh material.
   Material *mMaterial;
-  
-  /** true if the mesh is a convex mesh.
-  */
+  /// true if the mesh is a convex mesh.
   bool mIsConvex;
-
-  /** true if the mesh is a convex mesh.
-  */
+  /// true if the mesh is a convex mesh.
   bool mIsWatertight;
 
@@ -202,8 +176,5 @@
   /** Returns unique mesh id.
   */
-  int GetId() const
-  {
-	  return mId;
-  }
+  int GetId() const { return mId; }
 
 
@@ -245,5 +216,5 @@
 
 public:
-	MeshInstance(Mesh *mesh):Intersectable(), mMesh(mesh), mMaterial(NULL)
+	MeshInstance(Mesh *mesh): Intersectable(), mMesh(mesh), mMaterial(NULL)
 	{
 	}
@@ -315,35 +286,31 @@
 {
 public:
-  TransformedMeshInstance(Mesh *mesh);
-  
-  virtual AxisAlignedBox3 GetBox() const;
-   
-  
-  virtual int CastRay(Ray &ray);
-
-  virtual int CastRay(Ray &ray, const std::vector<int> &faces);
-
-  virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; }
-
-  int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
-
-  /** Transforms this mesh instance by m.
-  */
-  void ApplyWorldTransform(const Matrix4x4 &m);
-
-  /** Loads the transformation matrix into this mesh instance.
-  */
-  void LoadWorldTransform(const Matrix4x4 &m);
-
-  /** The transformation is returned in m.
-  */
-  void GetWorldTransform(Matrix4x4 &m) const;
-
-  /** Transforms a mesh according to the stored world transform.
-	  @param transformedMesh returns the tranformed mesh.
-  */
-  void GetTransformedMesh(Mesh &transformedMesh) const;
-
-  Vector3 GetNormal(const int idx) const;
+	TransformedMeshInstance(Mesh *mesh);
+
+	virtual AxisAlignedBox3 GetBox() const;
+
+	virtual int CastRay(Ray &ray);
+
+	virtual int CastRay(Ray &ray, const std::vector<int> &faces);
+
+	virtual int Type() const { return TRANSFORMED_MESH_INSTANCE; }
+
+	int GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
+
+	/** Transforms this mesh instance by m.
+	*/
+	void ApplyWorldTransform(const Matrix4x4 &m);
+	/** Loads the transformation matrix into this mesh instance.
+	*/
+	void LoadWorldTransform(const Matrix4x4 &m);
+	/** The transformation is returned in m.
+	*/
+	void GetWorldTransform(Matrix4x4 &m) const;
+	/** Transforms a mesh according to the stored world transform.
+		@param transformedMesh returns the tranformed mesh.
+	*/
+	void GetTransformedMesh(Mesh &transformedMesh) const;
+
+	Vector3 GetNormal(const int idx) const;
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 2593)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 2609)
@@ -20,5 +20,5 @@
 
 #define ABS_CONTRIBUTION_WEIGHT 0.0f
-#define VSS_STORE_VIEWCELLS 1
+#define VSS_STORE_VIEWCELLS 0
 
 
@@ -69,18 +69,14 @@
   // sampling pass in which this ray was generated
   short mPass;
-
   /// Distribution used to generate this ray
   short mDistribution;
-  
   /// number of cells where this ray made a contribution to the PVS
   int mPvsContribution;
-  
   /// sum of relative ray contributions per object
   float mRelativePvsContribution;
-
-  /// weighted contribution to the pvs (based on the pass the ray was casted at)
-  /// computed by the prperocessor
+  /** weighted contribution to the pvs (based on the pass the ray was casted at)
+	 ccomputed by the prperocessor
+  */
   float mWeightedPvsContribution;
-
   /// probability of this ray
   float mPdf;
@@ -107,5 +103,6 @@
   VssRay(const Ray &ray);
 	
-  
+  void Init(const Ray &ray);
+
   void Precompute();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp	(revision 2593)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.cpp	(revision 2609)
@@ -41,18 +41,26 @@
 
 
-VssRay::VssRay(const Ray &ray):
-	mRefCount(0),
-	mFlags(0),
-	mMailbox(-1),
-	mOriginObject(ray.sourceObject.mObject),
-	mPass(0),
+VssRay::VssRay(const Ray &ray)
+{
+	Init(ray);
+}
+
+
+void VssRay::Init(const Ray &ray)
+{	
+	mRefCount = 0;
+	mFlags = 0;
+	mMailbox = -1;
+	mOriginObject = ray.sourceObject.mObject;
+	mPass = 0;
+	mPdf = 1.0f;
+	mTerminationNode = NULL;
+	mOriginNode = NULL;
+	mPvsContribution = 0;
+
 #if VSS_STORE_VIEWCELLS
-	mViewCells(0),
-#endif
-	mPdf(1.0f),
-	mTerminationNode(NULL),
-	mOriginNode(NULL),
-	mPvsContribution(0)
-{
+	mViewCells.clear();
+#endif
+
 	if (ray.sourceObject.mObject)
 		mOrigin = ray.Extrap(ray.sourceObject.mT);
@@ -68,5 +76,5 @@
 	else
 	{
-		mTermination = ray.Extrap(1e6); //TODO: should be Limits::Infinity
+		mTermination = ray.Extrap(1e6f); //TODO: should be Limits::Infinity
 		mTerminationObject = NULL;
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 2582)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 2609)
@@ -2238,8 +2238,9 @@
 void AxisAlignedBox3::EnlargeToMinSize()
 {
-  const float epsMin = 1e-7;
-  const float epsAdd = 1e-6;
-  const float epsMul = 1.000005;
+  const float epsMin = 1e-7f;
+  const float epsAdd = 1e-6f;
+  const float epsMul = 1.000005f;
   float dir = mMax.x - mMin.x;
+
   assert(dir >= 0.f);
   if (dir < epsMin) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 2609)
@@ -56,4 +56,18 @@
 
 };
+
+
+Mesh::Mesh(const int vertices, const int faces):
+mFaces(),
+mMaterial(NULL),
+mKdTree(NULL),
+mVertices(),
+mIsConvex(false),
+mIsWatertight(false),
+mId(0)
+{
+	mVertices.reserve(vertices);
+	mFaces.reserve(faces);
+}
 
 
