Index: /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2737)
+++ /GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2738)
@@ -14,8 +14,8 @@
 SCENE=../data/Arena/arena_trees.obj
 #VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz
-#SCENE=../data/vienna/vienna_cropped.obj
+#SCENE=../data/vienna/2vienna_cropped.obj
 #SCENE=../data/roofs_new.obj
-#SCENE=../data/vienna/city_full_hp.obj
-SCENE=../data/vienna/vienna_rep.obj
+SCENE=../data/vienna/city_full_hp.obj
+#SCENE=../data/vienna/vienna_rep.obj
 
 #SCENE=../data/vienna/vienna_cropped.obj
@@ -25,5 +25,5 @@
 
 #LOG_PREFIX=../src/SG08/rebut-arena-pixel2
-LOG_PREFIX=../src/SG08/test
+LOG_PREFIX=../src/SG08/test_jitter_0.1
 
 ENVIRONMENT=gvs.env
@@ -43,6 +43,9 @@
 -gvs_initial_samples=16 \
 -gvs_max_viewcells=3 \
--gvs_min_contribution=50 \
+-gvs_min_contribution=200 \
 -gvs_per_viewcell=true \
+-gvs_radius_of_influence=5.0 \
+-gvs_use_deterministic_gvs- \
+-gvs_initial_jitter=0.1 \
 -preprocessor_detect_empty_viewspace+ \
 -preprocessor_snap_error_frames+ \
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2736)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2738)
@@ -4,6 +4,8 @@
 #include <fstream>
 #include <stack>
-
 #include "Preprocessor.h"
+#include "FlexibleHeap.h"
+
+
 
 namespace GtpVisibilityPreprocessor {
@@ -93,4 +95,15 @@
 
 
+struct ProbablyVisibleTriangleContainer
+{
+	KdNode *node;
+	ObjectContainer mTriangles;
+};
+
+
+typedef FlexibleHeap<ProbablyVisibleTriangleContainer *> ProbablyVisibleTriangleQueue;
+
+
+
 /** Sampling based visibility preprocessing. The implementation is 
 	based on heuristical sampling of view space.
@@ -336,7 +349,14 @@
 
 	bool mUseProbablyVisibleSampling;
+
+	float mInitialJitter;
+
+	bool mUseDeterministicGvs;
+
+	float mRadiusOfInfluence;
 };
 
-};
+
+}
 
 #endif
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 2731)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 2738)
@@ -1399,4 +1399,20 @@
 		 "5");
 
+	RegisterOption("GvsPreprocessor.initialJitter",
+				   optFloat,
+				   "gvs_initial_jitter=",
+				   "0.1");
+
+	RegisterOption("GvsPreprocessor.radiusOfInfluence",
+				   optFloat,
+				   "gvs_radius_of_influence=",
+				   "5.0");
+
+	RegisterOption("GvsPreprocessor.useDeterministicGvs",
+				   optBool,
+				   "gvs_use_deterministic_gvs",
+				   "false");
+
+
 
   /**********************************************************************/
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2737)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2738)
@@ -382,6 +382,6 @@
 				//-- output computed pvs
 
-				//mUseFalseColors = false;
-				mUseFalseColors = true;
+				mUseFalseColors = false;
+				//mUseFalseColors = true;
 				glPushAttrib(GL_CURRENT_BIT);
 				glColor3f(0, 1, 0);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2736)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2738)
@@ -1963,4 +1963,5 @@
 					mColors.push_back(RandomColor(0, 1));
 				}
+
 				color = mColors[kdint->mGenericIdx];
 			}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2736)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2738)
@@ -25,5 +25,5 @@
 #define NOT_ACCOUNTED_OBJECT 0
 #define ACCOUNTED_OBJECT 2
-#define DETERMINISTIC_GVS 0
+
 
 static const float MIN_DIST = 0.001f;
@@ -31,4 +31,6 @@
 static ObjectContainer myobjects;
 static int sInvalidSamples = 0;
+
+
 
 ///////////
@@ -87,4 +89,8 @@
 	Environment::GetSingleton()->GetBoolValue("ViewCells.useKdPvs", mUseKdPvs);
 
+	Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.initialJitter", mInitialJitter);
+	Environment::GetSingleton()->GetBoolValue("GvsPreprocessor.useDeterministicGvs", mUseDeterministicGvs);
+
+	Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.radiusOfInfluence", mRadiusOfInfluence);
 
 	char gvsStatsLog[100];
@@ -162,5 +168,5 @@
 										const VssRay &oldRay)
 {
-	// the predicted hitpoint: we expect to hit the same mesh again
+	// the predicted hitpoint is the point where the ray would have intersected the hit triangle
 	Vector3 predictedHit = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
 
@@ -168,8 +174,11 @@
 	float len = Magnitude(currentRay.mTermination - currentRay.mOrigin);
 	
-	// distance large => this is likely to be a discontinuity
-	if (!((predictedLen - len) > mThreshold))
+	// discrepancy between predicted and actual hit point large => this is likely to be a discontinuity
+
+	// matt: problem: this does only find CLOSER discontinuities, but not discontinuities which are FARTHER away
+	if ((predictedLen - len) < mThreshold)
+	//if ((fabs(predictedLen - len) < mThreshold)
 	// q: rather use relative distance?
-	//if ((predictedLen / len) > mThreshold)
+	//if ((predictedLen / len) < mThreshold)
 		return 0;
 
@@ -183,5 +192,5 @@
 	reverseRays.clear();
 
-	if (DETERMINISTIC_GVS)
+	if (mUseDeterministicGvs)
 	{
 		VssRay *reverseRay = 
@@ -395,13 +404,8 @@
 	int castRays = 0;
 
-	// cast reverse rays if necessary
-	castRays += CheckDiscontinuity(ray1, hitTriangle, oldRay);
-	castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
-
 	if (EqualVisibility(ray1, ray2) || (SqrMagnitude(p1 - p2) <= MIN_DIST))
-	{
 		return castRays;
-	}
-	
+	
+
 	// the new subdivision point
 	const Vector3 p = (p1 + p2) * 0.5f;
@@ -433,4 +437,7 @@
 	
 	//newRay->mFlags |= VssRay::BorderSample;
+
+	// cast reverse rays if necessary
+	castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
 
 	// subdivide further
@@ -495,5 +502,5 @@
 	const int numRandomRays = 16 - (int)simpleRays.size();
 
-	if (!DETERMINISTIC_GVS)
+	if (!mUseDeterministicGvs)
 	{
 		if (0)
@@ -514,4 +521,5 @@
 	generationTimer.Exit();
 
+
 	/////////////////////
 	//-- cast rays to vertices and determine visibility
@@ -547,4 +555,11 @@
 			(*rit)->mFlags |= VssRay::BorderSample;
 	}
+
+	for (size_t i = 0; i < vssRays.size(); ++ i)
+	{
+		// check for discontinuity and cast reverse rays if necessary
+		castRays += CheckDiscontinuity(*vssRays[i], hitTriangle, currentRay);
+	}
+	
 
     // recursivly subdivide each edge
@@ -578,5 +593,5 @@
 		hitTriangle = static_cast<TriangleIntersectable *>(tObj)->GetItem();
 	else
-		cout << "border sampling: " << Intersectable::GetTypeName(tObj) << " not yet implemented" << endl;
+		cout << "error: gvs sampling for " << Intersectable::GetTypeName(tObj) << " not implemented" << endl;
 
 	generationTimer.Entry();
@@ -623,12 +638,23 @@
 	const int numRandomRays = 16 - ((int)simpleRays.size() % 16);
 
-	SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), 
-								  currentRay.GetNormalizedDir(), 
-								  SamplingStrategy::GVS, 1.0f);
-
-	GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0, 0.01f);
-	//GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples);
+		if (!mUseDeterministicGvs)
+	{
+		if (0)
+		{
+			SimpleRay mainRay = SimpleRay(currentRay.GetOrigin(), 
+				                          currentRay.GetNormalizedDir(), 
+										  SamplingStrategy::GVS, 
+										  1.0f);
+			
+			GenerateJitteredRays(simpleRays, mainRay, numRandomRays, 0, 0.01f);
+		}
+		else
+			GenerateImportanceSamples(currentRay, hitTriangle, numRandomRays, simpleRays);
+	}
+	else
+		GenerateRays(numRandomRays, *mDistribution, simpleRays, sInvalidSamples);
 
 	generationTimer.Exit();
+
 
 
@@ -660,4 +686,10 @@
 	EnqueueRays(vssRays);
 	
+	for (size_t i = 0; i < vssRays.size(); ++ i)
+	{
+		// check for discontinuity and cast reverse rays if necessary
+		castRays += CheckDiscontinuity(*vssRays[i], hitTriangle, currentRay);
+	}
+
 #if 0
 	
@@ -726,5 +758,5 @@
 										SimpleRay &reverseRay)
 {
-	// get triangle occluding the path to the hit mesh
+	// optain triangle that occludes the path to the currently processed mesh
 	Triangle3 occluder;
 	Intersectable *tObj = currentRay.mTerminationObject;
@@ -749,16 +781,14 @@
 	const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
 
-	Vector3 newDir, newOrigin;
-
 	//////////////
 	//-- Construct the mutated ray with xnew,
 	//-- dir = predicted(x)- pnew as direction vector
 
-	newDir = predicted - newPoint;
+	Vector3 newDir = newDir = predicted - newPoint;
 
 	// take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ?
 	// difficult to say!!
 	const float offset = 0.5f;
-	newOrigin = newPoint - newDir * offset;
+	Vector3 newOrigin = newPoint - newDir * offset;
 	
 
@@ -777,5 +807,5 @@
 		// check if ray intersects view cell
 		if (!mCurrentViewCell->CastRay(ray))
-			return NULL;
+			return false;
 
 		Ray::Intersection &hit = ray.intersections[0];
@@ -808,5 +838,5 @@
 	else
 	{
-		GenerateRays(DETERMINISTIC_GVS ? numSamples : numSamples / 16, *mDistribution, simpleRays, sInvalidSamples);
+		GenerateRays(mUseDeterministicGvs ? numSamples : numSamples / 16, *mDistribution, simpleRays, sInvalidSamples);
 	}
 
@@ -819,5 +849,5 @@
 	castTimer.Entry();
 
-	if (DETERMINISTIC_GVS)
+	if (mUseDeterministicGvs)
 	{
 		const bool castDoubleRays = !mPerViewCell;
@@ -829,10 +859,9 @@
 	else
 	{
-		float scale = 0.1f;
 		if (0)
 			// casting bundles of 4 rays generated from the simple rays
 			CastRayBundles4(simpleRays, vssRays);
 		else
-			CastRayBundles16(simpleRays, vssRays, scale);
+			CastRayBundles16(simpleRays, vssRays, mInitialJitter);
 	}
 
@@ -879,5 +908,5 @@
 		mRayQueue.pop();
 		
-		if (1)
+		if (0)
 			castSamples += AdaptiveBorderSampling(*ray);
 		else
@@ -1515,5 +1544,5 @@
 			mGvsStats.mPassContribution = mGvsStats.mTotalContribution - oldContribution;
 
-			if (mGvsStats.mPassContribution < 2000)
+			if (!mUseDeterministicGvs && (mGvsStats.mPassContribution < 2000))
 				mUseProbablyVisibleSampling = true;
 			
@@ -1935,5 +1964,5 @@
 
 	Vector2 vr2(rr[0], rr[1]);
-	const float sigma = triangle.GetBoundingBox().Radius() * 5.0f;
+	const float sigma = triangle.GetBoundingBox().Radius() * mRadiusOfInfluence;
 	Vector2 gaussvec2;
 
