Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1982)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1983)
@@ -81,10 +81,23 @@
 {
 public:
-
+  
   struct PerViewCellStat {
 	float pvsSize;
 	float relPvsIncrease;
   };
-  
+
+  struct SamplesStatistics {
+	int mRays;
+	int mViewCells;
+	int mContributingRays;
+	int mPvsContributions;
+	void Reset() {
+	  mRays = 0;
+	  mViewCells = 0;
+	  mContributingRays = 0;
+	  mPvsContributions = 0;
+	};
+  };
+
   struct PvsStatistics 
 	{
@@ -811,5 +824,5 @@
   
   vector<PerViewCellStat> mPerViewCellStat;
-
+  SamplesStatistics mSamplesStat;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 1967)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 1983)
@@ -338,13 +338,10 @@
   ViewCell *viewcell = NULL;
 
-  PrVs prvs;
-  
-  if (1 || !mUseFilter) {
-	viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
-  } else {
-	//  mViewCellsManager->SetMaxFilterSize(1);
-	mViewCellsManager->GetPrVS(mViewPoint, prvs, mViewCellsManager->GetFilterWidth());
-	viewcell = prvs.mViewCell;
-  }
+  if (mDetectEmptyViewSpace) 
+	glEnable( GL_CULL_FACE );
+  else
+	glDisable( GL_CULL_FACE );
+  
+  viewcell = mViewCellsManager->GetViewCell(mViewPoint, true);
   
   if (viewcell) {
@@ -379,30 +376,31 @@
 	}
 
+	Intersectable::NewMail();
+
 	// Render PVS
 	if (mUseSpatialFilter && mRenderBoxes) {
-		for (int i=0; i < mPvsCache.filteredBoxes.size(); i++)
-			RenderBox(mPvsCache.filteredBoxes[i]);
+	  for (int i=0; i < mPvsCache.filteredBoxes.size(); i++)
+		RenderBox(mPvsCache.filteredBoxes[i]);
 	} else {
-		ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
+	  ObjectPvsIterator it = mPvsCache.mPvs.GetIterator();
+	  
+	  mPvsSize = mPvsCache.mPvs.GetSize();
+	  for (; it.HasMoreEntries(); ) {
+		ObjectPvsEntry entry = it.Next();
+		Intersectable *object = entry.mObject;
 		
-		mPvsSize = mPvsCache.mPvs.GetSize();
-		for (; it.HasMoreEntries(); ) {
-			ObjectPvsEntry entry = it.Next();
-			Intersectable *object = entry.mObject;
-			
-			if (mRenderVisibilityEstimates) {
-				
-				float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
-				glColor3f(visibility, 0.0f, 0.0f);
-				mUseForcedColors = true;
-				RenderIntersectable(object);
-				mUseForcedColors = false;
-			} else {
-				mUseForcedColors = false;
-				RenderIntersectable(object);
-			}
+		if (mRenderVisibilityEstimates) {
+		  float visibility = mTransferFunction*log10(entry.mData.mSumPdf + 1); // /5.0f
+		  glColor3f(visibility, 0.0f, 0.0f);
+		  mUseForcedColors = true;
+		  RenderIntersectable(object);
+		  mUseForcedColors = false;
+		} else {
+		  mUseForcedColors = false;
+		  RenderIntersectable(object);
 		}
+	  }
 	}
-
+	
 	if (mRenderFilter) {
 	  mWireFrame = true;
@@ -413,18 +411,14 @@
 	  glPushAttrib(GL_CURRENT_BIT);
 	  glColor3f(1.0f, 0.0f, 0.0f);
-	  gluSphere((::GLUquadric *)mSphere,
-							1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
+	  //	  gluSphere((::GLUquadric *)mSphere,
+	  //				1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
 	  glPopAttrib();
 	  glPopMatrix();
 	  mWireFrame = false;
 	}
-	
-	if (0 && mUseFilter)
-	  mViewCellsManager->DeleteLocalMergeTree(viewcell);
-
   } else {
-		ObjectContainer::const_iterator oi = mObjects.begin();
-		for (; oi != mObjects.end(); oi++)
-			RenderIntersectable(*oi);
+	ObjectContainer::const_iterator oi = mObjects.begin();
+	for (; oi != mObjects.end(); oi++)
+	  RenderIntersectable(*oi);
   }
 }
@@ -625,5 +619,4 @@
 	  RenderPvs();
 	}
-	
   }
 
@@ -947,4 +940,5 @@
   if (mViewCellsManager)
 	vc = mViewCellsManager->GetViewCells().size();
+
   int filter = 0;
   if (mViewCellsManager)
@@ -985,5 +979,7 @@
   if (mViewCellsManager) {
 	//  	mViewCellsManager->SetMaxFilterSize(number);
-    mViewCellsManager->CollectViewCells(number);
+
+	// $$ tmp off
+	mViewCellsManager->CollectViewCells(number);
 
 	// $$ does not work so far:(
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h	(revision 1969)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.h	(revision 1983)
@@ -11,5 +11,5 @@
 class QtGlViewer : public QGLWidget
 {
-  //Q_OBJECT
+  Q_OBJECT
 
 	friend class QtGlRendererWidget;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 1972)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 1983)
@@ -54,4 +54,7 @@
 	
 	mRenderer->RenderPvs();
+
+	mRenderer->RenderViewPoint();
+
 	
 // 	if (mRenderer->mShowRays) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1974)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 1983)
@@ -172,5 +172,5 @@
 		maxCostRatio 0.98
 		ct_div_ci 0.5
-		maxNodes 500000
+		maxNodes 200000
 #500000	
 	}
@@ -205,6 +205,6 @@
 
 	#number of active view cells
-	active 20000
-	maxViewCells 20000
+	active 200000
+	maxViewCells 200000
 
 	maxStaticMemory	40
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1974)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1983)
@@ -5,4 +5,5 @@
 using namespace std;
 
+#include "common.h"
 #include "Halton.h"
 namespace GtpVisibilityPreprocessor {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1982)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1983)
@@ -80,4 +80,5 @@
 
 	mViewCellsTree->SetViewCellsManager(this);
+	mSamplesStat.Reset();
 }
 
@@ -2076,4 +2077,5 @@
 	stat.avgPvs/=stat.viewcells;
 	stat.avgPvsEntries/=stat.viewcells;
+	stat.avgFilteredPvsEntries/=stat.viewcells;
 	stat.avgFilteredPvs/=stat.viewcells;
 	stat.avgFilterContribution/=stat.viewcells;
@@ -2109,4 +2111,13 @@
   s<<"#AVG_REL_PVS_INCREASE\n"<<pvsStat.avgRelPvsIncrease<<endl;
   s<<"#DEV_REL_PVS_INCREASE\n"<<pvsStat.devRelPvsIncrease<<endl;
+
+  s<<"#CONTRIBUTING_RAYS\n"<<mSamplesStat.mContributingRays<<endl;
+
+  if (mSamplesStat.mRays) {
+	s<<"#AVG_VIEWCELLS_PER_RAY\n"<<mSamplesStat.mViewCells/(float)mSamplesStat.mRays<<endl;
+  } else {
+	s<<"#AVG_VIEWCELLS_PER_RAY\n 1 \n";
+  }
+  mSamplesStat.Reset();
 }
 
@@ -2329,4 +2340,6 @@
 	ray.mRelativePvsContribution = 0.0f;
 
+	mSamplesStat.mRays++;
+	
 	if (!ray.mTerminationObject)
 		return 0.0f;
@@ -2352,5 +2365,6 @@
 	CastLineSegment(origin, termination, viewCells);
 
-	
+	mSamplesStat.mViewCells+=viewCells.size();
+
 	if (storeViewCells)
 	{	
@@ -2379,4 +2393,8 @@
 	}
 
+	mSamplesStat.mPvsContributions += ray.mPvsContribution;
+	if (ray.mPvsContribution)
+	  mSamplesStat.mContributingRays++;
+	
 #if AVG_RAY_CONTRIBUTIONS
 	ray.mRelativePvsContribution /= (float)viewCells.size();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1972)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 1983)
@@ -80,11 +80,12 @@
   mFrame = 0;
   mWireFrame = false;
-  Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
+  Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace",
+											mDetectEmptyViewSpace);
   mSnapErrorFrames = true;
   mSnapPrefix = "snap/";
   mUseForcedColors = false;
   mRenderBoxes = false;
-  mUseGlLists = true;
-  //mUseGlLists = false;
+  //mUseGlLists = true;
+  mUseGlLists = false;
 
   Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames);
@@ -683,6 +684,6 @@
 	  glCallList(leaf->mGlList);
 #else
-	  for (int i=0; i < leaf->mObjects.size(); i++)
-		RenderIntersectable(leaf->mObjects[i]);
+	for (int i=0; i < leaf->mObjects.size(); i++)
+	  RenderIntersectable(leaf->mObjects[i]);
 #endif
   } else {
@@ -1540,9 +1541,22 @@
 }
 
-
-
-
-
-
-
-}
+void
+GlRenderer::RenderViewPoint()
+{
+  mWireFrame = true;
+  glPushMatrix();
+  glTranslatef(mViewPoint.x, mViewPoint.y, mViewPoint.z);
+  glScalef(5.0f,5.0f,5.0f);
+  glPushAttrib(GL_CURRENT_BIT);
+  glColor3f(1.0f, 0.0f, 0.0f);
+  gluSphere((::GLUquadric *)mSphere,
+			1e-3*Magnitude(mViewCellsManager->GetViewSpaceBox().Size()), 6, 6);
+  glPopAttrib();
+  glPopMatrix();
+  mWireFrame = false;
+}
+
+
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 1972)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 1983)
@@ -118,4 +118,6 @@
 #if DEBUG_RAYCAST
 	Debug<<"C16 "<<flush;
+	static int counter=0;
+	Debug<<counter++<<endl;
 #endif
 
@@ -131,4 +133,9 @@
 
 	for (i=0; i < num; i++) {
+#if DEBUG_RAYCAST
+	  if (counter == 43964) {
+		Debug<<rays[i].mOrigin<<" "<<rays[i].mDirection<<endl;
+	  }
+#endif
 	  mlrtaStoreRayAS16(&rays[i].mOrigin.x,
 						&rays[i].mDirection.x,
@@ -137,5 +144,5 @@
 
 #if DEBUG_RAYCAST
-		Debug<<"TA\n"<<flush;
+	Debug<<"TA\n"<<flush;
 #endif
 
@@ -144,25 +151,27 @@
 						   forward_hit_triangles,
 						   forward_dist);
-	
-	if (castDoubleRay)
-	  {
-		for (i=0; i < num; i++) 
-		  {
-			Vector3 dir = -rays[i].mDirection;
-			mlrtaStoreRayAS16(&rays[i].mOrigin.x,
-							  &dir.x,
-							  i);
-		  }
-
-#if DEBUG_RAYCAST
-		Debug<<"TB\n"<<flush;
-#endif
-
-		mlrtaTraverseGroupAS16(&min.x,
-							   &max.x,
-							   backward_hit_triangles,
-							   backward_dist);
+
+#if DEBUG_RAYCAST
+	Debug<<"TAB\n"<<flush;
+#endif
+
+	if (castDoubleRay) {
+	  for (i=0; i < num; i++)  {
+		Vector3 dir = -rays[i].mDirection;
+		mlrtaStoreRayAS16(&rays[i].mOrigin.x,
+						  &dir.x,
+						  i);
 	  }
-
+	  
+#if DEBUG_RAYCAST
+	  Debug<<"TB\n"<<flush;
+#endif
+	  
+	  mlrtaTraverseGroupAS16(&min.x,
+							 &max.x,
+							 backward_hit_triangles,
+							 backward_dist);
+	}
+	
 #if DEBUG_RAYCAST
 	Debug<<"BBB\n"<<flush;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1974)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 1983)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: ne 14. I 01:57:15 2007
+# Generated by qmake (2.00a) (Qt 4.1.2) on: po 15. I 15:33:12 2007
 # Project:  preprocessor.pro
 # Template: app
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1968)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1983)
@@ -136,4 +136,6 @@
   _RenderScene();
 
+  void
+  RenderViewPoint();
 
   virtual void
Index: GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro	(revision 1974)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/preprocessor.pro	(revision 1983)
@@ -111,5 +111,6 @@
 Trackball.cpp ObjExporter.cpp SubdivisionCandidate.cpp \
 Mailable.cpp \
-CombinedPreprocessor.cpp Vector2.cpp
+CombinedPreprocessor.cpp Vector2.cpp GlobalLinesRenderer.cpp \
+RenderTexture.cpp
 
 SOURCES += BoostPreprocessorThread.cpp 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1976)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1983)
@@ -10,4 +10,6 @@
 
 namespace GtpVisibilityPreprocessor {
+
+#define MUTATION_USE_CDF 0
 
 
@@ -729,5 +731,5 @@
   
   float pContributingRays = contributingRays/(float)vssRays.size();
-  float importance = 1.0f/(pContributingRays + 1e-5);
+  float importance = sqr(1.0f/(pContributingRays + 1e-5));
   // set this values for last contributingRays
   int index = mBufferStart - 1;
@@ -739,5 +741,5 @@
   }
 
-  
+#if MUTATION_USE_CDF
   // compute cdf
   mRays[0].mCdf = mRays[0].mImportance/(mRays[0].mSamples+1);
@@ -749,5 +751,6 @@
 	mRays[i].mCdf *= scale;
   }
-
+#endif
+  
   cout<<"Importance = "<<
 	GetEntry(0).mImportance<<" "<<
@@ -888,5 +891,6 @@
 
   int index;
-#if 1
+
+#if !MUTATION_USE_CDF
   // get tail of the buffer
   index = (mLastIndex+1)%mRays.size();
