Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 428)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 430)
@@ -10,4 +10,6 @@
 #	filename ../data/vienna/vienna-simple.x3d
 #	filename ../data/vienna/vienna-buildings.x3d
+#filename ../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d
+#;../data/vienna/vienna-plane.x3d
 #	filename ../data/vienna/viewcells-25-sel.x3d
 	filename ../data/atlanta/atlanta2.x3d
@@ -16,4 +18,40 @@
 }
 
+Preprocessor {
+#	type sampling
+	type vss
+}
+
+VssPreprocessor {
+	samplesPerPass  100000
+	initialSamples 200000
+	vssSamples 300000
+	vssSamplesPerPass 100000
+	useImportanceSampling true
+}
+
+VssTree {
+	epsilon		1e-6
+
+	maxDepth 	40
+	minPvs		3
+	minRays		100
+	minSize		0.001
+  maxCostRatio	0.98
+	maxRayContribution 0.05
+	
+	maxTotalMemory	200
+	maxStaticMemory	50
+
+	splitType regular
+#	splitType heuristics
+
+	numberOfEndPointDomains	10000
+	ct_div_ci	0.0
+	randomize	false
+
+	refDirBoxMaxSize	0.1
+}
+
 Limits {
 
@@ -23,10 +61,4 @@
 }
 
-Preprocessor {
-	type sampling
-#	type exact
-#	type vss
-}
-
 Unigraphics {
 		meshGrouping 1
@@ -36,5 +68,5 @@
 	sahUseFaces true
 	Termination {
-		minCost 2
+		minCost 1
 		maxDepth 18
 		maxCostRatio 0.9
@@ -49,5 +81,5 @@
 MeshKdTree {
 	Termination {
-		minCost 4
+		minCost 1
 		maxDepth 18
 		maxCostRatio 0.9
@@ -62,5 +94,5 @@
 
 Sampling {
-	totalSamples	600000
+	totalSamples 600000
 	samplesPerPass  3
 }
@@ -68,7 +100,7 @@
 ViewCells {
 	#hierarchy kdTree
-	hierarchy vspTree
-	#hierarchy bspTree
-	# hierarchy sceneDependent
+	#hierarchy vspTree
+	hierarchy bspTree
+	#hierarchy sceneDependent
 	
 	height 5.0
@@ -196,5 +228,5 @@
 
 	maxDepth 	40
-	minPvs		1
+	minPvs		100
 	minRays		50
 	minSize		0.00001
@@ -223,10 +255,10 @@
 	
 	Termination {
-		maxDepth 	30
-		minPvs		60
-		minRays		1
-		minSize		0.1
-		maxCostRatio	999.0
-		maxRayContribution 0.2
+		maxDepth	 	10
+		minPvs			500
+		minRays			1
+		minSize			0.1
+		maxCostRatio		999.0
+		maxRayContribution 	0.2
 	}
 	
@@ -234,6 +266,6 @@
 	maxStaticMemory	600
 
-	splitType regular
-#	splitType heuristics
+	splitType 	regular
+	#splitType 	heuristics
 	ct_div_ci	0.0
 }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp	(revision 419)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp	(revision 430)
@@ -24,5 +24,5 @@
 		return new BspViewCell(mesh);
 	default:
-		Debug << "should not come here" << endl;
+		Debug << "should not come here 3" << endl;
 		return NULL;
 	}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 428)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 430)
@@ -308,7 +308,7 @@
 	environment->GetIntValue("BspTree.Termination.AxisAligned.minPolys", 
 							 mTermMinPolysForAxisAligned);
-	environment->GetIntValue("BspTree.Termination.AxisAligned.maxRays", 
+	environment->GetIntValue("BspTree.Termination.AxisAligned.minRays", 
 							 mTermMinRaysForAxisAligned);
-	environment->GetIntValue("BspTree.Termination.AxisAligned.maxObjects", 
+	environment->GetIntValue("BspTree.Termination.AxisAligned.minObjects", 
 							 mTermMinObjectsForAxisAligned);
 	//-- partition criteria
@@ -1553,5 +1553,5 @@
 						break;
 					default:
-						Debug << "Should not come here" << endl;
+						Debug << "Should not come here 2" << endl;
 						break;
 				}
@@ -2093,5 +2093,5 @@
 			break;
 		default:
-			Debug << "Should not come here" << endl;
+			Debug << "Should not come here 4" << endl;
 			break;
 		}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp	(revision 427)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssTree.cpp	(revision 430)
@@ -986,4 +986,5 @@
 				(*ri).mRay->Unref();
 
+				Debug << "computed t: " << (*ri).mRay->mT << endl;
 				// determine the side of this ray with respect to the plane
 				int side = node->ComputeRayIntersection(*ri, (*ri).mRay->mT);
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp	(revision 428)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp	(revision 430)
@@ -223,5 +223,5 @@
 loc(vssRay.mOrigin),
 sourceObject(0, vssRay.mOriginObject, 0),
-dir(vssRay.GetDir())
+dir(Normalize(vssRay.GetDir()))
 {
 	intersections.push_back(Intersection(vssRay.mT, vssRay.mTerminationObject, 0));
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 429)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.h	(revision 430)
@@ -76,10 +76,12 @@
 		if (!ray.intersections.empty())
 		{
-			mTermination = ray.Extrap(ray.intersections[0].mT);
+			mT = ray.intersections[0].mT;
+			mTermination = ray.Extrap(mT);
 			mTerminationObject = ray.intersections[0].mObject;
 		}
 		else
 		{
-			mTermination = mOrigin + ray.GetDir() * 99999;
+			mT = 1e6;//Limits::Infinity;
+			mTermination = mOrigin + ray.GetDir() * mT;
 			mTerminationObject = NULL;
 		}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 429)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 430)
@@ -423,22 +423,29 @@
 	}
 
-
+	//-- construct BSP view cells
+	if (ViewCell::sHierarchy == ViewCell::BSP) 
+	{
+		const int bspSamples = min((int)mVssRays.size(), mBspConstructionSamples);
+	
+		for (int i = 0; i < bspSamples; ++ i)
+			bspRays.push_back(new Ray(*mVssRays[i]));
+
+		//-- construct BSP tree using the samples
+		mBspTree = new BspTree(&mUnbounded);	
+
+		mBspTree->SetGenerateViewCells(true);
+		mBspTree->Construct(bspRays);
+
+		Exporter *exporter = Exporter::GetExporter("vccbsprays.x3d");
+			
+		// export rays piercing this view cell
+		exporter->ExportRays(bspRays, 1000, RgbColor(0, 1, 0));
+
+		// cast remaining initial rays into BSP tree
+		for (int i = bspSamples; i < (int)mVssRays.size(); ++ i)
+			CastRay(*mBspTree, *mVssRays[i]);
+	}
 
 	vssTree = new VssTree;
-	
-	const int bspSamples = min((int)mVssRays.size(), mBspConstructionSamples);
-	
-	for (int i = 0; i < bspSamples; ++ i)
-		bspRays.push_back(new Ray(*mVssRays[i]));
-
-	mBspTree = new BspTree(&mUnbounded);	
-
-	mBspTree->SetGenerateViewCells(true);
-	mBspTree->Construct(bspRays);
-
-	for (int i = bspSamples; i < (int)mVssRays.size(); ++ i)
-	{
-		CastRay(*mBspTree, *mVssRays[i]);
-	}
 
 	vssTree->Construct(mVssRays, mViewSpaceBox);
@@ -486,10 +493,13 @@
 		}
 
-		
-		for (int i = 0; i < (int)vssRays.size(); ++ i)
+		// cast rays into BSP tree
+		if (ViewCell::sHierarchy == ViewCell::BSP) 
 		{
-			CastRay(*mBspTree, *mVssRays[i]);
-		}
-		
+			for (int i = 0; i < (int)vssRays.size(); ++ i)
+			{
+				CastRay(*mBspTree, *mVssRays[i]);
+			}
+		}
+
 		samples+=num;
 		float pvs = vssTree->GetAvgPvsSize();
@@ -505,9 +515,19 @@
 	delete vssTree;
 
-	ObjectContainer objects;
-	ExportSplits(objects, bspRays, 10000);
-	ExportBspPvs(objects, bspRays, 10000);
-
-	CLEAR_CONTAINER(bspRays);
+	if (ViewCell::sHierarchy == ViewCell::BSP) 
+	{
+		Debug << mBspTree->GetStatistics();
+
+		ObjectContainer objects;
+		ExportSplits(objects, bspRays, 10000);
+		ExportBspPvs(objects, bspRays, 10000);
+
+		BspViewCellsStatistics stat;
+		mBspTree->EvaluateViewCellsStats(stat);
+		Debug << "original view cell partition:\n" << stat << endl;
+
+		// clear BSP samples
+		CLEAR_CONTAINER(bspRays);
+	}
 
 	return true;
@@ -519,4 +539,10 @@
 	Ray ray(vssRay);
 
+	/*Debug << ray << endl;
+	if (ray.intersections.empty())
+		Debug << "empty ray" << endl;
+	else 
+		Debug << "intersection: " << ray.intersections[0].mT << " " << ray.intersections[0].mObject << endl;
+*/
 	mBspTree->CastRay(ray);
 				
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 427)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 430)
@@ -99,5 +99,6 @@
 
 ViewCells {
-	hierarchy kdTree
+	#hierarchy kdTree
+	hierarchy vspTree
 	#hierarchy bspTree
 	# hierarchy sceneDependent
@@ -106,6 +107,11 @@
 	maxViewCells 0
 	
+	PostProcessing {
 	minPvsDif 100
-#	maxPvsSize 200
+		minPvs 10
+		maxPvs 150
+		samples 100000
+	}
+
 	
 #	filename ../data/atlanta/atlanta_viewcells_large.x3d
@@ -117,8 +123,8 @@
 BspTree {
 	Construction {
-		input fromRays
+		input fromSamples
 	#	input fromViewCells
 	#	input fromSceneGeometry
-		samples 100000
+		samples 150000
 		sideTolerance 0.005
 	}
@@ -158,19 +164,40 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 1024
-	
-	maxCandidates 80
-	
-	Termination {
-		# autopartition
-		maxRays 200
-		maxPolygons 5
-		maxDepth 100
+	splitPlaneStrategy 12
+	
+	maxPolyCandidates 70
+	maxRayCandidates 100
+	
+	# factors for evaluating split plane costs
+	Factor {
+		verticalSplits 1.0
+	  	largestPolyArea 1.0
+	  	blockedRays 1.0
+	  	leastRaySplits 1.0
+	  	balancedRays 1.0
+	  	pvsFactor 1.0
+	  	leastSplits 1.0
+	  	balancedPolys 1.0
+	  	balancedViewCells 1.0
+	}
+	
+	Termination {
+		# parameters used for autopartition
+		minRays 200
+		minPolygons -1
+		maxDepth 40
+		minPvs 35
+		minArea 0.01
+		maxRayContribution 0.005
+		#maxAccRayLength 100
+		
+		# used for pvs criterium
+		ct_div_ci 0.0
 		
 		# axis aligned splits
 		AxisAligned {
-			maxPolys 5000
-			maxRays 5000
-			maxObjects 2000
+			minPolys 5000
+			minRays 500
+			minObjects 10
 			maxCostRatio 0.9
 			ct_div_ci 0.5
@@ -182,11 +209,63 @@
 	}
 	
-	PostProcessing {
-		samples 100000
-	}
 		
-	# if split polys are stored for visualization
-	storeSplitPolys false
+	Visualization {
 	# x3d visualization of the split planes
 	exportSplits true
-}
+		# how much samples should be used in visualization
+		samples 20000
+	}
+}
+
+Simulation {
+	objRenderCost 1.0
+	vcOverhead 7.0
+	moveSpeed 3.0
+}
+
+VssTree {
+	epsilon		1e-6
+
+	maxDepth 	40
+	minPvs		1
+	minRays		50
+	minSize		0.00001
+	maxCostRatio	0.95
+	maxRayContribution 0.05
+	
+	maxTotalMemory	400
+	maxStaticMemory	20
+
+	splitType regular
+#	splitType heuristics
+
+	numberOfEndPointDomains	10000
+	ct_div_ci	0.0
+	randomize	false
+
+	refDirBoxMaxSize	0.1
+}
+
+VspKdTree {
+	epsilon		1e-6
+
+	Construction {
+		samples 500000
+	}
+	
+	Termination {
+		maxDepth 	30
+		minPvs		60
+		minRays		1
+		minSize		0.1
+		maxCostRatio	999.0
+		maxRayContribution 0.2
+	}
+	
+	maxTotalMemory	600
+	maxStaticMemory	600
+
+	splitType regular
+#	splitType heuristics
+	ct_div_ci	0.0
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 429)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 430)
@@ -574,9 +574,8 @@
 		int pvsSize = 0;
 
+		Debug << "overall scene size: " << (int)objects.size() << endl;
+		
 		BspViewCellsStatistics stat;
-		
-		Debug << "overall scene size: " << (int)objects.size() << endl;
 		mBspTree->EvaluateViewCellsStats(stat);
-		
 		Debug << "original view cell partition:\n" << stat << endl;
 		
@@ -820,10 +819,12 @@
 	{
 		// store samples for vsp kd tree construction
-		if ((object || !ray.intersections.empty()) && 
-			((int)mVspSampleRays.size() < mVspConstructionSamples))
-		{
-			ray.sourceObject = Ray::Intersection(0.0, object, faceIndex);
-			VssRay *sRay = new VssRay(ray);
-			mVspSampleRays.push_back(sRay);
+		if ((int)mVspSampleRays.size() < mVspConstructionSamples)
+		{
+			if (object || !ray.intersections.empty())
+			{
+				ray.sourceObject = Ray::Intersection(0.0, object, faceIndex);
+				VssRay *sRay = new VssRay(ray);
+				mVspSampleRays.push_back(sRay);
+			}
 		}
 		else
