Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 444)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 445)
@@ -102,5 +102,7 @@
 	#type kdTree
 	#type vspTree
-	type bspTree
+	#type bspTree
+	type vspBspTree
+	
 	#type sceneDependent
 	
@@ -112,7 +114,12 @@
 		minPvs 10
 		maxPvs 150
+		# how much samples are used for post processing
 		samples 10
 	}
 
+	Visualization {
+		# how much samples are be used for visualization
+		samples 90000
+	}
 	
 #	filename ../data/atlanta/atlanta_viewcells_large.x3d
@@ -176,5 +183,5 @@
 	  	leastRaySplits 1.0
 	  	balancedRays 1.0
-	  	pvsFactor 1.0
+	  	pvs 1.0
 	  	leastSplits 1.0
 	  	balancedPolys 1.0
@@ -213,6 +220,4 @@
 		# x3d visualization of the split planes
 		exportSplits true
-		# how much samples should be used in visualization
-		samples 90000
 	}
 }
@@ -270,2 +275,65 @@
 	ct_div_ci	0.0
 }
+
+VspBspTree {
+	Construction {
+		samples 200000
+		sideTolerance 0.005
+	}
+
+
+	# random polygon       = 1
+	# axis aligned         = 2
+	# least ray splits     = 256
+	# balanced rays        = 512
+	# pvs                  = 1024
+
+	splitPlaneStrategy 1024
+	
+	# maximal candidates for split planes
+	maxPolyCandidates 50
+	maxRayCandidates 50
+	
+	# maximal tested rays for split cost heuristics
+	maxTests 10000
+	
+	# factors for evaluating split plane costs
+	Factor {
+		leastRaySplits 1.0
+	  	balancedRays 1.0
+	  	pvs 1.0
+	}
+	
+	Termination {
+		# parameters used for autopartition
+		minRays 200
+		minPolygons -1
+		maxDepth 50
+		minPvs 100
+		minArea 0.01
+		maxRayContribution 0.005
+		#maxAccRayLength 100
+		
+		# used for pvs criterium
+		ct_div_ci 0.0
+	
+		# axis aligned splits
+		AxisAligned {
+			minPolys 5000
+			minRays 500
+			minObjects 10
+			maxCostRatio 0.9
+			ct_div_ci 0.5
+		}
+	}
+	
+	AxisAligned {
+		splitBorder 0.01
+	}
+	
+	
+	Visualization {
+		# x3d visualization of the split planes
+		exportSplits true
+	}
+}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 443)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 445)
@@ -329,5 +329,10 @@
 };
 
-/** Implementation of the view cell BSP tree. 
+/**
+	This is a view space partitioning specialised BSPtree.  
+	There are no polygon splits, but we split the sample rays. 
+	The candidates for the next split plane are evaluated only 
+	by checking the sampled	visibility information. 
+	The polygons are employed merely as candidates for the next split planes.
 */
 class VspBspTree 
@@ -409,5 +414,5 @@
 		@param sampleRays the set of sample rays the construction is based on
 		@param viewCells if not NULL, new view cells are 
-		created in the leafs and stored in the conatainer
+		created in the leafs and stored in the container
 	*/
 	void Construct(const VssRayContainer &sampleRays);
@@ -475,16 +480,4 @@
 	*/
 	VspBspLeaf *GetRandomLeaf(const bool onlyUnmailed = false);
-
-	/** Returns true if merge criteria are reached.
-	*/
-    bool ShouldMerge(VspBspLeaf *front, VspBspLeaf *back) const;
-
-	/** Merges view cells based on some criteria
-	    E.g., empty view cells can pe purged, view cells which have 
-		a very similar PVS can be merged to one larger view cell.
-
-		@returns true if merge was successful.
-	*/
-	bool MergeViewCells(VspBspLeaf *front, VspBspLeaf *back) const;
 
 	/** Traverses tree and counts all view cells as well as their PVS size.
@@ -704,10 +697,4 @@
 		  RANDOM_POLYGON = 1, 
 		  AXIS_ALIGNED = 2,
-		  LEAST_SPLITS = 4, 
-		  BALANCED_POLYS = 8,
-		  BALANCED_VIEW_CELLS = 16,
-		  LARGEST_POLY_AREA = 32,
-		  VERTICAL_AXIS = 64,
-		  BLOCKED_RAYS = 128,
 		  LEAST_RAY_SPLITS = 256,
 		  BALANCED_RAYS = 512,
@@ -746,23 +733,16 @@
 	/// number of candidates for split planes evaluated using the rays
 	int mMaxRayCandidates;
-	
+	/// balancing factor for PVS criterium
 	float mCtDivCi;
 
-	/// axis aligned split criteria
+	//-- axis aligned split criteria
 	float mAaCtDivCi;
 	float mSplitBorder;
 	float mMaxCostRatio;
 
-	// factors guiding the split plane heuristics
-	float mBlockedRaysFactor;
+	//-- factors guiding the split plane heuristics
 	float mLeastRaySplitsFactor;
 	float mBalancedRaysFactor;
 	float mPvsFactor;
-	float mLeastSplitsFactor;
-
-	//-- thresholds used for view cells merge
-	int mMinPvsDif;
-	int mMinPvs;
-	int mMaxPvs;
 
 	/// if area or accumulated ray lenght should be used for PVS heuristics
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 444)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 445)
@@ -236,6 +236,5 @@
 	//-- factors for bsp tree split plane heuristics
 	environment->GetFloatValue("VspBspTree.Factor.balancedRays", mBalancedRaysFactor);
-	environment->GetFloatValue("VspBspTree.Factor.pvsFactor", mPvsFactor);
-	environment->GetFloatValue("VspBspTree.Factor.leastSplits" , mLeastSplitsFactor);
+	environment->GetFloatValue("VspBspTree.Factor.pvs", mPvsFactor);
 	environment->GetFloatValue("VspBspTree.Termination.ct_div_ci", mCtDivCi);
 
@@ -255,9 +254,4 @@
 	environment->GetFloatValue("VspBspTree.Construction.sideTolerance", Vector3::sDistTolerance);
 	Vector3::sDistToleranceSqrt = Vector3::sDistTolerance * Vector3::sDistTolerance;
-
-	// post processing stuff
-	environment->GetIntValue("ViewCells.PostProcessing.minPvsDif", mMinPvsDif);
-	environment->GetIntValue("ViewCells.PostProcessing.minPvs", mMinPvs);
-	environment->GetIntValue("ViewCells.PostProcessing.maxPvs", mMaxPvs);
 
     Debug << "BSP max depth: " << mTermMaxDepth << endl;
@@ -273,10 +267,4 @@
 	if (mSplitPlaneStrategy & AXIS_ALIGNED)
 		Debug << "axis aligned ";
-	if (mSplitPlaneStrategy & LEAST_SPLITS)     
-		Debug << "least splits ";
-	if (mSplitPlaneStrategy & VERTICAL_AXIS)
-		Debug << "vertical axis ";
-	if (mSplitPlaneStrategy & BLOCKED_RAYS)
-		Debug << "blocked rays ";
 	if (mSplitPlaneStrategy & LEAST_RAY_SPLITS)
 		Debug << "least ray splits ";
@@ -1451,64 +1439,4 @@
 }
 
-bool VspBspTree::MergeViewCells(VspBspLeaf *front, VspBspLeaf *back) const
-{
-	BspViewCell *viewCell = 
-	NULL;//TODO	dynamic_cast<BspViewCell *>(ViewCell::Merge(*front->mViewCell, *back->mViewCell));
-	
-	if (!viewCell)
-		return false;
-
-	// change view cells of all leaves associated with the previous view cells
-	BspViewCell *fVc = front->mViewCell;
-	BspViewCell *bVc = back->mViewCell;
-
-	//TODO 
-	/*
-	vector<VspBspLeaf *> fLeaves = fVc->mVspBspLeaves;
-	vector<VspBspLeaf *> bLeaves = bVc->mVspBspLeaves;
-
-	vector<VspBspLeaf *>::const_iterator it;
-	
-	for (it = fLeaves.begin(); it != fLeaves.end(); ++ it)
-	{
-		(*it)->SetViewCell(viewCell);
-		viewCell->mVspBspLeaves.push_back(*it);
-	}
-	for (it = bLeaves.begin(); it != bLeaves.end(); ++ it)
-	{
-		(*it)->SetViewCell(viewCell);
-		viewCell->mVspBspLeaves.push_back(*it);
-	}
-	
-	DEL_PTR(fVc);
-	DEL_PTR(bVc);
-*/
-	return true;
-}
-
-bool VspBspTree::ShouldMerge(VspBspLeaf *front, VspBspLeaf *back) const
-{
-	ViewCell *fvc = front->mViewCell;
-	ViewCell *bvc = back->mViewCell;
-
-	if ((fvc == mRootCell) || (bvc == mRootCell) || (fvc == bvc))
-		return false;
-
-	int fdiff = fvc->GetPvs().Diff(bvc->GetPvs());
-
-	if (fvc->GetPvs().GetSize() + fdiff < mMaxPvs)
-	{
-		if ((fvc->GetPvs().GetSize() < mMinPvs) ||	
-			(bvc->GetPvs().GetSize() < mMinPvs) ||
-			((fdiff < mMinPvsDif) && (bvc->GetPvs().Diff(fvc->GetPvs()) < mMinPvsDif)))
-		{
-			return true;
-		}
-	}
-	
-	return false;
-}
-
-
 VspBspTreeStatistics &VspBspTree::GetStat()
 {
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 441)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 445)
@@ -1175,4 +1175,10 @@
 								 "true");
 
+
+  /************************************************************************************/
+  /*                         View cells related options                               */
+  /************************************************************************************/
+
+
   RegisterOption("ViewCells.type",
 		 optString,
@@ -1180,4 +1186,14 @@
 		 "bspTree");
 
+  RegisterOption("ViewCells.PostProcessing.samples",
+	  optInt,
+	  "-bsp_postprocessing_samples=",
+	  "200000");
+
+  RegisterOption("ViewCells.Visualization.samples",
+	  optInt,
+	  "-view_cells_visualization_samples=",
+	  "20000");
+
    RegisterOption("ViewCells.loadFromFile",
 		 optBool,
@@ -1215,4 +1231,9 @@
 		 "5.0");
    
+  /************************************************************************************/
+  /*                         Render simulation related options                        */
+  /************************************************************************************/
+
+
   RegisterOption("Simulation.objRenderCost",
 		 optFloat,
@@ -1229,4 +1250,12 @@
 		 "-simulation_moveSpeed",
 		 "1.0");
+
+
+
+
+  /************************************************************************************/
+  /*                         Bsp tree related options                                 */
+  /************************************************************************************/
+
 
   RegisterOption("BspTree.Construction.input",
@@ -1240,9 +1269,4 @@
 	  "100000");
 
-  RegisterOption("ViewCells.PostProcessing.samples",
-	  optInt,
-	  "-bsp_postprocessing_samples=",
-	  "200000");
-
   RegisterOption("BspTree.Construction.sideTolerance",
 	  optFloat,
@@ -1340,9 +1364,4 @@
 	  "5000");
 
-  RegisterOption("BspTree.Visualization.samples",
-	  optInt,
-	  "-bsp_visualization_samples=",
-	  "20000");
-
   RegisterOption("BspTree.Visualization.exportSplits",
 	  optBool,
@@ -1353,10 +1372,14 @@
   RegisterOption("BspTree.Factor.largestPolyArea", optFloat, "-bsp_factor_largest_poly=", "1.0");
   RegisterOption("BspTree.Factor.blockedRays", optFloat, "-bsp_factor_blocked=", "1.0");
-  RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "-bsp_factor_least_ray_splits=", "1.0");
-  RegisterOption("BspTree.Factor.balancedRays", optFloat, "-bsp_factor_balanced_rays=", "1.0");
-  RegisterOption("BspTree.Factor.pvsFactor", optFloat, "-bsp_factor_pvs=", "1.0");
   RegisterOption("BspTree.Factor.leastSplits", optFloat, "-bsp_factor_least_splits=", "1.0");
   RegisterOption("BspTree.Factor.balancedPolys", optFloat, "-bsp_factor_balanced_polys=", "1.0");
   RegisterOption("BspTree.Factor.balancedViewCells", optFloat, "-bsp_factor_balanced_view_cells=", "1.0");
+  RegisterOption("BspTree.Factor.leastRaySplits", optFloat, "-bsp_factor_least_ray_splits=", "1.0");
+  RegisterOption("BspTree.Factor.balancedRays", optFloat, "-bsp_factor_balanced_rays=", "1.0");
+  RegisterOption("BspTree.Factor.pvs", optFloat, "-bsp_factor_pvs=", "1.0");
+
+  /************************************************************************************/
+  /*                         Preprocessor related options                             */
+  /************************************************************************************/
 
   RegisterOption("Preprocessor.type",
@@ -1366,4 +1389,8 @@
 
 
+  /**************************************************************************************/
+  /*                  View space partition KD tree related options                      */
+  /**************************************************************************************/
+
   RegisterOption("VspKdTree.Construction.samples",
 		 optInt,
@@ -1449,4 +1476,8 @@
 	  "4");
   
+  /************************************************************************************/
+  /*                   VSS Preprocessor cells related options                         */
+  /************************************************************************************/
+
   RegisterOption("VssTree.maxDepth", optInt, "kd_depth=", "12");
   RegisterOption("VssTree.minPvs", optInt, "kd_minpvs=", "1");
@@ -1462,7 +1493,4 @@
 
   RegisterOption("VssTree.useRss", optBool, "rss=", "false");
-
-
-
   RegisterOption("VssTree.numberOfEndPointDomains", optInt, "endpoints=", "10000");
 
@@ -1486,4 +1514,111 @@
 
 
+
+  /************************************************************************************/
+  /*               View space partition BSP tree related options                      */
+  /************************************************************************************/
+
+
+  RegisterOption("VspBspTree.Termination.minPolygons",
+		 optInt,
+		 "-vsp_bsp_term_min_polygons=",
+		 "5");
+
+  RegisterOption("VspBspTree.Termination.minPvs",
+		 optInt,
+		 "-vsp_bsp_term_min_pvs=",
+		 "20");
+
+  RegisterOption("VspBspTree.Termination.minArea",
+		 optFloat,
+		 "-vsp_bsp_term_min_area=",
+		 "0.001");
+  
+  RegisterOption("VspBspTree.Termination.maxRayContribution",
+		 optFloat,
+		 "-vsp_bsp_term_ray_contribution=",
+		 "0.005");
+
+  RegisterOption("VspBspTree.Termination.minAccRayLenght",
+		 optFloat,
+		 "-vsp_bsp_term_min_acc_ray_length=",
+		 "50");
+
+   RegisterOption("VspBspTree.Termination.minRays",
+		 optInt,
+		 "-vsp_bsp_term_min_rays=",
+		 "-1");
+
+   RegisterOption("VspBspTree.Termination.ct_div_ci",
+		 optFloat,
+		 "-vsp_bsp_term_ct_div_ci=",
+		 "0.0");
+  
+  RegisterOption("VspBspTree.Termination.maxDepth",
+		 optInt,
+		 "-vsp_bsp_term_max_depth=",
+		 "100");
+
+  RegisterOption("VspBspTree.Termination.AxisAligned.maxCostRatio",
+		 optFloat,
+		 "-vsp_bsp_term_axis_aligned_max_cost_ratio=",
+		 "1.5");
+
+  
+  RegisterOption("VspBspTree.Termination.AxisAligned.ct_div_ci",
+		 optFloat,
+		 "-vsp_bsp_term_axis_aligned_ct_div_ci=",
+		 "0.5");
+
+  RegisterOption("VspBspTree.AxisAligned.splitBorder",
+		 optFloat,
+		 "-vsp_bsp__axis_aligned_split_border=",
+		 "0.1");
+
+  RegisterOption("VspBspTree.Termination.AxisAligned.minPolys",
+		 optInt,
+		 "-vsp_bsp_term_axis_aligned_max_polygons=",
+		 "50");
+
+   RegisterOption("VspBspTree.Termination.AxisAligned.minObjects",
+		 optInt,
+		 "-vsp_bsp_term_min_objects=",
+		 "3");
+
+  RegisterOption("VspBspTree.Termination.AxisAligned.minRays",
+		 optInt,
+		 "-vsp_bsp_term_axis_aligned_min_rays=",
+		 "-1");
+
+  RegisterOption("VspBspTree.splitPlaneStrategy",
+		 optString,
+		 "-vsp_bsp_split_method=",
+		 "leastSplits");
+
+  RegisterOption("VspBspTree.maxPolyCandidates",
+	  optInt,
+	  "-vsp_bsp_max_poly_candidates=",
+	  "20");
+
+  RegisterOption("VspBspTree.maxRayCandidates",
+	  optInt,
+	  "-vsp_bsp_max_plane_candidates=",
+	  "20");
+
+  RegisterOption("VspBspTree.maxTests",
+	  optInt,
+	  "-vsp_bsp_max_tests=",
+	  "5000");
+
+  RegisterOption("VspBspTree.Visualization.exportSplits",
+	  optBool,
+	  "-vsp_bsp_visualization.exportSplits",
+	  "false");
+
+   RegisterOption("VspBspTree.Factor.leastRaySplits", optFloat, "-vsp_bsp_factor_least_ray_splits=", "1.0");
+   RegisterOption("VspBspTree.Factor.balancedRays", optFloat, "-vsp_bsp_factor_balanced_rays=", "1.0");
+   RegisterOption("VspBspTree.Factor.pvs", optFloat, "-vsp_bsp_factor_pvs=", "1.0");
+
+   //////////////////////////////////////////////////////////////////////////////////
 }
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 444)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 445)
@@ -286,5 +286,5 @@
 	environment->GetFloatValue("BspTree.Factor.leastRaySplits", mLeastRaySplitsFactor);
 	environment->GetFloatValue("BspTree.Factor.balancedRays", mBalancedRaysFactor);
-	environment->GetFloatValue("BspTree.Factor.pvsFactor", mPvsFactor);
+	environment->GetFloatValue("BspTree.Factor.pvs", mPvsFactor);
 	environment->GetFloatValue("BspTree.Factor.leastSplits" , mLeastSplitsFactor);
 	environment->GetFloatValue("BspTree.Factor.balancedPolys", mBalancedPolysFactor);
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 444)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 445)
@@ -7,4 +7,7 @@
 #include "Environment.h"
 #include "ViewCellsManager.h"
+#include "ViewCellBsp.h"
+#include "VspBspTree.h"
+#include "VspKdTree.h"
 
 Preprocessor::Preprocessor():
@@ -12,4 +15,5 @@
 mBspTree(NULL),
 mVspKdTree(NULL),
+mVspBspTree(NULL),
 mViewCellsManager(NULL)
 {
@@ -22,4 +26,5 @@
 	DEL_PTR(mKdTree);
 	DEL_PTR(mVspKdTree);
+	DEL_PTR(mVspBspTree);
 	DEL_PTR(mViewCellsManager);
 }
@@ -167,4 +172,6 @@
 	environment->GetStringValue("ViewCells.type", viewCellsStr);
 
+	int constructionSamples = 0;
+
 	if (strcmp(viewCellsStr, "kdTree") == 0)
 	{
@@ -173,25 +180,30 @@
 	if (strcmp(viewCellsStr, "bspTree") == 0)
 	{
-		int bspConstructionSamples = 0;
-
 		mBspTree = new BspTree();
 
-		environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples);
-		mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples);
-	}
-	else if (strcmp(viewCellsStr, "vspTree") == 0)
-	{
-		int vspKdConstructionSamples = 0;
-		
-		environment->GetIntValue("VspKdTree.Construction.samples", vspKdConstructionSamples);
-        mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, vspKdConstructionSamples);
+		environment->GetIntValue("BspTree.Construction.samples", constructionSamples);
+		mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples);
+	}
+	if (strcmp(viewCellsStr, "vspBspTree") == 0)
+	{
+		mVspBspTree = new VspBspTree();
+
+		environment->GetIntValue("VspBspTree.Construction.samples", constructionSamples);
+		mViewCellsManager = new VspBspViewCellsManager(mVspBspTree, constructionSamples);
+	}
+	else if (strcmp(viewCellsStr, "vspKdTree") == 0)
+	{
+		mVspKdTree = new VspKdTree();		
+	
+		environment->GetIntValue("VspKdTree.Construction.samples", constructionSamples);
+        mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, constructionSamples);
 	}
 	else if (strcmp(viewCellsStr, "sceneDependent") == 0)
 	{
 		//TODO
-		int bspConstructionSamples = 0;
-
-		environment->GetIntValue("BspTree.Construction.samples", bspConstructionSamples);
-		mViewCellsManager = new BspViewCellsManager(mBspTree, bspConstructionSamples);
+		mBspTree = new BspTree();
+
+		environment->GetIntValue("BspTree.Construction.samples", constructionSamples);
+		mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples);
 	}
 	else
@@ -205,5 +217,5 @@
 
 	environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples);
- 	environment->GetIntValue("BspTree.Visualization.samples", visSamples);
+ 	environment->GetIntValue("ViewCells.Visualization.samples", visSamples);
 
 	mViewCellsManager->SetPostProcessSamples(postProcessSamples);
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 440)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.h	(revision 445)
@@ -7,7 +7,4 @@
 #include "Mesh.h"
 #include "KdTree.h"
-#include "ViewCellBsp.h"
-#include "ViewCell.h"
-#include "VspKdTree.h"
 
 class RenderSimulator;
@@ -15,5 +12,7 @@
 class Exporter;
 class ViewCellsManager;
-
+class BspTree;
+class VspKdTree;
+class VspBspTree;
 
 /** Namespace for the external visibility preprocessor
@@ -84,4 +83,6 @@
   KdTree *mKdTree;
   
+  /// View space partition bsp tree
+  VspBspTree *mVspBspTree;
   /// list of all loaded occluders
   ObjectContainer mOccluders;
