Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 1233)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h	(revision 1278)
@@ -13,9 +13,7 @@
 
 class ViewCellLeaf;
-//class BspViewCell;
 class Plane3;
 class BspTree;  
 class BspInterior;
-//class Polygon3;
 class AxisAlignedBox3;
 class Ray;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1264)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1278)
@@ -974,5 +974,6 @@
 public:
 
-	VspOspViewCellsManager(ViewCellsTree *viewCellsTree, VspTree *tree, OspTree *ospTree);
+	VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm);
+	
 	~VspOspViewCellsManager();
 
@@ -1068,7 +1069,7 @@
 
 	/// the view space / object partition hierarchies
-	VspTree *mVspTree;
-	OspTree *mOspTree;
-	BvHierarchy *mBvHierarchy;
+	//VspTree *mVspTree;
+	//OspTree *mOspTree;
+	//BvHierarchy *mBvHierarchy;
 
 	HierarchyManager *mHierarchyManager;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1264)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1278)
@@ -23,4 +23,5 @@
 #include "BvHierarchy.h"
 
+
 // should not count origin object for sampling because it disturbs heuristics
 #define SAMPLE_ORIGIN_OBJECTS 0
@@ -355,5 +356,5 @@
 	// shoot simple ray and add it to importance samples
 	mPreprocessor->CastRays(simpleRays, passSamples);
-	
+
 	Debug << "cast " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
@@ -409,8 +410,8 @@
 
 	//-- construction rays => we use uniform samples for this
+
 	CastPassSamples(mInitialSamples, mSamplingType,	initialSamples);
 	
 	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-
 
 	// construct view cells
@@ -428,5 +429,4 @@
 	Debug << "time needed for initial construction: "
 		  << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-
 
 	// take post processing time
@@ -436,5 +436,4 @@
 	ResetViewCells();
   	Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl;
-
 
 	if (0) // export initial view cells
@@ -940,4 +939,5 @@
 
 		//-- construction rays => we use uniform samples for this
+
 		cout << "casting " << samplesPerPass << " samples ... ";
 		Debug << "casting " << samplesPerPass << " samples ... ";
@@ -4803,14 +4803,11 @@
 
 
-VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, VspTree *vspTree, OspTree *ospTree):
-ViewCellsManager(vcTree), mVspTree(vspTree), mOspTree(ospTree)
-{
-	mHierarchyManager = new HierarchyManager(*vspTree, *ospTree);
+VspOspViewCellsManager::VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm)
+: ViewCellsManager(vcTree), mHierarchyManager(hm)
+{
 	Environment::GetSingleton()->GetIntValue("VspTree.Construction.samples", mInitialSamples);
 
-	mVspTree->SetViewCellsManager(this);
-	mOspTree->SetViewCellsManager(this);
-
-	mVspTree->SetViewCellsTree(mViewCellsTree);
+	mHierarchyManager->SetViewCellsManager(this);
+	mHierarchyManager->SetViewCellsTree(mViewCellsTree);
 }
 
@@ -4818,5 +4815,4 @@
 VspOspViewCellsManager::~VspOspViewCellsManager()
 {
-	DEL_PTR(mHierarchyManager);
 }
 
@@ -4833,5 +4829,5 @@
 	if (!ViewCellsTreeConstructed())
 	{
-		mVspTree->CollectViewCells(mViewCells, false);
+		mHierarchyManager->GetVspTree()->CollectViewCells(mViewCells, false);
 	}
 	else 
@@ -4844,5 +4840,5 @@
 bool VspOspViewCellsManager::ViewCellsConstructed() const
 {
-	return mVspTree->GetRoot() != NULL;
+	return mHierarchyManager->GetVspTree()->GetRoot() != NULL;
 }
 
@@ -4893,9 +4889,12 @@
 
 	// print subdivision statistics
-	Debug << mVspTree->GetStatistics() << endl;
-	Debug << mOspTree->GetStatistics() << endl;
-
-	OUT_STREAM stream("osptree.xml.zip");
-	mOspTree->Export(stream);
+	Debug << mHierarchyManager->GetVspTree()->GetStatistics() << endl;
+	mHierarchyManager->PrintObjectSpaceHierarchyStatistics(Debug);
+
+	if (0)
+	{
+		OUT_STREAM stream("osptree.xml.zip");
+		mHierarchyManager->ExportObjectSpaceHierarchy(stream);
+	}	
 
 	// print view cell statistics
@@ -4985,5 +4984,5 @@
 		
 	// compute tree by merging the nodes of the spatial hierarchy
-	ViewCell *root = ConstructSpatialMergeTree(mVspTree->GetRoot());
+	ViewCell *root = ConstructSpatialMergeTree(mHierarchyManager->GetVspTree()->GetRoot());
 	mViewCellsTree->SetRoot(root);
 
@@ -5094,5 +5093,5 @@
 		viewPoint = mViewSpaceBox.GetRandomPoint();
 
-		if (mVspTree->ViewPointValid(viewPoint))
+		if (mHierarchyManager->GetVspTree()->ViewPointValid(viewPoint))
 		{
 			return true;
@@ -5124,5 +5123,5 @@
 		VspLeaf *l = vspVc->mLeaf;
 
-		const AxisAlignedBox3 box = mVspTree->GetBoundingBox(vspVc->mLeaf);
+		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf);
 		
 		if (clipPlane)
@@ -5218,40 +5217,6 @@
 	}
 
-	if (1 && mOspTree->GetRoot()) 
-	{	
-		//-- export final object partition
-		Exporter *exporter = Exporter::GetExporter("final_object_partition.wrl");
-		
-		if (exporter)
-		{
-			cout << "exporting object space partition ... ";
-
-			if (0 && mExportGeometry)
-			{
-				exporter->ExportGeometry(objects);
-			}
-
-			// export rays
-			if (0 && mExportRays)
-			{
-				exporter->ExportRays(visRays, RgbColor(0, 1, 0));
-			}
-
-			exporter->SetWireframe();
-	
-			const int savedColorCode = mColorCode;
-			mColorCode = 0;
-			const int maxPvs = 200;//mOspTree.GetStatistics().maxPvs;
-
-			exporter->ExportOspTree(*mOspTree, mColorCode == 0 ? 0 : maxPvs);
-
-			mColorCode = savedColorCode;
-
-			delete exporter;
-
-			cout << "finished" << endl;
-		}
-	}
-
+	mHierarchyManager->ExportObjectSpaceHierarchyForViz(objects);
+	
 	//-- export single view cells
 	ExportPvs(objects, visRays);
@@ -5386,44 +5351,43 @@
 		exporter->SetFilled();
 
-		if (1)
+#if 0	
+		//-- export pvs
+
+		Intersectable::NewMail();
+		KdLeaf::NewMail();
+
+		vector<KdLeaf *> kdLeaves;
+
+		ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
+
+		for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit)
 		{	
-			//-- export pvs
-			
-			Intersectable::NewMail();
-			KdLeaf::NewMail();
-
-			vector<KdLeaf *> kdLeaves;
-
-			ObjectPvsMap::const_iterator oit, oit_end = pvs.mEntries.end();
-
-			for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit)
-			{	
-				Intersectable *obj = (*oit).first;
-
-				if (obj->Type() == Intersectable::KD_INTERSECTABLE)
-				{
-					m.mDiffuseColor = RgbColor(1, 1, 1);
-					exporter->SetForcedMaterial(m);
-
-					// export bounding box of node
-					KdIntersectable *kdObj  = dynamic_cast<KdIntersectable *>(obj);
-					AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetItem());
-					
-					exporter->SetWireframe();
-					exporter->ExportBox(box);
-					exporter->SetFilled();
-				}
-
-				m.mDiffuseColor = RgbColor(1, 0, 0);
+			Intersectable *obj = (*oit).first;
+
+			if (obj->Type() == Intersectable::KD_INTERSECTABLE)
+			{
+				m.mDiffuseColor = RgbColor(1, 1, 1);
 				exporter->SetForcedMaterial(m);
 
-				// export pvs entry
-				if (!obj->Mailed())
-				{
-					exporter->ExportIntersectable(obj);
-					obj->Mail();
-				}
-			}		
-		}
+				// export bounding box of node
+				KdIntersectable *kdObj  = dynamic_cast<KdIntersectable *>(obj);
+				AxisAlignedBox3 box = mOspTree->GetBoundingBox(kdObj->GetItem());
+
+				exporter->SetWireframe();
+				exporter->ExportBox(box);
+				exporter->SetFilled();
+			}
+
+			m.mDiffuseColor = RgbColor(1, 0, 0);
+			exporter->SetForcedMaterial(m);
+
+			// export pvs entry
+			if (!obj->Mailed())
+			{
+				exporter->ExportIntersectable(obj);
+				obj->Mail();
+			}
+		}		
+#endif
 	
 		DEL_PTR(exporter);
@@ -5438,5 +5402,5 @@
 													ViewCellContainer &viewCells) const
 {
-	return mVspTree->ComputeBoxIntersections(box, viewCells);
+	return mHierarchyManager->GetVspTree()->ComputeBoxIntersections(box, viewCells);
 }
 
@@ -5446,5 +5410,5 @@
 											ViewCellContainer &viewcells)
 {
-	return mVspTree->CastLineSegment(origin, termination, viewcells);
+	return mHierarchyManager->GetVspTree()->CastLineSegment(origin, termination, viewcells);
 }
 
@@ -5503,5 +5467,5 @@
 		   << " max=\"" << mViewSpaceBox.Max().x << " " << mViewSpaceBox.Max().y << " " << mViewSpaceBox.Max().z << "\" />" << endl;
 
-	mVspTree->Export(stream);
+	mHierarchyManager->GetVspTree()->Export(stream);
 	stream << endl << "</ViewSpaceHierarchy>" << endl;
 
@@ -5509,20 +5473,6 @@
 	//-- export the object space partition
 	
-	// the type of the view cells hierarchy
-	if (mHierarchyManager->GetObjectSpaceSubdivisonType() == 
-		HierarchyManager::KD_BASED_OBJ_SUBDIV)
-	{
-		stream << "<ObjectSpaceHierarchy type=\"osp\">" << endl;
-		mOspTree->Export(stream);
-		stream << endl << "</ObjectSpaceHierarchy>" << endl;
-	}
-	else if (mHierarchyManager->GetObjectSpaceSubdivisonType() == 
-	         HierarchyManager::BV_BASED_OBJ_SUBDIV)
-	{
-		stream << "<ObjectSpaceHierarchy type=\"bvh\">" << endl;
-		mBvHierarchy->Export(stream);
-		stream << endl << "</ObjectSpaceHierarchy>" << endl;
-	}
-
+	mHierarchyManager->ExportObjectSpaceHierarchy(stream);
+	
 	stream << "</VisibilitySolution>" << endl;
 	stream.close();
@@ -5544,5 +5494,5 @@
 	  return NULL;
 
-	return mVspTree->GetViewCell(point, active);
+	return mHierarchyManager->GetVspTree()->GetViewCell(point, active);
 }
 
@@ -5561,5 +5511,5 @@
 	{
 		VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf;
-		const AxisAlignedBox3 box = mVspTree->GetBoundingBox(leaf);
+		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf);
 
         IncludeBoxInMesh(box, *mesh);
@@ -5592,5 +5542,5 @@
 		VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf;
 		
-		const AxisAlignedBox3 box = mVspTree->GetBoundingBox(leaf);
+		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf);
 
 		const float lVol = box.GetVolume();
@@ -5720,26 +5670,5 @@
 											float &contribution) const
 {
-	if (!obj) return false;
-
-	switch (mHierarchyManager->GetObjectSpaceSubdivisonType())
-    {
-	case HierarchyManager::NO_OBJ_SUBDIV:
-			// potentially visible objects
-			return vc->AddPvsSample(obj, pdf, contribution);
-
-	case HierarchyManager::KD_BASED_OBJ_SUBDIV:
-		{
-			// potentially visible kd cells
-			KdLeaf *leaf = mOspTree->GetLeaf(hitPoint/*ray->mOriginNode*/);
-			return mOspTree->AddLeafToPvs(leaf, vc, pdf, contribution);
-		}
-	case HierarchyManager::BV_BASED_OBJ_SUBDIV:
-		{
-			BvhLeaf *leaf = mBvHierarchy->GetLeaf(obj);
-			return mBvHierarchy->AddLeafToPvs(leaf, vc, pdf, contribution);
-		}
-	default:
-		return false;
-	}
+	return mHierarchyManager->AddSampleToPvs(obj, hitPoint, vc, pdf, contribution);
 }
 
@@ -5759,7 +5688,8 @@
 	ViewCellsManager *vm = 
 		ViewCellsManager::LoadViewCells(filename, objects, finalizeViewCells, bconverter);
-
+#if 0
+	// insert scene objects in tree
 	mOspTree->InsertObjects(mOspTree->GetRoot(), *objects);
-
+#endif
 	return vm;
 }
@@ -5841,5 +5771,5 @@
 	}
 
-	Debug << "\nhere295 " << rc / mVspTree->GetBoundingBox().GetVolume() << endl;
+	Debug << "\nhere295 " << rc / mHierarchyManager->GetVspTree()->GetBoundingBox().GetVolume() << endl;
 	mViewCellsTree->ExportStats(fileName);
 	cout << "finished" << endl;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1262)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1278)
@@ -2879,7 +2879,7 @@
 
 SubdivisionCandidate *VspTree::PrepareConstruction(const VssRayContainer &sampleRays,
-									AxisAlignedBox3 *forcedViewSpace,
-									RayInfoContainer &rays)
-{
+												   AxisAlignedBox3 *forcedViewSpace,
+												   RayInfoContainer &rays)
+{	
 	// store pointer to this tree
 	VspSubdivisionCandidate::sVspTree = this;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1264)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParserXerces.h	(revision 1278)
@@ -25,4 +25,6 @@
 class VspNode;
 class BvHierarchy;
+class HierarchyManager;
+
 
 class ViewCellsParseHandlers: public HandlerBase
@@ -73,10 +75,10 @@
 
   VspBspTree *mVspBspTree;
-  VspTree *mVspTree;
-  OspTree *mOspTree;
+  HierarchyManager *mHierarchyManager;
   BvHierarchy *mBvHierarchy;
 
   BspTree *mBspTree;
   ViewCellsTree *mViewCellsTree;
+  VspTree *mVspTree;
 
   BspNode *mCurrentBspNode;
@@ -142,5 +144,4 @@
   void StartOspInterior(AttributeList& attributes);
 
-  void CreateObjectSpaceHierarchy();
   void CreateViewSpaceHierarchy();
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1264)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1278)
@@ -34,4 +34,5 @@
 #include "KdTree.h"
 #include "BvHierarchy.h"
+#include "HierarchyManager.h"
 
 
@@ -91,4 +92,5 @@
   , mObjects(objects)
   , mBoundingBoxConverter(bconverter)
+  , mHierarchyManager(NULL)
 {
 	std::stable_sort(mObjects->begin(), mObjects->end(), ilt);
@@ -354,5 +356,5 @@
 	if (element == "ViewCells")
 	{
-		cout << "parsing view cells" << endl;
+		cout << "\nparsing view cells" << endl;
 		
 		mCurrentState = PARSE_VIEWCELLS;
@@ -372,5 +374,5 @@
 	if (element == "ViewSpaceHierarchy")
 	{		
-		cout << "parsing view space hierarchy" << endl;
+		cout << "\nparsing view space hierarchy" << endl;
 		mCurrentState = PARSE_VIEWSPACE_HIERARCHY;
 		StartViewSpaceHierarchy(attributes);
@@ -380,5 +382,5 @@
 	if (element == "ObjectSpaceHierarchy")
 	{
-		cout << "parsing object space hierarchy" << endl;
+		cout << "\nparsing object space hierarchy" << endl;
 		mCurrentState = PARSE_OBJECTSPACE_HIERARCHY;
 		StartObjectSpaceHierarchy(attributes);
@@ -565,13 +567,13 @@
 		if (attrName == "type")
 		{
-			if (strcmp(ptr, "bsp") == 0)
+			if (strcmp(ptr, "osp") == 0)
 			{
-				Debug << "view space hierarchy: Bsp" << endl;
-				mViewSpaceHierarchyType = BSP;
+				Debug << "object space hierarchy: Osp" << endl;
+				mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::KD_BASED_OBJ_SUBDIV);
 			}
-			else if (strcmp(ptr, "vsp") == 0)
+			else if (strcmp(ptr, "bvh") == 0)
 			{
-				Debug << "view space hierarchy: Vsp" << endl;
-				mViewSpaceHierarchyType = VSP;
+				Debug << "object space hierarchy: Bvh" << endl;
+				mHierarchyManager = new HierarchyManager(mVspTree, HierarchyManager::BV_BASED_OBJ_SUBDIV);
 			}
 		}
@@ -778,26 +780,17 @@
 
 		mVspTree = new VspTree();
+
 		// set view space box
 		mVspTree->mBoundingBox = mViewSpaceBox;
+
+		// object space hierarchy already constructed
+		if (mHierarchyManager)
+		{
+			mHierarchyManager->mVspTree = mVspTree;
+			mVspTree->mHierarchyManager = mHierarchyManager;
+		}
 	}
 	
 	cout << "\nview space box: " << mViewSpaceBox << endl;
-}
-
-
-void ViewCellsParseHandlers::CreateObjectSpaceHierarchy()
-{
-	if (mViewSpaceHierarchyType == OSP)
-	{
-		Debug << "object hierarchy type: Osp" << endl;
-
-		mOspTree = new OspTree();
-	}
-	else if (mViewSpaceHierarchyType == VSP) 
-	{
-		Debug << "object hierarchy type: Vsp" << endl;
-
-		mVspTree = new VspTree();
-	}
 }
 
@@ -814,8 +807,8 @@
 	else if (mViewSpaceHierarchyType == VSP) 
 	{
-		Debug << "vcreating view cells manager: VsOspp" << endl;
+		Debug << "creating view cells manager: VspOsp" << endl;
 
 		// hack
-		mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mVspTree, mOspTree);
+		mViewCellsManager = new VspOspViewCellsManager(mViewCellsTree, mHierarchyManager);
 	}
 
@@ -978,5 +971,5 @@
 	else
 	{
-		mOspTree->mRoot = interior;
+		mHierarchyManager->mOspTree->mRoot = interior;
 	}
 
@@ -996,5 +989,5 @@
 	else
 	{
-		mOspTree->mRoot = leaf;
+		mHierarchyManager->mOspTree->mRoot = leaf;
 	}
 }
@@ -1002,5 +995,5 @@
 
 void ViewCellsParseHandlers::StartBvhLeaf(AttributeList& attributes)
-{
+{/*
 	KdLeaf * leaf = 
 		new KdLeaf(dynamic_cast<KdInterior *>(mCurrentKdNode), NULL);
@@ -1012,11 +1005,11 @@
 	else
 	{
-		mOspTree->mRoot = leaf;
-	}
+		mHierarchyManager->mBvHierarchy->mRoot = leaf;
+	}*/
 }
 
 
 void ViewCellsParseHandlers::StartBvhInterior(AttributeList& attributes)
-{
+{/*
 	AxisAlignedPlane plane;
 	int len = attributes.getLength();
@@ -1051,5 +1044,5 @@
 	}
 
-	mCurrentKdNode = interior;
+	mCurrentKdNode = interior;*/
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1264)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1278)
@@ -48,5 +48,5 @@
 
 bool ObjectDirectionBasedDistribution::GenerateSample(SimpleRay &ray) const
-{
+{	
 	Vector3 origin, direction; 
 
@@ -66,5 +66,5 @@
 	if (c <= Limits::Small) 
 		return false;
-
+	
 	// $$ jb the pdf is yet not correct for all sampling methods!
 	const float pdf = 1.0f;
@@ -78,5 +78,5 @@
 
 bool DirectionBasedDistribution::GenerateSample(SimpleRay &ray) const
-{
+{	
 	Vector3 origin, direction; 
 	mPreprocessor.mViewCellsManager->GetViewPoint(origin);
@@ -125,6 +125,6 @@
 {
 	Vector3 origin, direction; 
+
 	mPreprocessor.mViewCellsManager->GetViewPoint(origin);
-	
 	direction = mPreprocessor.mKdTree->GetBox().GetRandomPoint() - origin;
 	
