Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env	(revision 2529)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/demo1.env	(revision 2586)
@@ -41,5 +41,6 @@
 #	totalSamples 2000000
 	samplesPerPass 500000
-	samplesPerEvaluation 5000000
+#	samplesPerEvaluation 5000000
+	samplesPerEvaluation 1000000
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena	(revision 2572)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena	(revision 2586)
@@ -8,12 +8,15 @@
 VIEWCELLS=../data/Arena/arena-high-lods-57000-viewcells.xml.gz
 
+#-rss_distributions=mutation+object_direction+spatial \
+#-preprocessor_stats=$PREFIX-i-mixed-b1-n4a.log \
+
 PREFIX=../work/plots/osp-TEST
 
 $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
--rss_distributions=mutation+object_direction+spatial \
+-rss_distributions=spatial \
 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \
 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \
 -preprocessor_ray_cast_method=1 \
--preprocessor_stats=$PREFIX-i-mixed-b1-n4a.log \
+-preprocessor_stats=$PREFIX-i-spatial-b1-n4a.log \
 -preprocessor_histogram_file=$PREFIX-i-mixed-b1-n4a.hlog \
 demo1.env
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2575)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2586)
@@ -127,6 +127,9 @@
 		int mContributingRays;
 		int mPvsContributions;
+		float mRayLengths;
+
 		void Reset() 
 		{
+			mRayLengths = 0.0f;
 			mRays = 0;
 			mViewCells = 0;
@@ -654,5 +657,5 @@
 protected:
 
-	void ComputeViewCellContribution(ViewCell *viewCell,
+	bool ComputeViewCellContribution(ViewCell *viewCell,
 									 VssRay &ray, 
 									 Intersectable *obj,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2583)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2586)
@@ -1230,6 +1230,6 @@
 	{
 
-	  mRayCaster->SortRays(rays);
-		cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl;
+	  //mRayCaster->SortRays(rays);
+	//	cout<<"Rays sorted in "<<TimeDiff(t1, GetTime())<<" ms."<<endl;
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2583)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2586)
@@ -37,4 +37,6 @@
 
 
+#define MYSTATS 1
+
 
 namespace GtpVisibilityPreprocessor {
@@ -113,5 +115,5 @@
 	mViewCellsTree->SetViewCellsManager(this);
 	mSamplesStat.Reset();
-	mStats.open("mystats.log");
+	//mStats.open("mystats.log");
 }
 
@@ -146,9 +148,9 @@
 	PrintPvsStatistics(mStats);
 	
-	mStats <<
+	/*mStats <<
 		"#Pass\n" << pass ++ <<endl<<
 		"#Time\n" << time <<endl<<
 		"#TotalSamples\n" << totalRays << endl;
-	
+	*/	
 
 	totalRays += samplesPerPass;
@@ -204,10 +206,9 @@
 	else
 	{
-		//mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
-
 		mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
 		mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
 		        
 		mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+		//mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
 	}
 		
@@ -2554,9 +2555,12 @@
   s<<"#RATIO\n"<<pvsStat.renderCost / (pvsStat.mem + Limits::Small)<<endl;
   s<<"#CONTRIBUTING_RAYS\n"<<mSamplesStat.mContributingRays<<endl;
-
+  
   if (mSamplesStat.mRays) {
 	s<<"#AVG_VIEWCELLS_PER_RAY\n"<<mSamplesStat.mViewCells/(float)mSamplesStat.mRays<<endl;
+    s<<"#AVG_RAY_LENGTHS\n"<<mSamplesStat.mRayLengths << endl;
+
   } else {
 	s<<"#AVG_VIEWCELLS_PER_RAY\n 1 \n";
+	s<<"#AVG_RAY_LENGTHS\n 1 \n";
   }
   mSamplesStat.Reset();
@@ -2718,5 +2722,5 @@
 
 
-void ViewCellsManager::ComputeViewCellContribution(ViewCell *viewCell,
+bool ViewCellsManager::ComputeViewCellContribution(ViewCell *viewCell,
 												   VssRay &ray, 
 												   Intersectable *obj,
@@ -2728,7 +2732,8 @@
 #if 0
 	if (!obj || !viewCell->GetValid())
-		return;
+		return false;
 #endif
 
+	bool hasContri = false;
 	// if ray not outside of view space
 	float relContribution = 0.0f;
@@ -2741,9 +2746,10 @@
 		hasAbsContribution = viewCell->GetPvs().AddSampleDirtyCheck(obj, ray.mPdf);
 		//hasAbsContribution = viewCell->GetPvs().AddSample(obj,ray.mPdf);
-#if 1
+#if MYSTATS
+		
 		if (hasAbsContribution)
 		{
 			UpdateStatsForViewCell(viewCell, obj);
-			mVizBuffer.AddRay(&ray);
+			hasContri = true;
 		}
 #endif
@@ -2755,4 +2761,6 @@
 			viewCell->GetPvs().GetSampleContribution(obj, ray.mPdf, relContribution);
 	}
+
+	//cout << "here6: " << ray.GetDir() << " ";
 
 	// $$ clear the relative contribution as it is currently not correct anyway
@@ -2787,4 +2795,6 @@
 		ray.mRelativePvsContribution = relContribution;
 #endif
+
+	return hasContri;
 }
 
@@ -2832,5 +2842,5 @@
 
 	terminationObj = ray.mTerminationObject;
-
+	//cout << "rayd: " << ray.GetDir() << " ";
 	ComputeViewCellContribution(currentViewCell, 
 								ray, 
@@ -2864,4 +2874,7 @@
 	++ mSamplesStat.mRays;
 
+#if MYSTATS
+	mSamplesStat.mRayLengths += ray.Length();
+#endif
 	if (!ray.mTerminationObject)
 		return 0.0f;
@@ -2907,4 +2920,5 @@
 	viewCellCastTimer.Exit();
 #endif
+
 	mSamplesStat.mViewCells += (int)viewCells.size();
 
@@ -2936,16 +2950,30 @@
 #endif
 	
+	bool contri = false;
 	ViewCellContainer::const_iterator it = viewCells.begin();
-
+//cout << "rayd: " << ray.GetDir() << " ";
 	for (; it != viewCells.end(); ++ it) 
 	{
-		ComputeViewCellContribution(*it, 
+		if (ComputeViewCellContribution(*it, 
 			                        ray, 
 									terminationObj, 
 									ray.mTermination, 
-									addRays);
+									addRays))
+		{
+			contri = true;
+		}	
+
 		(*it)->IncNumPiercingRays();
-	}
-
+		
+	}
+
+#if MYSTATS
+	if (contri)
+	{
+		if (rand() < (RAND_MAX / 10))
+			cout << "rayd: " /*<< ray.GetOrigin() << " " << ray.GetTermination() << " "*/ << Normalize(ray.GetDir()) << " " << endl;
+		mVizBuffer.AddRay(&ray);
+	}
+#endif
 #ifdef PERFTIMER  
 	pvsTimer.Exit();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2582)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2586)
@@ -211,6 +211,6 @@
 		const float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f;
 		
-		glColor3f(1.0f, 0.0f, 0.0f);
-		//glColor3f(importance, importance, importance);
+		//glColor3f(1.0f, 0.0f, 0.0f);
+		glColor3f(importance, importance, importance);
 		glVertex3fv(&ray->mOrigin.x);
 		glVertex3fv(&ray->mTermination.x);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp	(revision 2580)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/CombinedPreprocessor.cpp	(revision 2586)
@@ -90,8 +90,9 @@
 
 	cerr<<"Casting rays..."<<endl;
-	//	bool doubleRays = true;
+	
 	bool doubleRays = true;
 	CastRays(rays, vssRays, doubleRays, pruneInvalidRays);
 	mTotalRaysCast += (int)vssRays.size();
+
 	cerr<<"Done..."<<endl;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2582)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2586)
@@ -75,4 +75,5 @@
 				++ samples;
 				rays.push_back(ray);
+				//cout << "d " << ray.mDirection << " ";
 			}
 		}
@@ -228,10 +229,9 @@
 
 	direction = mPreprocessor.sceneBox.GetRandomPoint(Vector3(r[3],
-																	   r[4],
-																	   r[5])
-															   ) - origin;
+													  r[4],
+													  r[5])) - origin;
 	
 	const float c = Magnitude(direction);
-
+	
 	if (c <= Limits::Small) 
 		return false;
@@ -242,4 +242,6 @@
 	ray = SimpleRay(origin, direction, SPATIAL_BOX_BASED_DISTRIBUTION, pdf);
   
+	//cout << "d " << direction << " o: " << origin;
+	
 	return true;
 }
@@ -576,7 +578,12 @@
 	}
 
-	for(; it != vssRays.end(); ++it) {
+	for(; it != vssRays.end(); ++it) 
+	{
 		VssRay *ray = *it;
-		for (i=0; i < mDistributions.size()-1; i++) {
+
+		//cout << " here4 " << ray->GetDir();
+
+		for (i=0; i < mDistributions.size()-1; i++) 
+		{
 			if (mDistributions[i]->mType == ray->mDistribution)
 				break;
