Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env	(revision 2604)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env	(revision 2614)
@@ -189,5 +189,5 @@
 MeshKdTree {
 	Termination {
-		minCost 150
+		minCost 20
 		maxDepth 18
 		maxCostRatio 0.9
@@ -195,6 +195,6 @@
 	}
 
-#	splitMethod spatialMedian
-	splitMethod SAH
+	splitMethod spatialMedian
+#	splitMethod SAH
 	splitBorder 0.01
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2604)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2614)
@@ -206,7 +206,7 @@
 	*/
 	virtual float ComputeSampleContribution(VssRay &ray, 
-											const bool addContributions,
-											const bool storeViewCells,
-											const bool useHitObject = false);
+											bool addContributions,
+											bool storeViewCells,
+											bool useHitObject = false);
 	/** Compute sample contribution only for current view cell.
 	*/
@@ -388,5 +388,5 @@
 	*/
 	void DeterminePvsObjects(VssRayContainer &rays,
-							 const bool useHitObjects = false);
+							 bool useHitObjects = false);
 	/** Sets validity of view cell
 	*/
@@ -640,10 +640,11 @@
 									 Intersectable *obj,
 									 const Vector3 &pt,
-									 const bool addRays);
+									 bool addRays);
 
 	void MergeViewCellsRecursivly(ObjectPvs &pvs, 
 								  const ViewCellContainer &viewCells, 
-								  const int leftIdx, 
-								  const int rightIdx) const;
+								  int leftIdx, 
+								  int rightIdx) const;
+
 	/** Intersects box with the tree and returns the number of intersected boxes.
 		@returns number of view cells found
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2610)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2614)
@@ -186,4 +186,5 @@
 	int numTriangles;
 
+	const int t = 500000;
 	inStream.read(reinterpret_cast<char *>(&numTriangles), sizeof(int));
 	root->mGeometry.reserve(numTriangles);
@@ -209,5 +210,5 @@
 		root->mGeometry.push_back(obj);
 		
-		if ((i ++) % 500000 == 499999)
+		if ((i ++) % t == t)
 			 cout<<"\r"<<i<<"/"<<numTriangles<<"\r";
 	}
@@ -1179,10 +1180,12 @@
 	// !!!!!!!!!!!!!!!! VH no sorting
 	if ( 
-	    rays.size() > 10000
+		rays.size() > 10000
 		)
-	  {
-	  mRayCaster->SortRays(rays);
-	  cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl;
-	}
+	{
+		mRayCaster->SortRays(rays);
+		cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl;
+	}
+
+	int numTransformed = 0;
 
 
@@ -1208,5 +1211,4 @@
 
 		static Ray hRay;
-
 		VssRayContainer::iterator vit, vit_end = vssRays.end();
 
@@ -1219,23 +1221,30 @@
 
 			bool foundIntersect = false;
+
 			for (tit = mDynamicObjects.begin(); tit != tit_end; ++ tit)
 			{
 				TransformedMeshInstance *tmi = *tit;
-				if (tmi->CastRay(hRay)) //cout << "z"; else cout<< "r";
+
+				float maxT, minT;
+	
+				// test with bounding box
+				if (tmi->GetBox().GetMinMaxT(hRay, &minT, &maxT))
 				{
-					cout << "i: " << Intersectable::GetTypeName(hRay.intersections[0].mObject);
-					foundIntersect = true;
+					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)
-				cout << "x: " << Intersectable::GetTypeName(hRay.intersections[0].mObject);
-
-			if (foundIntersect)
+			{
+				++ numTransformed;
 				// write new results back into vssRay
 				vssRay->Init(hRay);
-
-			if (foundIntersect)
-				cout << "y : " << Intersectable::GetTypeName(vssRay->mTerminationObject);
+			}
 
 			hRay.intersections.clear();
@@ -1258,6 +1267,6 @@
 
 	}
-	
-	//	cerr<<"Determining PVS objects"<<endl;
+	//cout << "numDummy: " << numTransformed << endl;	
+	//cerr<<"Determining PVS objects"<<endl;
 	DeterminePvsObjects(vssRays);
 	//	cerr<<"done."<<endl;
@@ -1620,10 +1629,8 @@
 	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)
+	const int t = 1000;
+	for (int j = 0, i = 0; j < numTriangles; ++ j, i += 3)
 	{
 		Triangle3 tri;
@@ -1633,6 +1640,5 @@
 		inStream.read(reinterpret_cast<char *>(&mesh->mVertices[i + 2]), sizeof(Vector3));
 
-		
-		mesh->mVertices[i].x += 20;
+		/*mesh->mVertices[i].x += 20;
 		mesh->mVertices[i + 1].x += 20;
 		mesh->mVertices[i + 2].x += 20;
@@ -1641,28 +1647,20 @@
 		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->mVertices[i] *= 100;
+		mesh->mVertices[i + 1] *= 100;
+		mesh->mVertices[i + 2] *= 100;
 
 		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))
+		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;
-	}
+
+	cout << "loaded " << numTriangles << " triangles" << endl;
 
 	mesh->Preprocess();
-	cout << "loaded " << numTriangles << " triangles" << endl;
+
+	cout << "finished preprocessing" << endl;
 
 	return mesh;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2613)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2614)
@@ -386,4 +386,5 @@
 	for (dit = mDynamicObjects.begin(); dit != dit_end; ++ dit)
 	{
+		//cerr << "here45\n****"<<endl;
 		RenderIntersectable(*dit);
 	}
@@ -659,4 +660,6 @@
 	int diffy = -(mousePoint.y - y);
 
+	const float t = 1.0f;
+
 	if (e->modifiers() & Qt::ControlModifier) 
 	{
@@ -664,5 +667,44 @@
 		mViewPoint.x += (x-mousePoint.x)*MOVE_SENSITIVITY / 2.0;
 	} 
-	else 
+	else if (e->modifiers() & Qt::AltModifier)
+	{
+		if (mCurrentDynamicObjectIdx >= 0)
+		{
+			Matrix4x4 tm;
+			TransformedMeshInstance *tmi;
+
+			switch (mTrafoType)
+			{
+			case 0:
+				{
+					const Vector3 transl(diffx, 0, diffy);
+					tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
+					tm = TranslationMatrix(transl);
+				}
+				break;
+			case 1:
+				{
+					float scalef = 1.0f + 0.01f * (diffx + diffy);
+					if (scalef < 0.9) scalef = 0.9f;
+					else if (scalef > 1.1f) scalef = 1.1f;
+					tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
+					tm = ScaleMatrix(scalef, scalef, scalef);
+				}
+				break;
+			case 2:
+				{
+					tmi = mViewCellsManager->GetPreprocessor()->mDynamicObjects[mCurrentDynamicObjectIdx];
+					tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
+				}
+				break;
+			default:
+				cerr << "not implemented" << endl;
+			}
+
+			tmi->ApplyWorldTransform(tm);
+			updateGL();
+		}
+	}
+	else
 	{
 		mViewPoint += mViewDirection*((mousePoint.y - y)*MOVE_SENSITIVITY);
@@ -889,8 +931,11 @@
 	mShowWeightedTriangles = false;
 	mShowDistribution = 15;
+	mCurrentDynamicObjectIdx = -1;
 
 	mSpatialFilterSize = 0.01;
 	mPvsSize = 0;
 	mRayVisualizationMethod = 0;
+	mTrafoType = 0;
+
 	mRenderError = 0.0f;
 	mShowRays = false;
@@ -950,7 +995,10 @@
 	connect(mControlWidget, SIGNAL(SetShowDistribution4(bool)), this, SLOT(SetShowDistribution4(bool)));
 
-
 	connect(mControlWidget,	SIGNAL(SetShowRays(bool)), this, SLOT(SetShowRays(bool)));
 
+	connect(mControlWidget, SIGNAL(SetTranslation(bool)), this, SLOT(SetTranslation(bool)));
+	connect(mControlWidget, SIGNAL(SetRotation(bool)), this, SLOT(SetRotation(bool)));
+	connect(mControlWidget, SIGNAL(SetScale(bool)), this, SLOT(SetScale(bool)));
+	
 	// setting the size here
 	resize(800, 600);
@@ -1009,7 +1057,9 @@
 void QtGlRendererWidget::LoadObject()
 {
-	string filename("../data/bunny.bn");
+	string filename("../data/teapot.bn");
 	
 	cout << "Loading model << " << filename << endl;
+
+	++ mCurrentDynamicObjectIdx;
 
 	if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename))
@@ -1587,5 +1637,5 @@
 	
 	rb1 = new QRadioButton("random colors", parent);
-	rb1->setText("wireframe");
+	rb1->setText("random");
 	connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetShowWireFrame(bool)));
 
@@ -1627,4 +1677,38 @@
 
 
+QGroupBox *QtRendererControlWidget::CreateTrafoPanel(QWidget *parent)
+{
+	QRadioButton *rb1, *rb2, *rb3;
+	
+	rb1 = new QRadioButton("translation", parent);
+	rb1->setText("translation");
+	connect(rb1, SIGNAL(toggled(bool)), SIGNAL(SetTranslation(bool)));
+
+	// Create a check box to be in the group box
+	rb2 = new QRadioButton("scale", parent);
+	rb2->setText("scale");
+	//vl->addWidget(rb1);
+	connect(rb2, SIGNAL(toggled(bool)), SIGNAL(SetScale(bool)));
+
+	rb3 = new QRadioButton("rotation", parent);
+	rb3->setText("rotation");
+	connect(rb3, SIGNAL(toggled(bool)), SIGNAL(SetRotation(bool)));
+    
+	QVBoxLayout *vbox2 = new QVBoxLayout;
+	QGroupBox *groupBox = new QGroupBox("Trafo types");
+
+	vbox2->addWidget(rb1);
+	vbox2->addWidget(rb2);
+	vbox2->addWidget(rb3);
+	
+	rb1->setChecked(true);
+
+	vbox2->addStretch(1);
+	groupBox->setLayout(vbox2);
+
+	return groupBox;
+}
+
+
 
 QGroupBox *QtRendererControlWidget::CreateRenderCostPanel(QWidget *parent)
@@ -1646,5 +1730,4 @@
 
 	QGroupBox *groupBox = new QGroupBox("Render cost options");
-
 	QVBoxLayout *vbox2 = new QVBoxLayout;
     
@@ -1857,4 +1940,7 @@
 	QGroupBox *groupBox3 = CreateRayVisualizationPanel(hbox);
 	vh->addWidget(groupBox3, 0, 0);
+
+	QGroupBox *groupBox4 = CreateTrafoPanel(hbox);
+	vh->addWidget(groupBox4, 0, 0);
 
 	//////////////////////////////////
@@ -2032,4 +2118,5 @@
 	cb->setChecked(false);
 	connect(cb, SIGNAL(toggled(bool)), SIGNAL(StoreStatistics()));*/
+
 	if (0) 
 	{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h	(revision 2567)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h	(revision 2614)
@@ -58,5 +58,4 @@
 	float scale;
 	QPoint lastPos;
-
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2609)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2614)
@@ -91,4 +91,5 @@
 
   QGroupBox *CreateVisualizationPanel(QWidget *parent);
+  QGroupBox *CreateTrafoPanel(QWidget *parent);
 
   public slots:
@@ -156,4 +157,8 @@
   void SetShowDistribution3(bool);
   void SetShowDistribution4(bool);
+
+  void SetTranslation(bool);
+  void SetRotation(bool);
+  void SetScale(bool);
 };
 
@@ -204,4 +209,6 @@
 	int mShowDistribution;
 
+	int mCurrentDynamicObjectIdx;
+
 	// some statistics
 	int mPvsSize;
@@ -214,4 +221,5 @@
 
 	int mRayVisualizationMethod;
+	int mTrafoType;
 
 	QtRendererControlWidget *mControlWidget;
@@ -267,7 +275,4 @@
 	virtual int GetHeight() const { return height(); }
 
-	// virtual void
-	//  SetupProjection(const int w, const int h, const float angle = 70.0f);
-
 	virtual void
 		SetupCameraProjection(const int w, const int h, const float angle = 70.0f);
@@ -479,5 +484,20 @@
 		mRayVisualizationMethod = 3;
 	}
-	
+
+	void SetTranslation(bool b)
+	{
+		mTrafoType = 0;
+	}
+
+	void SetScale(bool b)
+	{
+		mTrafoType = 1;
+	}
+	
+	void SetRotation(bool b)
+	{
+		mTrafoType = 2;
+	}
+
 	void SetShowDistribution1(bool b)
 	{
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2609)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2614)
@@ -242,15 +242,16 @@
 QtGlViewer::mouseMoveEvent(QMouseEvent *event)
 {
-  int dx = event->x() - lastPos.x();
-  int dy = event->y() - lastPos.y();  
-  
-  if (event->modifiers() & Qt::CTRL)
-		{
-			scale = scale*(1.0f - dy/(float)height());
-			if (scale < 0.01f)
-				scale = 0.01f;
-			updateGL();
-		}
-  else {
+	int dx = event->x() - lastPos.x();
+	int dy = event->y() - lastPos.y();  
+
+	if (event->modifiers() & Qt::CTRL)
+	{
+		scale = scale*(1.0f - dy/(float)height());
+		if (scale < 0.01f)
+			scale = 0.01f;
+		updateGL();
+	}
+	else
+	{
 		float W = width();
 		float H = height();
@@ -259,26 +260,26 @@
 		int y = event->y();
 		int lastY = lastPos.y();
-	
+
 		float quat[4];
 		trackball(quat,
-				  (2.0 * lastX - W) / W,
-				  (H - 2.0 * lastY) / H,
-				  (2.0 * x - W) / W,
-				  (H - 2.0 * y) / H
-				  );
+			(2.0 * lastX - W) / W,
+			(H - 2.0 * lastY) / H,
+			(2.0 * x - W) / W,
+			(H - 2.0 * y) / H
+			);
 
 		add_quats(quat, manipulatorLastQuat, manipulatorLastQuat);
-  }
-  
-  lastPos = event->pos();
-  updateGL();
-}
-
-void QtGlViewer::timerEvent(QTimerEvent *event) 
-{
-	update();
-}
-
-
-}
-
+	}
+
+	lastPos = event->pos();
+	updateGL();
+}
+
+	void QtGlViewer::timerEvent(QTimerEvent *event) 
+	{
+		update();
+	}
+
+
+}
+
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2609)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2614)
@@ -2407,5 +2407,5 @@
 												   Intersectable *obj,
 												   const Vector3 &pt,
-												   const bool addSamplesToPvs)
+												   bool addSamplesToPvs)
 {
 	// check if we are outside of view space
@@ -2424,4 +2424,6 @@
 	if (addSamplesToPvs) 
 	{
+		//if (obj->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)cout << "here12 " << endl;
+
 		hasAbsContribution = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf);
 		//hasAbsContribution = viewCell->GetPvs().AddSample(obj,ray.mPdf);
@@ -2437,6 +2439,4 @@
 			viewCell->GetPvs().GetSampleContribution(obj, ray.mPdf, relContribution);
 	}
-
-	//cout << "here6: " << ray.GetDir() << " ";
 
 	// $$ clear the relative contribution as it is currently not correct anyway
@@ -2483,7 +2483,6 @@
 
 void
-ViewCellsManager::DeterminePvsObjects(
-									  VssRayContainer &rays,
-									  const bool useHitObjects)
+ViewCellsManager::DeterminePvsObjects(VssRayContainer &rays,
+									  bool useHitObjects)
 {
 	if (!useHitObjects) 
@@ -2498,12 +2497,14 @@
 			// set only the termination object
 			vssRay->mTerminationObject = GetIntersectable(*vssRay, true);
+			
+			if (vssRay->mTerminationObject->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)	
+				cout << "r";
+
 #if 0
-		  if (vssRay->mTerminationObject == NULL) {
-			cerr<<"Error in DeterminePvsObjects - termination object maps to NULL!"<<endl;
-		  }
+		  if (vssRay->mTerminationObject == NULL)
+			  cerr<<"Error in DeterminePvsObjects - termination object maps to NULL!"<<endl;
 #endif
 		}
 	}
-  
 }
 
@@ -2547,7 +2548,7 @@
 float
 ViewCellsManager::ComputeSampleContribution(VssRay &ray,
-											const bool addRays,
-											const bool storeViewCells,
-											const bool useHitObjects)
+											bool addRays,
+											bool storeViewCells,
+											bool useHitObjects)
 {
 	ray.mPvsContribution = 0;
@@ -2595,5 +2596,4 @@
 		// traverse the view space subdivision
 		CastLineSegment(origin, termination, viewCells);
-
 		lastVssRay = &ray;
 	}
@@ -2631,5 +2631,6 @@
 	pvsTimer.Entry();
 #endif
-	
+	//if (terminationObj->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+	//	cout << "found tmi: " << Intersectable::GetTypeName(terminationObj) << " " << viewCells.size() << endl;
 	bool contri = false;
 	ViewCellContainer::const_iterator it = viewCells.begin();
@@ -2638,8 +2639,8 @@
 	{
 		if (ComputeViewCellContribution(*it, 
-			                        ray, 
-									terminationObj, 
-									ray.mTermination, 
-									addRays))
+			                            ray, 
+										terminationObj, 
+										ray.mTermination, 
+										addRays))
 		{
 			contri = true;
@@ -3166,6 +3167,6 @@
 void ViewCellsManager::MergeViewCellsRecursivly(ObjectPvs &pvs, 
 												const ViewCellContainer &viewCells, 
-												const int leftIdx, 
-												const int rightIdx) const
+												int leftIdx, 
+												int rightIdx) const
 {
 	if (leftIdx == rightIdx)
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2613)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2614)
@@ -368,4 +368,7 @@
 
 		Face *face = mesh->mFaces[i];
+		Vector3 normal = mesh->GetNormal(i);
+
+		glNormal3f(normal.x, normal.y, normal.z);
 		for (int j = 0; j < face->mVertexIndices.size(); j++) {
 			glVertex3fv(&mesh->mVertices[face->mVertexIndices[j]].x);
@@ -696,5 +699,5 @@
   
   mViewDirection = Normalize(Vector3(sin(dVector.x),
-									 //									 cos(dVector.y),
+									 //	cos(dVector.y),
 									 0.0f,
 									 cos(dVector.x)));
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 2609)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 2614)
@@ -42,9 +42,10 @@
   }
 
-  Face(const VertexIndexContainer &vertices):mVertexIndices(vertices.size()) {
+  Face(const VertexIndexContainer &vertices): mVertexIndices(vertices.size()) {
 	for (int i=0;  i < vertices.size(); i++)
 	  mVertexIndices[i] = vertices[i];
   }
-  
+
+
   ////////////////////////////
 
@@ -178,5 +179,6 @@
   int GetId() const { return mId; }
 
-
+  /** Returns normal of specified face.
+  */
   Vector3 GetNormal(const int idx) const;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp	(revision 2176)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/MeshKdTree.cpp	(revision 2614)
@@ -147,18 +147,17 @@
   vector<int>::const_iterator fi;
   vector<int> objectsFront, objectsBack;
-  
-  for ( fi = leaf->mFaces.begin();
-	fi != leaf->mFaces.end();
-	fi++) {
-    // determine the side of this ray with respect to the plane
-    AxisAlignedBox3 box = mMesh->GetFaceBox(*fi);
-
-    if (box.Max(axis) > position ) 
-      objectsFront.push_back(*fi);
-    
-    if (box.Min(axis) < position )
-      objectsBack.push_back(*fi);
-  }
-  
+
+  for ( fi = leaf->mFaces.begin(); fi != leaf->mFaces.end(); fi++) 
+  {
+	  // determine the side of this ray with respect to the plane
+	  AxisAlignedBox3 box = mMesh->GetFaceBox(*fi);
+
+	  if (box.Max(axis) > position ) 
+		  objectsFront.push_back(*fi);
+
+	  if (box.Min(axis) < position )
+		  objectsBack.push_back(*fi);
+  }
+
   MeshKdLeaf *back = new MeshKdLeaf(objectsBack);
   MeshKdLeaf *front = new MeshKdLeaf(objectsFront);
@@ -419,4 +418,5 @@
   mRoot = Subdivide(TraversalData(leaf, NULL, GetBox(), 0));
   
+  cout <<  "created " << 
   // remove the allocated array
   delete mSubdivisionCandidates;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 2609)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 2614)
@@ -104,5 +104,6 @@
 			root->mFaces.push_back(i);
 		
-		cout<<"KD";
+		//cout<<"KD";
+		cout<<"constructed mesh kd tree for " << (int)mFaces.size() << " faces" << endl;
 		
 		mKdTree->Construct();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2588)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2614)
@@ -584,9 +584,11 @@
 	}
 
+
 	for(; it != vssRays.end(); ++it) 
 	{
 		VssRay *ray = *it;
 
-		//cout << " here4 " << ray->GetDir();
+		//if (ray->mTerminationObject->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE)
+		//	cout << "found transofrmed mesh instance: " << Intersectable::GetTypeName(ray->mTerminationObject) << " " << endl;
 
 		for (i=0; i < mDistributions.size()-1; i++) 
@@ -596,8 +598,6 @@
 		}
 
-		float contribution =
-			mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray,
-			true,
-			false);
+		const float contribution =
+			mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, true, false);
 
 		mDistributions[i]->mContribution += contribution;
