Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2741)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_gvs_vps.sh	(revision 2742)
@@ -17,6 +17,6 @@
 #SCENE=../data/roofs_new.obj
 SCENE=../data/vienna/city_full_hp.obj
-SCENE=../data/vienna/vienna_rep.obj
-#SCENE=../data/vienna/vienna_cropped.obj
+#SCENE=../data/vienna/vienna_rep.obj
+SCENE=../data/vienna/vienna_cropped.obj
 
 VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz 
@@ -43,8 +43,8 @@
 -gvs_initial_samples=16 \
 -gvs_max_viewcells=1 \
--gvs_min_contribution=50 \
+-gvs_min_contribution=20 \
 -gvs_per_viewcell=true \
 -gvs_radius_of_influence=5.0 \
--gvs_use_deterministic_gvs- \
+-gvs_use_deterministic_gvs+ \
 -gvs_initial_jitter=0.1 \
 -preprocessor_detect_empty_viewspace+ \
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2725)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2742)
@@ -8,7 +8,7 @@
 
 
-#SCENE=../data/vienna/vienna_cropped.obj
+SCENE=../data/vienna/vienna_cropped.obj
 #SCENE=../data/vienna/city_full.obj
-SCENE=../data/vienna/city_full_hp.obj
+#SCENE=../data/vienna/city_full_hp.obj
 #SCENE=../data/vienna/vienna_rep.obj
 
@@ -40,5 +40,5 @@
  -preprocessor_detect_empty_viewspace+ \
  -preprocessor_use_vbos- \
- -preprocessor_ray_cast_method=3 \
+ -preprocessor_ray_cast_method=1 \
  -view_cells_random_viewpoint_list=$VIEWPOINTS \
  demo1.env
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2741)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2742)
@@ -178,5 +178,5 @@
 		with respect to the previous ray.
 	*/
-	void EnqueueRays(VssRayContainer &samples);
+	void EnqueueRays(const VssRayContainer &samples);
 	/** Hepler function for adaptive border sampling. It finds 
 		new sample points around a triangle in a eps environment
@@ -300,11 +300,16 @@
 		                             const Vector3 &predictedPoint, 
 									 SimpleRayContainer &rays, 
-									 int number);
+									 int number,
+									 const Triangle3 &triangle);
 
 	bool CreateRandomizedReverseRay(const VssRay &ray, 
 		                            const Vector3 &predictedPoint,
-									SimpleRay &simpleray);
+									SimpleRay &simpleray,
+									 const Triangle3 &triangle);
 
 	inline bool IntersectsViewCell(Vector3 &origin, const Vector3 &dir) const;
+
+	void DeleteOldRays();
+
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2729)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2742)
@@ -107,5 +107,6 @@
   { }
 
-  
+  void SheduleRayForDeletion(VssRay *ray);
+
   /*virtual void CastRaysEye4(SimpleRayContainer &rays,
     VssRayContainer &vssRays,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2736)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2742)
@@ -1182,7 +1182,9 @@
 		const int n = 4;
 		reserveRays = mSamplesPerPass * n;
-		cout << "setting ray pool size to " << reserveRays << endl;       
-
-	}
+
+	}
+
+#ifdef USE_RAY_POOL
+	cout << "setting ray pool size to " << reserveRays << endl;       
 
 	cout << "======================" << endl;
@@ -1192,5 +1194,6 @@
 	
 	cout<<"done."<<endl<<flush;
-	
+#endif
+
 	return true;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2738)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2742)
@@ -97,6 +97,6 @@
 
 		// for sg snapshot
-	  mViewPoint = Vector3(32.8596, 9.86079, -1023.79);
-	  mViewDirection = Vector3(-0.92196, 0, 0.387286);
+		mViewPoint = Vector3(32.8596, 9.86079, -1023.79);
+		mViewDirection = Vector3(-0.92196, 0, 0.387286);
 
 		// inside
@@ -106,38 +106,42 @@
 		if (1) {
 
-		// 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);
-
-		mViewPoint = Vector3(440.295, 196.959, -781.302);
-		mViewDirection = Vector3(-0.0566328, 0, -0.998395);
-
-		mViewPoint = Vector3(680.682, 189.552, -278.177);
-		mViewDirection = Vector3(0.942709, -0, -0.333584);
-
-		// strange error for gvs
-		mViewPoint = Vector3(1186.9, 193.552, -377.044);
-		mViewDirection = Vector3(-0.963031, -0, -0.269365);
-
-		mViewPoint = Vector3(1189.54, 220.087, -462.869);
-		mViewDirection = Vector3(-0.996972, -0, -0.0776569);
-
-		mViewPoint = Vector3(1199.53, 257.677, -457.145);
-		mViewDirection = Vector3(-0.71206, -0, -0.702108);
-
-		mViewPoint = Vector3(1188.22, 187.427, -381.739);
-		mViewDirection = Vector3(-0.963031, -0, -0.269365);
+			// 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);
+
+			mViewPoint = Vector3(440.295, 196.959, -781.302);
+			mViewDirection = Vector3(-0.0566328, 0, -0.998395);
+
+			mViewPoint = Vector3(680.682, 189.552, -278.177);
+			mViewDirection = Vector3(0.942709, -0, -0.333584);
+
+			// strange error for gvs
+			/*mViewPoint = Vector3(1186.9, 193.552, -377.044);
+			mViewDirection = Vector3(-0.963031, -0, -0.269365);
+
+			mViewPoint = Vector3(1189.54, 220.087, -462.869);
+			mViewDirection = Vector3(-0.996972, -0, -0.0776569);
+
+			mViewPoint = Vector3(1199.53, 257.677, -457.145);
+			mViewDirection = Vector3(-0.71206, -0, -0.702108);
+
+			mViewPoint = Vector3(1188.22, 187.427, -381.739);
+			mViewDirection = Vector3(-0.963031, -0, -0.269365);
+
+			mViewPoint = Vector3(1188.22, 187.427, -381.739);
+			mViewDirection = Vector3(-0.963031, -0, -0.269365);
+*/
 		}
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 2718)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 2742)
@@ -373,4 +373,6 @@
 							  const float pdf)
 {
+#ifdef USE_RAY_POOL
+
  #if DEBUG_RAYCAST
 	Debug<<"PR2a"<<flush;
@@ -392,6 +394,23 @@
 #endif
 
+#else
+	VssRay *vssRay = new VssRay(origin, termination, originObject, terminationObject, pass, pdf);
+#endif
 	return vssRay;
 }
+
+
+void RayCaster::SheduleRayForDeletion(VssRay *ray)
+{
+#ifndef USE_RAY_POOL
+	delete ray;
+#endif
+}
+
+
+/*void RayCaster::DeleteOldRays()
+{
+	CLEAR_CONTAINER(mOldRays);
+}*/
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2741)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2742)
@@ -140,4 +140,5 @@
 
 		// note: deletion of the ray is handled by ray pool
+		mRayCaster->SheduleRayForDeletion(ray);
 	}
 }
@@ -209,5 +210,4 @@
 
 	mGvsStats.mReverseSamples += (int)reverseRays.size();
-
 	EnqueueRays(reverseRays);
 
@@ -234,5 +234,5 @@
 	simpleRays.clear();
 
-	CreateRandomizedReverseRays(currentRay, predictedHit, simpleRays, 16);
+	CreateRandomizedReverseRays(currentRay, predictedHit, simpleRays, 16, hitTriangle);
 
 	static VssRayContainer reverseRays;
@@ -344,7 +344,13 @@
 bool GvsPreprocessor::HandleRay(VssRay *vssRay)
 {
-	if (!vssRay || !HasContribution(*vssRay))
+	if (!vssRay)
 		return false;
 
+	if (!HasContribution(*vssRay))
+	{
+		mRayCaster->SheduleRayForDeletion(vssRay);
+		return false;
+	}
+	
 	if (0 && GVS_DEBUG)
 		mVssRays.push_back(new VssRay(*vssRay));
@@ -354,4 +360,10 @@
 
 	++ mGvsStats.mTotalContribution;
+
+	if (mRayQueue.size() % 10000 == 0)
+		cout << "ray queue size: " << mRayQueue.size() << endl;
+
+	if (mGvsStats.mTotalContribution % 10000 == 0)
+		cout << "contri: " << mGvsStats.mTotalContribution << endl;
 
 	return true;
@@ -452,28 +464,27 @@
 	// cast single ray to check if a triangle was missed. note: not efficient!!
 	newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), !mPerViewCell);
+	++ castRays;
+	
 	castTimer.Exit();
 
-	++ castRays;
-
-	// this ray will not be further processed
-	// note: ray deletion is handled by ray pool
-	if (!newRay) return castRays;
-
-	rayTimer.Entry();
-
-	// new triangle discovered? => add new ray to queue
-	HandleRay(newRay);
-
-	rayTimer.Exit();
-	
+	if (!newRay)
+		return castRays;
+
 	//newRay->mFlags |= VssRay::BorderSample;
 
 	// cast reverse rays if necessary
-	castRays += CheckDiscontinuity(ray2, hitTriangle, oldRay);
-
+	castRays += CheckDiscontinuity(*newRay, hitTriangle, oldRay);
+	
 	// subdivide further
 	castRays += SubdivideEdge(hitTriangle, p1, p, ray1, *newRay, oldRay);
 	castRays += SubdivideEdge(hitTriangle, p, p2, *newRay, ray2, oldRay);
-	
+
+	rayTimer.Entry();
+
+	// new triangle discovered? => add new ray to queue
+	HandleRay(newRay);
+
+	rayTimer.Exit();
+
 	return castRays;
 }
@@ -549,7 +560,4 @@
 	int castRays = (int)simpleRays.size();
 
-	// handle cast rays
-	EnqueueRays(vssRays);
-
 	if (0)
 	{
@@ -567,5 +575,5 @@
 			(*rit)->mFlags |= VssRay::BorderSample;
 	}
-
+#if 0
     // recursivly subdivide each edge
 	for (int i = 0; i < numBorderSamples; ++ i)
@@ -580,7 +588,10 @@
 								  currentRay);
 	}
-	
+#endif	
 	mGvsStats.mBorderSamples += castRays;
 	
+	// handle cast rays
+	EnqueueRays(vssRays);
+
 	return castRays;
 }
@@ -602,6 +613,11 @@
 		cout << "error: gvs sampling for " << Intersectable::GetTypeName(tObj) << " not implemented" << endl;
 
+	
+	static SimpleRayContainer simpleRays;
+	simpleRays.clear();
+	
+
 	generationTimer.Entry();
-
+#if 0
 	static VertexContainer enlargedTriangle;
 	enlargedTriangle.clear();
@@ -625,8 +641,4 @@
 	}
 
-	/// create rays from sample points and handle them
-	static SimpleRayContainer simpleRays;
-	simpleRays.clear();
-	
 	VertexContainer::const_iterator vit, vit_end = subdivEnlargedTri.end();
 
@@ -639,5 +651,5 @@
 	}
 
-	
+#endif	
 	//////////
 	//-- fill up simple rays with random rays so we can cast 16 rays at a time
@@ -675,9 +687,5 @@
 	int castRays = (int)simpleRays.size();
 
-	// handle cast rays
-	EnqueueRays(vssRays);
-
-
-#if 1
+#if 0
 	for (size_t i = 0; i < vssRays.size(); ++ i)
 	{
@@ -685,5 +693,6 @@
 		castRays += CheckDiscontinuity2(*vssRays[i], hitTriangle, currentRay);
 	}
-
+#endif
+#if 0
 
     // recursivly subdivide each edge
@@ -702,5 +711,8 @@
 
 	mGvsStats.mBorderSamples += castRays;
-	
+
+	// handle cast rays
+	EnqueueRays(vssRays);
+
 	return castRays;
 }
@@ -844,5 +856,6 @@
 	else
 	{
-		GenerateRays(mUseDeterministicGvs ? numSamples : numSamples / 16, *mDistribution, simpleRays, sInvalidSamples);
+		GenerateRays(mUseDeterministicGvs ? 
+			numSamples : numSamples / 16, *mDistribution, simpleRays, sInvalidSamples);
 	}
 
@@ -883,5 +896,5 @@
 
 
-void GvsPreprocessor::EnqueueRays(VssRayContainer &samples)
+void GvsPreprocessor::EnqueueRays(const VssRayContainer &samples)
 {
 	rayTimer.Entry();
@@ -893,5 +906,4 @@
 		VssRay *ray = *vit;
 		HandleRay(ray);
-		// note: deletion of invalid samples handked by ray pool
 	}
 
@@ -918,6 +930,4 @@
 		else
 			castSamples += AdaptiveBorderSamplingOpt(*ray);
-
-		// note: don't have to delete because handled by ray pool
 	}
 
@@ -2001,5 +2011,4 @@
 void GvsPreprocessor::PrepareProbablyVisibleSampling()
 {
-	
 	// warning: using mailing!
 	Intersectable::NewMail();
@@ -2043,5 +2052,6 @@
 												  const Vector3 &predictedPoint, 
 												  SimpleRayContainer &rays, 
-												  int number)
+												  int number,
+												  const Triangle3 &triangle)
 {
 	size_t currentNumber = rays.size();
@@ -2052,8 +2062,11 @@
 	{
 		SimpleRay simpleRay;
-		if (CreateRandomizedReverseRay(ray, predictedPoint, simpleRay))
+		if (CreateRandomizedReverseRay(ray, predictedPoint, simpleRay, triangle))
 			rays.push_back(simpleRay);
 	}
 
+	if (rays.size() != 16)
+		cout << "x";
+	//else cout <<"y";
 	//cout << "generated " << rays.size() << " rays" << endl;
 }
@@ -2062,7 +2075,8 @@
 bool GvsPreprocessor::CreateRandomizedReverseRay(const VssRay &ray, 
 												 const Vector3 &predictedPoint, 
-												 SimpleRay &simpleRay)
-{
-	//Vector3 nd = ray.GetNormalizedDir();
+												 SimpleRay &simpleRay,
+												 const Triangle3 &triangle)
+{
+	/*Vector3 nd = ray.GetNormalizedDir();
 	const AxisAlignedBox3 box = mCurrentViewCell->GetBox();
 	//Vector3 nd = box.GetNearestFace(origin).GetNormal();
@@ -2070,5 +2084,5 @@
 
 	// Compute right handed coordinate system from direction
-	/*Vector3 U, V;
+	Vector3 U, V;
 	nd.RightHandedBase(U, V);
 	
@@ -2079,17 +2093,17 @@
 
 	Vector2 vr2(rr[0], rr[1]);
-	const float sigma = 1.0f;//triangle.GetBoundingBox().Radius() * mRadiusOfInfluence;
+	const float sigma = triangle.GetBoundingBox().Radius() * 1.0f;
 	Vector2 gaussvec2;
 
 	GaussianOn2D(vr2, sigma, // input
 		         gaussvec2); // output
-	
-	const Vector3 shift = gaussvec2.xx * U + gaussvec2.yy * V;
-
-	Vector3 newOrigin = ray.mOrigin + shift;
 	*/
+	const Vector3 shift = 0;//gaussvec2.xx * U + gaussvec2.yy * V;
+
+	const Vector3 newTermination = ray.mTermination + shift;
+	
 	//cout << "o: " << origin << " new o: " << newOrigin << endl;
-	Vector3 newOrigin = box.GetRandomPoint();
-	Vector3 direction = predictedPoint - newOrigin;
+	Vector3 newOrigin = mCurrentViewCell->GetBox().GetRandomPoint();
+	Vector3 direction = newTermination - newOrigin;
 
 	const float len = Magnitude(direction);
@@ -2101,8 +2115,5 @@
 
 	if (0 && !IntersectsViewCell(newOrigin, -direction))
-	{
-		//cout << "x";
 		return false;
-	}
 
 	//cout << "y";
@@ -2114,4 +2125,3 @@
 }
 
-
-}
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2741)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2742)
@@ -809,5 +809,6 @@
 	static Vector3 point;
 	static Vector3 normal;
-	static float r[2];
+
+	float r[2];
 
 	sHalton.GetNext(2, r);
@@ -831,5 +832,5 @@
 		//origin = mViewCell->GetBox().GetRandomSurfacePoint();
 		origin = mViewCell->GetBox().GetRandomPoint();
-
+//origin = Vector3(680.682, 189.552, -278.177);
 		// move a little bit back to avoid piercing through walls
 		// that bound the view cell
