Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1932)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1934)
@@ -13,4 +13,46 @@
 class VssRay;
 
+/** View space partition statistics.
+*/
+class GvsStatistics: public StatisticsBase
+{
+public:
+	
+	/// Constructor
+	GvsStatistics() 
+	{
+		Reset();
+	}
+	
+	void Reset() 
+	{
+		mPass = 0;
+		mTotalSamples = 0;
+		mPassContribution = 0;
+		mTotalContribution = 0;
+		mReverseSamples = 0;
+		mBorderSamples = 0;
+		mGvsPass = 0;
+	}
+
+
+public:
+
+	int mPass;
+	int mTotalSamples;
+	int mPassContribution;
+	int mTotalContribution;
+	int mReverseSamples;
+	int mBorderSamples;
+	int mGvsPass;
+		
+	void Print(ostream &app) const;
+
+	friend ostream &operator<<(ostream &s, const GvsStatistics &stat) 
+	{
+		stat.Print(s);
+		return s;
+	} 
+};
 
 
@@ -148,11 +190,14 @@
 	// stats
 
-	int mSampleContriPerPass;
+	/*int mSampleContriPerPass;
 	int mTotalSampleContri;
 	int mReverseSamples;
 	int mBorderSamples;
-	int mGvsPass;
-
-	ofstream mGvsStats;
+	int mGvsPass;*/
+
+	ofstream mGvsStatsStream;
+	GvsStatistics mGvsStats;
+
+	bool mOnlyRandomSampling;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1923)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1934)
@@ -1277,5 +1277,8 @@
 		 "1.5");
 
-
+	RegisterOption("GvsPreprocessor.stats",
+					optString,
+					"gvs_stats=",
+					"gvsStats.log");
 
   /***********************************************************************************/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1933)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1934)
@@ -274,6 +274,5 @@
 	Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.minObjects", mTermMinObjects);
 	Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.minRays", mTermMinRays);
-	Environment::GetSingleton()->GetFloatValue(
-		"BvHierarchy.Termination.minProbability", mTermMinProbability);
+	Environment::GetSingleton()->GetFloatValue("BvHierarchy.Termination.minProbability", mTermMinProbability);
     Environment::GetSingleton()->GetIntValue("BvHierarchy.Termination.missTolerance", mTermMissTolerance);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1933)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1934)
@@ -15,4 +15,6 @@
 {
   
+#define GVS_DEBUG 0
+
 struct VizStruct
 {
@@ -27,9 +29,5 @@
 Preprocessor(), 
 //mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION),
-mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION),
-mSampleContriPerPass(0), 
-mTotalSampleContri(0),
-mReverseSamples(0), 
-mBorderSamples(0)
+mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION)
 {
 	Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples);
@@ -39,4 +37,8 @@
 	Environment::GetSingleton()->GetFloatValue("GvsPreprocessor.threshold", mThreshold);	
 
+	char gvsStatsLog[100];
+	Environment::GetSingleton()->GetStringValue("GvsPreprocessor.stats", gvsStatsLog);
+	mGvsStatsStream.open(gvsStatsLog);
+
 	Debug << "Gvs preprocessor options" << endl;
 	Debug << "number of total samples: " << mTotalSamples << endl;
@@ -44,7 +46,14 @@
 	Debug << "number of samples per pass: " << mSamplesPerPass << endl;
 	Debug << "threshold: " << mThreshold << endl;
-	Debug << "eps: " << mEps << endl;
-
-	mGvsStats.open("gvspreprocessor.log");
+	Debug << "epsilon: " << mEps << endl;
+	Debug << "stats: " << gvsStatsLog << endl;
+
+	if (0)
+		mOnlyRandomSampling = true;
+	else
+		mOnlyRandomSampling = false;
+
+	//mGvsStatsStream.open("gvspreprocessor.log");
+	mGvsStats.Reset();
 }
 
@@ -67,5 +76,5 @@
 #endif
 	{
-		cout << "d";
+		//cout << "r";
 		// apply reverse sampling to find the gap
 		VssRay *newRay = ReverseSampling(currentRay, hitTriangle, oldRay);
@@ -82,5 +91,5 @@
 			delete newRay;
 		}
-		else if (mVssRays.size() < 3)
+		else if (GVS_DEBUG && (mVssRays.size() < 9))
 		{
 			mVssRays.push_back(new VssRay(oldRay));
@@ -99,5 +108,5 @@
 {
 	// compute the contribution to the view cells
-	const bool storeRaysForViz = true;
+	const bool storeRaysForViz = GVS_DEBUG;
 
 	mViewCellsManager->ComputeSampleContribution(*vssRay, 
@@ -124,6 +133,5 @@
 		}
 
-		//mVssRays.push_back(new VssRay(*vssRay));
-        ++ mSampleContriPerPass;
+        ++ mGvsStats.mPassContribution;
 
 		return true;
@@ -328,5 +336,5 @@
 	}
 
-	mBorderSamples += castRays;
+	mGvsStats.mBorderSamples += castRays;
 
 	return castRays;
@@ -371,5 +379,4 @@
 	const bool intersects = occluder.GetPlaneIntersection(plane, pt1, pt2);
 
-	cout << "triangle: " << occluder << " pt1: " << pt1 << " pt2: " << pt2 << endl;
 	if (!intersects)
 		cerr << "big error!! no intersection" << endl;
@@ -395,5 +402,5 @@
 	}
 
-	cout << "passing point: " << newPoint << endl << endl;
+	//cout << "passing point: " << newPoint << endl << endl;
 	return newPoint;
 }
@@ -407,4 +414,5 @@
 	Triangle3 occluder;
 	Intersectable *tObj = currentRay.mTerminationObject;
+
 	// q: why can this happen?
 	if (!tObj)
@@ -434,5 +442,5 @@
 		mRayCaster->CastRay(simpleRay, mViewCellsManager->GetViewSpaceBox());
 
-    ++ mReverseSamples;
+    ++ mGvsStats.mReverseSamples;
 
 	return reverseRay;
@@ -475,5 +483,5 @@
 	// reset samples
 	int castSamples = 0;
-	mSampleContriPerPass = 0;
+	mGvsStats.mPassContribution = 0;
 
 	while (castSamples < mSamplesPerPass) 
@@ -482,9 +490,10 @@
 		// cast a number of uniform samples to fill ray queue
 		castSamples += CastInitialSamples(mInitialSamples, mSamplingType);
-		castSamples += ProcessQueue();
-		//cout << "\ncast " << castSamples << " samples in a processing pass" << endl;
-	}
-
-	mTotalSampleContri += mSampleContriPerPass;
+
+		if (!mOnlyRandomSampling)
+			castSamples += ProcessQueue();
+	}
+
+	mGvsStats.mTotalContribution += mGvsStats.mPassContribution;
 	return castSamples;
 }
@@ -494,5 +503,5 @@
 {
 	int castSamples = 0;
-	++ mGvsPass;
+	++ mGvsStats.mGvsPass;
 
 	while (!mRayQueue.empty()) 
@@ -517,12 +526,6 @@
 	Randomize(0);
 	
-	mPass = 0;
-	mGvsPass = 0;
-	mSampleContriPerPass = 0; 
-	mTotalSampleContri = 0;
-	mReverseSamples = 0;
-	mBorderSamples = 0;
-
-	int castSamples = 0;
+	mGvsStats.Reset();
+	mGvsStats.Start();
 
 	if (!mLoadViewCells)
@@ -542,50 +545,59 @@
 	}
 
-	while (castSamples < mTotalSamples) 
-	{
-		castSamples += Pass();
+	mGvsStats.Stop();
+	mGvsStats.Print(mGvsStatsStream);
+
+	while (mGvsStats.mTotalSamples < mTotalSamples) 
+	{
+		++ mPass;
+
+		mGvsStats.mTotalSamples += Pass();
 				
 		////////
 		//-- stats
 
-		cout << "\nPass " << mPass << " #samples: " << castSamples << " of " << mTotalSamples << endl;
-		//mVssRays.PrintStatistics(mGvsStats);
-		mGvsStats 
-			<< "#Pass\n" << mPass << endl
-			<< "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl
-			<< "#TotalSamples\n" << castSamples << endl
-			<< "#ScDiff\n" << mSampleContriPerPass << endl
-			<< "#SamplesContri\n" << mTotalSampleContri << endl
-			<< "#ReverseSamples\n" << mReverseSamples << endl
-			<< "#BorderSamples\n" << mBorderSamples << endl			
-			<< "#GvsRuns\n" << mGvsPass << endl;
-
-		mViewCellsManager->PrintPvsStatistics(mGvsStats);
-
-		char str[64]; sprintf(str, "tmp/pass%04d-", mPass);
+		cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl;
+		mGvsStats.mPass = mPass;
+		mGvsStats.Stop();
+		mGvsStats.Print(mGvsStatsStream);
+		//mViewCellsManager->PrintPvsStatistics(mGvsStats);
+
+		if (GVS_DEBUG)
+		{
+			char str[64]; sprintf(str, "tmp/pass%04d-", mPass);
 		
-        // visualization
-		if (mSampleContriPerPass > 0)
-		{
-			const bool exportRays = true;
-			const bool exportPvs = true;
-
-			mViewCellsManager->ExportSingleViewCells(mObjects, 10, false, exportPvs, exportRays, 1000, str);
+			// visualization
+			if (mGvsStats.mPassContribution > 0)
+			{
+				const bool exportRays = true;
+				const bool exportPvs = true;
+
+				mViewCellsManager->ExportSingleViewCells(mObjects, 
+														 10, 
+														 false, 
+														 exportPvs, 
+														 exportRays, 
+														 1000, 
+														 str);
+			}
+
+			// remove pass samples
+			ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
+			for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
+			{
+				(*vit)->DelRayRefs();
+			}
 		}
 
-		// remove pass samples
-		ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
-		for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
-		{
-			(*vit)->DelRayRefs();
-		}
-
-		//CLEAR_CONTAINER(mVssRays);
 		// ComputeRenderError();
-		++ mPass;
-	}
-
-	cout << "cast " << 2 * castSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl;
-	Visualize();
+	}
+
+	cout << "cast " << 2 * mGvsStats.mTotalSamples / (1e3f * TimeDiff(startTime, GetTime())) << "M rays/s" << endl;
+
+	if (GVS_DEBUG)
+	{
+		Visualize();
+		CLEAR_CONTAINER(mVssRays);
+	}
 
 	return true;
@@ -649,3 +661,17 @@
 }
 
-}
+
+void GvsStatistics::Print(ostream &app) const
+{
+	app << "#Pass\n" << mPass << endl;
+	app << "#Time\n" << Time() << endl;
+	app << "#TotalSamples\n" << mTotalSamples << endl;
+	app << "#ScDiff\n" << mPassContribution << endl;
+	app	<< "#SamplesContri\n" << mTotalContribution << endl;
+	app << "#ReverseSamples\n" << mReverseSamples << endl;
+	app << "#BorderSamples\n" << mBorderSamples << endl;		
+	app << "#GvsRuns\n" << mGvsPass << endl;
+}
+
+
+}
