Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1623)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreBoundingBoxConverter.h	(revision 1676)
@@ -135,5 +135,5 @@
 				continue;
 			}
-			 mo->
+			 
 			const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox());
 					
@@ -225,5 +225,5 @@
 			
 	// get intersecting scene nodes (= candidates)
-	AxisAlignedBox mybox = EnlargeBox(box);
+	//AxisAlignedBox mybox = EnlargeBox(box);
 	//mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
 	mSceneMgr->findNodesIn(box, sceneNodeList, NULL);
@@ -253,8 +253,7 @@
 			const AxisAlignedBox bbox = mo->getWorldBoundingBox();
 
-			const bool overlaps = Overlap(nodeBox,
-										  OgreTypeConverter::ConvertFromOgre(bbox)
-										  );
-										  //,0.00001);
+			const bool overlaps = 
+				Overlap(nodeBox, OgreTypeConverter::ConvertFromOgre(bbox));
+										
 	
 			 if (overlaps)
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 1320)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 1676)
@@ -312,5 +312,5 @@
 				Name="VCLinkerTool"
 				IgnoreImportLibrary="TRUE"
-				AdditionalDependencies="OgreMain.lib CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib GtpVisibility.lib zdll.lib zziplib.lib Preprocessor.lib xerces-c_2.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib glew32.lib glew32s.lib"
+				AdditionalDependencies="OgreMain.lib CEGUIBase.lib OgreGUIRenderer.lib Plugin_OctreeSceneManager.lib GtpVisibility.lib zdll.lib zziplib.lib Preprocessor.lib xerces-c_2.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib glew32.lib glew32s.lib"
 				OutputFile="$(OutDir)/Plugin_VisibilitySceneManager.dll"
 				Version="0.99"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1640)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1676)
@@ -1201,7 +1201,8 @@
 bool OcclusionCullingSceneManager::LoadViewCells(const String &filename)
 {
-	if (mViewCellsLoaded) return true;
+	if (mViewCellsLoaded) 
+		return true;
+
 	// converter between view cell ids and Ogre entites 
-	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer iboxes;
 	OctreeBoundingBoxConverter bconverter(this);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/integration.txt
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/integration.txt	(revision 1676)
+++ GTP/trunk/Lib/Vis/Preprocessing/integration.txt	(revision 1676)
@@ -0,0 +1,137 @@
+1) include following libs into your application:
+
+Preprocessor.lib zdll.lib zziplib.lib xerces-c_2.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib glew32.lib glew32s.lib
+
+
+2) view cells are loaded using a similar piece of code like this:
+
+   OctreeBoundingBoxConverter bconverter(this);
+   ObjectContainer objects;
+
+   // load the view cells assigning the found objects to the pvss
+
+   GtpVisibilityPreprocessor::ViewCellsManager *viewCellsManager = 
+      GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &objects, &bconverter);
+
+      The bouning box converter is used to associate entities in the
+      engine and connect them to entities of the visibility
+      preprocessing file.
+
+3) The parameter objects:
+
+      The parameter objects of the type ObjectContainer contains the primitives which
+      will be set visible / invisible accoring to the pvs.
+      
+      They are given as pointers to an Intersectable. 
+      It is therefore necessary to write wrapper for the primitives in
+      your engine. Something like:
+
+ 
+/**
+	Wrapper for Ogre object intances for use with the preprocessed view cells.
+*/
+class __declspec(dllexport) OgreMeshInstance: public GtpVisibilityPreprocessor::Intersectable
+{
+public:
+	/** The default constructor taking an entity into account.
+	*/
+	OgreMeshInstance(Entity *ent);
+	
+	/** Returns 'mesh' associated with this instance. 
+	*/
+	Entity *GetEntity() const;
+
+	/** See get.
+	*/
+	void SetEntity(Entity *entity);
+
+
+	/////////////////////////////
+	//-- inherited functions from Intersectable
+
+	GtpVisibilityPreprocessor::AxisAlignedBox3 GetBox() const;
+	
+	int CastRay(GtpVisibilityPreprocessor::Ray &ray);
+	
+	bool IsConvex() const;
+	bool IsWatertight() const;
+	float IntersectionComplexity();
+  
+	int NumberOfFaces() const;
+	int Type() const;
+
+	int GetRandomSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point, 
+							  GtpVisibilityPreprocessor::Vector3 &normal);
+
+	int GetRandomVisibleSurfacePoint(GtpVisibilityPreprocessor::Vector3 &point,
+									 GtpVisibilityPreprocessor::Vector3 &normal,
+									 const GtpVisibilityPreprocessor::Vector3 &viewpoint,
+									 const int maxTries);
+  
+	ostream &Describe(ostream &s);
+	
+
+protected:
+	
+	Entity *mEntity;
+};
+
+
+4) The bounding box converter has to implement the following interface:
+  
+
+/** Class used to assign unique indices to objects using a comparison of bounding boxes.
+*/
+class BoundingBoxConverter
+{
+public:
+	/** Takes a vector of indexed bounding boxes and uses it to identify objects with a similar bounding box
+		and to assign them their index (id).
+		The objects are returned in the object container.
+		
+		@returns true if conversion was successful
+	*/
+	virtual bool IdentifyObjects(const IndexedBoundingBoxContainer &iboxes,
+				ObjectContainer &objects) const
+	{
+		// default: do nothing as we assume that a unique id is already assigned to the objects.
+		return true;
+	}
+};
+
+
+The interface only contains the method IdentifyObjects, which will be
+responsible for the conversion.
+
+5) The ViewCellsManager:
+
+This class is there to control the view cells. You can get a view
+point by using something like the following:
+
+GtpVisibilityPreprocessor::Vector3 viewPoint;
+
+ViewCell *currentViewCell = viewCellsManager->GetViewCell(const Vector3 &viewPoint);
+
+
+6) The view cell: the Pvs of the current view cell can be received by using
+
+ObjectPvs pvs = viewCell->GetPvs();
+
+Then objects of the pvs can be iterated over and set visibible like in
+this example for Ogre:
+
+
+     GtpVisibilityPreprocessor::ObjectPvsMap::const_iterator oit, oit_end = viewCell->GetPvs().mEntries.end();
+
+     ////////////
+     //-- set PVS of view cell to visible
+
+     for (oit = viewCell->GetPvs().mEntries.begin(); oit != oit_end; ++ oit)
+     {
+	GtpVisibilityPreprocessor::Intersectable *entry = (*oit).first;
+	// no associated geometry found
+	if (!entry) continue;
+	
+	OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance *>(entry);
+	omi->GetEntity()->setVisible(load);
+     }
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/vsposp_typical.sh	(revision 1676)
@@ -60,6 +60,6 @@
 
 ##################################################################################
-
- METHOD=gradient-mem
+MEMCONST=0.8
+ METHOD=gradient-mem-$MEMCONST
  echo "$SCENE $METHOD"
 
@@ -71,12 +71,56 @@
   -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
   -hierarchy_construction_type=2 \
-  -hierarchy_construction_consider_memory2=true \
- -bvh_construction_render_cost_decrease_weight=0.99 \
- -vsp_construction_render_cost_decrease_weight=0.99 \
-  -hierarchy_construction_multilevel=false \
-  -hierarchy_term_memory_const=0.9 \
-  -hierarchy_construction_recompute_split_on_repair=true
-
-sh movefiles.sh $LOG_PREFIX-$METHOD
+  -hierarchy_construction_consider_memory=true \
+ -bvh_construction_render_cost_decrease_weight=0.99 \
+ -vsp_construction_render_cost_decrease_weight=0.99 \
+  -hierarchy_construction_multilevel=false \
+  -hierarchy_term_memory_const=$MEMCONST \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+
+##################################################################################
+MEMCONST=0.5
+ METHOD=gradient-mem-$MEMCONST
+ echo "$SCENE $METHOD"
+
+  $PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+  -hierarchy_construction_type=2 \
+  -hierarchy_construction_consider_memory=true \
+ -bvh_construction_render_cost_decrease_weight=0.99 \
+ -vsp_construction_render_cost_decrease_weight=0.99 \
+  -hierarchy_construction_multilevel=false \
+  -hierarchy_term_memory_const=$MEMCONST \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
+##################################################################################
+MEMCONST=0.2
+ METHOD=gradient-mem-$MEMCONST
+ echo "$SCENE $METHOD"
+
+  $PROGRAM $ENVIRONMENT \
+  -view_cells_evaluation_stats_prefix=$LOG_PREFIX-$METHOD \
+  -view_cells_merge_stats=$LOG_PREFIX-$METHOD-mergeStats.log \
+  -vsp_subdivision_stats=$LOG_PREFIX-$METHOD-vsp-subdivisionStats.log \
+  -bvh_subdivision_stats=$LOG_PREFIX-$METHOD-bvh-subdivisionStats.log \
+  -hierarchy_subdivision_stats=$LOG_PREFIX-$METHOD-hierarchy-subdivisionStats.log \
+  -hierarchy_construction_type=2 \
+  -hierarchy_construction_consider_memory=true \
+ -bvh_construction_render_cost_decrease_weight=0.99 \
+ -vsp_construction_render_cost_decrease_weight=0.99 \
+  -hierarchy_construction_multilevel=false \
+  -hierarchy_term_memory_const=$MEMCONST \
+  -hierarchy_construction_recompute_split_on_repair=true
+
+sh movefiles.sh $LOG_PREFIX-$METHOD
+
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1666)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1676)
@@ -447,5 +447,5 @@
 	static ViewCellsManager *LoadViewCells(const string &filename, 
 										   ObjectContainer *objects, 
-										   const bool finalizeViewCells,
+										   bool finalizeViewCells = false,
 										   BoundingBoxConverter *bconverter = NULL);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1676)
@@ -2466,5 +2466,9 @@
 					"true");
 
-	
+	RegisterOption("BvHierarchy.minRaysForVisibility",
+					optInt,
+					"bvh_min_rays_for_vis=",
+					"0");
+
 
 	/*******************************************************************/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 1676)
@@ -233,4 +233,6 @@
 
 	inline bool ConsiderMemory() const { return mConsiderMemory; }
+	inline float GetMemoryConst() const { return mMemoryConst; }
+
 
 protected:
@@ -273,5 +275,6 @@
 						//const float minRenderCostDecr,
 						SubdivisionCandidate *oldCandidate,
-						const int minSteps);
+						const int minSteps,
+						const int maxSteps);
 
 	/** Default subdivision method.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1676)
@@ -491,9 +491,8 @@
 			if (hm->ConsiderMemory())
 			{
-				const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease;
-				const float mc = hm->GetHierarchyStats().mMemory +
-								 (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte();
-
-				return - (rc * mc) / float(1024 * 1024);
+				const float rc = mRenderCostDecrease / hm->GetHierarchyStats().mTotalCost;
+				const float mc = (float)mPvsEntriesIncr / (float)hm->GetHierarchyStats().mPvsEntries;
+				//cout << "y";			
+				return hm->GetMemoryConst() * rc + (1.0f - hm->GetMemoryConst()) * mc;
 			}
 			else
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1676)
@@ -251,6 +251,6 @@
 	Environment::GetSingleton()->GetBoolValue("BvHierarchy.useCostHeuristics", mUseCostHeuristics);
 	Environment::GetSingleton()->GetBoolValue("BvHierarchy.useSah", mUseSah);
-	
-	char subdivisionStatsLog[100];
+
+    char subdivisionStatsLog[100];
 	Environment::GetSingleton()->GetStringValue("BvHierarchy.subdivisionStats", subdivisionStatsLog);
 	mSubdivisionStats.open(subdivisionStatsLog);
@@ -260,4 +260,6 @@
 	
 	Environment::GetSingleton()->GetBoolValue("BvHierarchy.Construction.useGlobalSorting", mUseGlobalSorting);
+	Environment::GetSingleton()->GetIntValue("BvHierarchy.minRaysForVisibility", mMinRaysForVisibility);
+	
 
 	mUseBboxAreaForSah = true;
@@ -283,4 +285,6 @@
 	Debug << "render cost decrease weight: " << mRenderCostDecreaseWeight << endl;
 	Debug << "use global sort: " << mUseGlobalSorting << endl;
+	Debug << "minimal rays for visibility: " << mMinRaysForVisibility << endl;
+
 	Debug << endl;
 }
@@ -487,8 +491,16 @@
 	if (computeSplitPlane)
 	{
+		const bool sufficientSamples = splitCandidate.mParentData.mNumRays < mMinRaysForVisibility;
+
+		const bool useVisibiliyBasedHeuristics = 
+			!mUseSah &&
+			!(mHierarchyManager->GetViewSpaceSubdivisionType() == HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV) &&
+			sufficientSamples;
+
 		// compute best object partition
 		const float ratio =	SelectObjectPartition(splitCandidate.mParentData, 
 												  splitCandidate.mFrontObjects, 
-												  splitCandidate.mBackObjects);
+												  splitCandidate.mBackObjects,
+												  useVisibiliyBasedHeuristics);
 	
 		// cost ratio violated?
@@ -497,6 +509,5 @@
 		const int previousMisses = splitCandidate.mParentData.mMaxCostMisses;
 
-		splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? 
-										previousMisses + 1 : previousMisses);
+		splitCandidate.SetMaxCostMisses(maxCostRatioViolated ? previousMisses + 1 : previousMisses);
 
 	}
@@ -1218,5 +1229,6 @@
 float BvHierarchy::SelectObjectPartition(const BvhTraversalData &tData,
 										 ObjectContainer &frontObjects,
-										 ObjectContainer &backObjects)
+										 ObjectContainer &backObjects,
+										 bool useVisibilityBasedHeuristics)
 {
 	ObjectContainer nFrontObjects[3];
@@ -1245,7 +1257,5 @@
                 //-- split objects using heuristics
 				
-				if (!mUseSah &&
-					(mHierarchyManager->GetViewSpaceSubdivisionType() == 
-					HierarchyManager::KD_BASED_VIEWSPACE_SUBDIV))
+				if (useVisibilityBasedHeuristics)
 				{
 					///////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1667)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1676)
@@ -602,5 +602,5 @@
 ViewCellsManager *ViewCellsManager::LoadViewCells(const string &filename, 
 												  ObjectContainer *objects,
-												  const bool finalizeViewCells,
+												  bool finalizeViewCells,
 												  BoundingBoxConverter *bconverter)
 												 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1676)
@@ -444,9 +444,9 @@
 			if (hm->ConsiderMemory())
 			{
-				const float rc = hm->GetHierarchyStats().mTotalCost - mRenderCostDecrease;
-				const float mc = hm->GetHierarchyStats().mMemory +
-								 (float)mPvsEntriesIncr * ObjectPvs::GetEntrySizeByte();
-				
-				return - (rc * mc) / float(1024 * 1024);
+				const float rc = mRenderCostDecrease / hm->GetHierarchyStats().mTotalCost;
+				//const float mc = mMemoryIncr /  / hm->GetHierarchyStats().mMemory;
+				const float mc = (float)mPvsEntriesIncr / (float)hm->GetHierarchyStats().mPvsEntries;	
+				//cout << "x";
+				return hm->GetMemoryConst() * rc + (1.0f - hm->GetMemoryConst()) * mc;
 			}
 			else
@@ -672,5 +672,6 @@
 	float SelectObjectPartition(const BvhTraversalData &tData,
 								ObjectContainer &frontObjects,
-								ObjectContainer &backObjects);
+								ObjectContainer &backObjects,
+								bool useVisibilityBasedHeuristics);
 	
 	/** Writes the node to disk
@@ -733,8 +734,4 @@
 	float PrepareHeuristics(const BvhTraversalData &tData, const int axis);
 	
-	/** Reevaluates the priority of this split candidate
-		@returns priority
-	*/
-	//float EvalPriority(const BvhSubdivisionCandidate &splitCandidate) const;
 
 	////////////////////////////////////////////////
@@ -924,4 +921,6 @@
 
 	SortableEntryContainer *mSortedObjects[3];
+
+	int mMinRaysForVisibility;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BoundingBoxConverter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BoundingBoxConverter.h	(revision 1545)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BoundingBoxConverter.h	(revision 1676)
@@ -21,7 +21,6 @@
 {
 public:
-	//BoundingBoxConverter();
 	/** Takes a vector of indexed bounding boxes and uses it to identify objects with a similar bounding box
-		and to assign the index.
+		and assigns them their index (id).
 		The objects are returned in the object container.
 		
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1673)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1676)
@@ -256,5 +256,5 @@
 	
 	// calculate cost in MB
-	const float memoryCost = mHierarchyStats.mMemory  / (1024.0f * 1024.0f)
+	const float memoryCost = mHierarchyStats.mMemory  / float(1024 * 1024)
 							 + objectSpaceMem + viewSpaceMem;
 
@@ -383,8 +383,8 @@
 	// number of initial splits
 	const int minSteps = mMinStepsOfSameType;
+	const int maxSteps = mMinStepsOfSameType + 500;
 	float renderCostDecr = Limits::Infinity;
 
-	SubdivisionCandidate *osc = 
-		PrepareObjectSpaceSubdivision(sampleRays, objects);
+	SubdivisionCandidate *osc = PrepareObjectSpaceSubdivision(sampleRays, objects);
 	
 	objectSpaceQueue.Push(osc);
@@ -399,5 +399,6 @@
 	// for first round, use sah splits. Once view space partition
 	// has started, use render cost heuristics instead
-	const int ospSteps = RunConstruction(objectSpaceQueue, dirtyVspList, NULL, minSteps);
+	const int ospSteps = 
+		RunConstruction(objectSpaceQueue, dirtyVspList, NULL, minSteps, maxSteps);
 
 	cout << "\n" << ospSteps << " object space partition steps taken" << endl;
@@ -440,6 +441,9 @@
 			// for first round, use sah splits. Once view space partition
 			// has started, use render cost heuristics instead
-			const int ospSteps = 
-				RunConstruction(objectSpaceQueue, dirtyVspList, viewSpaceQueue.Top(), minSteps);
+			const int ospSteps = RunConstruction(objectSpaceQueue, 
+												 dirtyVspList, 
+												 viewSpaceQueue.Top(), 
+												 minSteps, 
+												 maxSteps);
 
 			cout << "\n" << ospSteps << " object space partition steps taken" << endl;
@@ -461,5 +465,5 @@
 			// process view space candidates
 			const int vspSteps = 
-				RunConstruction(viewSpaceQueue, dirtyOspList, objectSpaceQueue.Top(), minSteps);
+				RunConstruction(viewSpaceQueue, dirtyOspList, objectSpaceQueue.Top(), minSteps, maxSteps);
 
 			cout << "\n" << vspSteps << " view space partition steps taken" << endl;
@@ -700,5 +704,5 @@
 
 	// memory size in byte
-	mHierarchyStats.mMemory += (float)ObjectPvs::GetEntrySizeByte();
+	mHierarchyStats.mMemory += (float)ObjectPvs::GetEntrySizeByte() * pvsEntriesIncr;
 	mHierarchyStats.mRenderCostDecrease = sc->GetRenderCostDecrease();
 
@@ -841,6 +845,5 @@
 
 			cout << "\nstarting object space subdivision after " 
-				 << mVspTree->mVspStats.nodes << " (" 
-				 << mMinStepsOfSameType << ") " << endl;
+				 << mVspTree->mVspStats.nodes << " (" << mMinStepsOfSameType << ") " << endl;
 
 			SubdivisionCandidate *ospSc = PrepareObjectSpaceSubdivision(sampleRays, objects);
@@ -895,6 +898,10 @@
 									  SubdivisionCandidateContainer &dirtyCandidates,
 									  SubdivisionCandidate *oldCandidate,
-									  const int minSteps)
-{
+									  const int minSteps,
+									  const int maxSteps)
+{
+	if (minSteps >= maxSteps)
+		cout << "error!! " << minSteps << " equal or larger maxSteps" << endl;
+
 	int steps = 0;
 	SubdivisionCandidate::NewMail();
@@ -908,7 +915,8 @@
 
 		// minimum slope reached
-		if ((sc->GetPriority() < threshold) && !(steps < minSteps))
-		{
-			cout << "**************** breaking on " << sc->GetPriority() << " smaller than " << threshold << endl;
+		if ((steps > maxSteps) || 
+			((sc->GetPriority() < threshold) && !(steps < minSteps)))
+		{
+			cout << "\n**************** breaking on " << sc->GetPriority() << " smaller than " << threshold << endl;
 			break;
 		}
