Index: GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h	(revision 1932)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.h	(revision 1933)
@@ -44,5 +44,7 @@
 		@returns true if triangle intersects plane
 	*/
-	bool IntersectPlane(const Plane3 &plane, Vector3 &intersectA, Vector3 &intersectB) const;
+	bool GetPlaneIntersection(const Plane3 &plane, 
+							  Vector3 &intersectA, 
+							  Vector3 &intersectB) const;
 
 	///////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1923)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1933)
@@ -1023,5 +1023,5 @@
 
 		const bool noValidSplit = ((objectsLeft <= Limits::Small) || (objectsRight <= Limits::Small));
-		const float sum = noValidSplit ? 1e25 : objectsLeft * al + objectsRight * ar;
+		const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar;
       
 		/*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=(" 
@@ -1325,5 +1325,5 @@
 		// the heuristics
 	    const float sum = noValidSplit ? 
-			1e25 : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight;
+			1e25f : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight;
 
 #ifdef GTP_DEBUG
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1920)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1933)
@@ -824,14 +824,9 @@
 						 const bool onlyMailedRays) const;
 
-	/** Counts the view cells of this object. note: only
-		counts unmailed objects.
-	*/
-	int CountViewCells(Intersectable *obj) const;
-
-	/** Counts the view cells seen by this bvh leaf
-	*/
-	int CountViewCells(const ObjectContainer &objects) const;
-
 	/** Collects view cells which see an object.
+		@param useMailBoxing if mailing should be used and
+		only unmailed object should pass
+		@param setCounter counter for the sweep algorithm
+		@param onlyMailedRays if only mailed rays should be considered
 	*/
 	int CollectViewCells(Intersectable *object, 
@@ -840,4 +835,13 @@
 						 const bool setCounter,
 						 const bool onlyMailedRays) const;
+
+	/** Counts the view cells of this object. note: only
+		counts unmailed objects.
+	*/
+	int CountViewCells(Intersectable *obj) const;
+
+	/** Counts the view cells seen by this bvh leaf
+	*/
+	int CountViewCells(const ObjectContainer &objects) const;
 
 	/** Evaluates increase in pvs size.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp	(revision 1932)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Triangle3.cpp	(revision 1933)
@@ -186,7 +186,7 @@
 
 
-bool Triangle3::IntersectPlane(const Plane3 &plane, 
-							   Vector3 &intersectA, 
-							   Vector3 &intersectB) const
+bool Triangle3::GetPlaneIntersection(const Plane3 &plane, 
+									 Vector3 &intersectA, 
+									 Vector3 &intersectB) const
 {
 	int side[3];
@@ -215,5 +215,5 @@
 			intersectA = mVertices[i];
 			intersectB = mVertices[(i + 1) % 3];
-
+			
 			return true;
 		}
@@ -228,5 +228,6 @@
 
 		// intersection found
-		if ((side[i] >= 0) && (side[i_2] <= 0))
+		if ((side[i] >= 0) && (side[i_2] <= 0) ||
+			(side[i] <= 0) && (side[i_2] >= 0))
 		{	
 			const float t = plane.FindT(mVertices[i], mVertices[i_2]);
@@ -235,4 +236,5 @@
 			{
 				intersectA = mVertices[i] + t * (mVertices[i_2] - mVertices[i]);
+			
 				foundA = true;
 			}
@@ -240,4 +242,5 @@
 			{
 				intersectB = mVertices[i] + t * (mVertices[i_2] - mVertices[i]);
+			
 				return true;
 			}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1926)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1933)
@@ -343,5 +343,4 @@
 	{
 		cout << "executing main thread" << endl;
-
 		// just call the mail method -> will be executed in the main thread
 		pt->Main();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1932)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1933)
@@ -61,9 +61,17 @@
 	
 	// distance large => this is likely to be a discontinuity
+#if 1
 	if ((predictedLen - len) > mThreshold)
+#else // rather use relative distance
+	if ((predictedLen / len) > mThreshold)
+#endif
 	{
 		cout << "d";
+		// apply reverse sampling to find the gap
 		VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay);
-		
+
+		if (!newRay)
+			return false;
+
 		// set flag for visualization
 		newRay->mFlags |= VssRay::ReverseSample;
@@ -71,6 +79,14 @@
 		// if ray is not further processed => can delete ray
 		if (!HandleRay(newRay))
+		{
 			delete newRay;
-		
+		}
+		else if (mVssRays.size() < 3)
+		{
+			mVssRays.push_back(new VssRay(oldRay));
+			mVssRays.push_back(new VssRay(currentRay));
+			mVssRays.push_back(new VssRay(*newRay));
+		}
+
 		return true;
 	}
@@ -84,4 +100,5 @@
 	// compute the contribution to the view cells
 	const bool storeRaysForViz = true;
+
 	mViewCellsManager->ComputeSampleContribution(*vssRay, 
 												 true, 
@@ -317,5 +334,5 @@
 
 
-Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay,
+/*Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay,
 										 const Triangle3 &hitTriangle,
 										 const VssRay &oldRay) const
@@ -333,4 +350,51 @@
 
 	return newPoint;
+}*/
+
+
+Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay,
+										 const Triangle3 &occluder,
+										 const VssRay &oldRay) const
+{
+	//-- The plane p = (xp, hit(x), hit(xold)) is intersected
+	//-- with the newly found occluder (xold is the previous ray from
+	//-- which x was generated). On the intersecting line, we select a point
+	//-- pnew which lies just outside of the new triangle so the ray
+	//-- just passes through the gap
+
+	const Plane3 plane(currentRay.GetOrigin(), 
+					   currentRay.GetTermination(), 
+					   oldRay.GetTermination());
+	
+	Vector3 pt1, pt2;
+
+	const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2);
+
+	cout << "triangle: " << occluder << " pt1: " << pt1 << " pt2: " << pt2 << endl;
+	if (!intersects)
+		cerr << "big error!! no intersection" << endl;
+
+	// get the intersection point on the old ray
+	const Plane3 triPlane(occluder.GetNormal(), occluder.mVertices[0]);
+
+	const float t = triPlane.FindT(oldRay.mOrigin, oldRay.mTermination);
+	const Vector3 pt3 = oldRay.mOrigin + t * (oldRay.mTermination - oldRay.mOrigin);
+
+	// Evaluate new hitpoint just outside the triangle
+	Vector3 newPoint;
+
+	const float eps = mEps;
+	// the point is chosen to be on the side closer to the original ray
+	if (Distance(pt1, pt3) < Distance(pt2, pt3))
+	{
+		newPoint = pt1 + eps * (pt1 - pt2);
+	}	
+	else
+	{
+		newPoint = pt2 + eps * (pt2 - pt1);
+	}
+
+	cout << "passing point: " << newPoint << endl << endl;
+	return newPoint;
 }
 
@@ -340,23 +404,37 @@
 										 const VssRay &oldRay)
 {
-	//-- The plane p = (xp, hit(x), hit(xold)) is intersected
-	//-- with the newly found triangle (xold is the previous ray from
-	//-- which x was generated). On the intersecting line, we select a point
-	//-- pnew which lies just outside of the new triangle so the ray
-	//-- just passes by inside the gap
-    const Vector3 newPoint = GetPassingPoint(currentRay, hitTriangle, oldRay);
+	// get triangle occluding the path to the hit mesh
+	Triangle3 occluder;
+	Intersectable *tObj = currentRay.mTerminationObject;
+	// q: why can this happen?
+	if (!tObj)
+		return NULL;
+
+	// other types not implemented yet
+	if (tObj->Type() == Intersectable::TRIANGLE_INTERSECTABLE)
+		occluder = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem();
+	else
+		cout << "not yet implemented" << endl;
+	
+	// get a point which is passing just outside of the occluder
+    const Vector3 newPoint = GetPassingPoint(currentRay, occluder, oldRay);
 	const Vector3 predicted = CalcPredictedHitPoint(currentRay, hitTriangle, oldRay);
 
 	//-- Construct the mutated ray with xnew,
 	//-- dir = predicted(x)- pnew as direction vector
-	const Vector3 newDir = predicted - newPoint ;
-
-	// take xnew,p = intersect(viewcell, line(pnew, predicted(x)) as origin ?
+	const Vector3 newDir = predicted - newPoint;
+
+	// take xnew, p = intersect(viewcell, line(pnew, predicted(x)) as origin ?
 	// difficult to say!!
-	const Vector3 newOrigin = newDir * -5000.0f;
-
-	++ mReverseSamples;
-
-	return new VssRay(currentRay);
+	const Vector3 newOrigin = newPoint + newDir * -5000.0f;
+
+	const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f);
+
+	VssRay *reverseRay = 
+		mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox());
+
+    ++ mReverseSamples;
+
+	return reverseRay;
 }
 
@@ -533,5 +611,39 @@
 	}
 
-	exporter->ExportRays(mVssRays);
+	VssRayContainer::const_iterator rit, rit_end = mVssRays.end();
+	for (rit = mVssRays.begin(); rit != rit_end; ++ rit)
+	{
+		Intersectable *obj = (*rit)->mTerminationObject;
+		exporter->ExportIntersectable(obj);
+	}
+
+	VssRayContainer vcRays, vcRays2, vcRays3;
+
+	// prepare some rays for output
+	for (rit = mVssRays.begin(); rit != rit_end; ++ rit)
+	{
+		const float p = RandomValue(0.0f, (float)mVssRays.size());
+		if (1)//(p < raysOut)
+		{
+			if ((*rit)->mFlags & VssRay::BorderSample)
+			{
+				vcRays.push_back(*rit);
+			}
+			else if ((*rit)->mFlags & VssRay::ReverseSample)
+			{
+				vcRays2.push_back(*rit);
+			}
+			else
+			{
+				vcRays3.push_back(*rit);
+			}	
+		}
+	}
+
+	exporter->ExportRays(vcRays, RgbColor(1, 0, 0));
+	exporter->ExportRays(vcRays2, RgbColor(0, 1, 0));
+	exporter->ExportRays(vcRays3, RgbColor(1, 1, 1));
+
+	//exporter->ExportRays(mVssRays);
 	delete exporter;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1920)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1933)
@@ -1069,6 +1069,4 @@
 												   const ObjectContainer &objects)
 {	
-	SubdivisionCandidate *firstCandidate;
-
 	// object space partition constructed => reconstruct
 	switch (mObjectSpaceSubdivisionType)
@@ -2146,5 +2144,5 @@
 		char str[100];
 		char statsPrefix[100];
-		int histoStepSize;
+		//int histoStepSize;
 
 		Environment::GetSingleton()->GetStringValue("ViewCells.Evaluation.statsPrefix", statsPrefix);
@@ -2213,6 +2211,6 @@
 		bool isLeaf;
 		int timeStamp;
-		float rcDecr; 
-		int entriesIncr; 
+		//float rcDecr; 
+		//int entriesIncr; 
 
 		if (nextCandidate->Type() == SubdivisionCandidate::VIEW_SPACE)
