Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2694)
@@ -11,11 +11,11 @@
 echo "starting $TARGET version"
 
-#SCENE=../data/vienna/vienna_cropped.obj
-SCENE=../data/vienna/city_full.obj
+SCENE=../data/vienna/vienna_cropped.obj
+#SCENE=../data/vienna/city_full.obj
 
 VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 
 VIEWPOINTS=../data/vienna/testwalk.vp
 
-LOG_PREFIX=../src/SG08/try
+LOG_PREFIX=../src/SG08/try_100_real
 #LOG_PREFIX=../src/SG08/city_full_100
 
@@ -35,6 +35,6 @@
 -gvs_samples_per_pass=1000000 \
 -gvs_initial_samples=16 \
--gvs_max_viewcells=1 \
--gvs_min_contribution=3000 \
+-gvs_max_viewcells=20 \
+-gvs_min_contribution=100 \
 -gvs_per_viewcell=true \
 -gvs_stats=$LOG_PREFIX-gvsStats.log \
Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2692)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2694)
@@ -8,11 +8,11 @@
 
 
-#SCENE=../data/vienna/vienna_cropped.obj
-SCENE=../data/vienna/city_full.obj
+SCENE=../data/vienna/vienna_cropped.obj
+#SCENE=../data/vienna/city_full.obj
 
 VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz
 #VIEWCELLS=../data/vienna/vienna_cropped-seq-3000-false-20-viewcells.xml.gz
 #VIEWCELLS=../data/vienna/vienna_cropped-57000-viewcells.xml.gz
-VIEWPOINTS=../data/vienna/change.vp
+VIEWPOINTS=../data/vienna/testwalk.vp
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2694)
@@ -14,4 +14,6 @@
 class KdIntersectable;
 class ViewCellBasedDistribution;
+class ViewCellBorderBasedDistribution;
+
 
 /** View space partition statistics.
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2678)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h	(revision 2694)
@@ -65,4 +65,7 @@
 
 	virtual AxisAlignedBox3 GetBox() const;
+	/** Returns the box without the trafo.
+	*/
+	virtual AxisAlignedBox3 GetOriginalBox() const;
 
 	virtual void ApplyTransform(const Matrix4x4 &trafo);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 2662)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp	(revision 2694)
@@ -260,5 +260,5 @@
 			SceneGraphLeaf *leaf = static_cast<SceneGraphLeaf *>(node);
 
-			size += leaf->mGeometry.size();
+			size += (int)leaf->mGeometry.size();
 		}
 		else
@@ -318,4 +318,8 @@
 
 
-
-}
+AxisAlignedBox3 SceneGraphLeaf::GetOriginalBox() const 
+{
+	return mBox;
+}
+
+}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2694)
@@ -1604,53 +1604,12 @@
 
 
-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;
-
-	Mesh *mesh = new Mesh(numTriangles * 3, numTriangles);
-
-	const int t = 1000;
-	for (int j = 0, i = 0; j < numTriangles; ++ j, i += 3)
-	{
-		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));
-
-		// hack: objects initially very small
-		mesh->mVertices[i] *= 100;
-		mesh->mVertices[i + 1] *= 100;
-		mesh->mVertices[i + 2] *= 100;
-
-		mesh->AddFace(new Face(i + 0, i + 1, i + 2));
-
-		if ((j % t) == (t - 1))
-			 cout<<"\r"<<i<<"/"<<numTriangles<<"\r";
-	}
-
-	cout << "loaded " << numTriangles << " triangles" << endl;
-
-	mesh->Preprocess();
-
-	cout << "finished preprocessing" << endl;
-
-	return mesh;
-}
-
-
-bool Preprocessor::LoadDynamicGeometry(const string &filename)
+SceneGraphLeaf *Preprocessor::RegisterDynamicGeometryWithRayCaster(SceneGraphLeaf *leaf)
+{
+	if (mRayCaster)
+		mRayCaster->AddDynamicObjecs(leaf->mGeometry, leaf->GetTransformation());
+}
+
+
+SceneGraphLeaf *Preprocessor::LoadDynamicGeometry(const string &filename)
 {
 #if DYNAMIC_OBJECTS_HACK
@@ -1665,20 +1624,9 @@
 		cout<<"parsing obj file.."<<endl;
 		ObjParser *p = new ObjParser;
-		parsed = p->ParseFile(filename, 
-			leaf,
-			false);
-		leaf->UpdateBox();
-		cout<<leaf->GetBox();
-
-		float s = 10.0f;
-		leaf->ApplyTransform(ScaleMatrix(s, s, s));
-		leaf->ApplyTransform(TranslationMatrix(Vector3(0, 10, 0)));
-
-
+		parsed = p->ParseFile(filename, leaf, false);
 	} 
 	else 
 	{
 		cout<<"parsing binary obj file ... " << endl;
-
 		parsed = LoadBinaryObj(filename, leaf, NULL, 100);
 	}
@@ -1686,26 +1634,38 @@
 	if (parsed)
 	{
-		cout<<"success."<<endl;
+		const float scale = 0.01f;
+
+		ObjectContainer::const_iterator it, it_end = leaf->mGeometry.end();
+
+		for (it = leaf->mGeometry.begin(); it != it_end; ++ it)
+		{
+			TriangleIntersectable *tri = static_cast<TriangleIntersectable *>(*it);
+
+			Triangle3 t = tri->GetItem();
+
+			// scale object appropriately
+			t.mVertices[0] *= scale;
+			t.mVertices[1] *= scale;
+			t.mVertices[2] *= scale;
+
+			tri->SetItem(t);
+		}
+
+		//leaf->ApplyTransform(ScaleMatrix(s, s, s));
+		//leaf->ApplyTransform(TranslationMatrix(Vector3(0, 10, 0)));
+
 		leaf->UpdateBox();
-		cout<<leaf->GetBox();
-		mDynamicObjects.push_back(leaf);
-		//leaf->RebuildKtbTree();
 		mSceneGraph->GetRoot()->mChildren.push_back(leaf);
-
-		if (mRayCaster)
-			mRayCaster->AddDynamicObjecs(leaf->mGeometry, leaf->GetTransformation());
-
-
-		return true;
+		//mDynamicObjects.push_back(leaf);
+
+		cout<<"Dynamic object loaded successfully: " << leaf->GetBox() << endl;
+
+		return leaf;
 	} 
-	else
-	{
-		cout<<"failed."<<endl;
-
-	}
-
+		
 
 #endif
-	return false;
+	cout<<"Dynamic object loading failed."<<endl;
+	return NULL;
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2693)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2694)
@@ -18,4 +18,5 @@
 #include "LogWriter.h"
 #include "RayCaster.h"
+#include "ObjectPlacer.h"
 
 
@@ -271,5 +272,5 @@
 	if (pixelCount > pixelThres) 
 	{
-		cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << " vp: " << mViewPoint << endl;
+		cout << "f " << mFrame << " id " << viewcell->GetId() << " pvs " << pvsSize << " e " << pixelCount << " vp " << mViewPoint << " vd " << mViewDirection << endl;
 	
 		if (mSnapErrorFrames) 
@@ -510,4 +511,7 @@
 		_RenderDynamicObject(*dit);
 	}
+
+	if (mPendingDynamicObject)
+		_RenderDynamicObject(mPendingDynamicObject);
 #endif
 }
@@ -736,5 +740,17 @@
 	mousePoint.y = y;
 
-}
+	if (e->button() == Qt::RightButton)
+	{
+		if (mPlacer->GetCurrentObject())
+		{
+			Vector3 pt = Unproject(x, y);
+			cout << "unproject: " << pt << endl;
+
+			mPlacer->PlaceObject(pt);
+			mPendingDynamicObject = mPlacer->GetCurrentObject();
+		}
+	}
+}
+
 
 void QtGlRendererWidget::mouseReleaseEvent(QMouseEvent *e)
@@ -1047,7 +1063,11 @@
 
 	mRenderError = 0.0f;
+
 	mShowRays = false;
-
 	mReplayMode = false;
+
+	mPlacer = new ObjectPlacer();
+
+	mPendingDynamicObject = NULL;
 
 	SetSceneCut(1000);
@@ -1183,12 +1203,18 @@
 	++ mCurrentDynamicObjectIdx;
 
-	if (mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename)) {
-	  
-	  cout << "Loading finished" << endl;
-	} else
-	  cerr << "Loading failed" << endl;
+	SceneGraphLeaf *leaf = 
+		mViewCellsManager->GetPreprocessor()->LoadDynamicGeometry(filename);
+
+	if (leaf)
+	{
+		mPlacer->AddObject(leaf);
+		cout << "Loading finished" << endl;
+	}
+	else
+		cerr << "Loading failed" << endl;
 	
     updateGL();
 }
+
 
 void
@@ -2524,5 +2550,5 @@
 {
 	// swap y coordinate
-	//y = GetHeight() - y;
+	y = GetHeight() - y;
 
 	// HACK: should come from camera!
@@ -2534,9 +2560,9 @@
 	const int viewport[4] = {0,0, GetWidth(), GetHeight()};
 
+	RenderScene();
+
 	float z;
 	glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
-
-	RenderScene();
-
+	
 	GLdouble rx, ry, rz;
 	gluUnProject(x, y, z, modelview, projection, viewport, &rx, &ry, &rz);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h	(revision 2693)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.h	(revision 2694)
@@ -1,8 +1,11 @@
  #ifndef OBJECTPLACER_H
 #define OBJECTPLACER_H
+
+#include "Containers.h"
 
 namespace GtpVisibilityPreprocessor {
 
 class Vector3;
+class Preprocessor;
 
 
@@ -12,41 +15,38 @@
 {
 public:
+	/** Default constructor taking a pointer to the currently used preprocessor.
+	*/
+//	ObjectPlacer(Preprocessor *prep);
 	ObjectPlacer();
 
-	/// sets library objects
-	//void SetLibrary(BranchGroup *library);
-	/// selects the next library object
+	/** Sets library objects.
+	*/
+	void AddObject(SceneGraphLeaf *object);
+
+	/** Selects the next library object.
+	*/
 	void NextObject();
-	/// selects the previous library object
+	/** Selects the previous library object.
+	*/
 	void PreviousObject();
-	/// adds an object at the indicated position
-	void AddObject(const Vector3 &p);
-	/// remove the last added object
-	void RemoveLastObject();
+	/** Adds an object at the indicated position.
+	*/
+	void PlaceObject(const Vector3 &p);
 
-	/// Clear all objects
-	void Clear();
+	SceneGraphLeaf *GetCurrentObject();
 
-	/// Save the objects
-	/*void SaveObjects(const std::string &filename);
-
-	/// Get a node to visualize from the library
-	BranchGroup *GetLibraryVisualization();
-
-	/// Get the nodes that have already been placed
-	BranchGroup *GetPlacedNodeVisualization();
-
-*/	
 	virtual ~ObjectPlacer() {}
 
+	DynamicObjectsContainer &GetDynamicObjects() { return mDynamicObjects; }
+
+
 protected:
-	/*SceneBasePtr<BranchGroup> mLibrary;
-	SceneBasePtr<BranchGroup> mPlacedNodes;
-	SceneBasePtr<BranchGroup> mLibraryViz;
-	int mCurrentLibaryObject;
 
-	/// Get a link to an object in the library
-	void UpdateLibraryViz();
-*/
+	//Preprocessor *mPreprocessor;
+
+	DynamicObjectsContainer mDynamicObjects;
+		
+	int mCurrentObject;
+
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2693)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2694)
@@ -39,4 +39,5 @@
 class OcclusionQuery;
 class TransformedMeshInstance;
+class ObjectPlacer;
 
 
@@ -221,5 +222,4 @@
 	float mTransferFunction;
 
-
 	Vector3 mDummyViewPoint;
 
@@ -242,5 +242,10 @@
 	int mReplayTimerId;
 
+	ObjectPlacer *mPlacer;
+
 #if DYNAMIC_OBJECTS_HACK
+	
+	SceneGraphLeaf *mPendingDynamicObject;
+
 	DynamicObjectsContainer mDynamicObjects;
 #endif
@@ -254,4 +259,6 @@
 
 	QtGlRendererWidget() {};
+
+	~QtGlRendererWidget() { delete mPlacer; }
 
 	void SetThread(QtPreprocessorThread *t)
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.cpp	(revision 2693)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/ObjectPlacer.cpp	(revision 2694)
@@ -1,51 +1,24 @@
 #include "ObjectPlacer.h"
+#include "Matrix4x4.h"
+#include "SceneGraph.h"
 
-namespace GtpVisibilityPreprocessor {
+
+
+namespace GtpVisibilityPreprocessor 
+{
 
 // ---------------------------------------------------------------------------
 //  ObjectPlacer implementation
 // ---------------------------------------------------------------------------
-#if 0
+
 ObjectPlacer::ObjectPlacer()
-	:mCurrentLibaryObject(0), mPlacedNodes(new BranchGroup), mLibraryViz(new BranchGroup)
+: mCurrentObject(0)
 {
-	mLibraryViz->addChild(new BranchGroup);
-
-	BranchGroup *bg = new BranchGroup;
-	bg->addChild(new Box);
-	SetLibrary(bg);
 }
 
 
-void ObjectPlacer::SetLibrary(BranchGroup *library)
+void ObjectPlacer::AddObject(SceneGraphLeaf *obj)
 {
-	mLibrary = new BranchGroup;
-	if (!library)
-	{
-		mLibrary->addChild(new Box);
-	}
-	else
-	{
-		for (int i = 0; i < library->numChildren(); i ++)
-		{	
-			Node *n = library->getChild(i);
-			SharedGroup *s = new SharedGroup;
-			s->addChild(n);
-			
-			Link *l = new Link;
-			l->setSharedGroup(s);
-			mLibrary->addChild(l);
-		}
-	}
-	
-	UpdateLibraryViz();
-}
-
-void ObjectPlacer::UpdateLibraryViz()
-{
-	Link *l = new Link;
-	l->setSharedGroup(((Link *)mLibrary->getChild(mCurrentLibaryObject))->getSharedGroup());
-
-	mLibraryViz->setChild(l, 0);
+	mDynamicObjects.push_back(obj);
 }
 
@@ -53,62 +26,38 @@
 void ObjectPlacer::NextObject()
 {
-	if (mLibrary)
-		mCurrentLibaryObject = (mCurrentLibaryObject + 1) % (mLibrary->numChildren());
-	UpdateLibraryViz();
+	mCurrentObject = (mCurrentObject + 1) % (int)mDynamicObjects.size();
 }
+
 
 void ObjectPlacer::PreviousObject()
 {
-	if (mLibrary)
-		mCurrentLibaryObject = (mCurrentLibaryObject - 1) % (mLibrary->numChildren());
-	UpdateLibraryViz();
-}
-
-void ObjectPlacer::AddObject(const Point3f &p)
-{
-	//BranchGroup *o = new BranchGroup;
-	TransformGroup *tg = new TransformGroup;
-	Transform3D t;
-	t.setTranslation(p - Origin3f);
-	tg->setTransform(t);
-	//o->addChild(tg);
-
-	Link *l = new Link;
-	l->setSharedGroup(((Link *)(mLibrary->getChild(mCurrentLibaryObject)))->getSharedGroup());
-	tg->addChild(l);
-
-	mPlacedNodes->addChild(tg);
-}
-
-void ObjectPlacer::RemoveLastObject()
-{
-	if (mPlacedNodes->numChildren() > 0)
-		mPlacedNodes->removeChild(mPlacedNodes->numChildren()-1);
-}
-
-void ObjectPlacer::SaveObjects(const String &filename)
-{
-	WriteActionIV wa(filename, "");
-
-	wa.Apply(mPlacedNodes);
-}
-
-BranchGroup *ObjectPlacer::GetLibraryVisualization()
-{
-	return mLibraryViz;
-}
-
-BranchGroup *ObjectPlacer::GetPlacedNodeVisualization()
-{
-	return mPlacedNodes;
-}
-
-void ObjectPlacer::Clear()
-{
-	mPlacedNodes->removeAllChildren();	
+	mCurrentObject = (mCurrentObject - 1) % (int)mDynamicObjects.size();
 }
 
 
-void TestApp::Placer(const String &parm)
+SceneGraphLeaf *ObjectPlacer::GetCurrentObject() 
+{ 
+	if (mCurrentObject >= mDynamicObjects.size())
+		return NULL;
+
+	return mDynamicObjects[mCurrentObject];
+}
+
+
+void ObjectPlacer::PlaceObject(const Vector3 &pt)
+{
+	Vector3 p = pt;
+
+	SceneGraphLeaf *obj = mDynamicObjects[mCurrentObject];
+
+	// set pivot to ground of object
+	p.y -= obj->GetOriginalBox().Min().y;
+	Matrix4x4 trafo = TranslationMatrix(p);
+
+	obj->LoadTransform(trafo);
+}
+
+
+/*void TestApp::Placer(const String &parm)
 {
 	if (parm.Empty())
@@ -191,8 +140,6 @@
 	} else
 		OUT1("Unknown placer command");
+}
+*/
 
 }
-
-#endif
-
-}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2694)
@@ -192,7 +192,12 @@
 	/** Adds dynamic geometry
 	*/
-	bool LoadDynamicGeometry(const string &filename);
-
-	Mesh *Preprocessor::LoadBinaryObjIntoMesh(const string &filename);
+	SceneGraphLeaf *LoadDynamicGeometry(const string &filename);
+
+	/** Register the dynamic object to be handled by the ray caster for visibility
+		computation.
+	*/
+	SceneGraphLeaf *RegisterDynamicGeometryWithRayCaster(SceneGraphLeaf *leaf);
+
+	
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 2694)
@@ -218,20 +218,4 @@
 
 
-class ViewCellBorderBasedDistribution: public SamplingStrategy
-{
- public:
-	 ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
-		 : SamplingStrategy(preprocessor), mViewCell(viewCell)
-	 {
-		 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
-	 }
-
-private:
-  virtual bool GenerateSample(SimpleRay &ray);
-
-  ViewCell *mViewCell;
-};
-
-
 class GlobalLinesDistribution: public SamplingStrategy
 {
@@ -334,4 +318,27 @@
 };
 
+class ViewCellBorderBasedDistribution: public SamplingStrategy
+{
+ public:
+	 ViewCellBorderBasedDistribution(Preprocessor &preprocessor, ViewCell *viewCell)
+		 : SamplingStrategy(preprocessor), mViewCell(viewCell)
+	 {
+		 mType = VIEWCELL_BORDER_BASED_DISTRIBUTION;
+	 }
+
+	void SetViewCell(ViewCell *vc) { mViewCell = vc; }
+
+private:
+
+	// Generate a new sample according to a mixture distribution
+	virtual bool GenerateSample(SimpleRay &ray);
+
+	// halton sequence generator for deciding between distributions
+	static HaltonSequence sHalton;
+
+	ViewCell *mViewCell;
+};
+
+
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2692)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2694)
@@ -229,7 +229,7 @@
 
 			//KdNode *node = mKdTree->GetPvsNodeCheck(ray.mTermination, obj);
-			//if (!node) cerr << "e: " << obj->GetBox() << " " << ray.mTermination << endl;	else 
+			//if (!node) cerr << "e " << obj->GetBox() << " " << ray.mTermination << endl; else 
 			if (!node->Mailed())
-			{
+			{//cout<<"o ";
 				// add to pvs
 				node->Mail();
@@ -565,4 +565,5 @@
 	newOrigin = newPoint - newDir * offset;
 	
+
 	//////////////
 	//-- for per view cell sampling, we must check for intersection
@@ -738,7 +739,4 @@
 	m.mDiffuseColor = RgbColor(0, 1, 0);
 	exporter->SetForcedMaterial(m);
-
-	//mViewCellsManager->ExportViewCellGeometry(exporter, vc, NULL, NULL);
-	//mViewCellsManager->ExportViewCellGeometry(exporter, mCurrentViewCell, NULL, NULL);
 
 	AxisAlignedBox3 bbox = mCurrentViewCell->GetMesh()->mBox;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h	(revision 2615)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h	(revision 2694)
@@ -202,5 +202,5 @@
 
 	int CastSimpleRay(const SimpleRay &ray);
-        int CastSimpleRay(const SimpleRay &ray, int rayIndex);
+       int CastSimpleRay(const SimpleRay &ray, int rayIndex);
 	
 	AxisAlignedBox3 GetBox() const;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2694)
@@ -36,4 +36,5 @@
 
 HaltonSequence ViewCellBasedDistribution::sHalton;
+HaltonSequence ViewCellBorderBasedDistribution::sHalton;
 
 SamplingStrategy::SamplingStrategy(Preprocessor &preprocessor): 
@@ -289,44 +290,4 @@
   
   return true;
-}
-
-
-bool ViewCellBorderBasedDistribution::GenerateSample(SimpleRay &ray)
-{
-	Vector3 origin, direction; 
-
-	//ViewCellContainer &viewCells = mPreprocessor.mViewCellsManager->GetViewCells();
-
-	Vector3 point;
-	Vector3 normal, normal2;
-	
-	//const int vcIdx = (int)RandomValue(0, (float)viewCells.size() - 0.5f);
-	const int objIdx = (int)RandomValue(0, (float)mPreprocessor.mObjects.size() - 0.5f);
-
-	Intersectable *object = mPreprocessor.mObjects[objIdx];
-	ViewCell *viewCell = mViewCell;//viewCells[vcIdx];
-
-	object->GetRandomSurfacePoint(point, normal);
-	viewCell->GetRandomEdgePoint(origin, normal2);
-
-	direction = point - origin;
-
-	// $$ jb the pdf is yet not correct for all sampling methods!
-	const float c = Magnitude(direction);
-
-	if ((c <= Limits::Small) /*|| (DotProd(direction, normal) < 0)*/)
-	{
-		return false;
-	}
-
-	// $$ jb the pdf is yet not correct for all sampling methods!
-	const float pdf = 1.0f;
-	//cout << "p: " << point << " ";
-	direction *= 1.0f / c;
-	ray = SimpleRay(origin, direction, VIEWCELL_BORDER_BASED_DISTRIBUTION, pdf);
-
-	//cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl;
-
-	return true;
 }
 
@@ -886,5 +847,39 @@
 
 
-}
-
-
+bool ViewCellBorderBasedDistribution::GenerateSample(SimpleRay &ray)
+{
+	float r[3];
+	sHalton.GetNext(3, r);
+  
+	Vector3 origin, direction; 
+	Vector3 normal;
+
+	Vector3 point = mPreprocessor.sceneBox.GetRandomPoint(Vector3(r[0], r[1], r[2]));
+
+	mViewCell->GetRandomEdgePoint(origin, normal);
+
+	direction = point - origin;
+
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float c = Magnitude(direction);
+
+	if ((c <= Limits::Small) /*|| (DotProd(direction, normal) < 0)*/)
+	{
+		return false;
+	}
+
+	// $$ jb the pdf is yet not correct for all sampling methods!
+	const float pdf = 1.0f;
+	//cout << "p: " << point << " ";
+	direction *= 1.0f / c;
+	ray = SimpleRay(origin, direction, VIEWCELL_BORDER_BASED_DISTRIBUTION, pdf);
+
+	//cout << "ray: " << ray.mOrigin << " " << ray.mDirection << endl;
+
+	return true;
+}
+
+
+}
+
+
