Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 303)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 304)
@@ -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
 }
@@ -73,7 +73,8 @@
 	# vertical axis        = 64
 	
+	splitPlaneStrategy 4
 	# least splits + balanced polygons
 	#splitPlaneStrategy 12
-	splitPlaneStrategy 32
+	
 	#axis aligned + vertical axis
 	#splitPlaneStrategy 66
@@ -89,7 +90,7 @@
 	
 #       constructionMethod rays
-#	constructionMethod viewCells
-	constructionMethod sceneGeometry
-	maxCandidates 25
+	constructionMethod viewCells
+#	constructionMethod sceneGeometry
+	maxCandidates 0
 	maxViewCells 999999
 	Termination {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 303)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 304)
@@ -445,7 +445,8 @@
 
 	/** returns next candidate index
+		@param the current candidate index
 		@param max the range of candidates
 	*/
-	inline int GetNextCandidateIdx(const int max) const;
+	inline int GetNextCandidateIdx(int currentIdx, const int max) const;
 
 	/** Helper function which extracts a view cell on the front and the back
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 303)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 304)
@@ -260,6 +260,6 @@
 mRoot(NULL), 
 mViewCell(viewCell),
-mStorePolys(true)
-//mStorePolys(false)
+mStoreSplitPolys(true)
+//mStoreSplitPolys(false)
 {
 	Randomize(); // initialise random generator for heuristics
@@ -405,5 +405,5 @@
 										&coincident,
 										splits, 
-										mStorePolys);
+										mStoreSplitPolys);
 				
 				// extract view cells associated with the split polygons
@@ -422,5 +422,5 @@
 
 				// don't need coincident polygons anymore
-				interior->ProcessPolygons(&coincident, mStorePolys);
+				interior->ProcessPolygons(&coincident, mStoreSplitPolys);
 
 				//Debug << "split node on level " << tData.mDepth << " bk: " << backPolys->size() << " frnt: " << frontPolys->size() << endl;
@@ -542,13 +542,13 @@
 	mStat.polys = Copy2PolygonSoup(objects, *polys);
 
-	bool tmpStorePolys = mStorePolys;
-	mStorePolys = false;
+	bool tmpStorePolys = mStoreSplitPolys;
+	mStoreSplitPolys = false;
 
 	// construct tree from polygon soup
 	Construct(polys, viewCells);
 
-	mStorePolys = tmpStorePolys;
+	mStoreSplitPolys = tmpStorePolys;
 	// filter scene bounding box down the tree in order to store split polygons
-	if (mStorePolys)
+	if (mStoreSplitPolys)
 	{
 		Mesh *polyMesh = new Mesh();
@@ -627,5 +627,5 @@
 
 		// remaining polygons are discarded or added to node
-		tData.mNode->ProcessPolygons(tData.mPolygons, mStorePolys);
+		tData.mNode->ProcessPolygons(tData.mPolygons, mStoreSplitPolys);
 		DEL_PTR(tData.mPolygons);
 
@@ -660,5 +660,5 @@
 	
 	// don't need coincident polygons anymore
-	interior->ProcessPolygons(&coincident, mStorePolys);
+	interior->ProcessPolygons(&coincident, mStoreSplitPolys);
 
 	// push the children on the stack
@@ -721,5 +721,5 @@
 	int splits = 0;
 	
-	interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStorePolys);
+	interior->SplitPolygons(polys, frontPolys, backPolys, coincident, splits, mStoreSplitPolys);
 	
  	mStat.splits += splits;
@@ -885,7 +885,6 @@
 		/*int axis = box.Size().DrivingAxis();
 		Vector3 norm(0,0,0); norm[axis] = 1;
-		Vector3 pt = (box.Min()[axis] + box.Max()[axis]) * 0.5f;*/
-		
-		//return Plane3(norm, pt);
+		Vector3 position = (box.Min()[axis] + box.Max()[axis]) * 0.5f;
+		return Plane3(norm, position);*/
 	}
 
@@ -905,10 +904,14 @@
 	int bestPlaneIdx = 0;
 	
-	int limit = Min((int)polys.size(), maxTests);
+	int limit = maxTests > 0 ? Min((int)polys.size(), maxTests) : (int)polys.size();
+	
+	int candidateIdx = limit;
 
 	for (int i = 0; i < limit; ++ i)
 	{
-		int candidateIdx = GetNextCandidateIdx((int)polys.size());
+		candidateIdx = GetNextCandidateIdx(candidateIdx, polys, (int)polys.size() - i - i);
+
 		Plane3 candidatePlane = polys[candidateIdx]->GetSupportingPlane();
+		
 		
 		// evaluate current candidate
@@ -926,7 +929,18 @@
 }
 
-int BspTree::GetNextCandidateIdx(const int max) const
-{
-	return Random(max); // TODO: avoid testing same plane 2 times
+int BspTree::GetNextCandidateIdx(int currentIdx, PolygonContainer &polys, int max) const
+{
+#if 0
+	int candidateIdx = Random(max); // TODO: avoid testing same plane 2 times
+
+	// swap candidates
+	Polygon *p = polys[candidateIdx];
+	polys[candidateIdx] = polys[max];
+	polys[max] = p;
+
+	return max;
+#else
+	return ++ currentIdx;
+#endif
 }
 
@@ -1179,5 +1193,5 @@
 bool BspTree::StorePolys() const
 {
-	return mStorePolys;
+	return mStoreSplitPolys;
 }
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 303)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 304)
@@ -102,14 +102,7 @@
 		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 303)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 304)
@@ -41,5 +41,5 @@
   // if BSP tree construction method needs predefined view cells
 
-  if (1)//(BspTree::sConstructionMethod == BspTree::VIEW_CELLS)
+  if (BspTree::sConstructionMethod == BspTree::VIEW_CELLS)
   {
 	  if (vcFilename != "")
