Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 489)
@@ -155,5 +155,5 @@
 	height 5.0
 	maxViewCells 100
-	maxPvs 70
+	maxPvs 130
 	
 	
@@ -168,5 +168,5 @@
 	Visualization {
 		# how much samples are be used for visualization
-		samples 90000
+		samples 1000
 		#colorCode PVS
 		#colorCode MergedLeaves
@@ -219,8 +219,6 @@
 	# maximal cost for merging a view cell
 	PostProcess {
-<<<<<<< .mine
 		maxCostRatio 0.005
 		minViewCells 200
-
 		maxPvsSize   50000
 	}
@@ -289,5 +287,4 @@
 		maxCostRatio 0.1
 		minViewCells 200
-
 		maxPvsSize   500
 		useRaysForMerge false
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 489)
@@ -278,4 +278,8 @@
 	bool ViewPointValid(const Vector3 &viewPoint) const;
 
+	/** Returns the view cell corresponding to 
+		the space outside the valid view space.
+	*/
+	BspViewCell *GetOutOfBoundsCell() const;
 
 protected:
@@ -550,4 +554,9 @@
 	*/
 	void PropagateUpValidity(BspNode *node);
+
+	/** Creates or returns view cell corresponding to 
+		the space outside the valid view space.
+	*/
+	BspViewCell *GetOrCreateOutOfBoundsCell();
 
 	/// Pointer to the root of the tree
@@ -644,4 +653,6 @@
 	int mMaxPvs;
 
+	/// View cell corresponding to the space outside the valid view space
+	BspViewCell *mOutOfBoundsCell;
 
 private:
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 488)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 489)
@@ -258,6 +258,6 @@
 	virtual void ExportVcGeometry(Exporter *exporter, ViewCell *vc) const = 0;
 
-	/// the view cell corresponding to unbounded space
-	//ViewCell *mUnbounded;
+	/// the view cell corresponding to space ouside the valid view space
+	//ViewCell *mOutOfBoundsCell;
 
 	/// Renders the view cells.
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 489)
@@ -45,5 +45,6 @@
 mViewCellsManager(NULL),
 mStoreRays(false),
-mOnlyDrivingAxis(false)
+mOnlyDrivingAxis(false),
+mOutOfBoundsCell(NULL)
 {
 	bool randomize = false;
@@ -128,7 +129,17 @@
 	}
 
+
 	mSplitCandidates = new vector<SortableEntry>;
 
 	Debug << endl;
+}
+
+
+BspViewCell *VspBspTree::GetOrCreateOutOfBoundsCell()
+{
+	if (!mOutOfBoundsCell)
+		mOutOfBoundsCell = new BspViewCell();
+
+	return mOutOfBoundsCell;
 }
 
@@ -401,4 +412,5 @@
 	{
 		BspLeaf *leaf = dynamic_cast<BspLeaf *>(newNode);
+		BspViewCell *viewCell;
 
 		if (!CheckValid(tData))
@@ -406,8 +418,13 @@
 			leaf->SetTreeValid(false);
 			PropagateUpValidity(leaf);
-		}
-
-		// create new view cell for this leaf
-		BspViewCell *viewCell = new BspViewCell();
+			// view cell for invalid view space
+			viewCell = GetOrCreateOutOfBoundsCell();
+		}
+		else
+		{
+			// create new view cell for this leaf
+			viewCell = new BspViewCell();
+		}
+		
 		leaf->SetViewCell(viewCell);
 	
@@ -1206,6 +1223,9 @@
 	{
 		BspNode *node = nodeStack.top();
-
 		nodeStack.pop();
+		
+		// this subtree is not valid view space
+		if (!node->TreeValid())
+			continue;
 
 		if (node->IsLeaf())
@@ -1224,4 +1244,5 @@
 }
 
+
 AxisAlignedBox3 VspBspTree::GetBoundingBox() const
 {
@@ -1229,8 +1250,16 @@
 }
 
+
 BspNode *VspBspTree::GetRoot() const
 {
 	return mRoot;
 }
+
+
+BspViewCell *VspBspTree::GetOutOfBoundsCell() const
+{
+	return mOutOfBoundsCell;
+}
+
 
 void VspBspTree::EvaluateLeafStats(const VspBspTraversalData &data)
@@ -1399,4 +1428,7 @@
 		BspNode *node = nodeStack.top();
 		nodeStack.pop();
+		// this subtree is not valid view space
+		if (!node->TreeValid())
+			continue;
 
 		if (node->IsLeaf())
@@ -1635,4 +1667,8 @@
 		nodeStack.pop();
 
+		// view space not valid
+		if (!node->TreeValid())
+			continue;
+
 		if (node->IsLeaf())
 		{
@@ -1687,4 +1723,5 @@
 	return (int)neighbors.size();
 }
+
 
 BspLeaf *VspBspTree::GetRandomLeaf(const Plane3 &halfspace)
@@ -2002,4 +2039,5 @@
 
 			BspLeaf *leaf = new BspLeaf(interior->GetParent(), vc);
+			leaf->SetTreeValid(frontLeaf->TreeValid());
 
 			// replace a link from node's parent
@@ -2170,14 +2208,14 @@
 	  
 		iit = ray->intersections.begin();
-		BspLeaf *prevLeaf = (*(iit ++)).mLeaf;
+		BspLeaf *leaf = (*(iit ++)).mLeaf;
 		
 		// create leaf pvs (needed for post processing)
-		if (!prevLeaf->mPvs)
-		{
-			prevLeaf->mPvs = 
-				new ObjectPvs(prevLeaf->GetViewCell()->GetPvs());
+		if (!leaf->mPvs)
+		{
+			leaf->mPvs = 
+				new ObjectPvs(leaf->GetViewCell()->GetPvs());
 
 			BspMergeCandidate::sOverallCost += 
-				prevLeaf->mArea * prevLeaf->mPvs->GetSize();
+				leaf->mArea * leaf->mPvs->GetSize();
 			
 			++ leaves;
@@ -2185,10 +2223,16 @@
 		
 		// traverse intersections 
-		// consecutive leaves are neighbors => 
-		// add them to queue
+		// consecutive leaves are neighbors => add them to queue
 		for (; iit != ray->intersections.end(); ++ iit)
 		{
-            BspLeaf *leaf = (*iit).mLeaf;
-            
+			// next pair
+			BspLeaf *prevLeaf = leaf;
+            leaf = (*iit).mLeaf;
+
+			// view space does not correspond to valid space
+			if (!leaf->TreeValid() || !prevLeaf->TreeValid())
+				continue;
+
+            // create leaf pvs (needed for post processing)
 			if (!leaf->mPvs)
 			{
@@ -2229,6 +2273,4 @@
 				mMergeQueue.push(BspMergeCandidate(leaf, prevLeaf));
 			}
-
-			prevLeaf = leaf;
         }
 	}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 489)
@@ -1680,5 +1680,5 @@
 	RegisterOption("VspBspTree.Termination.maxViewCells",
 		optInt,
-		"-vsp_bsp_term_axis_aligned_max_view_cells=",
+		"-vsp_bsp_term_max_view_cells=",
 		"1000");
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 489)
@@ -39,14 +39,16 @@
 int BspTree::sFrontAndBackId = 0;
 
+
 /****************************************************************/
 /*                  class BspNode implementation                */
 /****************************************************************/
 
+
 BspNode::BspNode(): 
-mParent(NULL)
+mParent(NULL), mTreeValid(true)
 {}
 
 BspNode::BspNode(BspInterior *parent): 
-mParent(parent)
+mParent(parent), mTreeValid(true)
 {}
 
@@ -210,6 +212,4 @@
 mGenerateViewCells(true)
 {
-	
-
 	Randomize(); // initialise random generator for heuristics
 
@@ -428,5 +428,5 @@
 	DEL_PTR(mRoot);
 
-	// root cell not used
+	// HACK: view cells not generated => root cell not used
 	if (mGenerateViewCells)
 		DEL_PTR(mRootCell);
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 489)
@@ -12,7 +12,7 @@
 #include "RenderSimulator.h"
 
-bool useViewSpaceBox = true;//true;
+bool useViewSpaceBox = true;
 bool use2dSampling = false;
-bool useViewspacePlane = true;//true;
+bool useViewspacePlane = true;
 
 VssPreprocessor::VssPreprocessor():
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 487)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 489)
@@ -45,4 +45,6 @@
 	environment->GetBoolValue("ViewCells.Visualization.exportGeometry", mExportGeometry);
 
+	//Debug << "export rays: " << mExportRays << endl;
+	//Debug << "export geometry: " << mExportGeometry << endl;
 	char buf[50];
 	
@@ -1732,4 +1734,5 @@
 }
 
+
 // matt TODO: remove
 int VspBspViewCellsManager::MergeViewCells(const VssRayContainer &rays) const
@@ -1875,5 +1878,5 @@
     Debug << ss << endl;
 
-	cout << "Refining the view cells ... ";
+	cout << "Refining the merged view cells ... ";
 	startTime = GetTime();
 
@@ -1922,4 +1925,12 @@
 			if (mExportGeometry)
 				exporter->ExportGeometry(objects);
+
+			// export rays
+			/*if (mExportRays)
+			{
+				exporter->SetWireframe();
+				exporter->ExportRays(visRays, RgbColor(1, 1, 0));
+				exporter->SetFilled();
+			}*/
 			ExportViewCells(exporter);
 			delete exporter;
@@ -1931,6 +1942,7 @@
 	//-- visualization of the BSP splits
 	bool exportSplits = false;
-	environment->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits);
-	
+	environment->GetBoolValue("VspBspTree.Visualization.exportSplits", exportSplits);
+	Debug << "export splits: " << exportSplits << endl;
+
 	if (exportSplits)
 	{
@@ -1950,8 +1962,10 @@
 		return ViewCellsManager::GetViewPoint(viewPoint);
 
+	// TODO: set reasonable limit
 	const int limit = 10;
-
+cout << "===" << endl;
 	for (int i = 0; i < limit; ++ i)
 	{
+		cout << i << " " << endl;
 		viewPoint = mSceneBox.GetRandomPoint();
 		if (mVspBspTree->ViewPointValid(viewPoint))
