Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1528)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1533)
@@ -129,6 +129,8 @@
 	float mThreshold;
 	VssRayContainer mVssRays;
-	int mCastPassSamples;
-	int mCastTotalSamples;
+	int mSampleContriPerPass;
+	int mTotalSampleContri;
+	int mReverseSamples;
+	int mBorderSamples;
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 1528)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 1533)
@@ -43,5 +43,5 @@
 	int hits = 0;
 	int hittriangle;
-	Intersection hitA, hitB;
+	Intersection hitA(simpleRay.mOrigin), hitB(simpleRay.mOrigin);
 
 	float dist;
@@ -159,5 +159,5 @@
 	for (i=0; i < num; i++) 
 	{
-		Intersection hitA, hitB;
+		Intersection hitA(rays[i].mOrigin), hitB(rays[i].mOrigin);
 		
 		if (forward_hit_triangles[i] != -1 ) {
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1528)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1533)
@@ -23,5 +23,7 @@
 static vector<VizStruct> vizContainer;
 
-GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0), mCastPassSamples(0), mCastTotalSamples(0)
+GvsPreprocessor::GvsPreprocessor(): 
+Preprocessor(), mSamplingType(0), mSampleContriPerPass(0), mTotalSampleContri(0),
+mReverseSamples(0), mBorderSamples(0)
 {
 	Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples);
@@ -75,11 +77,10 @@
 	if (vssRay->mPvsContribution > 0)
 	{
-		cout << " h " << mCastPassSamples << " " << mSamplesPerPass << " " << mTotalSamples << " q: " << mRayQueue.size() << endl;
-		
-		cout << "error!!! " << vssRay->mPvsContribution << " " << vssRay->mTerminationObject << endl;
-
+		//cout << " h " << mSampleContriPerPass << " " << mSamplesPerPass << " " << mTotalSamples << endl;
 		mRayQueue.push(vssRay);
 		mVssRays.push_back(new VssRay(*vssRay));
-		++ mCastPassSamples;
+        
+		++ mSampleContriPerPass;
+
 		return true;
 	}
@@ -104,5 +105,5 @@
 	const Vector3 c = hitTriangle.mVertices[index] - hitTriangle.mVertices[indexL];
 	
-	const float len = 1;//Magnitude(a);
+	const float len = Magnitude(a);
 
 	const Vector3 dir1 = Normalize(CrossProd(a, b)); //N((pi-xp)×(pi+1- pi));
@@ -170,8 +171,9 @@
 	if (EqualVisibility(x, y))
 	{
-		return 2;
+		return 0;
 	}
 	else
 	{
+		cout << "s";
 		const Vector3 p = (p1 + p2) * 0.5f;
 		SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin);
@@ -179,13 +181,16 @@
 		VssRay *newRay = mRayCaster->CastSingleRay(sray, mViewSpaceBox);
 
-		if (!newRay) return 0;
+		if (!newRay) 
+			return 0;
+
 		const bool enqueued = HandleRay(newRay);
 		
 		const int s1 = SubdivideEdge(hitTriangle, p1, p, x, *newRay, oldRay);
 		const int s2 = SubdivideEdge(hitTriangle, p, p2, *newRay, y, oldRay);
-		return s1 + s2;
-		
+				
 		if (!enqueued)
 			delete newRay;
+		
+		return s1 + s2 + 1;
 	}
 }
@@ -224,7 +229,4 @@
 		SimpleRay sr(currentRay.GetOrigin(), rayDir);
 		simpleRays.AddRay(sr);
-
-		//cout << "here244 " << (*vit) << " " << currentRay.GetOrigin() << endl;
-		//cout << " sr" << sr.mOrigin << sr.mDirection << endl;
 	}
 
@@ -238,16 +240,15 @@
 	VssRayContainer vssRays;
 	CastRays(simpleRays, vssRays, false, false);
-	//CastRays(simpleRays, vssRays, true, true);
-	//cout << "here211 " << simpleRays.size() << " " << vssRays.size() << endl;
+
 	// add to ray queue
 	EnqueueRays(vssRays);
 	
 	const int n = (int)enlargedTriangle.size();
-	
-#if 0
+	int castRays = (int)vssRays.size();
+#if 1
     // recursivly subdivide each edge
 	for (int i = 0; i < n; ++ i)
 	{
-		SubdivideEdge(
+		castRays += SubdivideEdge(
 			hitTriangle,
 			enlargedTriangle[i], 
@@ -258,11 +259,13 @@
 	}
 #endif
-	return (int)vssRays.size();
+
+	mBorderSamples = castRays;
+	return castRays;
 }
 
 
 static Vector3 GetPassingPoint(const VssRay &currentRay,
-										 const Triangle3 &hitTriangle,
-										 const VssRay &oldRay)
+							   const Triangle3 &hitTriangle,
+							   const VssRay &oldRay)
 {
 	// intersect triangle plane with plane spanned by current samples
@@ -275,5 +278,4 @@
 	const float factor = 0.95f;
 	float t = triPlane.FindT(intersectLine);
-
 	const Vector3 newPoint = intersectLine.mOrigin + t * factor * intersectLine.mDirection;
 
@@ -286,5 +288,7 @@
 										 const VssRay &oldRay)
 {
-	cout << "r" << endl;
+	cout << "r";
+	++ mReverseSamples;
+
 	//-- The plane p = (xp, hit(x), hit(xold)) is intersected
 	//-- with the newly found triangle (xold is the previous ray from
@@ -315,7 +319,4 @@
 	GenerateRays(numSamples, sampleType, simpleRays);
 
-	//cout << "here909 " << simpleRays.size() << endl;
-	//for (int i = 0; i < simpleRays.size(); ++ i)
-	//	cout << "here544 " << simpleRays[i].mOrigin << endl;
 	// generate vss rays
 	VssRayContainer samples;
@@ -324,6 +325,5 @@
 	// add to ray queue
 	EnqueueRays(samples);
-//for (int i = 0; i < samples.size(); ++ i)
-//		cout << "here1544 " << samples[i]->mOrigin << endl;
+
 	Debug << "generated " <<  numSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
@@ -348,19 +348,19 @@
 	const int mSampleType = 0;
 	// reset samples
-	mCastPassSamples = 0;
-	
-	while (mCastPassSamples < mSamplesPerPass) 
+	int castSamples = 0;
+	mSampleContriPerPass = 0;
+	
+	while (castSamples < mSamplesPerPass) 
 	{	
 		// Ray queue empty => 
 		// cast a number of uniform samples to fill ray Queue
-		CastInitialSamples(mInitialSamples, mSampleType);
-		ProcessQueue();
-
-		cout << "\nround finished, cast " << mCastPassSamples << " of " << mSamplesPerPass << endl;
-	}
-
-	mCastTotalSamples += mCastPassSamples;
-
-	return mCastPassSamples;
+		castSamples += CastInitialSamples(mInitialSamples, mSampleType);
+		castSamples += ProcessQueue();
+		cout << "\ncast " << castSamples << " samples in a processing pass" << endl;
+	}
+
+	mTotalSampleContri += mSampleContriPerPass;
+
+	return castSamples;
 }
 
@@ -377,4 +377,5 @@
 	
 		castSamples += AdaptiveBorderSampling(*ray);
+		
 		delete ray;
 	}
@@ -386,9 +387,10 @@
 bool GvsPreprocessor::ComputeVisibility()
 {
+	cout << "Gvs Preprocessor started\n" << flush;
+
 	Randomize(0);
 	const long startTime = GetTime();
-	
+	int castSamples = 0;
 	mViewSpaceBox = mKdTree->GetBox();
-	cout << "Gvs Preprocessor started\n" << flush;
 	
 	if (!mLoadViewCells)
@@ -398,15 +400,20 @@
 	}
 
-	while (mCastTotalSamples < mTotalSamples) 
-	{
-		Pass();
+	while (castSamples < mTotalSamples) 
+	{
+		castSamples += Pass();
 				
 		////////
 		//-- stats
-		cout << "+";
-		cout << "\nsamples cast " << mCastPassSamples << " (=" << mCastTotalSamples << " of " << mTotalSamples << ")" << endl;
+		//cout << "+";
+		cout << "\nsamples cast: " << castSamples << " of " << mTotalSamples << endl;
+
 		//mVssRays.PrintStatistics(mStats);
 		mStats << "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl
-			   << "#TotalSamples\n" << mCastTotalSamples << endl;
+			   << "#TotalSamples\n" << castSamples << endl
+			   << "#ContributingSamples\n" << mTotalSampleContri << endl
+			   << "#Reverse samples\n" << mReverseSamples << endl
+			   << "#Border samples\n" << mBorderSamples << endl;
+				
 
 		mViewCellsManager->PrintPvsStatistics(mStats);
