Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 265)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 267)
@@ -13,6 +13,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
 }
@@ -64,7 +64,7 @@
 BspTree {
 #	splitPlaneStrategy leastSplits
-	splitPlaneStrategy balancedTree
+#	splitPlaneStrategy balancedTree
 #	splitPlaneStrategy nextPolygon
-#	splitPlaneStrategy combined
+	splitPlaneStrategy combined
 #       constructionMethod rays
 	constructionMethod viewCells
@@ -74,5 +74,5 @@
 	Termination {
 		maxPolygons 0
-		maxDepth 999
+		maxDepth 3000
 	}
 }
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 265)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 267)
@@ -82,5 +82,5 @@
   int Interior() const { return nodes / 2; }
   int Leaves() const { return (nodes / 2) + 1; }
-  int AvgDepth() const { return accumDepth / Leaves();};
+  float AvgDepth() const { return accumDepth / (double)Leaves();}; // TODO: computation wrong
   
   void Reset() 
@@ -394,5 +394,5 @@
 		@returns the number of polygons
 	*/
-	int Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects);
+	int Copy2PolygonSoup(const ObjectContainer &objects, PolygonContainer &polys, int maxObjects = 0);
 	/** Extracts the meshes of the view cells and copies them into the mesh. 
 		Adds view cell aabb to the aabb of the tree.
@@ -400,5 +400,5 @@
 		@returns the number of polygons
 	*/
-	int Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects);
+	int Copy2PolygonSoup(const ViewCellContainer &viewCells, PolygonContainer &polys, int maxObjects = 0);
 
 	/** Extract polygons of this mesh and add to polygon container.
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 265)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 267)
@@ -30,4 +30,7 @@
 int BspTree::sBalancedTreeTable[4] = {-1, 1, 0, 0};
 
+const int FACTOR_BALANCE = 1;
+const int FACTOR_LEAST_SPLITS = 1;
+
 /****************************************************************/
 /*                  class BspNode implementation                */
@@ -144,7 +147,7 @@
 								int &splits, bool storePolys)
 {
-//#ifdef _Debug
+#ifdef _Debug
 	Debug << "Splitting polygons of node " << this << " with plane " << mPlane << endl;
-//#endif
+#endif
 	bool inside = false;
 
@@ -157,5 +160,4 @@
 		int classification = poly->ClassifyPlane(mPlane);
 
-		//Debug << "polygon plane: " << poly->GetSupportingPlane() << endl;
 		Polygon3 *front_piece = NULL;
 		Polygon3 *back_piece = NULL;
@@ -169,20 +171,20 @@
 					inside = (DotProd(mPlane.mNormal, poly->GetSupportingPlane().mNormal) > 0);
 					
-				Debug << "coincident" << endl;
+				//Debug << "coincident" << endl;
 				// discard polygons or saves them in node
 				ProcessPolygon(poly, storePolys);
 				break;
 			case Polygon3::FRONT_SIDE:
-				Debug << "front" << endl;
+				//Debug << "front" << endl;
 				frontPolys->push_back(poly);
 				break;
 			case Polygon3::BACK_SIDE:
 				inside = true;
-				Debug << "back" << endl;
+				//Debug << "back" << endl;
 				backPolys->push_back(poly);
 				break;
 			case Polygon3::SPLIT:
 				inside = true;
-				Debug << "split " << poly << endl;
+				//Debug << "split " << poly << endl;
 
 				front_piece = new Polygon3();
@@ -279,5 +281,5 @@
 	app << "#N_NODES ( Number of nodes )\n" << nodes << "\n";
 
-	app << "#N_LEAVES ( Number of interior nodes )\n" << Interior() << "\n";
+	app << "#N_INTERIORS ( Number of interior nodes )\n" << Interior() << "\n";
 
 	app << "#N_LEAVES ( Number of leaves )\n" << Leaves() << "\n";
@@ -313,5 +315,5 @@
 	app << "#N_PMINDEPTH ( Minimal reached depth )\n" << minDepth << endl;
 
-	app << "#AVGEPTH ( average depth )\n" << AvgDepth() << endl;
+	app << "#AVGDEPTH ( average depth )\n" << AvgDepth() << endl;
 
 	app << "#N_ADDED_RAYREFS  ( Number of dynamically added ray references )\n"<<
@@ -389,8 +391,7 @@
 				int splits = 0;
 		
-				Debug << "Splitting poly, YEAHH\n";
 				// split viecell polygons with respect to split plane
 				bool inside = interior->SplitPolygons(tData.mPolygons, frontPolys, backPolys, splits, mStorePolys);
-				//Debug << "Reached level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl;
+				//Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl;
 				mStat.splits += splits;
 
@@ -408,11 +409,8 @@
 		{
 			if (tData.mPolygons->size() > 0)
-				Debug << "WARNING (should not come here): polygon size: " << tData.mPolygons->size() << " inside: " << tData.mIsInside  << endl;
+				Debug << "WARNING (should not come here): polygon size: " << (int)tData.mPolygons->size() << " inside: " << tData.mIsInside  << endl;
 
 			BspNode *root = Subdivide(tStack, tData, viewCell);		
 
-			//if (!root->IsLeaf())
-			//	Debug << "WARNING should NOT have subdivided further\n";
-         
 			if (!mRoot) // tree empty => new root
 				mRoot = root;
@@ -514,5 +512,5 @@
 		// copy view cell meshes into one big polygon soup
 		PolygonContainer *polys = new PolygonContainer();
-		Copy2PolygonSoup(viewCells, *polys, sMaxCandidates);
+		Copy2PolygonSoup(viewCells, *polys);
 
 		// polygons are stored only during view cell insertion
@@ -524,5 +522,5 @@
 	}
 	
-	//-- insert all viewcells
+	//-- insert all viewcells one after another
 	ViewCellContainer::const_iterator it;
 
@@ -530,13 +528,16 @@
 	mStat.polys = 0;
 	mStat.splits = 0;
-	//int counter = 0;
-	
+	mStat.accumDepth = 0;
+
 	long startTime = GetTime();
+
+	int counter = 0;
 	Debug << "**** Starting view cell insertion ****" << endl;
 	for (it = viewCells.begin(); it != viewCells.end(); ++ it)
 	{
-		//Debug << "*** Inserting view cell " << counter ++ << " ***" << endl;
+		Debug << "** inserting view cell " << counter ++ << " **" << endl;
 		InsertViewCell(*it);
 	}
+
 	Debug << "**** Finished view cell insertion ****" << endl;
 	Debug << "insertion time: "<< TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
@@ -552,10 +553,8 @@
 	
 	// copy mesh instance polygons into one big polygon soup
-	mStat.polys = Copy2PolygonSoup(objects, *polys, sMaxCandidates);
+	mStat.polys = Copy2PolygonSoup(objects, *polys);
 
 	// construct tree from polygon soup
-	Construct(polys);
-
-	// TODO: generate view cells
+	Construct(polys, viewCells);
 }
 
@@ -609,7 +608,7 @@
 		//&& !(viewCell && tData.mIsInside && dynamic_cast<BspLeaf *>(tData.mNode)->GetViewCell()))  
 	{
-#ifdef _DEBUG
+//#ifdef _DEBUG
 		Debug << "subdivision terminated at depth " << tData.mDepth << ", #polys: " << (int)tData.mPolygons->size() << endl;
-#endif
+//#endif
 
 		EvaluateLeafStats(tData);
@@ -623,4 +622,5 @@
 				Debug << "ERROR: leaf already has view cell" << endl;
 
+			Debug << "insert view cell" << endl;
 			leaf->SetViewCell(viewCell);
 		}
@@ -638,5 +638,4 @@
 	bool inside = false;
 
-	Debug << "Subdividing node at depth " << tData.mDepth << endl;
 	BspInterior *interior = SubdivideNode(dynamic_cast<BspLeaf *>(tData.mNode),
 										  tData.mPolygons,
@@ -732,9 +731,6 @@
 		}
 	}
-	
-	if (lowestCost > 0)
-		Debug << "Split plane cost: " << lowestCost << " plane: " << (*polygons)[bestPlaneIdx]->GetSupportingPlane() << endl;
-	else
-		Debug << "no splits for plane: " << (*polygons)[bestPlaneIdx]->GetSupportingPlane() << endl;
+	//Debug << "Plane lowest cost: " << lowestCost << endl;
+	
 	return (*polygons)[bestPlaneIdx]->GetSupportingPlane();
 }
@@ -758,12 +754,9 @@
 		{
 			sumLeastSplits += sLeastSplitsTable[classification];
-			Debug << "Adding " <<  sLeastSplitsTable[classification] << " for poly " << *it << "!";
-		}
-	}
-
-	Debug << "\n" << candidatePlane << " evaluation: " << abs(sumBalanced) + abs(sumLeastSplits) << endl;
+		}
+	}
 
 	// return linear combination of both sums
-	return abs(sumBalanced) + abs(sumLeastSplits);
+	return FACTOR_BALANCE * abs(sumBalanced) + FACTOR_LEAST_SPLITS *abs(sumLeastSplits);
 }
 
@@ -791,4 +784,6 @@
 	else if (strcmp(splitPlaneStrategyStr, "balancedTree") == 0)
 		sSplitPlaneStrategy = BspTree::BALANCED_TREE;
+	else if (strcmp(splitPlaneStrategyStr, "combined") == 0)
+		sSplitPlaneStrategy = BspTree::COMBINED;
 	else 
 	{
@@ -927,4 +922,5 @@
 		mStat.minDepth = data.mDepth;
 
+	// accumulate depth to compute average
 	mStat.accumDepth += data.mDepth;
 
