Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 399)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 400)
@@ -56,5 +56,5 @@
 
 Sampling {
-	totalSamples	100000
+	totalSamples	300000
 	samplesPerPass  3
 }
@@ -88,5 +88,5 @@
 	#	input fromViewCells
 	#	input fromSceneGeometry
-		samples 50000
+		samples 100000
 		sideTolerance 0.005
 	}
@@ -126,5 +126,5 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 8
+	splitPlaneStrategy 1024
 	
 	maxPolyCandidates 50
@@ -133,9 +133,9 @@
 	Termination {
 		# autopartition
-		maxRays 200
-		maxPolygons 20
-		maxDepth 30
-		minPvs -1
-		minArea -0.001
+		maxRays 100
+		maxPolygons 10
+		maxDepth 50
+		minPvs 20
+		minArea 0.001
 		
 		# axis aligned splits
@@ -158,5 +158,5 @@
 		exportSplits true
 		# how much samples should be used in visualization
-		samples 100000
+		samples 1000
 	}
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 399)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 400)
@@ -345,5 +345,5 @@
 		/// area of current node
 		float mArea;
-		BspNodeGeometry *mCell;
+		BspNodeGeometry *mGeometry;
 
 		/// pvs size
@@ -358,5 +358,5 @@
 		mPvs(0),
 		mArea(0.0),
-		mCell(NULL)
+		mGeometry(NULL)
 		{}
 		
@@ -376,5 +376,5 @@
 		mPvs(pvs),
 		mArea(area),
-		mCell(cell)
+		mGeometry(cell)
 		{}
     };
@@ -541,7 +541,5 @@
 	*/
 	Plane3 SelectPlane(BspLeaf *leaf, 
-					   BspTraversalData &data,
-					   BspTraversalData &frontData,
-					   BspTraversalData &backData);
+					   BspTraversalData &data);
 
 	/** Evaluates the contribution of the candidate split plane.
@@ -554,7 +552,5 @@
 	*/
 	float SplitPlaneCost(const Plane3 &candidatePlane,
-						 BspTraversalData &data,
-						 BspTraversalData &frontData,
-						 BspTraversalData &backData) const;
+						 BspTraversalData &data) const;
 
 	/** Strategies where the effect of the split plane is tested
@@ -574,7 +570,5 @@
 						 const int pvs,
 						 const float area,
-						 const BspNodeGeometry &cell, 
-						 BspTraversalData &frontData,
-						 BspTraversalData &backData) const;
+						 const BspNodeGeometry &cell) const;
 
 	/** Filters next view cell down the tree and inserts it into the appropriate leaves
@@ -624,7 +618,5 @@
 	*/
 	Plane3 SelectPlaneHeuristics(BspLeaf *leaf,
-								 BspTraversalData &data,
-								 BspTraversalData &frontData,
-								 BspTraversalData &backData);
+								 BspTraversalData &data);
 
 	/** Extracts the meshes of the objects and adds them to polygons. 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 399)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 400)
@@ -17,5 +17,5 @@
 int BspTree::sTermMinPvs = 20;
 int BspTree::sTermMaxDepth = 20;
-float BspTree::sTermMinArea = 0.001;
+float BspTree::sTermMinArea = 0.001f;
 int BspTree::sMaxPolyCandidates = 10;
 int BspTree::sMaxRayCandidates = 10;
@@ -747,5 +747,5 @@
 		DEL_PTR(tData.mPolygons);
 		DEL_PTR(tData.mRays);
-		DEL_PTR(tData.mCell);
+		DEL_PTR(tData.mGeometry);
 		
 		return leaf;
@@ -762,7 +762,7 @@
 	
 	BspTraversalData tFrontData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell, 
-								new BoundedRayContainer(), 0, NULL, 0);
+								new BoundedRayContainer(), 0, 0, new BspNodeGeometry());
 	BspTraversalData tBackData(NULL, new PolygonContainer(), tData.mDepth + 1, mRootCell, 
-							   new BoundedRayContainer(), 0, NULL, 0);
+							   new BoundedRayContainer(), 0, 0, new BspNodeGeometry());
 
 	// create new interior node and two leaf nodes
@@ -801,5 +801,5 @@
 	DEL_PTR(tData.mPolygons);
 	DEL_PTR(tData.mRays);
-	DEL_PTR(tData.mCell);		
+	DEL_PTR(tData.mGeometry);		
 
 	return interior;
@@ -844,5 +844,5 @@
 	// select subdivision plane
 	BspInterior *interior = 
-		new BspInterior(SelectPlane(leaf, tData, frontData, backData)); 
+		new BspInterior(SelectPlane(leaf, tData)); 
 
 #ifdef _DEBUG
@@ -858,4 +858,18 @@
 											*backData.mPolygons, 
 											coincident);
+
+	// split geometry
+	tData.mGeometry->SplitGeometry(*frontData.mGeometry, *backData.mGeometry, 
+								   *this, interior->mPlane);
+	
+	// compute area
+	frontData.mArea = frontData.mGeometry->GetArea();
+	backData.mArea = backData.mGeometry->GetArea();
+
+	// compute pvs
+	frontData.mPvs = ComputePvsSize(*frontData.mRays);
+	backData.mPvs = ComputePvsSize(*backData.mRays);
+
+
 
 	BspInterior *parent = leaf->GetParent();
@@ -1022,7 +1036,5 @@
 
 Plane3 BspTree::SelectPlane(BspLeaf *leaf, 
-							BspTraversalData &data,
-							BspTraversalData &frontData,
-							BspTraversalData &backData)
+							BspTraversalData &data)
 {
 	if (data.mPolygons->empty() && data.mRays->empty())
@@ -1068,11 +1080,9 @@
 
 	// use heuristics to find appropriate plane
-	return SelectPlaneHeuristics(leaf, data, frontData, backData); 
+	return SelectPlaneHeuristics(leaf, data); 
 }
 
 Plane3 BspTree::SelectPlaneHeuristics(BspLeaf *leaf,
-									  BspTraversalData &data,
-									  BspTraversalData &frontData,
-									  BspTraversalData &backData)
+									  BspTraversalData &data)
 {
 	float lowestCost = MAX_FLOAT;
@@ -1091,5 +1101,5 @@
 		// evaluate current candidate
 		const float candidateCost = 
-			SplitPlaneCost(poly->GetSupportingPlane(), data, frontData, backData);
+			SplitPlaneCost(poly->GetSupportingPlane(), data);
 
 		if (candidateCost < lowestCost)
@@ -1146,6 +1156,5 @@
 		}
 		
-		const float candidateCost = 
-			SplitPlaneCost(plane, data, frontData, backData);
+		const float candidateCost = SplitPlaneCost(plane, data);
 
 		if (candidateCost < lowestCost)
@@ -1315,7 +1324,5 @@
 							  const int pvs,
 							  const float area,
-							  const BspNodeGeometry &cell, 
-							  BspTraversalData &frontData,
-							  BspTraversalData &backData) const
+							  const BspNodeGeometry &cell) const
 {
 	float val = 0;
@@ -1328,8 +1335,6 @@
 	int frontAndBackId = 0;
 
-	frontData.mPvs = 0;
-	backData.mPvs = 0;
-	frontData.mArea = 0;
-	backData.mArea = 0;
+	int frontPvs = 0;
+	int backPvs = 0;
 
 	// probability that view point lies in child
@@ -1348,11 +1353,11 @@
 		{	
 			// construct child geometry with regard to the candidate split plane
-			frontData.mCell = new BspNodeGeometry();
-			backData.mCell = new BspNodeGeometry();
-
-			cell.SplitGeometry(*frontData.mCell, *backData.mCell, *this, candidatePlane);
-		
-			pFront = frontData.mArea = frontData.mCell->GetArea();
-			pBack = backData.mArea = backData.mCell->GetArea();
+			BspNodeGeometry frontCell;
+			BspNodeGeometry backCell;
+
+			cell.SplitGeometry(frontCell, backCell, *this, candidatePlane);
+		
+			pFront = frontCell.GetArea();
+			pBack = backCell.GetArea();
 
 			pOverall = area;
@@ -1392,5 +1397,5 @@
 				// assure that we only count a object 
 				// once for the front and once for the back side of the plane
-				IncPvs(*ray->intersections[0].mObject, frontData.mPvs, backData.mPvs, 
+				IncPvs(*ray->intersections[0].mObject, frontPvs, backPvs, 
 					   cf, frontId, backId, frontAndBackId);
 			}
@@ -1399,5 +1404,5 @@
 			if (ray->sourceObject.mObject)
 			{
-				IncPvs(*ray->sourceObject.mObject, frontData.mPvs, backData.mPvs, 
+				IncPvs(*ray->sourceObject.mObject, frontPvs, backPvs, 
 					   cf, frontId, backId, frontAndBackId);
 			}
@@ -1419,14 +1424,14 @@
 	if ((sSplitPlaneStrategy & BALANCED_RAYS) && !rays.empty())
 			val += sBalancedRaysFactor * fabs(sumBalancedRays) / (float)rays.size();
-pOverall = 1; pFront = 1; pBack = 1;
+
 	if ((sSplitPlaneStrategy & PVS) && area && pvs)
-		val += sPvsFactor * (frontData.mPvs * pFront + (backData.mPvs * pBack)) /
+		val += sPvsFactor * (frontPvs * pFront + (backPvs * pBack)) /
 			   (pOverall * (float)pvs * 2);
 
-	Debug << "totalpvs: " << pvs << " ptotal: " << pOverall
-		  << " frontpvs: " << frontData.mPvs << " pFront: " << pFront 
-		  << " backpvs: " << backData.mPvs << " pBack: " << pBack 
+/*	Debug << "totalpvs: " << pvs << " ptotal: " << pOverall
+		  << " frontpvs: " << frontPvs << " pFront: " << pFront 
+		  << " backpvs: " << backPvs << " pBack: " << pBack 
 		  << " val " << val << endl;
-
+*/
 	return val;
 }
@@ -1485,7 +1490,5 @@
 
 float BspTree::SplitPlaneCost(const Plane3 &candidatePlane,
-							  BspTraversalData &data,
-							  BspTraversalData &frontData,
-							  BspTraversalData &backData) const
+							  BspTraversalData &data) const
 {
 	float val = 0;
@@ -1516,5 +1519,5 @@
 	{
 		val += SplitPlaneCost(candidatePlane, *data.mRays, data.mPvs, 
-							  data.mArea, *data.mCell, frontData, backData);
+							  data.mArea, *data.mGeometry);
 	}
 
@@ -2403,6 +2406,6 @@
 	}
 
-	Debug << "returning new geometry " << mPolys.size() << " f: " << front.mPolys.size() << " b: " << back.mPolys.size() << endl;
-	Debug << "old area " << GetArea() << " f: " << front.GetArea() << " b: " << back.GetArea() << endl;
+	//Debug << "returning new geometry " << mPolys.size() << " f: " << front.mPolys.size() << " b: " << back.mPolys.size() << endl;
+	//Debug << "old area " << GetArea() << " f: " << front.GetArea() << " b: " << back.GetArea() << endl;
 }
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 399)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 400)
@@ -726,5 +726,5 @@
 			// throw away samples because BSP leaves not stored in order 
 			// Need ordered rays for post processing => collect new rays
-			//CLEAR_CONTAINER(mSampleRays);
+			CLEAR_CONTAINER(mSampleRays);
 		}
 	}
@@ -885,6 +885,6 @@
 			ViewCellPvsMap::iterator it = vc->GetPvs().mEntries.begin();
 
-			//exporter->SetWireframe();
-			exporter->SetFilled();
+			exporter->SetWireframe();
+			//exporter->SetFilled();
 
 			Material m;//= RandomMaterial();
@@ -907,5 +907,5 @@
 
 			// export rays piercing this view cell
-			exporter->ExportRays(vcRays[i], 10000, RgbColor(0, 1, 0));
+			exporter->ExportRays(vcRays[i], 1000, RgbColor(0, 1, 0));
 
 			m.mDiffuseColor = RgbColor(1, 0, 0);
@@ -982,5 +982,5 @@
 			Exporter *exporter = Exporter::GetExporter(s);
 			
-			exporter->SetFilled();//Wireframe();
+			exporter->SetWireframe();
 
 			Material m;//= RandomMaterial();
