Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 498)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 501)
@@ -13,7 +13,7 @@
 #;../data/vienna/vienna-plane.x3d
 #	filename ../data/vienna/viewcells-25-sel.x3d
-	filename ../data/atlanta/atlanta2.x3d
+#	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
-#	filename ../data/soda/soda5.dat
+	filename ../data/soda/soda5.dat
 }
 
@@ -35,4 +35,5 @@
 	loadInitialSamples  false
 	storeInitialSamples false
+	useViewSpaceBox true
 }
 
@@ -195,5 +196,5 @@
 		colorCode Random
 		exportRays false
-		exportGeometry false
+		exportGeometry true
 	}
 	
@@ -222,8 +223,8 @@
 	Termination {
 		maxDepth	 	40
-		minPvs			50
-		minRays			300
-		minSize			0.001
-		maxCostRatio		0.9
+		minPvs			1
+		minRays			100
+		minSize			0.0001
+		maxCostRatio		0.95
 		missTolerance		4
 		maxRayContribution 	0.5
@@ -231,5 +232,5 @@
 	
 	maxTotalMemory	100
-	maxStaticMemory	50
+	maxStaticMemory	80
 
 	splitType 	regular
@@ -285,5 +286,5 @@
 		minPolygons 		-1
 		maxDepth		30
-		minPvs 			20
+		minPvs 			2
 		#minArea 		0.0001
 		minArea 		0.000
@@ -293,5 +294,5 @@
 		#maxAccRayLength	100
 		
-		maxViewCells		20000
+		maxViewCells		8000
 		
 		# used for pvs criterium
@@ -308,5 +309,5 @@
 	PostProcess {
 		maxCostRatio 0.1
-		minViewCells 500
+		minViewCells 200
 		maxPvsSize   1000
 		useRaysForMerge false
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 497)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 501)
@@ -258,9 +258,11 @@
 
 	/** Collapses the tree with respect to the view cell partition.
-	*/
-	void CollapseTree();
-
-  ViewCell *
-  GetViewCell(const Vector3 &point);
+		@returns number of collapsed nodes
+	*/
+	int CollapseTree();
+
+	/** Returns view cell the current point is located in.
+	*/
+	ViewCell *GetViewCell(const Vector3 &point);
 
 	/** Constructs bsp rays for post processing and visualization.
@@ -314,8 +316,10 @@
 	/** Collapses the tree with respect to the view cell partition,
 		i.e. leaves having the same view cell are collapsed.
+		@param node the root of the subtree to be collapsed
+		@param collapsed returns the number of collapsed nodes
 		@returns node of type leaf if the node could be collapsed, 
 		this node otherwise
 	*/
-	BspNode *CollapseTree(BspNode *node);
+	BspNode *CollapseTree(BspNode *node, int &collapsed);
 	/** Shuffles the leaves, i.e., tests if exchanging
 		the leaves helps in improving the view cells.
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 500)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.cpp	(revision 501)
@@ -951,6 +951,4 @@
 	pvsFront = nPvsFront[bestAxis];
 
-	if (bestAxis == 1)
-		Debug << "y axis!" << endl;
 	return nCostRatio[bestAxis];
 }
@@ -1211,4 +1209,5 @@
 		parent->ReplaceChildLink(leaf, node);
 	}
+
 	// and setup child links
 	node->SetupChildLinks(back, front);
@@ -2398,13 +2397,13 @@
 
 
-VspKdNode *VspKdTree::CollapseTree(VspKdNode *node)
-{
-    if (node->IsLeaf())
+VspKdNode *VspKdTree::CollapseTree(VspKdNode *node, int &collapsed)
+{
+	if (node->IsLeaf())
 		return node;
 
 	VspKdInterior *interior = dynamic_cast<VspKdInterior *>(node);
 
-	VspKdNode *front = CollapseTree(interior->GetFront());
-	VspKdNode *back = CollapseTree(interior->GetBack());
+	VspKdNode *front = CollapseTree(interior->GetFront(), collapsed);
+	VspKdNode *back = CollapseTree(interior->GetBack(), collapsed);
 
 	if (front->IsLeaf() && back->IsLeaf())
@@ -2420,11 +2419,15 @@
 			VspKdLeaf *leaf = new VspKdLeaf(interior->GetParent(), 0);
 			leaf->SetViewCell(vc);
-
-			VspKdInterior *parent = 
-				dynamic_cast<VspKdInterior *>(leaf->mParent);
+			//leaf->SetTreeValid(frontLeaf->TreeValid());
+
 			// replace a link from node's parent
-			if (parent)
+			if (leaf->mParent)
+			{
+				// replace a link from node's parent
+				VspKdInterior *parent = 
+					dynamic_cast<VspKdInterior *>(leaf->mParent);
 				parent->ReplaceChildLink(node, leaf);
-
+			}
+			++ collapsed;
 			delete interior;
 
@@ -2437,10 +2440,14 @@
 
 
-void VspKdTree::CollapseTree()
-{
-	CollapseTree(mRoot);
+int VspKdTree::CollapseTree()
+{
+	int collapsed = 0;
+	CollapseTree(mRoot, collapsed);
 	// revalidate leaves
 	RepairVcLeafLists();
-}
+
+	return collapsed;
+}
+
 
 int VspKdTree::RefineViewCells(const VssRayContainer &rays)
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.h	(revision 359)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.h	(revision 501)
@@ -87,46 +87,47 @@
   bool mUseBoxes;
 
-  MutualVisibilitySampler(SceneGraph *sceneGraph,
-													KdTree *kdTree,
-													const AxisAlignedBox3 &source,
-													const AxisAlignedBox3 &target,
-													const float solidAngleThreshold);
+  MutualVisibilitySampler(
+						  SceneGraph *sceneGraph,
+						  KdTree *kdTree,
+						  const AxisAlignedBox3 &source,
+						  const AxisAlignedBox3 &target,
+						  const float solidAngleThreshold
+						  );
   int
   ComputeVisibility();
 
   void
-  ConstructInitialSamples(
-													const AxisAlignedBox3 &source,
-													const AxisAlignedBox3 &target,
-													vector<RayShaft *> &samples
-													);
+  ConstructInitialSamples(const AxisAlignedBox3 &source,
+						  const AxisAlignedBox3 &target,
+						  vector<RayShaft *> &samples
+						  );
 	
   void
   ConstructInitialSamples2(
-													 const AxisAlignedBox3 &source,
-													 const AxisAlignedBox3 &target,
-													 vector<RayShaft *> &samples
-													 );
+						   const AxisAlignedBox3 &source,
+						   const AxisAlignedBox3 &target,
+						   vector<RayShaft *> &samples
+						   );
 	
   void
   ConstructInitialSamples3(
-													 const AxisAlignedBox3 &source,
-													 const AxisAlignedBox3 &target,
-													 vector<RayShaft *> &samples
-													 );
+						   const AxisAlignedBox3 &source,
+						   const AxisAlignedBox3 &target,
+						   vector<RayShaft *> &samples
+						   );
 	
   void
   AddInitialSamples(
-										const Rectangle3 &sourceRect,
-										const Rectangle3 &targetRect,
-										vector<RayShaft *> &samples
-										);
+					const Rectangle3 &sourceRect,
+					const Rectangle3 &targetRect,
+					vector<RayShaft *> &samples
+					);
 	
   void
   AddInitialSamples2(
-										 const Rectangle3 &sourceRect,
-										 const Rectangle3 &targetRect,
-										 vector<RayShaft *> &samples
-										 );
+					 const Rectangle3 &sourceRect,
+					 const Rectangle3 &targetRect,
+					 vector<RayShaft *> &samples
+					 );
 	
   // the split sample method contains a methodology to create new samples
@@ -134,26 +135,26 @@
   bool
   SplitSample(
-							const RayShaft &source,
-							RayShaft &sample1,
-							RayShaft &sample2
-							);
+			const RayShaft &source,
+			RayShaft &sample1,
+			RayShaft &sample2
+			);
   void
   PerformSplit(
-							 const RayShaft &sample,
-							 const bool splitSource,
-							 const int axis,
-							 RayShaft &sample1,
-							 RayShaft &sample2
-							 );
+				const RayShaft &sample,
+				const bool splitSource,
+				const int axis,
+				RayShaft &sample1,
+				RayShaft &sample2
+				 );
   
 	
   bool
   SampleTerminationCriteriaMet(
-															 const RayShaft &sample);
+								 const RayShaft &sample);
   
   float
   GetSpatialAngle(const RayShaft &sample,
-									const Vector3 &point
-									);
+				  const Vector3 &point
+				 );
 	
   int
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 500)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 501)
@@ -2111,5 +2111,5 @@
 }
 
-BspNode *VspBspTree::CollapseTree(BspNode *node)
+BspNode *VspBspTree::CollapseTree(BspNode *node, int &collapsed)
 {
 	if (node->IsLeaf())
@@ -2118,6 +2118,6 @@
 	BspInterior *interior = dynamic_cast<BspInterior *>(node);
 
-	BspNode *front = CollapseTree(interior->GetFront());
-	BspNode *back = CollapseTree(interior->GetBack());
+	BspNode *front = CollapseTree(interior->GetFront(), collapsed);
+	BspNode *back = CollapseTree(interior->GetBack(), collapsed);
 
 	if (front->IsLeaf() && back->IsLeaf())
@@ -2137,5 +2137,6 @@
 			if (leaf->GetParent())
 				leaf->GetParent()->ReplaceChildLink(node, leaf);
-
+						
+			++ collapsed;
 			delete interior;
 
@@ -2148,9 +2149,12 @@
 
 
-void VspBspTree::CollapseTree()
-{
-	CollapseTree(mRoot);
+int VspBspTree::CollapseTree()
+{
+	int collapsed = 0;
+	(void)CollapseTree(mRoot, collapsed);
 	// revalidate leaves
 	RepairVcLeafLists();
+
+	return collapsed;
 }
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 492)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 501)
@@ -1188,4 +1188,10 @@
    
 
+    RegisterOption("VssPreprocessor.useViewSpaceBox",
+	  optBool,
+	  "-vss_use_viewspace_box=",
+	  "true");
+   
+
   /************************************************************************************/
   /*                         View cells related options                               */
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 496)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 501)
@@ -13,5 +13,5 @@
 #include "GlRenderer.h"
 
-static bool useViewSpaceBox = false;
+static bool useViewSpaceBox = true;
 static bool use2dSampling = false;
 static bool fromBoxVisibility = false;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 499)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 501)
@@ -12,7 +12,6 @@
 #include "RenderSimulator.h"
 
-bool useViewSpaceBox = false;
 bool use2dSampling = false;
-bool useViewspacePlane = false;
+bool useViewspacePlane = true;
 
 VssPreprocessor::VssPreprocessor():
@@ -29,4 +28,5 @@
   environment->GetBoolValue("VssPreprocessor.loadInitialSamples", mLoadInitialSamples);
   environment->GetBoolValue("VssPreprocessor.storeInitialSamples", mStoreInitialSamples);
+  environment->GetBoolValue("VssPreprocessor.useViewSpaceBox", mUseViewSpaceBox);
 
   mStats.open("stats.log");
@@ -389,5 +389,5 @@
 	box->SetMax(1, box->Min(1));
 
-  if (useViewSpaceBox)
+  if (mUseViewSpaceBox)
   {
 	mViewSpaceBox = box;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 500)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspKdTree.h	(revision 501)
@@ -669,14 +669,19 @@
 
 	/** Collapses the tree with respect to the view cell partition.
-	*/
-	void CollapseTree();
+		@returns number of collapsed nodes
+	*/
+	int CollapseTree();
 
 protected:
 
-	/** Collapses the tree with respect to the view cell partition.
+	/** Collapses the tree with respect to the view cell partition,
+		i.e. leaves having the same view cell are collapsed.
+		@param node the root of the subtree to be collapsed
+		@param collapsed returns the number of collapsed nodes
 		@returns node of type leaf if the node could be collapsed, 
 		this node otherwise
 	*/
-	VspKdNode *CollapseTree(VspKdNode *node);
+	VspKdNode *CollapseTree(VspKdNode *node, int &collapsed);
+
 	// incremental construction
 	virtual void UpdateRays(VssRayContainer &remove, VssRayContainer &add);
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 490)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 501)
@@ -32,5 +32,6 @@
   /// if initial samples should be stored in file
   bool mStoreInitialSamples;
-
+  /// if box around view space should be used
+  bool mUseViewSpaceBox;
   // rays cast during the processing
   VssRayContainer mVssRays;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 498)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 501)
@@ -95,4 +95,5 @@
 	return mSceneBox.IsInside(viewPoint);
 }
+
 
 void ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays)
@@ -1765,6 +1766,6 @@
 	cout << "collapsing invalid tree regions ... ";
 	long startTime = GetTime();
-	mVspBspTree->CollapseTree(); 
-	Debug << "tree collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl;
+	int collapsedLeaves = mVspBspTree->CollapseTree(); 
+	Debug << "collapsed in " << TimeDiff(startTime, GetTime()) * 1e-3 << " seconds" << endl;
     cout << "finished" << endl;
 	
