Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 569)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 572)
@@ -437,4 +437,7 @@
 	// load now because otherwise bounding box not correct
 	mViewCellsManager->LoadViewCells(mViewCellsFilename, &mObjects);
+	// $$JB tmp make all viewcelss valid
+	mViewCellsManager->SetValidity(0, 9999999999); 
+
   }
   
@@ -515,4 +518,10 @@
 	if (1) 
 	  mViewCellsManager->Visualize(mObjects, selectedRays);
+
+	// viewcells->UpdatePVS(newVssRays);
+	Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl;
+	// cull viewcells with PVS > median (0.5f)
+	mViewCellsManager->SetValidityPercentage(0, 0.5f); 
+	Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl;
 	
 	ComputeRenderError();
@@ -547,9 +556,4 @@
   }
   
-  // viewcells->UpdatePVS(newVssRays);
-  Debug<<"Valid viewcells before set validity: "<<mViewCellsManager->CountValidViewcells()<<endl;
-  // cull viewcells with PVS > median (0.5f)
-  mViewCellsManager->SetValidityPercentage(0, 0.5f); 
-  Debug<<"Valid viewcells after set validity: "<<mViewCellsManager->CountValidViewcells()<<endl;
   
   while (1) {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h	(revision 563)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h	(revision 572)
@@ -70,4 +70,6 @@
   int mFrame;
   bool mWireFrame;
+  
+bool mDetectEmptyViewSpace;
 
   KdTree *mKdTree;
@@ -164,5 +166,4 @@
   int mPvsStatFrames;
   vector<float> mPvsErrorBuffer;
-
 private:
 	
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 571)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 572)
@@ -1268,4 +1268,8 @@
   if (!mBspTree)
 	return NULL;
+
+  if (!mViewSpaceBox.IsInside(point))
+	return NULL;
+
   return mBspTree->GetViewCell(point);
 }
@@ -2614,4 +2618,8 @@
 	if (!mVspBspTree)
 		return NULL;
+
+	if (!mViewSpaceBox.IsInside(point))
+	  return NULL;
+
 	return mVspBspTree->GetViewCell(point);
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 569)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp	(revision 572)
@@ -46,4 +46,6 @@
   mFrame = 0;
   mWireFrame = false;
+  environment->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
+
 }
 
@@ -69,5 +71,8 @@
 {
 
-  SetupFalseColor(object->mId);
+  glPushAttrib(GL_CURRENT_BIT);
+  if (mUseFalseColors)
+	SetupFalseColor(object->mId);
+  
 
   switch (object->Type()) {
@@ -82,4 +87,6 @@
 	break;
   }
+
+  glPopAttrib();
 }
 
@@ -88,6 +95,13 @@
 GlRenderer::RenderViewCell(ViewCell *vc)
 {
-	if (vc->GetMesh())
-		RenderMesh(vc->GetMesh());
+  if (vc->GetMesh()) {
+
+	if (vc->GetValid()) 
+	  glColor3f(0,1,0);
+	else
+	  glColor3f(0,0,1);
+	
+	RenderMesh(vc->GetMesh());
+  }
 }
 
@@ -117,6 +131,4 @@
   if (m)
 	glColor3fv(&(m->mDiffuseColor.r));
-  else
-	glColor3f(1.0f, 1.0f, 1.0f);
 }
 
@@ -194,15 +206,28 @@
 GlRendererBuffer::RandomViewPoint()
 {
-  Vector3 pVector = Vector3(halton.GetNumber(1),
-							halton.GetNumber(2),
-							halton.GetNumber(3));
+  
+  
+  // do not use this function since it could return different viewpoints for
+  // different executions of the algorithm
+
+  //mViewCellsManager->GetViewPoint(mViewPoint);
+
+  while (1) {
+	Vector3 pVector = Vector3(halton.GetNumber(1),
+							  halton.GetNumber(2),
+							  halton.GetNumber(3));
+	
+	mViewPoint =  mSceneGraph->GetBox().GetPoint(pVector);
+	ViewCell *v = mViewCellsManager->GetViewCell(mViewPoint);
+	if (v && v->GetValid())
+	  break;
+	// generate a new vector
+	halton.GenerateNext();
+  }
+  
   
   Vector3 dVector = Vector3(2*M_PI*halton.GetNumber(4),
 							M_PI*halton.GetNumber(5),
 							0.0f);
-  
-  mViewCellsManager->GetViewPoint(mViewPoint);
-
-  // mViewPoint =  mSceneGraph->GetBox().GetPoint(pVector);
   
   mViewDirection = Normalize(Vector3(sin(dVector.x),
@@ -210,5 +235,4 @@
 									 0.0f,
 									 cos(dVector.x)));
-
   halton.GenerateNext();
 }
@@ -221,4 +245,5 @@
 								   KdTree *tree):
 QGLPixelBuffer(QSize(w, h)), GlRenderer(sceneGraph, viewcells, tree) {
+ 
  
  environment->GetIntValue("Preprocessor.pvsRenderErrorSamples", mPvsStatFrames);
@@ -238,42 +263,48 @@
   
   mUseFalseColors = true;
-
-  SetupCamera();
-  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-  glEnable( GL_CULL_FACE );
-  
-  RenderScene();
-
-  // now check whether any backfacing polygon would pass the depth test
+  
+
   static int query = -1;
+  unsigned int pixelCount;
+
   if (query == -1)
 	glGenOcclusionQueriesNV(1, (unsigned int *)&query);
-  
-  glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-  glDepthMask(GL_FALSE);
-  glDisable( GL_CULL_FACE );
-  
-  glBeginOcclusionQueryNV(query);
-  
-  RenderScene();
-  
-  glEndOcclusionQueryNV();
-
-  // at this point, if possible, go and do some other computation
-  glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-  glDepthMask(GL_TRUE);
-  glEnable( GL_CULL_FACE );
-  
-  unsigned int pixelCount;
-  // reenable other state
-  glGetOcclusionQueryuivNV(query,
-						   GL_PIXEL_COUNT_NV,
-						   &pixelCount);
-
-  if (pixelCount > 0)
-	return -1.0f; // backfacing polygon found -> not a valid viewspace sample
+
+  if (mDetectEmptyViewSpace) {
+	// now check whether any backfacing polygon would pass the depth test
+	SetupCamera();
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glEnable( GL_CULL_FACE );
+	
+	RenderScene();
+	
+	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+	glDepthMask(GL_FALSE);
+	glDisable( GL_CULL_FACE );
+	
+	glBeginOcclusionQueryNV(query);
+	
+	RenderScene();
+	
+	glEndOcclusionQueryNV();
+	
+	// at this point, if possible, go and do some other computation
+	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+	glDepthMask(GL_TRUE);
+	glEnable( GL_CULL_FACE );
+	
+	// reenable other state
+	glGetOcclusionQueryuivNV(query,
+							 GL_PIXEL_COUNT_NV,
+							 &pixelCount);
+	
+	if (pixelCount > 0)
+	  return -1.0f; // backfacing polygon found -> not a valid viewspace sample
+  } else
+	glDisable( GL_CULL_FACE );
+	
 
   ViewCell *viewcell = mViewCellsManager->GetViewCell(mViewPoint);
-  
+	
   if (viewcell) {
 	SetupCamera();
@@ -323,6 +354,11 @@
   SetupCamera();
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-  glEnable( GL_CULL_FACE );
-  
+
+
+  if (mDetectEmptyViewSpace) 
+	glEnable( GL_CULL_FACE );
+  else
+	glDisable( GL_CULL_FACE );
+
   ObjectContainer::const_iterator oi = mObjects.begin();
   for (; oi != mObjects.end(); oi++)
@@ -379,7 +415,7 @@
   // now render im1
   if (viewcell) {
-	if (mTopView) {
+	if (1 || mTopView) {
 	  mWireFrame = true;
-	  RenderMeshInstance(viewcell);
+	  RenderIntersectable(viewcell);
 	  mWireFrame = false;
 	}
