Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1414)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1416)
@@ -151,7 +151,7 @@
     */
     virtual bool LoadViewCellsGeometry(const string filename);
-
-	
-	/** Constructs view cell from base triangle. The ViewCell is extruded along the normal vector.
+	
+	/** Constructs view cell from base triangle. 
+		The view cell is extruded along the normal vector.
 		@param the base triangle
 		@param the height of the newly created view cell
@@ -347,15 +347,16 @@
 	*/
 	int GetMinPvsSize() const;
-
 	/** Returns maximal ratio. i.e., currentPVs / maxPvs,
 		where pvs is still considered valid.
 	*/
 	float GetMaxPvsRatio() const;
-
 	/** Exports view cell geometry.
 	*/
-	virtual void ExportViewCellGeometry(Exporter *exporter, 
-										ViewCell *vc,
-										const AxisAlignedPlane *clipPlane = NULL) const = 0;
+	virtual	void ExportViewCellGeometry(
+		Exporter *exporter,
+		ViewCell *vc,
+		const AxisAlignedBox3 *box,
+		const AxisAlignedPlane *clipPlane = NULL
+		) const = 0;
 
 	/** Brings the view cells into their final state, computes meshes and volume.
@@ -483,4 +484,5 @@
 	//////////////////////////////////////////////////////////////////
 
+
 	/** Returns true if the view cell is equivalent to a 
 		node of the spatial hierarchy. This function can be used for merged
@@ -553,26 +555,34 @@
 	void EvaluateViewCellsStats();
 
+
+	///////////////////////
 	//-- helper functions for view cell visualization
 
 	/** Exports the view cell partition.
 	*/
-	void ExportViewCellsForViz(Exporter *exporter) const;
+	void ExportViewCellsForViz(
+		Exporter *exporter, 
+		const AxisAlignedBox3 *box,
+		const AxisAlignedPlane *clipPlane = NULL) const;
 
 	/** Sets exporter color.
 	*/
 	virtual void ExportColor(Exporter *exporter, ViewCell *vc) const;
+	/** Creates meshes from the view cells.
+	*/
+	void CreateViewCellMeshes();
+	/** Creates clip plane for visualization.
+	*/
+	void CreateClipPlane();
+
+	AxisAlignedPlane *GetClipPlane();
+	///////////////////////
 
 	/** Returns volume of the view space.
 	*/
 	virtual float GetViewSpaceVolume();
-	
-	/** Creates meshes from the view cells.
-	*/
-	void CreateViewCellMeshes();
-
-	/** Takes different measures to prepares the view cells after loading them from disc.
+	/** Prepares the view cells for sampling after loading them from disc.
 	*/
 	virtual void PrepareLoadedViewCells() {};
-
 	/** Constructs local view cell merge hierarchy.
 	*/
@@ -586,8 +596,4 @@
 									   const ViewCellContainer &viewCells);
   
-	/** Creates clip plane for visualization.
-	*/
-	void CreateClipPlane();
-
 	/** Updates pvs of all view cells for statistical evaluation after some more sampling
 	*/
@@ -600,25 +606,22 @@
 	/// if bounding boxes should be exported together with the view cells
 	bool mExportBboxesForPvs;
-		
-	//Environment *environment;
-	AxisAlignedPlane mClipPlane;
-
+	/// the clip plane for visualization
+	AxisAlignedPlane mClipPlaneForViz;
+	/// if the visualization is using the clip plane
 	bool mUseClipPlaneForViz;
-
-
 	/// Renders the view cells.
 	Renderer *mRenderer;
-
 	/// Loaded view cells
 	ViewCellContainer mViewCells;
-	/// the corresponding view cell tree holding the logical description of view cells
+	/// the view cell hierarchy (i.e., the logical description of view cells)
 	ViewCellsTree *mViewCellsTree;
 	
-	/// if the values in the view cell leaves and the interiors are up to date
-	/// this is meant for lazy storing of the pvs, where only a scalar indicating
-	/// pvs size is stored in interiors and not the pvs itself.
+	/** if the values in the view cell leaves and the interiors are up to date
+		this is meant for lazy storing of the pvs, where only a scalar indicating
+		pvs size is stored in interiors and not the pvs itself.
+	*/
 	bool mViewCellPvsIsUpdated;
 
-	/// maximum number of samples taken for construction of the view cells
+	/// maximum number of samples for the view cell construction
 	int mConstructionSamples;
 	int mSamplesPerPass;
@@ -732,7 +735,9 @@
 	void CreateMesh(ViewCell *vc);
 
-	void ExportViewCellGeometry(Exporter *exporter, 
-								ViewCell *vc, 
-								const AxisAlignedPlane *clipPlane = NULL) const;
+	void ExportViewCellGeometry(Exporter *exporter,
+								ViewCell *vc,
+								const AxisAlignedBox3 *box,
+								const AxisAlignedPlane *clipPlane = NULL
+								) const;
 	
 	void CollectMergeCandidates(const VssRayContainer &rays, 
@@ -741,5 +746,7 @@
 	void Finalize(ViewCell *viewCell, const bool createMesh);
 
-	bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
+	bool ExportViewCells(const string filename, 
+						 const bool exportPvs, 
+						 const ObjectContainer &objects);
 
 	/** Constructs merge hierarchy which corresponds to the spatial hierarchy.
@@ -805,14 +812,18 @@
 	*/
 	//  virtual void PrintStatistics(ostream &s) const;
-	ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const { return NULL; }
+	ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const 
+	{ return NULL; }
 
 	float GetProbability(ViewCell *viewCell);
 	
-
 	void CreateMesh(ViewCell *vc);
 
-	void ExportViewCellGeometry(Exporter *exporter, 
-								ViewCell *vc,
-								const AxisAlignedPlane *clipPlane = NULL) const;
+	void ExportViewCellGeometry(
+		Exporter *exporter,
+		ViewCell *vc,
+		const AxisAlignedBox3 *box,
+		const AxisAlignedPlane *clipPlane = NULL
+		) const;
+
 
 	void CollectMergeCandidates(const VssRayContainer &rays, 
@@ -879,13 +890,18 @@
 	void CreateMesh(ViewCell *vc);
 
-	bool ExportViewCells(const string filename, const bool exportPvs, const ObjectContainer &objects);
+	bool ExportViewCells(
+		const string filename, 
+		const bool exportPvs, 
+		const ObjectContainer &objects);
 
 	int CastBeam(Beam &beam);
-
-	void ExportViewCellGeometry(Exporter *exporter, 
-								ViewCell *vc,
-								const AxisAlignedPlane *clipPlane = NULL) const;
-
-	//float GetVolume(ViewCell *viewCell) const;
+	
+	void ExportViewCellGeometry(
+		Exporter *exporter,
+		ViewCell *vc,
+		const AxisAlignedBox3 *box,
+		const AxisAlignedPlane *clipPlane = NULL
+		) const;
+
 
 	void Finalize(ViewCell *viewCell, const bool createMesh);
@@ -920,5 +936,4 @@
 	*/
 	int GetMaxTreeDiff(ViewCell *vc) const;
-	
 
 	/** Prepare view cells for use after loading them from disc.
@@ -1039,15 +1054,19 @@
 	virtual void EvalViewCellPartition();
 #endif
+
 	/** Exports view cell geometry.
 	*/
-	void ExportViewCellGeometry(Exporter *exporter, 
+	void ExportViewCellGeometry(
+		Exporter *exporter,
 		ViewCell *vc,
-		const AxisAlignedPlane *clipPlane = NULL) const;
-
-	int ComputeBoxIntersections(const AxisAlignedBox3 &box, 
+		const AxisAlignedBox3 *box,
+		const AxisAlignedPlane *clipPlane = NULL
+		) const;
+
+	int ComputeBoxIntersections(
+		const AxisAlignedBox3 &box, 
 		ViewCellContainer &viewCells) const;
 	
 	void CollectViewCells();
-
 
 	/** Prepare view cells for use after loading them from disc.
@@ -1067,9 +1086,4 @@
 
 	/////////////////////////////////////////
-
-	/// the view space / object partition hierarchies
-	//VspTree *mVspTree;
-	//OspTree *mOspTree;
-	//BvHierarchy *mBvHierarchy;
 
 	HierarchyManager *mHierarchyManager;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1416)
@@ -25,6 +25,4 @@
 
 
-
-//Environment *environment = NULL;
 Environment *Environment::sEnvironment = NULL;
 
@@ -39,4 +37,5 @@
 	return sEnvironment;
 }
+
 
 void Environment::DelSingleton()
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.h	(revision 1416)
@@ -49,6 +49,6 @@
 				  mUseForcedMaterial(false),
 				  mExportRayDensity(false)
-  {
-  }
+  {}
+
   virtual ~Exporter() {}
   
@@ -117,5 +117,8 @@
 
   virtual void
-  ExportGeometry(const ObjectContainer &objects, const bool exportSingleMesh = false, AxisAlignedBox3 *bbox = NULL);
+  ExportGeometry(
+	const ObjectContainer &objects, 
+	const bool exportSingleMesh = false, 
+	AxisAlignedBox3 *bbox = NULL);
 
   virtual void
@@ -147,5 +150,9 @@
 
   void ExportKdIntersectable(const KdIntersectable &kdObj);
-  bool ExportBvHierarchy(const BvHierarchy &bvHierarchy, const int maxPvs, AxisAlignedBox3 *box = NULL);
+
+  bool ExportBvHierarchy(
+	  const BvHierarchy &bvHierarchy, 
+	  const int maxPvs, 
+	  const AxisAlignedBox3 *box = NULL);
 
   virtual void ExportMeshInstance(MeshInstance *mi);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1416)
@@ -800,8 +800,6 @@
 	
 	if (!loadKdTree)
-	{
-		/////////////////
+	{	//////
 		//-- build new kd tree from scene geometry
-
 		BuildKdTree();
 		KdTreeStatistics(cout);
@@ -817,4 +815,5 @@
 			return false;
 		}
+
 		cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1416)
@@ -201,8 +201,10 @@
 
 	AxisAlignedBox3 GetViewSpaceBox() const;
+	AxisAlignedBox3 GetObjectSpaceBox() const;
 
 	void ExportObjectSpaceHierarchy(
 		Exporter *exporter, 
-		const ObjectContainer &objects) const;
+		const ObjectContainer &objects,
+		const AxisAlignedBox3 *bbox) const;
 
 
@@ -255,5 +257,5 @@
 		Exporter *exporter, 
 		const ObjectContainer &objects, 
-		AxisAlignedBox3 *box) const;
+		const AxisAlignedBox3 *box) const;
 
 	void PrepareBvHierarchy(
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1416)
@@ -356,9 +356,9 @@
 	
 	ResetViewCells();
-  	if (0) Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl;
-
-	//-- optionally export initial view cell partition
-	if (0) 
-	{
+  		
+	if (0) //-- optionally export initial view cell partition
+	{
+        Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl;
+
 		const string filename("viewcells.wrl");
 		Exporter *exporter = Exporter::GetExporter(filename.c_str());
@@ -374,5 +374,5 @@
 
 			exporter->SetWireframe();
-			ExportViewCellsForViz(exporter);
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
 
 			delete exporter;
@@ -429,6 +429,6 @@
 	
 #if 0
-	////////////////////////////////////////////////
-	//-- get stats after the additional sampling step
+	///////////////
+	//-- Get stats after the additional sampling step
 	//-- and before the bottom-up merge step
 
@@ -445,5 +445,5 @@
 
 
-	///////////////////////////////////////////////
+	////////////////////
 	//
 	//-- post processing of the initial construction
@@ -476,5 +476,5 @@
 
 	
-	//////////////////////////////////////////////////////////////
+	////////////////
 	//-- Evaluation of the resulting view cell partition. 
 	//-- We cast a number of new samples and measure the render cost
@@ -486,5 +486,5 @@
 
 	
-	///////////////////////////////////
+	/////////////////
 	//-- Finally, we do some visualization
 
@@ -508,4 +508,10 @@
 
 	return numSamples;
+}
+
+
+AxisAlignedPlane * ViewCellsManager::GetClipPlane()
+{
+	return mUseClipPlaneForViz ? &mClipPlaneForViz : NULL;
 }
 
@@ -1692,11 +1698,9 @@
 
 	Environment::GetSingleton()->GetFloatValue("ViewCells.Visualization.clipPlanePos", pos);
-
-	Vector3 point = mViewSpaceBox.Min() +  mViewSpaceBox.Size() * pos;
-
-	if (mUseClipPlaneForViz)
-        Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.clipPlaneAxis", axis);
-
-	mClipPlane = AxisAlignedPlane(axis, point[axis]);
+	Vector3 absPos = mViewSpaceBox.Min() +  mViewSpaceBox.Size() * pos;
+	
+	Environment::GetSingleton()->GetIntValue("ViewCells.Visualization.clipPlaneAxis", axis);
+
+	mClipPlaneForViz = AxisAlignedPlane(axis, absPos[axis]);
 }
 
@@ -1946,6 +1950,9 @@
 }
 
-// matt: todo
-void ViewCellsManager::ExportViewCellsForViz(Exporter *exporter) const
+
+void ViewCellsManager::ExportViewCellsForViz(Exporter *exporter,
+											 const AxisAlignedBox3 *sceneBox,
+											 const AxisAlignedPlane *clipPlane
+											 ) const
 {
 	ViewCellContainer::const_iterator it, it_end = mViewCells.end();
@@ -1956,7 +1963,5 @@
 		{
 			ExportColor(exporter, *it);	
-
-			ExportViewCellGeometry(exporter, *it, 
-				mUseClipPlaneForViz ? &mClipPlane : NULL);
+			ExportViewCellGeometry(exporter, *it, sceneBox, clipPlane);
 		}
 	}
@@ -2670,9 +2675,7 @@
 	const int savedColorCode = mColorCode;
 	
-	//BspLeaf::NewMail();
 	if (1) // export merged view cells
 	{
-		mColorCode = 0;
-		
+		mColorCode = 0; // hack color code
 		Exporter *exporter = Exporter::GetExporter("merged_view_cells.wrl");
 		
@@ -2683,10 +2686,10 @@
 		{
 			if (mExportGeometry)
+			{
 				exporter->ExportGeometry(objects);
-
-			//exporter->SetWireframe();
+			}
+
 			exporter->SetFilled();
-			ExportViewCellsForViz(exporter);
-
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
 
 			delete exporter;
@@ -2695,23 +2698,21 @@
 	}
 
-	if (1) // export merged view cells using pvs color coding
-	{
+	if (1) 
+	{
+		// export merged view cells using pvs color coding
 		mColorCode = 1;
 
 		Exporter *exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl");
-	
 		cout << "exporting view cells after merge (pvs size) ... ";	
 
 		if (exporter)
 		{
-			//exporter->SetWireframe();
-			//exporter->SetForcedMaterial(RandomMaterial());
-
 			if (mExportGeometry)
+			{
 				exporter->ExportGeometry(objects);
-
-			//exporter->SetWireframe();
+			}
+			
 			exporter->SetFilled();
-			ExportViewCellsForViz(exporter);
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
 
 			delete exporter;
@@ -2769,16 +2770,10 @@
 		if (exporter)
 		{
-			//exporter->SetWireframe();
-			
 			if (mExportGeometry)
+			{
 				exporter->ExportGeometry(objects);
-
-			//exporter->SetFilled();
-			const bool b = mUseClipPlaneForViz;
-			mUseClipPlaneForViz = false;
-
-			ExportViewCellsForViz(exporter);
-			
-			mUseClipPlaneForViz = b;
+			}
+
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
 			delete exporter;
 		}
@@ -2788,5 +2783,8 @@
 	mColorCode = savedColorCode;
 
+
+	//////////////////
 	//-- visualization of the BSP splits
+
 	bool exportSplits = false;
 	Environment::GetSingleton()->GetBoolValue("BspTree.Visualization.exportSplits", exportSplits);
@@ -2890,5 +2888,5 @@
 		exporter->SetForcedMaterial(m);
 
-		ExportViewCellGeometry(exporter, vc);
+		ExportViewCellGeometry(exporter, vc, NULL, NULL);
 		
 		// export rays piercing this view cell
@@ -2962,5 +2960,7 @@
 void BspViewCellsManager::ExportViewCellGeometry(Exporter *exporter,
 												 ViewCell *vc,
-												 const AxisAlignedPlane *clipPlane) const
+												 const AxisAlignedBox3 *sceneBox,
+												 const AxisAlignedPlane *clipPlane
+												) const
 {
 	// export mesh if available
@@ -3437,8 +3437,9 @@
 void KdViewCellsManager::ExportViewCellGeometry(Exporter *exporter,
 												ViewCell *vc,
-												const AxisAlignedPlane *clipPlane) const
+												const AxisAlignedBox3 *sceneBox,
+												const AxisAlignedPlane *clipPlane
+												) const
 {
 	ViewCellContainer leaves;
-
 	mViewCellsTree->CollectLeaves(vc, leaves);
 	ViewCellContainer::const_iterator it, it_end = leaves.end();
@@ -3447,5 +3448,4 @@
 	{
 		KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it);
-	
 		exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaf));
 	}
@@ -3718,5 +3718,5 @@
 				exporter->SetFilled();
 
-			ExportViewCellsForViz(exporter);
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
 
 			if (mExportGeometry)
@@ -3737,5 +3737,6 @@
 	if (1) 
 	{
-		mColorCode = 1; // export merged view cells using pvs coding
+		// use pvs size for color coding
+		mColorCode = 1;
 		Exporter *exporter = Exporter::GetExporter("merged_view_cells_pvs.wrl");
 
@@ -3744,10 +3745,7 @@
 		if (exporter)
 		{
-			if (0)
-				exporter->SetWireframe();
-			else
-				exporter->SetFilled();
-
-			ExportViewCellsForViz(exporter);
+			exporter->SetFilled();
+
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
 
 			if (mExportGeometry)
@@ -4033,12 +4031,10 @@
 	GetRaySets(sampleRays, mVisualizationSamples, visRays);
 
-	//-- export final view cell partition
-
+	
 	if (0) 
 	{	
-		// hack pvs
-		//const int savedColorCode = mColorCode;
-		//mColorCode = 1;
-	
+		//////////////////
+		//-- export final view cell partition
+
 		Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl");
 		
@@ -4074,21 +4070,10 @@
 			}
 
-			//exporter->SetFilled();
-
-			// HACK: export without clip plane
-			const bool b = mUseClipPlaneForViz;
-			//mUseClipPlaneForViz = false;
-
-			ExportViewCellsForViz(exporter);
-			
-			mUseClipPlaneForViz = b;
+			ExportViewCellsForViz(exporter, NULL, GetClipPlane());
+
 			delete exporter;
-
 			cout << "finished" << endl;
 		}
-
-		//mColorCode = savedColorCode;
-	}
-
+	}
 
 	if (0)
@@ -4316,6 +4301,7 @@
 		}
 		
-
+		////////////////
 		//-- export view cell geometry
+
 		exporter->SetWireframe();
 
@@ -4324,12 +4310,11 @@
 		exporter->SetForcedMaterial(m);
 
-		ExportViewCellGeometry(exporter, vc);
-	
+		ExportViewCellGeometry(exporter, vc, NULL, NULL);
 		exporter->SetFilled();
 
-
-		//-- export pvs
 		if (1)
 		{
+			////////
+			//-- export pvs
 			ObjectPvsMap::const_iterator oit,
 				oit_end = pvs.mEntries.end();
@@ -4396,9 +4381,9 @@
 
 		exporter->SetForcedMaterial(RgbColor(0,1,0));
-		ExportViewCellGeometry(exporter, GetViewCell(viewPoint));
+		ExportViewCellGeometry(exporter, GetViewCell(viewPoint), NULL, NULL);
 
 		//exporter->ResetForcedMaterial();
 		exporter->SetForcedMaterial(RgbColor(0,0,1));
-		ExportViewCellGeometry(exporter, testPrVs.mViewCell);
+		ExportViewCellGeometry(exporter, testPrVs.mViewCell, NULL, NULL);
 
      	exporter->SetForcedMaterial(RgbColor(1,0,0));
@@ -4491,5 +4476,5 @@
 		m.mDiffuseColor.b = 1.0f;
 		//exporter->SetForcedMaterial(m);
-		//ExportViewCellGeometry(exporter, vc, mClipPlane);
+		//ExportViewCellGeometry(exporter, vc, mClipPlaneForViz);
 
 		/*	// counting the pvss
@@ -4510,6 +4495,8 @@
 
 void VspBspViewCellsManager::ExportViewCellGeometry(Exporter *exporter,
-                                                    ViewCell *vc,
-													const AxisAlignedPlane *clipPlane) const
+													ViewCell *vc,
+													const AxisAlignedBox3 *sceneBox,
+													const AxisAlignedPlane *clipPlane
+													) const
 {
 	if (clipPlane)
@@ -5013,5 +5000,7 @@
 void VspOspViewCellsManager::ExportViewCellGeometry(Exporter *exporter,
 													ViewCell *vc,
-													const AxisAlignedPlane *clipPlane) const
+													const AxisAlignedBox3 *sceneBox,
+													const AxisAlignedPlane *clipPlane
+													) const
 {
 	ViewCellContainer leaves;
@@ -5021,12 +5010,7 @@
 
 	Plane3 plane;
-	
+
 	if (clipPlane)
-	{
 		plane = clipPlane->GetPlane();
-	}
-
-	AxisAlignedBox3 bbox = GetViewSpaceBox();
-	bbox.Scale(Vector3(0.5, 1, 0.5));			
 
 	for (it = leaves.begin(); it != it_end; ++ it)
@@ -5035,7 +5019,8 @@
 		VspLeaf *l = vspVc->mLeaf;
 
-		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf);
+		const AxisAlignedBox3 box = 
+			mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf);
 		
-		if (!Overlap(box, bbox))
+		if (!Overlap(*sceneBox, box))
 			continue;
 
@@ -5049,5 +5034,5 @@
 			{
 				AxisAlignedBox3 fbox, bbox;
-				box.Split(clipPlane->mAxis, clipPlane->mPosition, fbox, bbox);
+				bbox.Split(clipPlane->mAxis, clipPlane->mPosition, fbox, bbox);
 
 				exporter->ExportBox(bbox);
@@ -5084,5 +5069,5 @@
 	if (1) 
 	{	
-		/////////////////////////////
+		////////////
 		//-- export final view cells
 
@@ -5098,7 +5083,11 @@
 			cout << "exporting final view cells (after initial construction + post process) ... ";
 
+			// matt: hack
+			AxisAlignedBox3 bbox = mHierarchyManager->GetViewSpaceBox();
+			bbox.Scale(Vector3(0.5, 1, 0.5));
+
 			if (mExportGeometry)
 			{
-				exporter->ExportGeometry(objects, true);
+				exporter->ExportGeometry(objects, true, &bbox);
 			}
 
@@ -5109,13 +5098,7 @@
 			}
 
-			// HACK: export without clip plane
-			const bool b = mUseClipPlaneForViz;
-			if (0) mUseClipPlaneForViz = false;
-
-			ExportViewCellsForViz(exporter);
-			
-			mUseClipPlaneForViz = b;
+			ExportViewCellsForViz(exporter, &bbox, GetClipPlane());
+		
 			delete exporter;
-
 			cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl;
 		}
@@ -5132,7 +5115,11 @@
 		{
 			const long starttime = GetTime();
+			
+			// matt: hack
+			AxisAlignedBox3 bbox = mHierarchyManager->GetObjectSpaceBox();
+			bbox.Scale(Vector3(0.5, 1, 0.5));
 
 			cout << "exporting object space hierarchy ... ";
-			mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects);
+			mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, &bbox);
 		
 			delete exporter;
@@ -5187,5 +5174,4 @@
 		mViewCellsTree->GetPvs(vc, pvs);
 
-		//bspLeaves[j]->Mail();
 		char s[64]; sprintf(s, "bsp-pvs%04d.wrl", i);
 		Exporter *exporter = Exporter::GetExporter(s);
@@ -5266,10 +5252,9 @@
 		exporter->SetWireframe();
 
-		Material m;//= RandomMaterial();
+		Material m;
 		m.mDiffuseColor = RgbColor(0, 1, 0);
 		exporter->SetForcedMaterial(m);
 
-		ExportViewCellGeometry(exporter, vc);
-	
+		ExportViewCellGeometry(exporter, vc, NULL, NULL);
 		exporter->SetFilled();
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1416)
@@ -106,5 +106,5 @@
 bool Exporter::ExportBvHierarchy(const BvHierarchy &bvHierarchy, 
 								 const int maxPvs,
-								 AxisAlignedBox3 *box)
+								 const AxisAlignedBox3 *box)
 {
 	vector<BvhLeaf *> leaves;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1311)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1416)
@@ -974,6 +974,7 @@
 
 			exporter->SetForcedMaterial(m);
-			mViewCellsManager->ExportViewCellGeometry(exporter, *it);
-		}
+			mViewCellsManager->ExportViewCellGeometry(exporter, *it, NULL, NULL);
+		}
+
 		delete exporter;
 		cout << "finished" << endl;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1415)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1416)
@@ -143,5 +143,5 @@
 	if (mOspTree)
 		mOspTree->SetViewCellsManager(vcm);
-	if (mBvHierarchy)
+	else if (mBvHierarchy)
 		mBvHierarchy->SetViewCellsManager(vcm);
 }
@@ -163,4 +163,19 @@
 {
 	return mVspTree->mBoundingBox;
+}
+
+
+AxisAlignedBox3 HierarchyManager::GetObjectSpaceBox() const
+{
+	switch (mObjectSpaceSubdivisionType)
+	{
+	case KD_BASED_OBJ_SUBDIV:
+		return mOspTree->mBoundingBox;
+	case BV_BASED_OBJ_SUBDIV:
+		return mBvHierarchy->mBoundingBox;
+	default:
+		// empty box
+		return AxisAlignedBox3();
+	}
 }
 
@@ -360,6 +375,6 @@
 		{
 			KdNode *n = mOspTree->Subdivide(mTQueue, sc, globalTerminationCriteriaMet);
-
-			if (n->IsLeaf()) // local or global termination criteria failed
+			// local or global termination criteria failed
+			if (n->IsLeaf()) 
 				return false;
 		}
@@ -367,11 +382,11 @@
 		{
 			BvhNode *n = mBvHierarchy->Subdivide(mTQueue, sc, globalTerminationCriteriaMet);
-
-			if (n->IsLeaf()) // local or global termination criteria failed
+			// local or global termination criteria failed
+			if (n->IsLeaf())
 				return false;
 		}
 	}
 
-	return true;//!globalTerminationCriteriaMet;
+	return true;
 }
 
@@ -746,5 +761,6 @@
 
 void HierarchyManager::ExportObjectSpaceHierarchy(Exporter *exporter,
-												  const ObjectContainer &objects) const
+												  const ObjectContainer &objects,
+												  const AxisAlignedBox3 *bbox) const
 {
 	switch (mObjectSpaceSubdivisionType)
@@ -757,8 +773,5 @@
 	case BV_BASED_OBJ_SUBDIV:
 		{
-			AxisAlignedBox3 bbox = mBvHierarchy->GetBoundingBox();
-			bbox.Scale(Vector3(0.5, 1, 0.5));
-			
-			ExportBvHierarchy(exporter, objects, &bbox);
+			ExportBvHierarchy(exporter, objects, bbox);
 			break;
 		}
@@ -771,5 +784,5 @@
 void HierarchyManager::ExportBvHierarchy(Exporter *exporter, 
 										 const ObjectContainer &objects,
-										 AxisAlignedBox3 *bbox) const
+										 const AxisAlignedBox3 *bbox) const
 {
 	exporter->SetWireframe();
