Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 469)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/Preprocessor.vcproj	(revision 487)
@@ -410,7 +410,4 @@
 			</File>
 		</Filter>
-		<File
-			RelativePath=".\VTune\Preprocessor.vpj">
-		</File>
 	</Files>
 	<Globals>
Index: trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 487)
@@ -143,4 +143,5 @@
 }
 
+
 ViewCells {
 	loadFromFile false
@@ -154,4 +155,6 @@
 	height 5.0
 	maxViewCells 100
+	maxPvs 70
+	
 	
 	PostProcess {
@@ -170,5 +173,5 @@
 		#colorCode MergedTreeDiff
 		colorCode Random
-		exportRays false
+		exportRays true
 		exportGeometry true
 	}
@@ -216,6 +219,8 @@
 	# maximal cost for merging a view cell
 	PostProcess {
+<<<<<<< .mine
 		maxCostRatio 0.005
-		minViewCells 100
+		minViewCells 200
+
 		maxPvsSize   50000
 	}
@@ -283,5 +288,6 @@
 	PostProcess {
 		maxCostRatio 0.1
-		minViewCells 100
+		minViewCells 200
+
 		maxPvsSize   500
 		useRaysForMerge false
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.h	(revision 487)
@@ -268,9 +268,14 @@
 	void ConstructBspRays(vector<BspRay *> &bspRays,
 						  const VssRayContainer &rays);
-
 	
 	/** Merge view cells of leaves l1 and l2.
 	*/
 	bool MergeViewCells(BspLeaf *l1, BspLeaf *l2) const;
+
+	/** Returns true if this view point is in a valid view space,
+		false otherwise.
+	*/
+	bool ViewPointValid(const Vector3 &viewPoint) const;
+
 
 protected:
@@ -535,4 +540,14 @@
 					 BspViewCell *vc1, 
 					 BspViewCell *vc2) const;
+
+	/**
+		Checks if this traversal data corresponds to
+		a valid view space region.
+	*/
+	bool CheckValid(const VspBspTraversalData &data) const;
+
+	/** Propagates valid flag up the tree.
+	*/
+	void PropagateUpValidity(BspNode *node);
 
 	/// Pointer to the root of the tree
@@ -620,8 +635,13 @@
 	vector<SortableEntry> *mSplitCandidates;
 
+
 	typedef priority_queue<BspMergeCandidate> MergeQueue;
+
 	MergeQueue mMergeQueue;
-	
+	/// if rays should be used to collect merge candidates
 	bool mUseRaysForMerge;
+	/// maximal allowed pvs so that view cell is valid
+	int mMaxPvs;
+
 
 private:
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 485)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.h	(revision 487)
@@ -211,13 +211,24 @@
 	*/
 	int GetDepth() const;
-	static int sMailId;
-	int mMailbox;
-  
+
+	/** returns true if the whole subtree is valid
+	*/
+	bool TreeValid() const;
+
+	void SetTreeValid(const bool v);
+
+	//-- mailing options
+
 	void Mail() { mMailbox = sMailId; }
 	static void NewMail() { ++ sMailId; }
 	bool Mailed() const { return mMailbox == sMailId; }
 
+	static int sMailId;
+	int mMailbox;
+
 protected:
 
+	/// if this sub tree is a completely valid view space region
+	bool mTreeValid;
 	/// parent of this node
 	BspInterior *mParent;
@@ -294,4 +305,5 @@
 	void SetViewCell(BspViewCell *viewCell);
 
+	/// Rays piercing this leaf.
 	VssRayContainer mVssRays;
 	
Index: trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h	(revision 487)
@@ -175,5 +175,5 @@
 
 
-  Vector3 GetRandomPoint() {
+  Vector3 GetRandomPoint() const {
     Vector3 size = Size();
     return mMin + Vector3(RandomValue(0, size.x),
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 485)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.h	(revision 487)
@@ -55,6 +55,5 @@
 	*/
 	virtual int Construct(const ObjectContainer &objects, 
-						  const VssRayContainer &rays,
-						  AxisAlignedBox3 *sceneBbox = NULL) = 0;
+						  const VssRayContainer &rays) = 0;
 
 	/** Computes sample contributions of the rays to the view cells PVS.
@@ -217,5 +216,14 @@
 	void SetRenderer(Renderer *renderer);
 
-	
+	/** Computes a (random) view point in the valid view space.
+		@returns true if valid view point was found
+	*/
+	virtual bool GetViewPoint(Vector3 &viewPoint) const;
+
+	/** Sets a view space boundary.
+	*/
+	void SetViewSpaceBox(const AxisAlignedBox3 &box);
+
+
 protected:
 
@@ -251,5 +259,5 @@
 
 	/// the view cell corresponding to unbounded space
-	ViewCell *mUnbounded;
+	//ViewCell *mUnbounded;
 
 	/// Renders the view cells.
@@ -280,4 +288,13 @@
 
 	ViewCellsStatistics mViewCellsStats;
+	/// the scene bounding box
+	AxisAlignedBox3 mSceneBox;
+
+	//-- visualization options
+	
+	/// color code for view cells
+	int mColorCode;
+	bool mExportGeometry;
+	bool mExportRays;
 };
 
@@ -299,6 +316,5 @@
 
 	int Construct(const ObjectContainer &objects, 
-				  const VssRayContainer &rays,
-				  AxisAlignedBox3 *sceneBbox);
+				  const VssRayContainer &rays);
 
 
@@ -372,6 +388,5 @@
 
 	int Construct(const ObjectContainer &objects, 
-				  const VssRayContainer &rays,
-				  AxisAlignedBox3 *sceneBbox);
+				  const VssRayContainer &rays);
 
 	int CastLineSegment(const Vector3 &origin,
@@ -426,6 +441,5 @@
 
 	int Construct(const ObjectContainer &objects, 
-				  const VssRayContainer &rays,
-				  AxisAlignedBox3 *sceneBbox);
+				  const VssRayContainer &rays);
 
 
@@ -483,7 +497,5 @@
 
 	int Construct(const ObjectContainer &objects, 
-				  const VssRayContainer &rays,
-				  AxisAlignedBox3 *sceneBbox);
-
+				  const VssRayContainer &rays);
 
 	int PostProcess(const ObjectContainer &objects, 
@@ -510,4 +522,6 @@
 	AxisAlignedBox3 GetSceneBbox() const;
 
+	bool GetViewPoint(Vector3 &viewPoint) const;
+
 protected:
 	/** DEPRECATED
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 487)
@@ -85,4 +85,6 @@
 	environment->GetBoolValue("VspBspTree.splitUseOnlyDrivingAxis", mOnlyDrivingAxis);
 	environment->GetBoolValue("VspBspTree.PostProcess.useRaysForMerge", mUseRaysForMerge);
+	environment->GetIntValue("ViewCells.maxPvs", mMaxPvs);
+
 
 	//-- debug output
@@ -400,8 +402,22 @@
 		BspLeaf *leaf = dynamic_cast<BspLeaf *>(newNode);
 
+		if (!CheckValid(tData))
+		{
+			leaf->SetTreeValid(false);
+			PropagateUpValidity(leaf);
+		}
+
 		// create new view cell for this leaf
 		BspViewCell *viewCell = new BspViewCell();
 		leaf->SetViewCell(viewCell);
-		
+	
+		//-- update pvs
+		int conSamp = 0, sampCon = 0;
+		AddToPvs(leaf, *tData.mRays, conSamp, sampCon);
+
+		mStat.contributingSamples += conSamp;
+		mStat.sampleContributions += sampCon;
+
+		//-- store additional info
 		if (mStoreRays)
 		{
@@ -415,14 +431,6 @@
 		leaf->mArea = tData.mArea;
 
-		//-- update pvs
-		int conSamp = 0, sampCon = 0;
-		AddToPvs(leaf, *tData.mRays, conSamp, sampCon);
-	
-		mStat.contributingSamples += conSamp;
-		mStat.sampleContributions += sampCon;
-
-		EvaluateLeafStats(tData);
-	}
-
+		EvaluateLeafStats(tData);		
+	}
 
 	//-- cleanup
@@ -431,4 +439,5 @@
 	return newNode;
 }
+
 
 BspNode *VspBspTree::SubdivideNode(VspBspTraversalData &tData,
@@ -519,5 +528,5 @@
 
 	// replace a link from node's parent
-	if (!leaf->IsRoot())
+	if (parent)
 	{
 		parent->ReplaceChildLink(leaf, interior);
@@ -1897,7 +1906,7 @@
 				if (extSide < 0)
 					node = in->GetBack();
-				else if (extSide > 0)
+				else 
 					node = in->GetFront();
-
+								
 				continue; // no far child
 			}
@@ -1908,9 +1917,7 @@
 			// find intersection of ray segment with plane
 			extp = splitPlane.FindIntersection(origin, extp, &t);
-			//cout << "x";
 		} 
 		else
 		{
-			//cout << "o";
 			// reached leaf => intersection with view cell
 			BspLeaf *leaf = dynamic_cast<BspLeaf *>(node);
@@ -1937,5 +1944,5 @@
 		}
 	}
-	//cout << "!!!!!!!!!!!" << endl;
+
 	return hits;
 }
@@ -2506,4 +2513,50 @@
 }
 
+bool VspBspTree::ViewPointValid(const Vector3 &viewPoint) const
+{
+	BspNode *node = mRoot;
+
+	while (1)
+	{
+		// early exit
+		if (node->TreeValid())
+			return true;
+
+		if (node->IsLeaf())
+			return false;
+			
+		BspInterior *in = dynamic_cast<BspInterior *>(node);
+		Plane3 splitPlane = in->GetPlane();
+			
+		if (splitPlane.Side(viewPoint) <= 0) 
+		{
+			node = in->GetBack();
+		} 
+		else
+		{
+			node = in->GetFront();
+		}
+	}
+
+	// should never come here
+	return false;
+}
+
+
+bool VspBspTree::CheckValid(const VspBspTraversalData &data) const
+{
+	return data.mPvs <= mMaxPvs;
+}
+
+
+void VspBspTree::PropagateUpValidity(BspNode *node)
+{
+	while (!node->IsRoot() && node->TreeValid())
+	{
+		node = node->GetParent();
+		node->SetTreeValid(false);
+	}
+}
+
 
 /************************************************************************/
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp	(revision 487)
@@ -1207,4 +1207,10 @@
 		 "0");
 
+  
+  RegisterOption("ViewCells.maxPvs",
+		 optInt,
+		 "-view_cells_max_pvs",
+		 "300");
+
   RegisterOption("ViewCells.PostProcess.minPvsDif",
 		 optInt,
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 487)
@@ -76,4 +76,5 @@
 }
 
+
 int BspNode::GetDepth() const
 {
@@ -89,4 +90,17 @@
 	return depth;
 }
+
+
+bool BspNode::TreeValid() const
+{
+	return mTreeValid;
+}
+
+
+void BspNode::SetTreeValid(const bool v)
+{
+	mTreeValid = v;
+}
+
 
 /****************************************************************/
@@ -186,5 +200,4 @@
 	return true; 
 }
-
 
 /****************************************************************/
@@ -1762,8 +1775,10 @@
 }
 
+
 AxisAlignedBox3 BspTree::GetBoundingBox() const
 {
 	return mBox;
 }
+
 
 BspNode *BspTree::GetRoot() const
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h	(revision 485)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h	(revision 487)
@@ -81,7 +81,7 @@
 	  const float dv = DotProd(v, mNormal);
     
-	  // does not intersect
+	  // does not intersect or coincident
 	  if (signum(dv) == 0)
-		  return -1;
+		  return 0;
 	
 	  return - Distance(a) / dv; // TODO: could be done more efficiently
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp	(revision 485)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp	(revision 487)
@@ -86,6 +86,6 @@
     return; // has been already precomputed
 
-  const float eps = 1e-6;
-  const float invEps = 1e6;
+  const float eps = 1e-6f;
+  const float invEps = 1e6f;
   
   // it does change the ray direction very slightly,
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 477)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp	(revision 487)
@@ -430,7 +430,13 @@
 	
   if (useViewSpaceBox)
+  {
 	mViewSpaceBox = box;
+	mViewCellsManager->SetViewSpaceBox(*box);
+  }
   else
+  {
 	mViewSpaceBox = NULL;
+	mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox());
+  }
 		
 
@@ -448,5 +454,7 @@
 	for (int k=0; k < s; k++) {
 			
-	  Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+	  //Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+	  Vector3 viewpoint; 
+	  mViewCellsManager->GetViewPoint(viewpoint);
 	  Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 			
@@ -497,5 +505,5 @@
   if (mUseViewcells) {
 	// construct view cells
-	mViewCellsManager->Construct(mObjects, mVssRays, mViewSpaceBox);
+	mViewCellsManager->Construct(mObjects, mVssRays);
 	
 	VssRayContainer selectedRays;
@@ -555,5 +563,8 @@
 	if (!mUseImportanceSampling) {
 	  for (int j=0; j < num; j++) {
-		Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+	    //changed by matt
+		//Vector3 viewpoint = GetViewpoint(mViewSpaceBox); 
+		Vector3 viewpoint; 
+		mViewCellsManager->GetViewPoint(viewpoint);
 		Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 		rays.push_back(SimpleRay(viewpoint, direction));
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 485)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.cpp	(revision 487)
@@ -378,9 +378,13 @@
 
   if (useViewSpaceBox)
+  {
 	mViewSpaceBox = box;
+	mViewCellsManager->SetViewSpaceBox(*box);
+  }
   else
+  {
 	mViewSpaceBox = NULL;
-
-
+	mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox());
+  }
   VssTree *vssTree = NULL;
 
@@ -395,6 +399,8 @@
 	int s = Min(mSamplesPerPass, mInitialSamples);
 	for (int k=0; k < s; k++) {
-
-	  Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+      // changed by matt
+	  //Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+	  Vector3 viewpoint; 
+	  mViewCellsManager->GetViewPoint(viewpoint);
 	  Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 
@@ -453,5 +459,5 @@
 
   // construct view cells
-  mViewCellsManager->Construct(mObjects, mVssRays, mViewSpaceBox);
+  mViewCellsManager->Construct(mObjects, mVssRays);
 
   vssTree = new VssTree;
@@ -501,5 +507,8 @@
 	if (!mUseImportanceSampling) {
 	  for (int j=0; j < num; j++) {
-		Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+	    // changed by matt
+		//Vector3 viewpoint = GetViewpoint(mViewSpaceBox);
+		Vector3 viewpoint; 
+		mViewCellsManager->GetViewPoint(viewpoint);
 		Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 		rays.push_back(SimpleRay(viewpoint, direction));
Index: trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 464)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp	(revision 487)
@@ -57,8 +57,6 @@
 	p->KdTreeStatistics(cout);
 	
-  
 	// parse view cells related options
 	p->PrepareViewCells();
-
 
   //  p->mSceneGraph->Export("soda.x3d");
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp	(revision 467)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssRay.cpp	(revision 487)
@@ -211,5 +211,5 @@
   
   s<<"##### VSS RAY STAT ##########\n";
-  s<<"#RAYS\n"<<size()<<endl;
+  s<<"#RAYS\n"<<(int)size()<<endl;
   s<<"#AVG_RAY_PVS_CONTRIBUTION\n"<<sumContributions/(float)size()<<endl;
   s<<"#AVG_RAY_RELATIVE_PVS_CONTRIBUTION\n"<<sumRelContributions/
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 477)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 487)
@@ -250,4 +250,6 @@
   mSceneGraph->CollectObjects(&objects);
 
+  mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox());
+  
   Vector3 point, normal, direction;
   //Ray ray;
Index: trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h	(revision 464)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.h	(revision 487)
@@ -9,4 +9,5 @@
 class RssTree;
 class RssTreeLeaf;
+
 
 /** Sampling based visibility preprocessing. The implementation is based on heuristical
@@ -32,5 +33,5 @@
 
   ofstream mStats;
-	
+
   ObjectContainer mObjects;
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 469)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/VssPreprocessor.h	(revision 487)
@@ -9,4 +9,5 @@
 class VssTree;
 class VssTreeLeaf;
+
 
 /** Sampling based visibility preprocessing. The implementation is based on heuristical
Index: trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 486)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 487)
@@ -21,4 +21,5 @@
 mTotalArea(0.0f)
 {
+	mSceneBox.Initialize();
 	ParseEnvironment();
 }
@@ -30,4 +31,5 @@
 mVisualizationSamples(0)
 {
+	mSceneBox.Initialize();
 	ParseEnvironment();
 }
@@ -81,4 +83,12 @@
 
 
+bool ViewCellsManager::GetViewPoint(Vector3 &viewPoint) const
+{
+	viewPoint = mSceneBox.GetRandomPoint();
+
+	return true;
+}
+
+
 void ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays)
 {
@@ -88,9 +98,8 @@
   
 	VssRayContainer::const_iterator it, it_end = rays.end();
-	int i = 0;	
+
 	for (it = rays.begin(); it != it_end; ++ it) 
-	{	Debug << "here " << i ++ << endl;
+	{	
 		ComputeSampleContributions(*(*it));
-		Debug << "**" << endl;
 	}
 }
@@ -104,5 +113,7 @@
 
 	for (it = mViewCells.begin(); it != it_end; ++ it)
+	{
 		(*it)->UpdateViewCellsStats(mViewCellsStats);
+	}
 }
 
@@ -295,4 +306,10 @@
 
 
+void ViewCellsManager::SetViewSpaceBox(const AxisAlignedBox3 &box)
+{
+	mSceneBox = box;
+}
+
+
 void ViewCellsManager::ResetViewCells()
 {
@@ -432,6 +449,5 @@
 
 int BspViewCellsManager::Construct(const ObjectContainer &objects, 
-								   const VssRayContainer &rays,
-								   AxisAlignedBox3 *sceneBbox)
+								   const VssRayContainer &rays)
 {
 	// if view cells were already constructed
@@ -1024,6 +1040,5 @@
 
 int KdViewCellsManager::Construct(const ObjectContainer &objects, 
-								  const VssRayContainer &rays,
-								  AxisAlignedBox3 *sceneBbox)
+								  const VssRayContainer &rays)
 {
 	// if view cells already constructed
@@ -1309,6 +1324,5 @@
 
 int VspKdViewCellsManager::Construct(const ObjectContainer &objects, 
-									 const VssRayContainer &rays,
-									 AxisAlignedBox3 *sceneBbox)
+									 const VssRayContainer &rays)
 {
 	// if view cells already constructed
@@ -1327,5 +1341,5 @@
 		  << (int)constructionRays.size() << " samples" << endl;
 
-	mVspKdTree->Construct(constructionRays, sceneBbox);
+	mVspKdTree->Construct(constructionRays, &mSceneBox);
 	Debug << mVspKdTree->GetStatistics() << endl;
 
@@ -1684,6 +1698,5 @@
 
 int VspBspViewCellsManager::Construct(const ObjectContainer &objects, 
-									  const VssRayContainer &rays,
-									  AxisAlignedBox3 *sceneBbox)
+									  const VssRayContainer &rays)
 {
 	// if view cells were already constructed
@@ -1697,11 +1710,11 @@
 
 	GetRaySets(rays, mConstructionSamples, constructionRays, &savedRays);
-	
+
 	Debug << "construction rays: " << (int)savedRays.size() << endl;
 	Debug << "saved rays: " << (int)constructionRays.size() << endl;
 
-	mVspBspTree->Construct(constructionRays, sceneBbox);
+	mVspBspTree->Construct(constructionRays, &mSceneBox);
+
 	Debug << mVspBspTree->GetStatistics() << endl;
-
 	ResetViewCells();
 
@@ -1932,4 +1945,21 @@
 	
 
+bool VspBspViewCellsManager::GetViewPoint(Vector3 &viewPoint) const
+{
+	if (!ViewCellsConstructed())
+		return ViewCellsManager::GetViewPoint(viewPoint);
+
+	const int limit = 10;
+
+	for (int i = 0; i < limit; ++ i)
+	{
+		viewPoint = mSceneBox.GetRandomPoint();
+		if (mVspBspTree->ViewPointValid(viewPoint))
+			return true;
+	}
+
+	return false;
+}
+
 void VspBspViewCellsManager::ExportSplits(const ObjectContainer &objects,
 										  const VssRayContainer &rays)
