Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1143)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1144)
@@ -440,7 +440,7 @@
 	{
 		mVspTree = new VspTree();
-		//mOspTree = new OspTree();
+		mOspTree = new OspTree();
 		// HACK
-		mOspTree = new OspTree(*mKdTree);
+		//mOspTree = new OspTree(*mKdTree);
 
 		mViewCellsManager = new VspOspViewCellsManager(mVspTree, mOspTree);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1143)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1144)
@@ -947,7 +947,7 @@
 		if (obj) 
 		{
-			// potentially visible kd cells
 			if (mStoreKdPvs)
 			{
+				// potentially visible kd cells
 				KdLeaf *leaf = mOspTree->GetLeaf(ray->mTermination, ray->mTerminationNode);
 				AddKdLeafToPvs(leaf, vc, ray->mPdf, contribution);
@@ -1076,4 +1076,5 @@
 		// add objects without the objects which are in several kd leaves
 		pvsSize += (int)(leaf->mObjects.size() - leaf->mMultipleObjects.size());
+		//Debug << "here11 " << (int)leaf->mObjects.size() << " " << leaf->mMultipleObjects.size() << endl;
 	}
 	else
@@ -1116,5 +1117,5 @@
 	RayInfoContainer::const_iterator ri, ri_end = rays.end();
 
-	//-- set all kd nodes as belonging to the front pvs
+	//-- set all kd nodes / objects as belonging to the front pvs
 
 	for (ri = rays.begin(); ri != ri_end; ++ ri)
@@ -1214,5 +1215,5 @@
 		Intersectable *object = *oit;
 
-		// object not previously in left pvs
+		// object not previously in pvs
 		if (!object->Mailed())
 		{
@@ -1946,5 +1947,5 @@
 	nodeStack.push(mRoot);
 
-	const AxisAlignedBox3 box = GetBBox(n);
+	const AxisAlignedBox3 box = GetBoundingBox(n);
 
 	while (!nodeStack.empty())
@@ -2007,5 +2008,5 @@
 			VspNode *next;
 			
-			if (GetBBox(interior->GetBack()).Side(plane) < 0)
+			if (GetBoundingBox(interior->GetBack()).Side(plane) < 0)
 			{
 				next = interior->GetFront();
@@ -2013,5 +2014,5 @@
             else
 			{
-				if (GetBBox(interior->GetFront()).Side(plane) < 0)
+				if (GetBoundingBox(interior->GetFront()).Side(plane) < 0)
 				{
 					next = interior->GetBack();
@@ -2549,5 +2550,5 @@
 
 
-AxisAlignedBox3 VspTree::GetBBox(VspNode *node) const
+AxisAlignedBox3 VspTree::GetBoundingBox(VspNode *node) const
 {
 	if (!node->GetParent())
@@ -2584,5 +2585,5 @@
 		nodeStack.pop();
 
-		const AxisAlignedBox3 bbox = GetBBox(node);
+		const AxisAlignedBox3 bbox = GetBoundingBox(node);
 
 		if (bbox.Includes(box))
@@ -3693,5 +3694,5 @@
 
 
-AxisAlignedBox3 OspTree::GetBBox(KdNode *node) const
+AxisAlignedBox3 OspTree::GetBoundingBox(KdNode *node) const
 {
 	if (!node->mParent)
@@ -3814,4 +3815,5 @@
 KdLeaf *OspTree::GetLeaf(const Vector3 &pt, KdNode *node) const
 {
+	// start from root of tree
 	if (node == NULL)
 	{
@@ -3835,8 +3837,8 @@
 		else 	
 		{	
+			// find point
 			KdInterior *interior = dynamic_cast<KdInterior *>(node);
         
-			// random decision
-			if (interior->mPosition < pt[interior->mAxis])
+			if (interior->mPosition > pt[interior->mAxis])
 			{
 				nodeStack.push(interior->mBack);
@@ -3942,5 +3944,6 @@
 {
 	// search nodes
-	std::map<KdNode *, KdIntersectable *>::const_iterator it = mKdIntersectables.find(node);
+	std::map<KdNode *, KdIntersectable *>::
+		const_iterator it = mKdIntersectables.find(node);
 
 	if (it != mKdIntersectables.end()) 
@@ -4054,11 +4057,9 @@
 											  RayInfoContainer &rays)
 {
-	// get clipped rays
-	mOspTree.ProcessRays(sampleRays, rays);
-
 	// store pointer to this tree
 	OspTree::OspSplitCandidate::sOspTree = &mOspTree;
 	mOspTree.mOspStats.nodes = 1;
 	
+	// compute bounding box from objects
 	mOspTree.ComputeBoundingBox(objects, forcedObjectSpace);
 
@@ -4066,4 +4067,6 @@
 	mGlobalCostMisses = 0;
 
+	// get clipped rays
+	mOspTree.ProcessRays(sampleRays, rays);
 
 	// add first candidate for view space partition
@@ -4086,9 +4089,8 @@
 
 		
-	//mOspTree.ProcessMultipleRefs(NULL, kdleaf, NULL);
-
 	// compute first split candidate
 	OspTree::OspSplitCandidate *oSplitCandidate = 
 		new OspTree::OspSplitCandidate(oData);
+
     mOspTree.EvalSplitCandidate(*oSplitCandidate);
 
@@ -4252,6 +4254,7 @@
 	/////////////////////////////////////////////////////////////
 
-
+	Debug << "**************** osp construction **************" << endl;
 	cout << "starting osp contruction ... " << endl;
+
 	startTime = GetTime();
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1143)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1144)
@@ -5216,14 +5216,15 @@
 		VspLeaf *l = vspVc->mLeaf;
 
-		const AxisAlignedBox3 box = mVspTree->GetBBox(vspVc->mLeaf);
+		const AxisAlignedBox3 box = mVspTree->GetBoundingBox(vspVc->mLeaf);
 		
 		if (clipPlane)
 		{
 			if (box.Side(plane) == -1)
+			{
 				exporter->ExportBox(box);
+			}
 			else if (box.Side(plane) == 0)
 			{
 				AxisAlignedBox3 fbox, bbox;
-
 				box.Split(clipPlane->mAxis, clipPlane->mPosition, fbox, bbox);
 
@@ -5485,7 +5486,4 @@
 			KdLeaf::NewMail();
 
-			m.mDiffuseColor = RgbColor(1, 0, 0);
-			exporter->SetForcedMaterial(m);
-
 			// export pvs entries
 			for (oit = pvs.mEntries.begin(); oit != oit_end; ++ oit)
@@ -5493,4 +5491,22 @@
 				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->GetNode());
+					
+					exporter->SetWireframe();
+					exporter->ExportBox(box);
+					exporter->SetFilled();
+				}
+
+				m.mDiffuseColor = RgbColor(1, 0, 0);
+				exporter->SetForcedMaterial(m);
+
+				// export pvs entry
 				if (!obj->Mailed())
 				{
@@ -5626,5 +5642,5 @@
 	{
 		VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf;
-		const AxisAlignedBox3 box = mVspTree->GetBBox(leaf);
+		const AxisAlignedBox3 box = mVspTree->GetBoundingBox(leaf);
 
         IncludeBoxInMesh(box, *mesh);
@@ -5657,5 +5673,5 @@
 		VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaf;
 		
-		const AxisAlignedBox3 box = mVspTree->GetBBox(leaf);
+		const AxisAlignedBox3 box = mVspTree->GetBoundingBox(leaf);
 
 		const float lVol = box.GetVolume();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1139)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 1144)
@@ -50,5 +50,5 @@
 		SetWireframe();
 		SetForcedMaterial(white);
-		ExportBox(ospTree.GetBBox(leaf));
+		ExportBox(ospTree.GetBoundingBox(leaf));
 
 		SetFilled();
@@ -79,8 +79,10 @@
 	Intersectable::NewMail();
 
+	// todo: traverse to leaves
 	if (node->IsLeaf())
 	{
+		// eyport leaf pvs
 		KdLeaf *leaf = dynamic_cast<KdLeaf *>(node);
-		
+
 		ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1143)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1144)
@@ -628,5 +628,5 @@
 	/** Returns bounding box of the specified node.
 	*/
-	AxisAlignedBox3 GetBBox(VspNode *node) const;
+	AxisAlignedBox3 GetBoundingBox(VspNode *node) const;
 
 	/** Returns list of BSP leaves with pvs smaller than
@@ -1276,5 +1276,5 @@
 	/** Returns bounding box of the specified node.
 	*/
-	AxisAlignedBox3 GetBBox(KdNode *node) const;
+	AxisAlignedBox3 GetBoundingBox(KdNode *node) const;
 
 	/** Returns list of leaves with pvs smaller than
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 1143)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 1144)
@@ -315,12 +315,12 @@
 	}
 
+    mStat.objectRefs -= (int)leaf->mObjects.size();
+    mStat.objectRefs += objectsBack + objectsFront;
+  }
+
 	// store objects referenced in more than one leaf
 	// for easy access
 	ProcessMultipleRefs(back);
 	ProcessMultipleRefs(front);
-
-    mStat.objectRefs -= (int)leaf->mObjects.size();
-    mStat.objectRefs += objectsBack + objectsFront;
-  }
 
   delete leaf;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1143)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 1144)
@@ -195,11 +195,4 @@
   ObjectContainer mObjects;
 
-  /** Objects that are part of several leaves.
-  */
-  ObjectContainer mMultipleObjects;
-
-  /// universal counter
-  int mCounter;
-	
   /** Ray set description of the rays passing through this node */
   PassingRaySet mPassingRays;
@@ -209,10 +202,14 @@
 
   /// pvs of view cells seeing this node.
-  // ViewCellPvs mViewCellPvs;
   SplitCandidate *mSplitCandidate;
 
-  /** pointer to view cell.
-  */
+  /// pointer to view cell.
   KdViewCell *mViewCell;
+
+   /// Objects that are referenced in more than one leaf.
+  ObjectContainer mMultipleObjects;
+
+  /// universal counter
+  int mCounter;
 };
 
