Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2534)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_vienna	(revision 2571)
@@ -19,7 +19,8 @@
 #PREFIX=../work/plots/atlanta2-rss9
 
+#-rss_distributions=mutation+object_direction+spatial \
 
 $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
--rss_distributions=mutation+object_direction+spatial \
+-rss_distributions=object_direction \
 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \
 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena	(revision 2567)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena	(revision 2571)
@@ -13,5 +13,5 @@
 
 $COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
--rss_distributions=spatial \
+-rss_distributions=mutation+object_direction+spatial \
 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ \
 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2570)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2571)
@@ -79,4 +79,34 @@
 typedef pair<ViewCell *, SimpleRayContainer> ViewCellPoints;
 
+struct VizBuffer
+{
+	VizBuffer(): mIndex(0), mMaxSize(10000)
+	{
+	}
+
+	int GetSize() const {return (int)mVizRays.size();}
+
+	void AddRay(VssRay *ray)
+	{
+		if (mVizRays.size() < mMaxSize)
+			mVizRays.push_back(ray);
+		else
+			mVizRays[mIndex] = ray;
+		
+		mIndex = (mIndex + 1) % mMaxSize;
+	}
+
+	VssRayContainer &GetRays() { return mVizRays;}
+
+	VssRay *GetRay(int i) { return mVizRays[i % 100];}
+
+protected:
+
+	const int mMaxSize;
+	int mIndex;
+	VssRayContainer mVizRays;
+};
+
+
 /**	Manages different higher order operations on the view cells.
 */
@@ -600,9 +630,11 @@
 	void ResetPvs();
 
-	Preprocessor *GetPreprocessor() const {
+	Preprocessor *GetPreprocessor() const 
+	{
 		return mPreprocessor;
 	}
 
-	void SetPreprocessor(Preprocessor *p) {
+	void SetPreprocessor(Preprocessor *p) 
+	{
 		mPreprocessor = p;
 	}
@@ -614,4 +646,8 @@
 
 	void UpdatePvsForEvaluation();
+
+
+	VizBuffer mVizBuffer;
+
 
 protected:
@@ -810,4 +846,5 @@
 
 
+
 	//////////////////
 	//-- visualization options
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2559)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2571)
@@ -17,5 +17,4 @@
 class SimpleRayContainer;
 class AxisAlignedBox3;
-//class Vector3;
 struct VssRayContainer;
 class Preprocessor;
@@ -107,5 +106,7 @@
 			return mRays + mIndex ++;
 		}
+
 	protected:
+
 		VssRay *mRays;
 		int mIndex;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2570)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2571)
@@ -303,5 +303,4 @@
 	glEnable(GL_LIGHT1);
 
-
 	// set position of the light
 	GLfloat infinite_light[] = {  1.0, 0.8, 1.0, 0.0  };
@@ -313,8 +312,8 @@
 
 	glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
-	//   glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
+	// glColorMaterial( GL_FRONT_AND_BACK, GL_SPECULAR);
 	glEnable(GL_COLOR_MATERIAL);
 
-	glShadeModel( GL_FLAT );
+	glShadeModel(GL_FLAT);
 }
 
@@ -712,4 +711,9 @@
 			glColor3f(0.6f, 0.6f, 0.6f);
 			RenderPvs();
+		}
+
+		if (1 && mShowRays) 
+		{
+			RenderRays(mViewCellsManager->mVizBuffer.GetRays());
 		}
 	}
@@ -1151,6 +1155,7 @@
 	if (mViewCellsManager) 
 	{
+		const float f = number / 1000.0f;
 		AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
-		Vector3 p = box.Min() + (number/1000.0f)*box.Max();
+		Vector3 p = (1.0f - f) * box.Min() + f * box.Max();
 		mSceneCutPlane.mNormal = Vector3(0,-1,0);
 		mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p);
@@ -1278,5 +1283,5 @@
 		ViewCell *vc = viewcells[i];
 
-		if (mShowPvsSizes) // pv
+		if (mShowPvsSizes) // pvs size
 		{
 			//const int p = vc->GetPvs().CountObjectsInPvs();
@@ -1336,7 +1341,6 @@
 	{
 		//glDisable(GL_CULL_FACE);
-		//glEnable(GL_CULL_FACE);
-		//glFrontFace(GL_CCW);	
 		//glCullFace(GL_BACK);
+
 		if (!mUseTransparency)
 		{
@@ -1346,6 +1350,4 @@
 		else
 		{
-			//glCullFace(GL_BACK);
-			//cout << "here29 " << mTransparency << endl;
 			glDisable(GL_DEPTH_TEST);
 			glEnable(GL_BLEND);
@@ -1410,4 +1412,9 @@
 		glEnable(GL_DEPTH_TEST);	
 	}
+	
+	glEnable(GL_CULL_FACE);
+	glDisable(GL_CULL_FACE);
+
+	glDisable(GL_CLIP_PLANE0);
 
 	mUseFalseColors = false;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2569)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2571)
@@ -16,4 +16,5 @@
 #include "RssPreprocessor.h"
 #include "SceneGraph.h"
+#include "ViewCellsManager.h"
 
 
@@ -50,24 +51,63 @@
   
 // This method has to be rendefined by all renderer implementations
-void
-QtGlViewer::RenderScene()
-{
+void QtGlViewer::RenderScene()
+{
+	GLfloat mat_ambient[] = {0.1, 0.1, 0.1, 1.0};
+
+	// mat_specular and mat_shininess are NOT default values
+	GLfloat mat_diffuse[] = {0.5, 1.0, 0.5, 1.0};
+	GLfloat mat_specular[] = {0.3, 0.3, 0.3, 1.0};
+	GLfloat mat_shininess[] = {1.0};
+
+	GLfloat light_ambient[] = {0.1, 0.1, 0.1, 1.0};
+	GLfloat light_diffuse[] = {0.5, 0.5, 0.5, 1.0};
+	GLfloat light_specular[] = {0.0, 0.0, 0.0, 1.0};
+
+	GLfloat lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0};
+
+
+	// default material
+	/*glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
+	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
+	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
+	glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
+*/
+	// a light
+	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+	glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+	glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
+	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
+
+	
+	//GLfloat infinite_light2[] = {-0.3, 1.5f, 1.0f, 0.0f};
+	//glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
+	glColor3f(0.8f, 0.8f, 0.8f);
+	
+	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+	glDisable(GL_COLOR_MATERIAL);
+	//glEnable(GL_COLOR_MATERIAL);
+
 	++ mRenderer->mFrame;
 	
-	//glDisable(GL_DEPTH_TEST);
+	glEnable(GL_DEPTH_TEST);
+	glDepthMask(GL_TRUE);
+
+	glCullFace(GL_BACK);
+	glShadeModel(GL_FLAT);
+
+	glDisable(GL_BLEND);
 
 	mRenderer->mDummyViewPoint = mDummyViewPoint;
-	glColor3f(0.8f, 0.8f, 0.8f);
+	
+	//glEnable(GL_LIGHTING);
+
 	mRenderer->RenderPvs();
 	
-// 	if (mRenderer->mShowRays) {
-// 	  RssPreprocessor *p = (RssPreprocessor *)
-// 			mRenderer->mViewCellsManager->GetPreprocessor();
-// 	  if (p->mRssTree) {
-// 			VssRayContainer rays;
-// 			p->mRssTree->CollectRays(rays, 10000);
-// 			mRenderer->RenderRays(rays);
-// 	  }
-// 	}
+	glDisable(GL_LIGHTING);
+
+ 	if (0 && mRenderer->mShowRays) 
+	{
+ 		mRenderer->RenderRays(mRenderer->mViewCellsManager->mVizBuffer.GetRays());
+ 	}
 
 	if (mRenderer->mShowRenderCost) 
@@ -101,4 +141,12 @@
         << "Info: GL Extensions = "<<extString<<endl<<flush;
 
+
+	glEnable(GL_LIGHTING);
+	glEnable(GL_LIGHT0);
+	//glEnable(GL_LIGHT1);
+
+	// set position of the light
+	GLfloat infinite_light[] = {0, -1.0, 0, 1.0f};
+	glLightfv(GL_LIGHT0, GL_POSITION, infinite_light);
 
   return;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2570)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2571)
@@ -2671,31 +2671,34 @@
 void ViewCellsManager::UpdateStatsForViewCell(ViewCell *vc, Intersectable *obj)
 {
-		KdIntersectable *kdObj = static_cast<KdIntersectable *>(obj);
-
-        const AxisAlignedBox3 box = kdObj->GetBox();
-		const float dist = SqrDistance(vc->GetBox().Center(), box.Center());
-
-		float f;
-
-		const float radius = mViewSpaceBox.Radius();
-		const float fullRadius = mViewSpaceBox.Radius();
-
-		const float minVal = 0.1f;
-		const float maxVal = 1.0f;
-
-		if (dist <= radius) 
-			f = maxVal;
-		else if (dist >= fullRadius)
-			f = minVal;
-		else // linear blending
-		{
-			f = minVal * (dist - radius) + maxVal * (fullRadius - radius - dist);
-		}
-
-		const int numTriangles = kdObj->ComputeNumTriangles();
-
-		vc->GetPvs().mStats.mDistanceWeightedTriangles += f * numTriangles; 
-		vc->GetPvs().mStats.mDistanceWeightedPvs += f;
-		vc->GetPvs().mStats.mWeightedTriangles += numTriangles;
+	KdIntersectable *kdObj = static_cast<KdIntersectable *>(obj);
+
+	const AxisAlignedBox3 box = kdObj->GetBox();
+	const float dist = Distance(vc->GetBox().Center(), box.Center());
+
+	float f;
+
+	const float radius = box.Radius();
+	const float fullRadius = max(0.2f * mViewSpaceBox.Radius(), radius);
+
+	const float minVal = 0.01f;
+	const float maxVal = 1.0f;
+
+	if (dist <= radius) 
+		f = maxVal;
+	else if (dist >= fullRadius)
+		f = minVal;
+	else // linear blending
+	{
+		f = minVal * (dist - radius) / (fullRadius - radius) + 
+			maxVal * (fullRadius - radius - dist) / (fullRadius - radius);
+	}
+
+	//cout << "x " << radius << " " << dist << " " << fullRadius << " " << f << " " << f * f << endl;
+
+	const int numTriangles = kdObj->ComputeNumTriangles();
+
+	vc->GetPvs().mStats.mDistanceWeightedTriangles += f * numTriangles; 
+	vc->GetPvs().mStats.mDistanceWeightedPvs += f ;
+	vc->GetPvs().mStats.mWeightedTriangles += numTriangles;
 }
 
@@ -2725,5 +2728,9 @@
 		//hasAbsContribution = viewCell->GetPvs().AddSample(obj,ray.mPdf);
 #if 1
-		UpdateStatsForViewCell(viewCell, obj);
+		if (hasAbsContribution)
+		{
+			UpdateStatsForViewCell(viewCell, obj);
+			mVizBuffer.AddRay(&ray);
+		}
 #endif
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2564)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2571)
@@ -211,5 +211,6 @@
 		const float importance = log10(1e3*ray->mWeightedPvsContribution)/3.0f;
 		
-		glColor3f(importance, importance, importance);
+		glColor3f(1.0f, 0.0f, 0.0f);
+		//glColor3f(importance, importance, importance);
 		glVertex3fv(&ray->mOrigin.x);
 		glVertex3fv(&ray->mTermination.x);
@@ -1455,31 +1456,31 @@
 	  
 	  if (mPvsErrorBuffer[i].mError > 0.0f) 
-		{
+	  {
 		  int pvsSize;
-		  
+
 		  // compute the pixel error
 		  float error = GetPixelError(pvsSize);
-		  
+
 		  mPvsErrorBuffer[i].mError = error;
 		  mPvsErrorBuffer[i].mPvsSize = pvsSize;
-		  
+
 		  cout << "(" << i << "," << mPvsErrorBuffer[i].mError <<")";
-		}
-	  
+	  }
+
 	  err = mPvsErrorBuffer[i].mError;
-	  
+
 	  if (err >= 0.0f) 
-		{
+	  {
 		  if (err > mPvsStat.maxError)
-			mPvsStat.maxError = err;
-		  
+			  mPvsStat.maxError = err;
+
 		  mPvsStat.sumError += err;
-			mPvsStat.sumPvsSize += mPvsErrorBuffer[i].mPvsSize;
-			
-			if (err == 0.0f)
+		  mPvsStat.sumPvsSize += mPvsErrorBuffer[i].mPvsSize;
+
+		  if (err == 0.0f)
 			  ++ mPvsStat.errorFreeFrames;
-			
-			++ mPvsStat.frames;
-		}
+
+		  ++ mPvsStat.frames;
+	  }
 	}
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp	(revision 2570)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.cpp	(revision 2571)
@@ -132,5 +132,5 @@
 
 KdIntersectable::KdIntersectable(KdNode *item, const AxisAlignedBox3 &box) :
-  IntersectableWrapper<KdNode *>(item), mNumTriangles(-1)
+  IntersectableWrapper<KdNode *>(item), mNumTriangles(-1), mBox(box)
 {
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2569)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2571)
@@ -1410,5 +1410,5 @@
 		// not in map => create new entry
 		const int id = (int)mKdIntersectables.size();
-		KdIntersectable *kdObj = new KdIntersectable(node, GetBox(node));;
+		KdIntersectable *kdObj = new KdIntersectable(node, GetBox(node));
 		node->mIntersectable = kdObj;
 		
