Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1489)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1492)
@@ -40,6 +40,17 @@
 	};
 
+	typedef stack<GvsRayInfo> RayQueue;
 
-	typedef stack<GvsRayInfo> RayQueue;
+	struct PendingRay
+	{
+		PendingRay(VssRay *ray, const bool d)
+			: mRay(ray), mFoundDiscontinuity(d) 
+		{}
+
+		VssRay *mRay;
+		bool mFoundDiscontinuity;
+	};
+
+	typedef stack<PendingRay> PendingQueue;
 
 	/** Runs the adaptive sampling until the ray queue is empty. 
@@ -92,5 +103,5 @@
 		with respect to the previous ray.
 	*/
-	void EnqueueSamples(VssRayContainer &samples, VssRay *prevRay = NULL);
+	void EnqueueRays(VssRayContainer &samples, VssRay *prevRay = NULL);
 	
 	//////////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1492)
@@ -127,5 +127,4 @@
 		exit(1);
 	}
-
 
 	string externKdTree = ReplaceSuffix(filename, ".obj", ".kdf");
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1489)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1492)
@@ -32,4 +32,5 @@
 											   const VssRay &oldRay) const
 {
+	//|predicted(x)-xp|-|hit(x)-xp| > ?,
     //const Plane3 plane = tri->GetPlane();
 	return false;
@@ -57,9 +58,9 @@
 	new sample points around a triangle in a eps environment
 */
-static void CreateNewSamples(VertexContainer &samples, 
-							 const Triangle3 &hitTriangle,
-							 const VssRay &ray, 
-							 const int index,
-							 const float eps)
+static void CreateNewRays(SimpleRayContainer &simpleRays, 
+						  const Triangle3 &hitTriangle,
+						  const VssRay &ray, 
+						  const int index,
+						  const float eps)
 {
 	const int indexU = (index + 1) % 3;
@@ -69,38 +70,30 @@
 	const Vector3 b = hitTriangle.mVertices[indexU] - hitTriangle.mVertices[index];
 	const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL];
+	
 	const float len = Magnitude(a);
+
+	const Vector3 dir1 = CrossProd(a, b); //N((pi-xp)×(pi+1- pi));
+	const Vector3 dir2 = CrossProd(a, c); // N((pi-xp)×(pi- pi-1))
+	const Vector3 dir3 = DotProd(dir1, dir2) > 0 ? 
+		Normalize(dir2 + dir1) : Normalize(CrossProd(a, dir2) + CrossProd(dir1, a)); // N((pi-xp)×di,i-1+di,i+1×(pi-xp))
 
 	// compute the new three hit points
 	// pi, i + 1
-	const Vector3 dir1 = CrossProd(a, b); //N((pi-xp)×(pi+1- pi));
 	const Vector3 pt1 = hitTriangle.mVertices[index] + eps * len * dir1; //pi+ e·|pi-xp|·di, j
-	samples.push_back(pt1);
-
 	// pi, i - 1
-    const Vector3 dir2 = CrossProd(a, c); // N((pi-xp)×(pi- pi-1))
-	const Vector3 pt2 = hitTriangle.mVertices[index] + eps * len * dir2; //pi+ e·|pi-xp|·di, j
-	samples.push_back(pt2);
-
+    const Vector3 pt2 = hitTriangle.mVertices[index] + eps * len * dir2; //pi+ e·|pi-xp|·di, j
 	// pi, i
-	const Vector3 dir3 = DotProd(dir1, dir2) > 0 ? 
-		Normalize(dir2 + dir1) : Normalize(CrossProd(a, dir2) + CrossProd(dir1, a)); // N((pi-xp)×di,i-1+di,i+1×(pi-xp))
 	const Vector3 pt3 = hitTriangle.mVertices[index] + eps * len * dir3; //pi+ e·|pi-xp|·di, j
-	samples.push_back(pt3);
-}
-
-
-/** Generate rays from sample points.
-*/
-static void CreateRays(VssRayContainer &rays,
-					   const VertexContainer &samples)
-{
-	VertexContainer::const_iterator vit, vit_end = samples.end();
-	
-	for (vit = samples.begin(); vit != vit_end; ++ vit)
-	{
-		const Vector3 currentSample = *vit;
-		VssRay *ray;// = new VssRay(ray->mOrigin, currentSample);
-	}
-}
+	
+	/// create simple rays and store them in container
+	Vector3 rayDir;
+	rayDir = Normalize(pt1 - ray.GetOrigin());
+	simpleRays.push_back(SimpleRay(rayDir, ray.GetOrigin()));
+	rayDir = Normalize(pt2 - ray.GetOrigin());
+	simpleRays.push_back(SimpleRay(rayDir, ray.GetOrigin()));
+	rayDir = Normalize(pt3 - ray.GetOrigin());
+	simpleRays.push_back(SimpleRay(rayDir, ray.GetOrigin()));
+}
+
 
 
@@ -117,31 +110,22 @@
 	}
 
-	VertexContainer samples;
-	samples.reserve(9);
-
-	CreateNewSamples(samples, hitTriangle, prevRay, 0, mEps);
-	CreateNewSamples(samples, hitTriangle, prevRay, 1, mEps);
-	CreateNewSamples(samples, hitTriangle, prevRay, 2, mEps);
+	SimpleRayContainer simpleRays;
+	simpleRays.reserve(9);
+
+	CreateNewRays(simpleRays, hitTriangle, prevRay, 0, mEps);
+	CreateNewRays(simpleRays, hitTriangle, prevRay, 1, mEps);
+	CreateNewRays(simpleRays, hitTriangle, prevRay, 2, mEps);
 
 	VssRayContainer vssRays;
-	CreateRays(vssRays, samples);
-
-	VssRayContainer::const_iterator rit, rit_end = vssRays.end();
-	
-	for (rit = vssRays.begin(); rit != rit_end; ++ rit)
-	{
-		VssRay *ray = *rit;
-
-		// discontinuity found? 
-		// schedule for reverse sampling or adaptive border sampling
-		const bool gap = DiscontinuityFound(*ray, prevRay);
-		mRayQueue.push(GvsRayInfo(ray, gap));
-	}
-
-	return 9;
-}
-
-
-int GvsPreprocessor::ReverseSampling(const VssRay &ray)
+	
+	CastRays(simpleRays, vssRays);
+	// add to ray queue
+	EnqueueRays(vssRays);
+
+	return (int)vssRays.size();
+}
+
+
+int GvsPreprocessor::ReverseSampling(const VssRay &oldRay)
 {
 	cout << "r" << endl;
@@ -165,5 +149,5 @@
 	
 	// add to ray queue
-	EnqueueSamples(samples);
+	EnqueueRays(samples);
 
 	Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
@@ -173,5 +157,5 @@
 
 
-void GvsPreprocessor::EnqueueSamples(VssRayContainer &samples, VssRay *oldRay)
+void GvsPreprocessor::EnqueueRays(VssRayContainer &samples, VssRay *oldRay)
 {
 	// add samples to ray queue
@@ -183,5 +167,4 @@
 		mRayQueue.push(GvsRayInfo(*vit, gap));
 	}
-
 }
 
