Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 675)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 693)
@@ -1280,4 +1280,8 @@
 	const float vol = box.GetVolume();
 
+	Debug << "vsb volume: " << vol << endl;
+	Debug << "root volume: " << mRoot->GetVolume() << endl;
+	Debug << "root pvs: " << mRoot->GetPvs().GetSize() << endl;
+
 	int totalPvs;
 	float totalRenderCost, avgRenderCost, expectedCost;
@@ -1394,5 +1398,4 @@
 	mRoot = root;
 }
-
 
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 660)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 693)
@@ -87,4 +87,19 @@
 }
 
+// HACK
+void RotateMesh(Mesh *mesh)
+{
+	VertexContainer::const_iterator it, it_end = mesh->mVertices.end();
+
+	const float angle = 30.0f * PI / 180.0f;
+	const Matrix4x4 rot = RotationYMatrix(30);
+
+	for (it = mesh->mVertices.begin(); it != it_end; ++ it)
+	{
+		const Vector3 pt = rot * (*it);
+	}
+}
+
+
 void
 X3dParseHandlers::EndShape()
@@ -109,4 +124,6 @@
 			
 			mesh->mFaces.push_back(new Face(vc));
+			if (0)
+				RotateMesh(mesh);
 			mesh->Preprocess();
 			// make an instance of this mesh
@@ -121,8 +138,10 @@
 	}
 	else
-	{
- 
+	{ 
 		if (mCurrentMesh->mFaces.size()) 
 		{
+			// HACK
+			if (0)
+				RotateMesh(mCurrentMesh);
 			mCurrentMesh->Preprocess();
 			// make an instance of this mesh
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 677)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 693)
@@ -500,5 +500,11 @@
 	bool mEvaluateViewCells;
 
-	bool mShowVisualization;	
+	bool mShowVisualization;
+
+	// HACK in order to detect empty view cells
+	void CollectEmptyViewCells();
+	void TestEmptyViewCells();
+
+	ViewCellContainer mEmptyViewCells;
 };
 
@@ -590,4 +596,5 @@
 	void ExportBspPvs(const ObjectContainer &objects);
 
+	void TestSubdivision();
 };
 
@@ -827,4 +834,5 @@
 					  const VssRayContainer &rays);
 
+	void TestSubdivision();
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 492)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.h	(revision 693)
@@ -78,7 +78,7 @@
   void AddRectangle(const Rectangle3 &triangle);
 
-	void Cleanup();
-	bool
-	ValidateFace(const int face);
+  void Cleanup();
+  
+  bool ValidateFace(const int face);
 
   void AddFace(Face *face) 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 685)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 693)
@@ -158,5 +158,5 @@
 		// cast again to ensure that there is no objectA
 		SetupRay(ray, pointB, direction);
-		ray.mFlags |= Ray::CULL_BACKFACESw;
+		ray.mFlags |= Ray::CULL_BACKFACES;
 		
 		if (mKdTree->CastRay(ray)) 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 574)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 693)
@@ -42,5 +42,5 @@
   environment->Parse(argc, argv, USE_EXE_PATH);
   MeshKdTree::ParseEnvironment();
-  
+
   char buff[128];
   environment->GetStringValue("Preprocessor.type", buff);
@@ -65,4 +65,5 @@
 		  exit(1);
 		}
+
 
   QApplication *app = NULL;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 685)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 693)
@@ -136,4 +136,54 @@
 
 
+void ViewCellsManager::CollectEmptyViewCells()
+{
+	mEmptyViewCells.clear();
+	ViewCellContainer leaves;
+	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
+
+	ViewCellContainer::const_iterator it, it_end = leaves.end();
+
+	cout << "collecting empty view cells" << endl;
+	int i = 0;
+	for (it = leaves.begin(); it != it_end; ++ it)
+	{
+		if ((*it)->GetPvs().Empty())
+		{
+			++ i;
+			mEmptyViewCells.push_back(*it);
+		}
+	}
+	cout << "view cells found: " << i << endl;
+}
+
+
+void ViewCellsManager::TestEmptyViewCells()
+{
+	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), mEmptyViewCells);
+
+	ViewCellContainer::const_iterator it, it_end = mEmptyViewCells.end();
+
+	char buf[50];
+	int i = 0;
+	for (it = mEmptyViewCells.begin(); it != it_end; ++ it)
+	{
+		if (!(*it)->GetPvs().Empty())
+		{
+			sprintf(buf, "empty-viewcells-%09d.x3d", (*it)->GetId());
+			Exporter *exporter = Exporter::GetExporter(buf);
+			
+			if (exporter && i < 20)
+			{
+				Debug << "view cell " << (*it)->GetId() << " not empty, pvs: " << (*it)->GetPvs().GetSize() << endl;
+				ExportViewCellGeometry(exporter, *it);
+			}
+
+			++ i;
+		}
+	}
+	Debug << "\nfound " << i << " new view cells (" << " of " << mEmptyViewCells.size() << ")" << endl << endl;
+}
+
+
 int ViewCellsManager::CastPassSamples(const int samplesPerPass, 
 									  const int sampleType, 
@@ -235,5 +285,4 @@
 	}
 
-
 	//-- guided rays are used for further sampling
 	const int n = mConstructionSamples; //+initialSamples;
@@ -308,4 +357,7 @@
 	// merge the view cells
 	PostProcess(preprocessor->mObjects, postProcessSamples);
+
+	// only for testing
+	CollectEmptyViewCells();
 
 
@@ -441,4 +493,7 @@
 		disposeRays(evaluationSamples, NULL);
 	}
+
+	// find empty view cells bug
+	TestEmptyViewCells();
 }
 
@@ -728,4 +783,6 @@
 {
 	ViewCellContainer::const_iterator it, it_end = mViewCells.end();
+
+	// volume and area of the view cells are recomputed and a view cell mesh is created
 	for (it = mViewCells.begin(); it != it_end; ++ it)
 	{
@@ -1146,5 +1203,4 @@
 		}
 	}
-
 }
 
@@ -1418,4 +1474,8 @@
 		cout << "finished" << endl;
 	}
+
+	
+	// only for testing
+	TestSubdivision();
 
 	mColorCode = savedColorCode;
@@ -1692,4 +1752,33 @@
 
 
+void BspViewCellsManager::TestSubdivision()
+{
+	ViewCellContainer leaves;
+	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
+
+	ViewCellContainer::const_iterator it, it_end = leaves.end();
+
+	const float vol = mViewSpaceBox.GetVolume();
+	float subdivVol = 0;
+	float newVol = 0;
+
+	for (it = leaves.begin(); it != it_end; ++ it)
+	{
+		BspNodeGeometry geom;
+		BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf;
+		mBspTree->ConstructGeometry(leaf, geom);
+
+		const float lVol = geom.GetVolume();
+		
+		newVol += lVol;
+		subdivVol += (*it)->GetVolume();
+	}
+	
+	Debug << "exact volume: " << vol << endl;
+	Debug << "subdivision volume: " << subdivVol << endl;
+	Debug << "new volume: " << newVol << endl;
+}
+
+
 void BspViewCellsManager::ExportViewCellGeometry(Exporter *exporter,
 												 ViewCell *vc,
@@ -1762,5 +1851,5 @@
 	ViewCellContainer::const_iterator it, it_end = leaves.end();
 
-	for (it = leaves.begin(); it != it_end; ++ it)
+    for (it = leaves.begin(); it != it_end; ++ it)
 	{
 		BspNodeGeometry geom;
@@ -1768,7 +1857,14 @@
 		mBspTree->ConstructGeometry(leaf, geom);
 
-		area += geom.GetArea();
-		volume += geom.GetVolume();
-		CreateMesh(*it);
+		float lVol = geom.GetVolume();
+		float lArea = geom.GetArea();
+
+		//(*it)->SetVolume(vol);
+		//(*it)->SetArea(area);
+
+		area += lArea;
+		volume += lVol;
+
+        CreateMesh(*it);
 	}
 
@@ -2937,4 +3033,8 @@
 	
 
+	Debug << "here4" << endl;
+	// only for testing
+	TestSubdivision();
+
 	//-- refines the merged view cells
 	if (0)
@@ -2953,5 +3053,4 @@
 	cout << ss << endl;
 	Debug << ss << endl;
-
 
 
@@ -3619,5 +3718,4 @@
 	CreateUniqueViewCellIds();
 
-
 	stream.open(filename.c_str());
 	stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl;
@@ -3678,5 +3776,5 @@
 	ViewCellContainer::const_iterator it, it_end = leaves.end();
 
-	for (it = leaves.begin(); it != it_end; ++ it)
+    for (it = leaves.begin(); it != it_end; ++ it)
 	{
 		BspNodeGeometry geom;
@@ -3684,7 +3782,14 @@
 		mVspBspTree->ConstructGeometry(leaf, geom);
 
-		area += geom.GetArea();
-		volume += geom.GetVolume();
-		CreateMesh(*it);
+		float lVol = geom.GetVolume();
+		float lArea = geom.GetArea();
+
+		//(*it)->SetVolume(vol);
+		//(*it)->SetArea(area);
+
+		area += lArea;
+		volume += lVol;
+
+        CreateMesh(*it);
 	}
 
@@ -3694,9 +3799,38 @@
 
 
+void VspBspViewCellsManager::TestSubdivision()
+{
+	ViewCellContainer leaves;
+	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
+
+	ViewCellContainer::const_iterator it, it_end = leaves.end();
+
+	const float vol = mViewSpaceBox.GetVolume();
+	float subdivVol = 0;
+	float newVol = 0;
+
+	for (it = leaves.begin(); it != it_end; ++ it)
+	{
+		BspNodeGeometry geom;
+		BspLeaf *leaf = dynamic_cast<BspViewCell *>(*it)->mLeaf;
+		mVspBspTree->ConstructGeometry(leaf, geom);
+
+		const float lVol = geom.GetVolume();
+		
+		newVol += lVol;
+		subdivVol += (*it)->GetVolume();
+	}
+	
+	Debug << "exact volume: " << vol << endl;
+	Debug << "subdivision volume: " << subdivVol << endl;
+	Debug << "new volume: " << newVol << endl;
+}
+
+
 void VspBspViewCellsManager::PrepareLoadedViewCells()
 {
 	// TODO: do I still need this here?
 	if (0)
-	mVspBspTree->RepairViewCellsLeafLists();
+		mVspBspTree->RepairViewCellsLeafLists();
 }
 
