Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 448)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 451)
@@ -19,17 +19,20 @@
 
 Preprocessor {
-#	type sampling
-	type vss
+	type sampling
+#	type vss
+#	type rss
 }
 
 VssPreprocessor {
-	samplesPerPass  10000
-	initialSamples 200000
-	vssSamples 100000
-	vssSamplesPerPass 10000
+	samplesPerPass  100000
+	initialSamples 500000
+	vssSamples 1000000
+	vssSamplesPerPass 50000
 	useImportanceSampling true
 }
 
+
 VssTree {
+	useRss    false
 	epsilon		1e-6
 
@@ -38,12 +41,54 @@
 	minRays		100
 	minSize		0.001
-  	maxCostRatio	0.98
+ 	maxCostRatio	2.0
 	maxRayContribution 0.05
 	
 	maxTotalMemory	200
-	maxStaticMemory	50
+	maxStaticMemory	100
 
 	splitType regular
-#	splitType heuristics
+#	splitType heuristic
+#	splitType hybrid
+	splitUseOnlyDrivingAxis true
+
+	interleaveDirSplits	false
+    dirSplitDepth 40
+
+	numberOfEndPointDomains	10000
+	ct_div_ci	0.0
+	randomize	false
+
+	refDirBoxMaxSize	0.1
+}
+
+RssPreprocessor {
+	samplesPerPass  100000
+	initialSamples 500000
+	vssSamples 5000000
+	vssSamplesPerPass 100000
+	useImportanceSampling true
+}
+
+RssTree {
+	useRss    false
+	epsilon		1e-6
+
+	maxDepth 	40
+	minPvs		5
+	minRays		30
+	minSize		0.001
+ 	maxCostRatio	0.9
+	maxRayContribution 0.1
+	
+	maxTotalMemory	200
+	maxStaticMemory	100
+
+#	splitType regular
+#	splitType heuristic
+	splitType hybrid
+	splitUseOnlyDrivingAxis false
+
+	interleaveDirSplits	true
+    dirSplitDepth 9
 
 	numberOfEndPointDomains	10000
@@ -229,26 +274,4 @@
 }
 
-VssTree {
-	epsilon		1e-6
-
-	maxDepth 	40
-	minPvs		100
-	minRays		50
-	minSize		0.00001
-	maxCostRatio	0.95
-	maxRayContribution 0.05
-	
-	maxTotalMemory	200
-	maxStaticMemory	20
-
-	splitType regular
-#	splitType heuristics
-
-	numberOfEndPointDomains	10000
-	ct_div_ci	0.0
-	randomize	false
-
-	refDirBoxMaxSize	0.1
-}
 
 VspKdTree {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 450)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 451)
@@ -9,5 +9,5 @@
 #include "VssRay.h"
 #include "RssTree.h"
-#include "ViewCellBsp.h"
+#include "ViewCellsManager.h"
 
 static bool useViewSpaceBox = true;//true;
@@ -378,4 +378,6 @@
   int totalSamples = 0;
 
+  /// Rays used for post processing and visualizations.
+  RayContainer storedRays;
 
   AxisAlignedBox3 *box = new AxisAlignedBox3(mKdTree->GetBox());
@@ -407,6 +409,4 @@
   RssTree *rssTree = NULL;
 
-  RayContainer bspRays;
-
   while (totalSamples < mInitialSamples) {
 	int passContributingSamples = 0;
@@ -423,5 +423,5 @@
 	  Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 			
-	  sampleContributions = CastRay(viewpoint, direction, mVssRays);
+	  CastRay(viewpoint, direction, mVssRays);
 			
 			
@@ -473,5 +473,8 @@
 	ExportPvs("rss-pvs-initial.x3d", rssTree);
   }
-  
+
+  // construct view cells
+  mViewCellsManager->Construct(mObjects, mVssRays, mViewSpaceBox);
+
   rssTree = new RssTree;
   // viewcells = Construct(mVssRays);
@@ -550,4 +553,34 @@
 	}
 
+	//-- prepare traversal rays for view cell intersections
+	RayContainer passRays;
+
+	VssRayContainer::const_iterator it, it_end = vssRays.end();
+	
+	for (it = vssRays.begin(); it != it_end; ++ it)
+		passRays.push_back(new Ray(*(*it)));
+	
+	int sampleContributions = 0;
+	int contributingSamples = 0;
+
+	/// compute view cell contribution of rays
+	mViewCellsManager->ComputeSampleContributions(passRays,
+												  sampleContributions, 
+												  contributingSamples);
+	
+	//-- save rays for post processing
+	if (((int)storedRays.size() < mViewCellsManager->GetPostProcessSamples()) ||
+		((int)storedRays.size() < mViewCellsManager->GetVisualizationSamples()))
+	{
+		RayContainer::const_iterator it, it_end = passRays.end();
+
+		for (it = passRays.begin(); it != it_end; ++ it)
+			storedRays.push_back(new Ray(*(*it)));
+	}
+	else
+	{
+		CLEAR_CONTAINER(passRays);
+	}
+
 	samples+=num;
 	float pvs = rssTree->GetAvgPvsSize();
@@ -575,49 +608,2 @@
 }
 
-void
-RssPreprocessor::CastRay(const BspTree &tree, const VssRay & vssRay)
-{
-  //-- cast ray to BSP tree to get intersection with view cells
-  Ray ray(vssRay);
-  mBspTree->CastRay(ray);
-				
-  //if (0 && ray.sourceObject.mObject)
-  //sampleContributions += 
-  //AddObjectSamples(ray.sourceObject.mObject, ray);
-			
-  if (!ray.intersections.empty()) // second intersection found
-  {
-	  //sampleContributions += 
-	  AddObjectSamples(ray.intersections[0].mObject, ray);
-  }
-}
-
-int
-RssPreprocessor::AddObjectSamples(Intersectable *obj, const Ray &ray)
-{
-  int contributingSamples = 0;
-  int j;
- 
-  // object can be seen from the view cell => add to view cell pvs
-  for (j=0; j < ray.bspIntersections.size(); ++ j)
-	{ 	
-	  BspLeaf *leaf = ray.bspIntersections[j].mLeaf;
-	  // if ray not in unbounded space
-/*	  if (leaf->GetViewCell() != &mUnbounded)
-		contributingSamples += 
-		  leaf->GetViewCell()->GetPvs().AddSample(obj);*/
-	}
- 
-  // rays passing through this viewcell
-  if (mPass > 1)
-	for (j=1; j < ((int)ray.bspIntersections.size() - 1); ++ j) 
-	  {
-		BspLeaf *leaf = ray.bspIntersections[j].mLeaf;
-		
-	/*	if (leaf->GetViewCell() != &mUnbounded)
-		  leaf->GetViewCell()->
-			AddPassingRay(ray, contributingSamples ? 1 : 0);*/
-	  }
-  
-  return contributingSamples;
-}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 448)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 451)
@@ -489,5 +489,5 @@
   int pass = 0;
 
-  /// Rays used for post processing and visualizations.
+  /// Rays used for post processing and visualizations
   RayContainer storedRays;
   // cast view cell samples
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 446)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 451)
@@ -144,8 +144,11 @@
 
 ViewCells {
-	#hierarchy kdTree
-	hierarchy vspTree
-	#hierarchy bspTree
-	# hierarchy sceneDependent
+	loadFromFile false
+	#type kdTree
+	type vspKdTree
+	#type bspTree
+	#type vspBspTree
+	
+	#type sceneDependent
 	
 	height 5.0
@@ -156,7 +159,12 @@
 		minPvs 10
 		maxPvs 150
-		samples 100000
-	}
-
+		# 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
@@ -168,9 +176,6 @@
 BspTree {
 	Construction {
-		input fromSamples
-	#	input fromViewCells
-	#	input fromSceneGeometry
-		samples 150000
-		sideTolerance 0.005
+		samples 50000
+		epsilon 0.005
 	}
 
@@ -209,8 +214,10 @@
 	#splitPlaneStrategy 130
 	
-	splitPlaneStrategy 12
-	
-	maxPolyCandidates 70
-	maxRayCandidates 100
+	splitPlaneStrategy 1024
+	
+	maxPolyCandidates 50
+	maxRayCandidates 50
+	
+	maxTests 10000
 	
 	# factors for evaluating split plane costs
@@ -221,5 +228,5 @@
 	  	leastRaySplits 1.0
 	  	balancedRays 1.0
-	  	pvsFactor 1.0
+	  	pvs 1.0
 	  	leastSplits 1.0
 	  	balancedPolys 1.0
@@ -232,5 +239,5 @@
 		minPolygons -1
 		maxDepth 40
-		minPvs 35
+		minPvs 100
 		minArea 0.01
 		maxRayContribution 0.005
@@ -258,6 +265,4 @@
 	# x3d visualization of the split planes
 	exportSplits true
-		# how much samples should be used in visualization
-		samples 20000
 	}
 }
@@ -274,10 +279,10 @@
 
 	Construction {
-		samples 500000
-	}
-	
-	Termination {
-		maxDepth 	30
-		minPvs		60
+		samples 100000
+	}
+	
+	Termination {
+		maxDepth	 	40
+		minPvs			50
 		minRays		1
 		minSize		0.1
@@ -286,6 +291,6 @@
 	}
 	
-	maxTotalMemory	600
-	maxStaticMemory	600
+	maxTotalMemory	400
+	maxStaticMemory	200
 
 	splitType regular
@@ -293,2 +298,65 @@
 	ct_div_ci	0.0
 }
+
+VspBspTree {
+	Construction {
+		samples 100000
+		epsilon 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 40
+		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/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 448)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 451)
@@ -361,5 +361,5 @@
 		
 		float avgRayContrib = (passContributingSamples > 0) ? 
-			passSampleContributions/(float)passContributingSamples : 0;
+			passSampleContributions / (float)passContributingSamples : 0;
 
 		cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h	(revision 450)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h	(revision 451)
@@ -104,12 +104,4 @@
 			);
 
-  void
-  CastRay(const BspTree &tree, const VssRay & vssRay);
-
-  int
-  AddObjectSamples(Intersectable *obj, const Ray &ray);
-
-
-	
 };
 
