Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env	(revision 2677)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env	(revision 2686)
@@ -75,5 +75,5 @@
 	visibilityFile visibility.xml
 	loadMeshes false
-	loadKdTree	false
+	loadKdTree false
 	exportKdTree false
 
@@ -177,10 +177,9 @@
 		maxCostRatio 0.98
 		ct_div_ci 0.5
-		maxNodes 50000
-#500000	
-	}
-
-	splitMethod spatialMedian
-#	splitMethod SAH
+		maxNodes 100000
+	}
+
+#	splitMethod spatialMedian
+	splitMethod SAH
 	splitBorder 0.01
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2682)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2686)
@@ -5,12 +5,14 @@
 
 #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=500000 -total_samples=100000000"
+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=100000000 -view_cells_import_random_viewcells+"
 
 
-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-seq-3000-false-20-viewcells.xml.gz
+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
 
 
@@ -24,4 +26,5 @@
 
 DISTRIBUTIONS=mutation+object_direction+spatial
+#DISTRIBUTIONS=spatial
 
 $COMMAND -preprocessor=combined \
@@ -32,5 +35,7 @@
 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \
 -preprocessor_stats=$PREFIX-i-mixed-b1-n4a.log \
+-preprocessor_detect_empty_viewspace- \
 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4a.hlog \
+-view_cells_random_viewpoint_list=$VIEWPOINTS \
 demo1.env
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2606)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2686)
@@ -186,5 +186,5 @@
 	float importance = 1.0f;
 	if (mUsePassImportance) 
-	  importance = 1.0f/(pContributingRays + 1e-5);
+	  importance = 1.0f/(pContributingRays + 1e-5f);
 	// set this values for last contributingRays
 	int index = mBufferStart - 1;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 2647)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 2686)
@@ -1694,4 +1694,10 @@
 				   "view_cells_import_random_viewcells", 
 				   "false");
+	
+	RegisterOption("ViewCells.randomViewPointsList",
+		optString,
+		"view_cells_random_viewpoint_list=",
+		"");
+
 
 	RegisterOption("ViewCells.exportRandomViewCells",
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2685)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2686)
@@ -30,34 +30,7 @@
 
 #include <QVBoxLayout>
-static GLint cubeArray[][3] = {
-    {0, 0, 0}, {0, 1, 0}, {1, 1, 0}, {1, 0, 0},
-    {0, 0, 1}, {1, 0, 1}, {1, 1, 1}, {0, 1, 1},
-    {0, 0, 0}, {1, 0, 0}, {1, 0, 1}, {0, 0, 1},
-    {0, 1, 0}, {0, 1, 1}, {1, 1, 1}, {1, 1, 0},
-    {0, 1, 0}, {0, 0, 0}, {0, 0, 1}, {0, 1, 1},
-    {1, 0, 0}, {1, 1, 0}, {1, 1, 1}, {1, 0, 1}
-};
-
-static GLint cubeTextureArray[][2] = {
-    {0, 0}, {1, 0}, {1, 1}, {0, 1},
-    {0, 0}, {0, 1}, {1, 1}, {1, 0},
-    {0, 0}, {1, 0}, {1, 1}, {0, 1},
-    {1, 0}, {0, 0}, {0, 1}, {1, 1},
-    {0, 0}, {1, 0}, {1, 1}, {0, 1},
-    {1, 0}, {0, 0}, {0, 1}, {1, 1}
-};
-
-static GLint faceArray[][2] = {
-    {1, -1}, {1, 1}, {-1, 1}, {-1, -1}
-};
-
-static GLubyte colorArray[][4] = {
-    {170, 202, 0, 255},
-    {120, 143, 0, 255},
-    {83, 102, 0, 255},
-    {120, 143, 0, 255}
-};
-
-
+
+
+using namespace std;
 
 
@@ -79,4 +52,8 @@
 
 
+static SimpleRayContainer sViewPointsList;
+static SimpleRayContainer::const_iterator sViewPointsListIt;
+
+
 
 static inline bool ilt(Intersectable *obj1, Intersectable *obj2)
@@ -99,64 +76,4 @@
 }
 #endif
-
-
-void QtGlRendererBuffer::dummyBuffer()
-{ 
-	//QGLPixelBuffer *dummy = new QGLPixelBuffer(QSize(256, 256), format(), this);
-    
-	// set up the pbuffer context
-    makeCurrent();
-    
-	glEnableClientState(GL_VERTEX_ARRAY);
-    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-    glVertexPointer(3, GL_INT, 0, cubeArray);
-    glTexCoordPointer(2, GL_INT, 0, cubeTextureArray);
-    glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorArray);
-
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glEnable(GL_BLEND);
-    glEnable(GL_TEXTURE_2D);
-    glEnable(GL_DEPTH_TEST);
-
-    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
-
-    glViewport(0, 0, size().width(), size().height());
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    glOrtho(-1, 1, -1, 1, -99, 99);
-    glTranslatef(-0.5f, -0.5f, 0.0f);
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity();
-
-   
-	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
-
-	// draw cube background
-	glPushMatrix();
-	glLoadIdentity();
-	glTranslatef(0.5f, 0.5f, -2.0f);
-	glDisable(GL_TEXTURE_2D);
-	glEnableClientState(GL_COLOR_ARRAY);
-	glVertexPointer(2, GL_INT, 0, faceArray);
-	glDrawArrays(GL_QUADS, 0, 4);
-	glVertexPointer(3, GL_INT, 0, cubeArray);
-	glDisableClientState(GL_COLOR_ARRAY);
-	glEnable(GL_TEXTURE_2D);
-	glPopMatrix();
-
-	// draw cube
-	glTranslatef(0.5f, 0.5f, 0.5f);
-	glRotatef(3.0f, 1.0f, 1.0f, 1.0f);
-	glTranslatef(-0.5f, -0.5f, -0.5f);
-	glColor4f(0.9f, 0.9f, 0.9f, 1.0f);
-	glDrawArrays(GL_QUADS, 0, 24);
-
-	QImage im = toImage();
-	QString qstr("test.png");
-
-	im.save(qstr, "PNG");
-
-	doneCurrent();
-}
 
 
@@ -210,4 +127,6 @@
 {
 	EnableDrawArrays();
+	
+	// prepare pvs for rendering
 	PreparePvs(pvs);
 
@@ -348,8 +267,10 @@
 	pErrorPixels = (float)pixelCount / (GetWidth() * GetHeight());
 
+	const int pixelThres = 100000;
+
 	// some error happened
-	if (pixelCount > 0) 
-	{
-		cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << endl;
+	if (pixelCount > pixelThres) 
+	{
+		cout << "frame " << mFrame << " vc id: " << viewcell->GetId() << " pvs: " << pvsSize << " pc: " << pixelCount << " vp: " << mViewPoint << endl;
 	
 		if (mSnapErrorFrames) 
@@ -611,4 +532,5 @@
 	{
 		Intersectable *obj = it.Next();
+
 		switch (obj->Type())
 		{
@@ -620,15 +542,8 @@
 			break;
 #if DYNAMIC_OBJECTS_HACK
-#if USE_TRANSFORMED_MESH_INSTANCE_HACK
-
-		case Intersectable::TRANSFORMED_MESH_INSTANCE:
-			mDynamicObjects.push_back(static_cast<TransformedMeshInstance *>(obj));
-			break;
-
-#else
+
 		case Intersectable::SCENEGRAPHLEAF_INTERSECTABLE:
 			mDynamicObjects.push_back(static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem());
 			break;
-#endif
 #endif
 		default:
@@ -660,5 +575,5 @@
 	if (viewcell) 
 	{
-#if 0
+#if 1
 		// copy the pvs so that it can be filtered ...
 		if (PvsChanged(viewcell)) 
@@ -689,8 +604,10 @@
 			PreparePvs(mPvsCache.mPvs);
 			emit PvsUpdated();
+
 			mCurrentPvsCost = mPvsCache.mPvs.EvalPvsCost();
 		}
 #else
 	
+		// update the indices for rendering
 		PreparePvs(viewcell->GetPvs());
 		emit PvsUpdated();
@@ -721,5 +638,6 @@
 			mWireFrame = false;
 		}
-		mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost();
+		
+		//mCurrentPvsCost = viewcell->GetPvs().EvalPvsCost();
 	} 
 	else 
@@ -797,8 +715,29 @@
 
 
-void QtGlRendererWidget::timerEvent(QTimerEvent *event) 
-{
-	//std::cout << "Timer ID:" << event->timerId();
-	update();
+void QtGlRendererWidget::timerEvent(QTimerEvent *timerEvent) 
+{
+	if (mReplayMode && (timerEvent->timerId() == mReplayTimerId))
+	{
+		if (sViewPointsListIt == sViewPointsList.end())
+		{
+			cout << "stopping replay" << endl;
+			mReplayMode = false;
+		}
+		else
+		{
+			SimpleRay sray = *sViewPointsListIt;
+
+			mViewPoint = sray.mOrigin;
+			mViewDirection = sray.mDirection;
+
+			++ sViewPointsListIt;
+		}
+
+
+		updateGL();
+	}
+
+	if (timerEvent->timerId() == mUpdateTimerId)
+		update();
 }
 
@@ -826,4 +765,7 @@
 QtGlRendererWidget::mouseMoveEvent(QMouseEvent *e)
 {
+	if (mReplayMode)
+		return;
+
 	float MOVE_SENSITIVITY = Magnitude(mSceneGraph->GetBox().Diagonal())*1e-3;
 	float TURN_SENSITIVITY = 0.1f;
@@ -838,5 +780,4 @@
 
 	const float t = 1.0f;
-
 	if (e->modifiers() & Qt::ControlModifier) 
 	{
@@ -1079,4 +1020,5 @@
 	mComputeGVS = false;
 	mUseRandomColorPerPvsObject = false;
+	//mUseRandomColorPerPvsObject = true;
 
 	mHideByCost = false;
@@ -1087,5 +1029,6 @@
 
 	const int delay = 250; // in milliseconds
-	timerId = startTimer(delay);
+	mUpdateTimerId = startTimer(delay);
+	mReplayTimerId = startTimer(1); // use fastest replay rate
 
 	bool tmp;
@@ -1121,4 +1064,6 @@
 	mShowRays = false;
 
+	mReplayMode = false;
+
 	SetSceneCut(1000);
 	mControlWidget = new QtRendererControlWidget(NULL);
@@ -1133,4 +1078,5 @@
 	connect(mControlWidget, SIGNAL(StoreStatistics(void)), this, SLOT(StoreStatistics(void)));
 	connect(mControlWidget, SIGNAL(ComputeGVS(void)), this, SLOT(ComputeGVS(void)));
+	connect(mControlWidget, SIGNAL(ReplayViewPoints(void)), this, SLOT(ReplayViewPoints(void)));
 	connect(mControlWidget, SIGNAL(LoadObject(void)), this, SLOT(LoadObject(void)));
 
@@ -2303,5 +2249,4 @@
 	connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetRenderFilter(bool)));
 
-
 	/*vbox = new QGroupBox("PVS Errors", this);
 	layout()->addWidget(vbox);
@@ -2328,7 +2273,17 @@
 #endif
 
+#if 0
+	
 	button = new QPushButton("Compute GVS", vbox);
 	vbox->layout()->addWidget(button);
 	connect(button, SIGNAL(clicked()), SIGNAL(ComputeGVS()));
+
+#else
+	
+	button = new QPushButton("Replay view points", vbox);
+	vbox->layout()->addWidget(button);
+	connect(button, SIGNAL(clicked()), SIGNAL(ReplayViewPoints()));
+
+#endif
 
 #if DYNAMIC_OBJECTS_HACK
@@ -2410,5 +2365,5 @@
 	// create the pbuffer
 	//pbuffer = new QGLPixelBuffer(QSize(512, 512), format(), this);
-	timerId = startTimer(20);
+	//mUpdateTimerId = startTimer(20);
 	setWindowTitle(("OpenGL pbuffers"));
 }
@@ -2514,19 +2469,17 @@
 	while (it.HasMoreEntries())
 	{
-		Intersectable *object = it.Next(pvsData);
+		Intersectable *obj = 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);
+			KdIntersectable *kdint = static_cast<KdIntersectable *>(obj);
 
 			if (kdint->mGenericIdx == -1)
 			{
 				kdint->mGenericIdx = (int)mColors.size();
-				mColors.push_back(RandomColor());
+				mColors.push_back(RandomColor(0, 1));
 			}
 			color = mColors[kdint->mGenericIdx];
@@ -2540,15 +2493,44 @@
 
 		mUseForcedColors = true;
-		RenderIntersectable(object);
+		RenderIntersectable(obj);
 		mUseForcedColors = false;
 	}
 }
 
-void
-QtGlRendererWidget::UpdateDynamicObjects()
-{
-  preprocessor->ScheduleUpdateDynamicObjects();
-  
-}
-
-}
+
+void QtGlRendererWidget::UpdateDynamicObjects()
+{
+	preprocessor->ScheduleUpdateDynamicObjects();  
+}
+
+
+void QtGlRendererWidget::ReplayViewPoints()
+{
+	ViewCellPointsList *vcPoints = mViewCellsManager->GetViewCellPointsList();
+
+	ViewCellPointsList::const_iterator vit,	vit_end = vcPoints->end();
+
+	sViewPointsList.clear();
+
+	for (vit = vcPoints->begin(); vit != vit_end; ++ vit) 
+	{
+		ViewCellPoints *vp = *vit;
+
+		SimpleRayContainer::const_iterator rit, rit_end = vp->second.end();
+	
+		for (rit = vp->second.begin(); rit != rit_end; ++ rit)
+		{
+			sViewPointsList.push_back(*rit);
+		}
+	}
+
+	if (!sViewPointsList.empty())
+	{
+		cout << "replaying " << (int)sViewPointsList.size() << " view points " << endl;
+
+		mReplayMode = true;
+		sViewPointsListIt = sViewPointsList.begin();
+	}
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2679)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2686)
@@ -75,6 +75,5 @@
 	int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const;
 
-	unsigned int mydynamicTexture;
-void dummyBuffer();
+
 public:
 
@@ -107,4 +106,6 @@
 
   signals:
+  
+  void ReplayViewPoints();
   void UpdateDynamicObjects();
   void ComputeVisibility();
@@ -195,5 +196,4 @@
 	float mSpatialFilterSize;
 
-	//LogWriter *mLogWriter;
 	Plane3 mSceneCutPlane;
 	float mHidingCost;
@@ -213,4 +213,6 @@
 
 	int mCurrentDynamicObjectIdx;
+
+	bool mReplayMode;
 
 	// some statistics
@@ -236,4 +238,7 @@
 
 	bool mUseRandomColorPerPvsObject;
+
+	int mUpdateTimerId;
+	int mReplayTimerId;
 
 #if DYNAMIC_OBJECTS_HACK
@@ -281,6 +286,7 @@
 	virtual int GetHeight() const { return height(); }
 
-	virtual void
-		SetupCameraProjection(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);
 
 	void RenderViewCells();
@@ -303,16 +309,15 @@
 
 	void AssignColorByComparison(const ViewCellContainer &viewcells,
-								 //const ViewCellInfoContainer &info1, 
 								 const ViewCellInfoContainer &compareInfo);
 
 	void WriteViewCellInfos();
 
-
-	/////////
-	//QMutex mMutex;
-
+	
 
 public slots:
 	
+	/** Replay the view points stored in the view points list.
+	*/
+	void ReplayViewPoints();
 	void UpdateDynamicObjects();
 	void UpdateAllPvs();
@@ -553,5 +558,5 @@
 	}
 
-
+	
 	/** Prepare pvs for rendering.
 	*/
@@ -565,5 +570,4 @@
 
 	float ComputeRenderCost(ViewCell *vc);
-
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2670)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2686)
@@ -67,9 +67,9 @@
 	GLfloat mat_shininess[] = {  1.0  };
 
-	GLfloat light_ambient[]  = {  0.2, 0.2, 0.2, 1.0  };
-	GLfloat light_diffuse[]  = {  0.4, 0.4, 0.4, 1.0  };
-	GLfloat light_specular[] = {  0.3, 0.3, 0.3, 1.0  };
-
-	GLfloat lmodel_ambient[] = {0.3, 0.3, 0.3, 1.0};
+	GLfloat light_ambient[]  = {  0.2f, 0.2f, 0.2f, 1.0f  };
+	GLfloat light_diffuse[]  = {  0.4f, 0.4f, 0.4f, 1.0f  };
+	GLfloat light_specular[] = {  0.3f, 0.3f, 0.3f, 1.0f };
+
+	GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RandomViewCellsHandler.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RandomViewCellsHandler.cpp	(revision 2648)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RandomViewCellsHandler.cpp	(revision 2686)
@@ -136,6 +136,6 @@
 
 	ViewCellPoints *currentViewCell = NULL;
-	int i = 0;
-	int j = 0;
+
+	AxisAlignedBox3 bbox = mViewCellsManager->GetViewSpaceBox();
 
  	string buf;
@@ -152,9 +152,6 @@
 				currentViewCell->first = mViewCellsManager->GetViewCellById(id);
 					
-				if (1)//i ++ < 5)
-				{
-					viewCells.push_back(currentViewCell);
-					j = 0;
-				}
+				viewCells.push_back(currentViewCell);
+
 				break;
 			}
@@ -164,8 +161,27 @@
 				sscanf(buf.c_str(), "p %f %f %f %f %f %f", &pt.x, &pt.y, &pt.z, &dir.x, &dir.y, &dir.z);
 				
+				if (0)
+				{
+					// add new point to view space box
+					if (!bbox.IsInside(pt))
+						bbox.Include(pt);
+				}
+				else
+				{
+					// other variant: clamp to box
+					bbox.ClampToBox(pt);
+				}
+
 				SimpleRay ray(pt, dir, 0, 1);
 
-				if (1)//j ++ < 5)
-					currentViewCell->second.push_back(ray);
+				// no view cell specified => create dummy view cell
+				if (!currentViewCell)
+				{
+					currentViewCell = new ViewCellPoints();
+					viewCells.push_back(currentViewCell);
+					currentViewCell->first = NULL;
+				}
+
+				currentViewCell->second.push_back(ray);
 
 				break;
@@ -175,4 +191,7 @@
 		}
 	}
+
+	// set updated view space box containing all view points
+	mViewCellsManager->SetViewSpaceBox(bbox);
 
 	return true;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2685)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2686)
@@ -90,26 +90,36 @@
 	mSceneGraph->CollectObjects(mObjects);
 
-#if 1
-	viewCellsManager->GetViewPoint(mViewPoint);
-	mViewDirection = Vector3(0,0,1);
-#else
-
-	// for sg snapshot
-	mViewPoint = Vector3(32.8596, 9.86079, -1023.79);
-	mViewDirection = Vector3(-0.92196, 0, 0.387286);
-
-	// inside
-	mViewPoint = Vector3(14.1254, 10.9818, -1032.75);
-	mViewDirection = Vector3(-0.604798, 0, 0.796379);
-
-	// outside
-	mViewPoint = Vector3(35.092, 17.7078, -857.966);
-	mViewDirection = Vector3(-0.411287, 0, -0.911506);
-
-	// strange viewcell for error measurements (id 534)
-	mViewPoint = Vector3(1405.9, 218.284, -736.785);
-	mViewDirection = Vector3(0.989155, 0, 0.146877);
-
-#endif
+	if (0)
+	{
+		viewCellsManager->GetViewPoint(mViewPoint);
+		mViewDirection = Vector3(0,0,1);
+	}
+	else
+	{
+
+		// for sg snapshot
+		mViewPoint = Vector3(32.8596, 9.86079, -1023.79);
+		mViewDirection = Vector3(-0.92196, 0, 0.387286);
+
+		// inside
+		mViewPoint = Vector3(14.1254, 10.9818, -1032.75);
+		mViewDirection = Vector3(-0.604798, 0, 0.796379);
+
+		// outside
+		mViewPoint = Vector3(35.092, 17.7078, -857.966);
+		mViewDirection = Vector3(-0.411287, 0, -0.911506);
+
+		// strange viewcell for error measurements (id 534)
+		mViewPoint = Vector3(1405.9, 218.284, -736.785);
+		mViewDirection = Vector3(0.989155, 0, 0.146877);
+
+		// high error for city_full
+		mViewPoint = Vector3(842.521, 194.708, -136.708);
+		mViewDirection = Vector3(0.730514, 0, -0.682897);
+
+		// also high error for city_full
+		mViewPoint = Vector3(1038.7f, 192.4f, -471.0f);
+		mViewDirection = Vector3(-0.8f, 0.0f, -0.6f);
+	}
 
 	mFrame = 0;
@@ -118,6 +128,6 @@
 		                                      mDetectEmptyViewSpace);
 
-	mSnapErrorFrames = false;
-	//mSnapErrorFrames = true;
+	//mSnapErrorFrames = false;
+	mSnapErrorFrames = true;
 
 	mSnapPrefix = "snap/";
@@ -1532,6 +1542,6 @@
 
 	static bool first = true;
+
 	if (first) {
-
 
 		bool exportRandomViewCells;
@@ -1900,4 +1910,6 @@
 		TriangleIntersectable *obj = static_cast<TriangleIntersectable *>(leaf->mGeometry[i]);
 
+		if (obj->GetId() != i)
+			cerr << "****\n****riesenfehler" << endl;
 		Triangle3 tri = obj->GetItem();
 		const Vector3 n = tri.GetNormal();
@@ -1916,4 +1928,6 @@
 	}
 
+	cout << "\n******** created vertex arrays **********" << endl;	
+
 	if (mUseVbos)
 	{
@@ -1933,7 +1947,7 @@
 		delete [] mData;
 		mData = NULL;
-	}
-
-	cout << "\n******** created vertex buffer objects **********" << endl;	
+
+		cout << "\n******** created vertex buffer objects **********" << endl;	
+	}
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2662)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2686)
@@ -392,6 +392,6 @@
 #ifdef USE_HAVRAN_RAYCASTER
 
-  int hit_triangles[16];
-  float dist[16];
+  //int hit_triangles[16];
+  //float dist[16];
   Vector3 normals[16];
   Vector3 min = sbox.Min();
@@ -400,5 +400,5 @@
   int packets = rays.size() / 16;
   
-  int i, j, k = 0;
+  int i, k = 0;
   Vector3 dir;
   
@@ -413,5 +413,5 @@
 
   for (; k < rays.size(); k++) {
-    double normal[3];
+    //double normal[3];
     mKtbtree->FindNearestI(rays[k]);
     // ??? What to do with the results ? These are
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor05.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor05.vcproj	(revision 2685)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor05.vcproj	(revision 2686)
@@ -157,5 +157,5 @@
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="&quot;$(QTDIR)\lib&quot;;..\src\GL;&quot;..\lib05\$(ConfigurationName)&quot;;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;&quot;..\MultiLevelRayTracing\RTScene\$(ConfigurationName)&quot;;&quot;..\MultiLevelRayTracing\RTWorld\$(ConfigurationName)&quot;;&quot;QtInterface\$(ConfigurationName)&quot;;&quot;..\..\..\..\..\..\NonGTP\Xerces\xerces-c_2_8_0\lib&quot;;&quot;$(CG_LIB_PATH)&quot;"
-				GenerateDebugInformation="false"
+				GenerateDebugInformation="true"
 				SubSystem="1"
 				LargeAddressAware="2"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 2575)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.h	(revision 2686)
@@ -81,4 +81,8 @@
   float SqrRadius() const { return 0.5f*SqrMagnitude(Size()); }
   
+  /** Clamps the point to the box.
+  */
+  void ClampToBox(Vector3 &pt) const;
+
   // Return whether the box is unbounded.  Unbounded boxes appear
   // when unbounded objects such as quadric surfaces are included.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2681)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2686)
@@ -59,4 +59,31 @@
 
 
+static string GetViewPointsListName(const string &filename)
+{
+	string viewCellPointsFile;
+
+	char buff[200];
+	Environment::GetSingleton()->GetStringValue("ViewCells.randomViewPointsList", buff);
+
+	string vpList(buff);
+
+	if (vpList == "")
+	{
+		// if not specified, take file that has same prefix as scene file
+		if (strstr(filename.c_str(), ".obj"))
+			viewCellPointsFile = ReplaceSuffix(filename, ".obj", ".vc");
+		else if (strstr(filename.c_str(), ".dat"))
+			viewCellPointsFile = ReplaceSuffix(filename, ".dat", ".vc");
+		else if (strstr(filename.c_str(), ".x3d"))
+			viewCellPointsFile = ReplaceSuffix(filename, ".x3d", ".vc");
+	}
+	else
+	{
+		viewCellPointsFile = vpList;
+	}
+
+	return viewCellPointsFile;
+}
+
 
 void Cleanup()
@@ -240,24 +267,18 @@
 		cout << "view cells successfully loaded" << endl;
 
-	string viewCellPointsFile;
-
-	if (strstr(filename.c_str(), ".obj"))
-		viewCellPointsFile = ReplaceSuffix(filename, ".obj", ".vc");
-	else if (strstr(filename.c_str(), ".dat"))
-		viewCellPointsFile = ReplaceSuffix(filename, ".dat", ".vc");
-	else if (strstr(filename.c_str(), ".x3d"))
-		viewCellPointsFile = ReplaceSuffix(filename, ".x3d", ".vc");
+
+	const string viewCellPointsFile = GetViewPointsListName(filename);
 
 	bool importRandomViewCells;
-	Environment::GetSingleton()->GetBoolValue("ViewCells.importRandomViewCells",
-		importRandomViewCells);
+	Environment::GetSingleton()->GetBoolValue("ViewCells.importRandomViewCells", importRandomViewCells);
 
 	if (importRandomViewCells)
 	{
-		cout << "importing random view cells" << endl;
+		cout << "importing random view points" << endl;
+
 		if (preprocessor->mViewCellsManager->ImportViewCellsList(viewCellPointsFile))
 			cout << "successfully loaded " << viewCellPointsFile << endl;
 		else
-			cerr << "error: file << " << viewCellPointsFile << " not found, generating random view points!" << endl;
+			cerr << "error: file << " << viewCellPointsFile << " not found" << endl;
 	}
 
@@ -369,5 +390,5 @@
 			//rendererWidget->SetWindowTitle("Global Visualization");
 
-			if (1) // not working with vbo
+			if (0 && !rendererWidget->GetUseVbos()) // viewer not working with vbo
 			{
 				cout << "starting the qt viewer" << endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ReverseGvs.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ReverseGvs.cpp	(revision 2584)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ReverseGvs.cpp	(revision 2686)
@@ -175,5 +175,5 @@
 	float importance = 1.0f;
 	if (mUsePassImportance) 
-	  importance = 1.0f/(pContributingRays + 1e-5);
+	  importance = 1.0f/(pContributingRays + 1e-5f);
 	// set this values for last contributingRays
 	int index = mBufferStart - 1;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2677)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 2686)
@@ -212,4 +212,6 @@
   Vector3 GetViewPoint() const { return mViewPoint; }
 
+  bool GetUseVbos() const { return mUseVbos; }
+
 
 public:
@@ -245,5 +247,5 @@
 	void RenderKdLeaf(KdLeaf *leaf);
 
-
+	
 	//////////////////
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbs.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbs.cpp	(revision 2632)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktbs.cpp	(revision 2686)
@@ -189,5 +189,5 @@
 CKTBSBuildUp::ProvideID(ostream &app)
 {
-  bool tempvar;
+  //bool tempvar;
   
   string termCrit;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp	(revision 2629)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/havran/ktball.cpp	(revision 2686)
@@ -462,5 +462,5 @@
   stack[stackTop].depth = 0;
   stack[stackTop].bbox = bbox;
-  int tmpdir;
+  //int tmpdir;
 #ifdef __TAGGED_KDR
   int taggedLists = 0;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2677)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2686)
@@ -226,5 +226,5 @@
 			mTrianglePvs.push_back(obj);
 		
-			mGenericStats = mTrianglePvs.size();
+			mGenericStats = (int)mTrianglePvs.size();
 
 			// exchange the triangle with the node in the pvs for kd pvs
@@ -971,6 +971,4 @@
 
         ComputeViewCell(vc);
-		// $$ JB HACK compute just first viewcell
-		//		break;
 	}
 }
@@ -979,6 +977,4 @@
 void GvsPreprocessor::PerViewCellComputation2()
 {
-	ViewCell *vc;
-
 	while (1)
 	{
@@ -1138,4 +1134,5 @@
 		// provide list of view cells to compute
 		CompileViewCellsList();
+
 		// start per view cell gvs
 		PerViewCellComputation();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 2609)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 2686)
@@ -2482,4 +2482,16 @@
 }
 
-}
-
+
+void AxisAlignedBox3::ClampToBox(Vector3 &pt) const
+{
+	if (pt.x > mMax.x) pt.x = mMax.x;
+	if (pt.y > mMax.y) pt.y = mMax.y;
+	if (pt.z > mMax.z) pt.z = mMax.z;
+
+	if (pt.x < mMin.x) pt.x = mMin.x;
+	if (pt.y < mMin.y) pt.y = mMin.y;
+	if (pt.z < mMin.z) pt.z = mMin.z;
+}
+
+}
+
