Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 474)
@@ -153,5 +153,5 @@
 	
 	height 5.0
-	maxViewCells 5000
+	maxViewCells 3000
 	
 	PostProcessing {
@@ -236,6 +236,6 @@
 	
 	# maximal candidates for split planes
-	maxPolyCandidates 50
-	maxRayCandidates 50
+	maxPolyCandidates 100
+	maxRayCandidates 100
 	
 	# maximal tested rays for split cost heuristics
@@ -251,12 +251,12 @@
 	Termination {
 		# parameters used for autopartition
-		minRays 		100
+		minRays 		10
 		minPolygons 		-1
 		maxDepth		30
-		minPvs 			100
-		minArea 		0.01
+		minPvs 			20
+		minArea 		0.0001
 		maxRayContribution	0.005
 		maxCostRatio		0.9
-		missTolerance		1
+		missTolerance		3
 		#maxAccRayLength	100
 		
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 474)
@@ -112,24 +112,25 @@
 		{}
 
+		/** Returns cost of the traversal data.
+		*/
+		float GetCost() const
+		{
+#if 0
+			return mPvs * mArea;
+#endif
+#if 1
+			return (float)(mPvs * (int)mRays->size());
+#endif
+#if 0
+			return (float)mPvs;
+#endif
+#if 0
+			return mArea * (float)mRays->size();
+#endif
+		}
+
 		friend bool operator<(const VspBspTraversalData &a, const VspBspTraversalData &b)
 		{
-#if 0
-			return a.mPvs * a.mArea < b.mPvs * b.mArea;
-#endif
-#if 1
-			return a.mPvs * (int)a.mRays->size() < b.mPvs * (int)b.mRays->size();
-#endif
-#if 0
-			return a.mPvs < b.mPvs;
-#endif
-#if 0
-			return 
-				a.mPvs / (float)(a.mRays->size() + Limits::Small())
-				>
-				b.mPvs / (float)(b.mRays->size() + Limits::Small());
-#endif
-#if 0
-			return a.mPvs * (int)a.mRays->size() <	b.mPvs * (int)b.mRays->size();
-#endif
+			return a.GetCost() < b.GetCost();
 		}
     };
@@ -544,6 +545,6 @@
 	/// maximal number of test rays used to evaluate candidate split plane
 	int mMaxTests;
-	/// number of different bsp split plane criteria
-	int mNumCriteria;
+	/// normalizes different bsp split plane criteria
+	float mCostNormalizer;
 	/// maximal number of view cells
 	int mMaxViewCells;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 474)
@@ -38,5 +38,5 @@
 mRoot(NULL),
 mPvsUseArea(true),
-mNumCriteria(0)
+mCostNormalizer(Limits::Small)
 {
 	mRootCell = new BspViewCell();
@@ -91,27 +91,27 @@
 	Debug << "max polygon candidates: " << mMaxPolyCandidates << endl;
 	Debug << "max plane candidates: " << mMaxRayCandidates << endl;
-
+	
 	Debug << "Split plane strategy: ";
 	if (mSplitPlaneStrategy & RANDOM_POLYGON)
+	{
 		Debug << "random polygon ";
-
+	}
 	if (mSplitPlaneStrategy & AXIS_ALIGNED)
 	{
-		++ mNumCriteria;
 		Debug << "axis aligned ";
 	}
 	if (mSplitPlaneStrategy & LEAST_RAY_SPLITS)
 	{
-		++ mNumCriteria;
+		mCostNormalizer += mLeastRaySplitsFactor;
 		Debug << "least ray splits ";
 	}
 	if (mSplitPlaneStrategy & BALANCED_RAYS)
 	{
-		++ mNumCriteria;
+		mCostNormalizer += mBalancedRaysFactor;
 		Debug << "balanced rays ";
 	}
 	if (mSplitPlaneStrategy & PVS)
 	{
-		++ mNumCriteria;
+		mCostNormalizer += mPvsFactor;
 		Debug << "pvs";
 	}
@@ -273,4 +273,5 @@
 	}
 
+	mTermMinArea *= mBox.SurfaceArea(); // normalize
 	mStat.polys = (int)polys.size();
 
@@ -315,5 +316,4 @@
 
 	    tStack.pop();
-
 		// subdivide leaf node
 		BspNode *r = Subdivide(tStack, tData);
@@ -412,10 +412,10 @@
 		++ maxCostMisses;
 
-		/*if (maxCostMisses >= mTermMissTolerance)
+		if (maxCostMisses >= mTermMissTolerance)
 		{
 			// terminate branch because of max cost
 			++ mStat.maxCostNodes; 
             return leaf;
-		}*/
+		}
 	}
 
@@ -471,7 +471,6 @@
 									   mEpsilon);
 	
-		// area is normalized with view space area
-		frontData.mArea = frontData.mGeometry->GetArea() / mBox.SurfaceArea();
-		backData.mArea = backData.mGeometry->GetArea() / mBox.SurfaceArea();
+		frontData.mArea = frontData.mGeometry->GetArea();
+		backData.mArea = backData.mGeometry->GetArea();
 	}
 
@@ -810,10 +809,10 @@
 		const int candidateIdx = (int)RandomValue(0, (Real)(-- maxIdx));
 		//Debug << "current Idx: " << maxIdx << " cand idx " << candidateIdx << endl;
-
+		
 		Polygon3 *poly = (*data.mPolygons)[candidateIdx];
-		
+
 		// swap candidate to the end to avoid testing same plane
 		std::swap((*data.mPolygons)[maxIdx], (*data.mPolygons)[candidateIdx]);
-
+	
 		//Polygon3 *poly = (*data.mPolygons)[(int)RandomValue(0, (int)polys.size() - 1)];
 
@@ -829,13 +828,9 @@
 	}
 	
-	//Debug << "lowest: " << lowestCost << endl;
-
 	//-- choose candidate planes extracted from rays
-	// we use different methods chosen with
-	// equal probability
+	//-- different methods are available
 	for (int i = 0; i < mMaxRayCandidates; ++ i)
 	{
 		plane = ChooseCandidatePlane3(*data.mRays);
-
 		const float candidateCost = SplitPlaneCost(plane, data);
 
@@ -846,12 +841,12 @@
 		}
 	}
+
+#ifdef _DEBUG
+	Debug << "plane lowest cost: " << lowestCost << endl;
+#endif
 
 	// cost ratio miss
 	if (lowestCost > mTermMaxCostRatio)
 		return false;
-
-#ifdef _DEBUG
-	Debug << "plane lowest cost: " << lowestCost << endl;
-#endif
 
 	return true;
@@ -1011,22 +1006,23 @@
 	{
 		const float oldCost = pOverall * (float)data.mPvs + Limits::Small;
-
-		cost += mPvsFactor * (frontPvs * pFront + (backPvs * pBack)) / oldCost;
-
-		// give penalty to unbalanced split
-		if (0)
-		if (((pFront * 0.2 + Limits::Small) > pBack) || 
-			(pFront < (pBack * 0.2 + Limits::Small)))
-			cost += 0.5;
+		cost += mPvsFactor * (frontPvs * pFront + backPvs * pBack) / oldCost;
+
+		//cost += mPvsFactor * 0.5 * (frontPvs * pFront + backPvs * pBack) / oldCost;
+		//Debug << "new cost: " << cost << " over" << frontPvs * pFront + backPvs * pBack << " old cost " << oldCost << endl;
+	
+		if (0) // give penalty to unbalanced split
+			if (((pFront * 0.2 + Limits::Small) > pBack) || 
+				(pFront < (pBack * 0.2 + Limits::Small)))
+					cost += 0.5;
 	}
 
 #ifdef _DEBUG
-//  	Debug << "totalpvs: " << pvs << " ptotal: " << pOverall
-//  		  << " frontpvs: " << frontPvs << " pFront: " << pFront 
-//  		  << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl;
+  	Debug << "totalpvs: " << data.mPvs << " ptotal: " << pOverall
+  		  << " frontpvs: " << frontPvs << " pFront: " << pFront 
+  		  << " backpvs: " << backPvs << " pBack: " << pBack << endl << endl;
 #endif
-
-	// normalize by number of criteria
-	return cost / (float)(mNumCriteria + Limits::Small);
+	
+	// normalize cost by sum of linear factors
+	return cost / (float)mCostNormalizer;
 }
 
@@ -1118,23 +1114,24 @@
 	if (data.mDepth < mStat.minDepth)
 		mStat.minDepth = data.mDepth;
-
+	
+	if (data.mDepth >= mTermMaxDepth)
+		++ mStat.maxDepthNodes;
+
+	if (data.mPvs < mTermMinPvs)
+		++ mStat.minPvsNodes;
+
+	if ((int)data.mRays->size() < mTermMinRays)
+		++ mStat.minRaysNodes;
+
+	if (data.GetAvgRayContribution() > mTermMaxRayContribution)
+		++ mStat.maxRayContribNodes;
+	
+	if (data.mArea <= mTermMinArea) 
+	{
+		//Debug << "area: " << data.mArea / mBox.SurfaceArea() << " min area: " << mTermMinArea / mBox.SurfaceArea() << endl;
+		++ mStat.minAreaNodes;
+	}
 	// accumulate depth to compute average depth
 	mStat.accumDepth += data.mDepth;
-	
-
-	if (data.mDepth >= mTermMaxDepth)
-		++ mStat.maxDepthNodes;
-
-	if (data.mPvs < mTermMinPvs)
-		++ mStat.minPvsNodes;
-
-	if ((int)data.mRays->size() < mTermMinRays)
-		++ mStat.minRaysNodes;
-
-	if (data.GetAvgRayContribution() > mTermMaxRayContribution)
-		++ mStat.maxRayContribNodes;
-	
-	if (data.mGeometry->GetArea() <= mTermMinArea) 
-		++ mStat.minAreaNodes;
 
 #ifdef _DEBUG
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 474)
@@ -344,7 +344,4 @@
 
 	app << "#N_SPLITS ( Number of splits )\n" << splits << "\n";
-
-	app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n" 
-		<<	maxDepthNodes * 100 / (double)Leaves() << endl;
 
 	app << "#N_PMAXDEPTHLEAVES ( Percentage of leaves at maximum depth )\n" 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 474)
@@ -165,5 +165,5 @@
   if (!use2dSampling) {
 	Vector3 normal;
-	int i = RandomValue(0, mObjects.size()-1);
+	int i = (int)RandomValue(0, (Real)((int)mObjects.size()-1));
 	Intersectable *object = mObjects[i];
 	object->GetRandomSurfacePoint(point, normal);
@@ -561,6 +561,4 @@
 
 	mViewCellsManager->Visualize(mObjects, storedRays);
-
-	Debug << "here2" << endl;
   }
 
@@ -569,8 +567,8 @@
   
   mRenderSimulator->RenderScene();
-  Debug << "here3" << endl;
+  
   SimulationStatistics ss;
   mRenderSimulator->GetStatistics(ss);
-  Debug << "here244" << endl;
+  
   cout << " finished" << endl;
   cout << ss << endl;
@@ -579,5 +577,4 @@
   delete vssTree;
 
-  Debug << "here4" << endl;
   return true;
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 474)
@@ -477,13 +477,13 @@
 #if 0
 			return
-				leafa->rays.size()*a.mBox.GetVolume()
+				leafa->rays.size() * a.mBox.GetVolume()
 				<
-				leafb->rays.size()*b.mBox.GetVolume();
+				leafb->rays.size() * b.mBox.GetVolume();
 #endif
 #if 1
 			return
-				leafa->GetPvsSize()*a.mBox.GetVolume()
+				leafa->GetPvsSize() * a.mBox.GetVolume()
 				<
-				leafb->GetPvsSize()*b.mBox.GetVolume();
+				leafb->GetPvsSize() * b.mBox.GetVolume();
 #endif
 #if 0
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 473)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 474)
@@ -268,5 +268,4 @@
 	const int limit = min(mConstructionSamples, (int)sourceRays.size());
 
-	Debug << "size: " << sourceRays.size() << " limit " << limit << endl;
 	VssRayContainer::const_iterator it, it_end = sourceRays.end();
 	
@@ -478,5 +477,4 @@
 
 	}
-
 
 	cout << "starting post processing using " << mPostProcessSamples << " samples ... ";
@@ -1422,7 +1420,6 @@
 
 	GetRaySets(rays, constructionRays, savedRays);
-	Debug << "rays " << rays.size() << " construction rays " << constructionRays.size() << endl;
+	
 	mVspBspTree->Construct(constructionRays);
-	
 	mVspBspTree->CollectViewCells(mViewCells);
 	
@@ -1631,5 +1628,4 @@
 	bool exportGeometry = false;
 
-	Debug << "here344" << endl;
 	environment->GetBoolValue("VspBspTree.Visualization.exportRays", exportRays);
 	environment->GetBoolValue("VspBspTree.Visualization.exportGeometry", exportGeometry);
@@ -1687,6 +1683,6 @@
 			ObjectPvsMap::iterator it = vc->GetPvs().mEntries.begin();
 
-			exporter->SetWireframe();
-			//exporter->SetFilled();
+			//exporter->SetWireframe();
+			exporter->SetFilled();
 
 			Material m;//= RandomMaterial();
@@ -1843,5 +1839,4 @@
 		}
 	}
-	Debug << "here222211" << endl;
 }
 
