Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.h	(revision 1233)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdIntersectable.h	(revision 1314)
@@ -11,4 +11,6 @@
 class KdNode;
 class BvhNode;
+struct Face;
+
 
 /**
@@ -57,4 +59,5 @@
 	T *mItem;
 };
+
 
 template<typename T>
@@ -161,4 +164,17 @@
 };
 
+class FaceIntersectable: public IntersectableWrapper<Face>
+{
+public:
+	FaceIntersectable(Face *item):
+	IntersectableWrapper<Face>(item) {}
+
+	int Type() const
+	{
+		return Intersectable::FACE_INTERSECTABLE;
+	}
+};
+
+
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1311)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1314)
@@ -2426,5 +2426,4 @@
 					"0");
 
-
 	RegisterOption("Hierarchy.Construction.minDepthForOsp",
 					optInt,
@@ -2432,4 +2431,8 @@
 					"-1");
 
+	RegisterOption("Hierarchy.Construction.repairQueue",
+					optBool,
+					"hierarchy_construction_repair_queue=",
+					"true");
 
 	//////////////////////////////////////////////////////////////////////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1313)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1314)
@@ -292,4 +292,6 @@
 	int mTermMaxLeaves;
 	ofstream mSubdivisionStats;
+
+	bool mRepairQueue;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1305)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1314)
@@ -657,7 +657,10 @@
 		}
 		
-		friend bool operator<(const SortableEntry &a, const SortableEntry &b)
-		{
-			return a.value < b.value;
+		friend inline bool operator<(const SortableEntry &a, const SortableEntry &b)
+		{	// prefer max event
+			//if (EpsilonEqual(a.value, b.value, 0.0001f))
+			//	return (a.type == ERayMax);
+
+			return (a.value < b.value);
 		}
 	};
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1313)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1314)
@@ -619,7 +619,25 @@
 	float volBack = volLeft;
 	float volFront = volRight;
-
 	float newRenderCost = nTotalObjects * totalVol;
 
+#ifdef _DEBUG
+	const int leaves = mBvhStats.Leaves();
+	const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90));
+	
+	ofstream sumStats;
+	ofstream vollStats;
+	ofstream volrStats;
+
+	if (printStats)
+	{
+		char str[64]; 	
+		sprintf(str, "tmp/bvh_heur_sum-%04d.log", leaves);
+		sumStats.open(str);
+		sprintf(str, "tmp/bvh_heur_voll-%04d.log", leaves);
+		vollStats.open(str);
+		sprintf(str, "tmp/bvh_heur_volr-%04d.log", leaves);
+		volrStats.open(str);
+	}
+#endif
 
 	/////////////////////////////
@@ -647,4 +665,23 @@
 						  volRight * (float)nObjectsRight;
 
+#ifdef _DEBUG
+		
+		if (printStats)
+		{
+			sumStats
+				<< "#Position\n" << nObjectsRight << endl
+				<< "#Sum\n" << sum / viewSpaceVol << endl
+				<< "#Vol\n" << (volLeft +  volRight) / viewSpaceVol << endl;
+
+			vollStats
+				<< "#Position\n" << nObjectsRight << endl
+				<< "#Vol\n" << volLeft / viewSpaceVol << endl;
+
+			volrStats
+				<< "#Position\n" << nObjectsRight << endl
+				<< "#Vol\n" << volRight / viewSpaceVol << endl;
+		}
+#endif
+
 		if (sum < newRenderCost)
 		{
@@ -675,4 +712,5 @@
 	const float ratio = newRenderCost / oldRenderCost;
 
+#ifdef _DEBUG
 	Debug << "\n§§§§ eval local cost §§§§" << endl
 		  << "back pvs: " << (int)objectsBack.size() << " front pvs: " << (int)objectsFront.size() << " total pvs: " << nTotalObjects << endl 
@@ -680,4 +718,5 @@
 		  << "old rc: " << oldRenderCost / viewSpaceVol << " new rc: " << newRenderCost / viewSpaceVol << endl
 		  << "render cost decrease: " << oldRenderCost / viewSpaceVol - newRenderCost / viewSpaceVol << endl;
+#endif
 
 	return ratio;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1313)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1314)
@@ -973,5 +973,5 @@
 	mLocalSubdivisionCandidates->clear();
 
-	int requestedSize = 2 * (int)(rays.size());
+	const int requestedSize = 2 * (int)(rays.size());
 
 	// creates a sorted split candidates array
@@ -992,14 +992,23 @@
 	{
 		const bool positive = (*rit).mRay->HasPosDir(axis);
-				
+		const bool delayMinEvent = false;
+
+		// origin point
 		pos = (*rit).ExtrapOrigin(axis);
-		
-		mLocalSubdivisionCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMin : SortableEntry::ERayMax, 
-									pos, (*rit).mRay));
-
+		const int oType = positive ? SortableEntry::ERayMin : SortableEntry::ERayMax;
+
+		if (delayMinEvent && oType == SortableEntry::ERayMin)
+			pos += mEpsilon; // for walls
+
+		mLocalSubdivisionCandidates->push_back(SortableEntry(oType, pos, (*rit).mRay));
+
+		// termination point
 		pos = (*rit).ExtrapTermination(axis);
-
-		mLocalSubdivisionCandidates->push_back(SortableEntry(positive ? SortableEntry::ERayMax : SortableEntry::ERayMin, 
-									pos, (*rit).mRay));
+		const int tType = positive ? SortableEntry::ERayMax : SortableEntry::ERayMin;
+
+		if (delayMinEvent && tType == SortableEntry::ERayMin)
+			pos += mEpsilon; // for walls
+
+		mLocalSubdivisionCandidates->push_back(SortableEntry(tType, pos, (*rit).mRay));
 	}
 
@@ -1206,4 +1215,26 @@
 	vector<SortableEntry>::const_iterator ci, ci_end = mLocalSubdivisionCandidates->end();
 
+#ifdef _DEBUG
+	const float volRatio = tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume());
+	const int leaves = mVspStats.Leaves();
+	const bool printStats = ((axis == 0) && (leaves > 0) && (leaves < 90));
+	
+	ofstream sumStats;
+	ofstream pvslStats;
+	ofstream pvsrStats;
+
+	if (printStats)
+	{
+		char str[64]; 
+		
+		sprintf(str, "tmp/vsp_heur_sum-%04d.log", leaves);
+		sumStats.open(str);
+		sprintf(str, "tmp/vsp_heur_pvsl-%04d.log", leaves);
+		pvslStats.open(str);
+		sprintf(str, "tmp/vsp_heur_pvsr-%04d.log", leaves);
+		pvsrStats.open(str);
+	}
+
+#endif
 	for (ci = mLocalSubdivisionCandidates->begin(); ci != ci_end; ++ ci)
 	{
@@ -1224,4 +1255,21 @@
 			sum = pvsl * ((*ci).value - minBox) + pvsr * (maxBox - (*ci).value);
 			
+#ifdef _DEBUG
+			if (printStats)
+			{
+				sumStats
+					<< "#Position\n" << currentPos << endl
+					<< "#Sum\n" << sum * volRatio << endl
+					<< "#Pvs\n" << pvsl + pvsr << endl;
+
+				pvslStats
+					<< "#Position\n" << currentPos << endl
+					<< "#Pvsl\n" << pvsl << endl;
+
+				pvsrStats
+					<< "#Position\n" << currentPos << endl
+					<< "#Pvsr\n" << pvsr << endl;
+			}
+#endif
 
 			if (sum < minSum)
@@ -1260,6 +1308,5 @@
 	}
 	
-	const float volRatio = tData.mBoundingBox.GetVolume() / (sizeBox * mBoundingBox.GetVolume());
-
+#ifdef _DEBUG
 	Debug << "\n§§§§ eval local cost §§§§" << endl
 		  << "back pvs: " << penaltyBack << " front pvs: " << penaltyFront << " total pvs: " << penaltyOld << endl 
@@ -1267,5 +1314,5 @@
 		  << "old rc: " << oldRenderCost * volRatio << " new rc: " << newRenderCost * volRatio << endl
 		  << "render cost decrease: " << oldRenderCost * volRatio - newRenderCost * volRatio << endl;
-
+#endif
 	return ratio;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1292)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1314)
@@ -13,5 +13,5 @@
 #include "Environment.h"
 #include "ResourceManager.h"
-
+#include "KdIntersectable.h"
 
 
@@ -93,5 +93,5 @@
 
 			// correct face index (nust be relative to start of verices)
-			(*vit) = distance(hashTable.begin(), hit);
+			(*vit) = (int)distance(hashTable.begin(), hit);
 			//Debug << "new idx: " << (*vit) << endl;
 		}
@@ -185,7 +185,6 @@
 				Face *face = LoadFace(str, vertices, hashTable);
 				if (!face) break;
-				
+#if 1
 				faces.push_back(face);
-
 				if (faces.size() >= nMaxFaces)
 				{
@@ -197,22 +196,23 @@
 					
 					if (parents) 
-					  {
 						AssociateFacesWithInstance(mi, *parents);
-					  }
-					
+										
 					// reset tables
 					hashTable.clear();
 					faces.clear();
 				}
+#else
+				root->mGeometry.push_back(new FaceIntersectable(face));
+				hashTable.clear();
+#endif
 				break;
-			}      // end face
+			}   // end face
 		default:
 			break;
 		}
-
 	}
 
 	// there could be faces remaining
-	if (1 && !faces.empty())
+	if (!faces.empty())
 	{	
 		Mesh *mesh = CreateMesh(faces, hashTable);
@@ -222,8 +222,6 @@
 		
 		if (parents) 
-		{
 			AssociateFacesWithInstance(mi, *parents);
-		}
-
+		
 		root->mGeometry.push_back(mi);	
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 1293)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Intersectable.h	(revision 1314)
@@ -63,5 +63,6 @@
 		 OGRE_MESH_INSTANCE,
 		 KD_INTERSECTABLE,
-		 BVH_INTERSECTABLE
+		 BVH_INTERSECTABLE,
+		 FACE_INTERSECTABLE
 		};
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1313)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1314)
@@ -105,8 +105,14 @@
 		"Hierarchy.Construction.minDepthForOsp", mMinDepthForObjectSpaceSubdivion);
 	
+	Environment::GetSingleton()->GetBoolValue(
+		"Hierarchy.Construction.repairQueue", mRepairQueue);
+
 	Debug << "******** Hierachy Manager Parameters ***********" << endl;
 	Debug << "max leaves: " << mTermMaxLeaves << endl;
 	Debug << "min global cost ratio: " << mTermMinGlobalCostRatio << endl;
 	Debug << "global cost miss tolerance: " << mTermGlobalCostMissTolerance << endl;
+	Debug << "construction type: " << mConstructionType << endl;
+	Debug << "min depth for object space subdivision: " << mMinDepthForObjectSpaceSubdivion << endl;
+	Debug << "repair queue: " << mRepairQueue << endl;
 }
 
@@ -343,7 +349,4 @@
 	PrepareViewSpaceSubdivision(sampleRays, objects, forcedViewSpace);
 
-	//const bool repairQueue = false;
-	const bool repairQueue = true;
-cout << "here55 " << mVspTree->mVspStats.maxDepth << " (" << mMinDepthForObjectSpaceSubdivion << ") " << endl;
 	// start object space subdivision immediately?
 	if (StartObjectSpaceSubdivision())
@@ -379,5 +382,5 @@
 			// reevaluate candidates affected by the split for view space splits, 
 			// this would be object space splits and other way round
-			if (repairQueue) RepairQueue();
+			if (mRepairQueue) RepairQueue();
 		}
 
@@ -386,12 +389,12 @@
 		if (StartObjectSpaceSubdivision())
 		{
+			mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;
+
+			cout << "starting object space subdivision at maximal view space subdivison depth " << mVspTree->mVspStats.maxDepth << " (" << mMinDepthForObjectSpaceSubdivion << ") " << endl;
+			PrepareObjectSpaceSubdivision(sampleRays, objects);
+
 			cout << "reseting queue ... ";
 			ResetQueue();
 			cout << "finished" << endl;
-
-			cout << "starting object space subdivision at maximal view space subdivison depth " << mVspTree->mVspStats.maxDepth << " (" << mMinDepthForObjectSpaceSubdivion << ") " << endl;
-						
-			mObjectSpaceSubdivisionType = savedObjectSpaceSubdivisionType;
-			PrepareObjectSpaceSubdivision(sampleRays, objects);
 		}
 
