Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 302)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 303)
@@ -8,6 +8,6 @@
 #	filename glasgow1.x3d
 #	filename vienna.x3d
-	filename ../data/vienna/vienna-simple.x3d
-#	filename ../data/vienna/viewcells-25-sel.x3d
+#	filename ../data/vienna/vienna-simple.x3d
+	filename ../data/vienna/viewcells-25-sel.x3d
 #	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
@@ -15,6 +15,6 @@
 #	viewcells ../data/atlanta/atlanta_viewcells_large.x3d
 #	viewcells ../data/atlanta/atlanta_viewcells_large2.x3d
-#	viewcells ../data/vienna/viewcells-25-sel.x3d
-	viewcells ../data/vienna/viewcells-25.x3d
+	viewcells ../data/vienna/viewcells-25-sel.x3d
+#	viewcells ../data/vienna/viewcells-25.x3d
 #	viewcells ../data/vienna/viewcells-large-sel.x3d
 }
@@ -75,20 +75,25 @@
 	# least splits + balanced polygons
 	#splitPlaneStrategy 12
+	splitPlaneStrategy 32
 	#axis aligned + vertical axis
-	splitPlaneStrategy 66
+	#splitPlaneStrategy 66
+	
 	# axis aligned + balanced view cells
 	# splitPlaneStrategy 18
+	
 	# largest polygon area
 	#splitPlaneStrategy 32
+	
 	# axus aligned + balanced polygons
 	#splitPlaneStrategy 72
+	
 #       constructionMethod rays
-	constructionMethod viewCells
-#	constructionMethod sceneGeometry
+#	constructionMethod viewCells
+	constructionMethod sceneGeometry
 	maxCandidates 25
 	maxViewCells 999999
 	Termination {
-		maxPolysForAxisAligned 200
-		maxPolygons 0
+		maxPolysForAxisAligned 50
+		maxPolygons 5
 		maxDepth 100
 	}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 302)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 303)
@@ -513,5 +513,5 @@
 
 	/// if polygons should be stored in the tree
-	bool mStorePolys;
+	bool mStoreSplitPolys;
 
 	/// view cell corresponding to unbounded space
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 302)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 303)
@@ -22,5 +22,5 @@
 float BspTree::sCt_div_ci = 1.0f;
 float BspTree::sSplitBorder = 1.0f;
-float BspTree::sMaxCostRatio = 0.9;
+float BspTree::sMaxCostRatio = 0.9f;
 
 //-- factors for bsp tree split plane heuristics
@@ -260,6 +260,6 @@
 mRoot(NULL), 
 mViewCell(viewCell),
-//mStorePolys(true)
-mStorePolys(false)
+mStorePolys(true)
+//mStorePolys(false)
 {
 	Randomize(); // initialise random generator for heuristics
@@ -437,6 +437,6 @@
 		else // reached leaf => subdivide current viewcell
 		{
-			if (tData.mPolygons->size() > 0)
-				Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl;
+			//if (tData.mPolygons->size() > 0)
+			//	Debug << "Subdividing further: polygon size: " << (int)tData.mPolygons->size() << ", view cell: " << tData.mViewCell << endl;
 
 			BspNode *root = Subdivide(tStack, tData, viewCells);		
@@ -504,4 +504,5 @@
 			// TODO: handle transformed mesh instances
 		default:
+			Debug << "intersectable type not supported" << endl;
 			break;
 		}
@@ -528,5 +529,4 @@
 	// construct tree from viewcell polygons
 	Construct(polys);
-	//Export("bsp.x3d");
 }
 
@@ -542,6 +542,26 @@
 	mStat.polys = Copy2PolygonSoup(objects, *polys);
 
+	bool tmpStorePolys = mStorePolys;
+	mStorePolys = false;
+
 	// construct tree from polygon soup
 	Construct(polys, viewCells);
+
+	mStorePolys = tmpStorePolys;
+	// filter scene bounding box down the tree in order to store split polygons
+	if (mStorePolys)
+	{
+		Mesh *polyMesh = new Mesh();
+
+		for (int i = 0; i < 6; ++i)
+			polyMesh->AddRectangle(mBox.GetFace(i));
+
+		PolygonContainer *polys = new PolygonContainer();
+		 		AddMesh2Polygons(polyMesh, *polys, NULL);
+		
+		InsertPolygons(polys);
+
+		delete polyMesh;
+	}
 }
 
@@ -585,7 +605,7 @@
 	if ((tData.mPolygons->size() <= sTermMaxPolygons) || (tData.mDepth >= sTermMaxDepth))
 	{
-//#ifdef _DEBUG
+#ifdef _DEBUG
 		Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl;
-//#endif
+#endif
 
 		EvaluateLeafStats(tData);
@@ -602,13 +622,8 @@
 		}
 		//-- add viewcell stored in split polygon
-		else
-		{
-			if (leaf->GetViewCell())
-				Debug << "ERROR: leaf already has view cell " << endl;//leaf->mViewCellIdx << endl;
-
-			//leaf->mViewCellIdx = counter; Debug << "insert view cell " << tData.mViewCell << endl;
+		else if (leaf->GetViewCell())
 			leaf->SetViewCell(tData.mViewCell);
-		}
-	
+		//else Debug << "Leaf already has view cell " << endl;
+
 		// remaining polygons are discarded or added to node
 		tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys);
@@ -635,5 +650,5 @@
 	
     if (!viewCells)
-	{
+	{	// extract the pointer to the view cells
 		ExtractViewCells(&backViewCell,
 						 &frontViewCell,
@@ -643,5 +658,5 @@
 						 backPolys->empty());
 	}
-    
+	
 	// don't need coincident polygons anymore
 	interior->ProcessPolygons(&coincident, mStorePolys);
@@ -683,4 +698,6 @@
 			foundFront = true;
 		}
+		//if (foundFront) Debug << "front viewCell: " << *frontViewCell << endl;
+		//if (foundBack) Debug << "back viewCell: " << *backViewCell << endl;
 	}
 }
@@ -921,6 +938,7 @@
 	{
 		Vector3 tinyAxis(0,0,0); tinyAxis[mBox.Size().TinyAxis()] = 1.0f;
-		// want to put a penalty on the dot product between the "tiny" vertical axis
+		// we put a penalty on the dot product between the "tiny" vertical axis
 		// and the split plane axis
+		// NOTE: weight with poly size because vertical split more important if too many polygons
 		val += sVerticalSplitsFactor * 
 			   fabs(DotProd(candidatePlane.mNormal, tinyAxis)) * (float)polys.size();
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 297)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 303)
@@ -95,5 +95,5 @@
 	ObjectContainer objects;
 	RayContainer rays;
-
+ViewCellContainer dummy;
 	switch (BspTree::sConstructionMethod)
 	{
@@ -102,8 +102,14 @@
 		break;
 	case BspTree::SCENE_GEOMETRY:
+#if 0
 		CLEAR_CONTAINER(mViewCells); // we generate new view cells
-
 		mSceneGraph->CollectObjects(&objects);
 		mBspTree->Construct(objects, &mViewCells);
+#else
+		for (int i=0; i< mViewCells.size(); ++i)
+			objects.push_back(mViewCells[i]);
+		
+		mBspTree->Construct(objects, &dummy);
+#endif
 		break;
 	case BspTree::RAYS:
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 302)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 303)
@@ -40,5 +40,6 @@
 
   // if BSP tree construction method needs predefined view cells
-  if (BspTree::sConstructionMethod == BspTree::VIEW_CELLS)
+
+  if (1)//(BspTree::sConstructionMethod == BspTree::VIEW_CELLS)
   {
 	  if (vcFilename != "")
@@ -52,6 +53,7 @@
   p->BuildBspTree();
   p->BspTreeStatistics(Debug);
-  p->Export("vc_bsptree.x3d", false, false, true);
+  p->Export("vc_bsptree2.x3d", false, false, true);
 
+#if 0
   //-- export the complementary view cells
   // i.e., the view cells not associated with leafs in the tree.
@@ -70,7 +72,9 @@
   if (exporter) 
   {	
+	  Debug << Exporting complementary view cells" << endl;
 	  exporter->ExportViewCells(&vc_compl); // export view cells
 	  delete exporter;
   }
+#endif
 
 #endif
