Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1774)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1778)
@@ -40,4 +40,10 @@
 
 
+/// sorting operator
+inline static bool ilt2(Intersectable *obj1, Intersectable *obj2)
+{
+	return obj1->GetBox().SurfaceArea() < obj2->GetBox().SurfaceArea();
+}
+
 /***************************************************************/
 /*              class BvhNode implementation                   */
@@ -219,5 +225,5 @@
 	ReadEnvironment();
 	mSubdivisionCandidates = new SortableEntryContainer;
-	for (int i = 0; i < 3; ++ i)
+	for (int i = 0; i < 4; ++ i)
 		mSortedObjects[i] = NULL;
 }
@@ -230,5 +236,5 @@
 
 	// delete the presorted objects
-	for (int i = 0; i < 3; ++ i)
+	for (int i = 0; i < 4; ++ i)
 	{
 		DEL_PTR(mSortedObjects[i]);
@@ -1194,6 +1200,9 @@
 	ofstream volrStats;
 
-	const bool printStats =
-		PrepareOutput(axis, mBvhStats.Leaves(), sumStats, vollStats, volrStats);
+	const bool printStats = PrepareOutput(axis, 
+										  mBvhStats.Leaves(), 
+										  sumStats, 
+										  vollStats, 
+										  volrStats);
 #endif
 
@@ -1346,6 +1355,8 @@
 	// collect and mark the view cells as belonging to front pvs
 	ViewCellContainer viewCells;
-	CollectViewCells(tData.mNode->mObjects, viewCells, true, true);
-	
+
+	const int numRays = CollectViewCells(tData.mNode->mObjects, viewCells, true, true);
+	//cout << "here4 " << numRays << endl;
+
 	ViewCellContainer::const_iterator vit, vit_end = viewCells.end();
 	for (vit = viewCells.begin(); vit != vit_end; ++ vit)
@@ -1443,5 +1454,4 @@
 		sAxis = box.Size().DrivingAxis();
 	}
-
 
 	// only use a subset of the rays for visibility based heuristics
@@ -1743,5 +1753,7 @@
 
 		if (onlyMailedRays && !ray->Mailed())
+		{//if (onlyMailedRays)cout << "u";
 			continue;
+		}//else if (onlyMailedRays) cout << "z";
 
 		//ray->Mail();
@@ -2139,4 +2151,22 @@
 		}
 	}
+
+	// create new objects
+	if (!mSortedObjects[3])
+	{
+		mSortedObjects[3] = new SortableEntryContainer();
+	}
+/*
+	// last sorted list: by size
+	tData.mSortedObjects[3] = new ObjectContainer();
+	tData.mSortedObjects[3]->reserve((int)mSortedObjects[i]->size());
+
+	SortableEntryContainer::const_iterator oit, oit_end = mSortedObjects[i]->end();
+
+	for (oit = mSortedObjects[3]->begin(); oit != oit_end; ++ oit)
+	{
+		tData.mSortedObjects[3]->push_back((*oit).mObject);
+	}
+*/
 }
 
@@ -2443,34 +2473,57 @@
 
 
-void BvHierarchy::InititialSubdivision()
-{
-}
-
-
-void ChooseSplitPlane(BvhLeaf *leaf)
-{/*
-std::stable_sort(objects.begin(), objects.end(), ilt);
-	
-	// intersected objects
-	MeshInstance sObj(NULL);
-	
-	if (sObj.mId >= 0)
-	{
-			ObjectContainer::iterator oit =
-				lower_bound(objects.begin(), objects.end(), &sObj, ilt);
-			sourceObj = *oit;
-		}
-*/	
-}
-
-
-bool BvHierarchy::InitialTerminationCriteriaMet(BvhLeaf *leaf)
-{
-	/*if (((int)leaf->mObjects.size() < mInititialObjectsSize) ||
-		(leaf->mObjects.end().GetBoundingBox().SurfaceArea() < mMinInitialSuffaceArea))
-
-	{
-	return true; 
+void BvHierarchy::InititialSubdivision(ObjectContainer &objects)
+{
+	/*std::stable_sort(objects.begin(), objects.end(), ilt2);
+	ObjectContainer::iterator oit;
+
+	stack<BvhLeaf *> tStack;
+
+	while (!tStack.empty())
+	{
+		BvhLeaf *leaf = tStack.top();
+
+		if (!InitialTerminationCriteriaMet(leaf))
+		{
+			ChooseSplitIndex(objects, oit);
+			SubdivideLeaf(leaf, oit);
+		}
 	}*/
+}
+
+
+void BvHierarchy::ChooseSplitIndex(const ObjectContainer &objects, 
+								   ObjectContainer::const_iterator &oit)
+{
+	ObjectContainer::const_iterator oit2, oit2_end = objects.end();
+    
+	float maxAreaDiff = 0.0f;
+
+	for (oit2 = objects.begin(); oit2 != (objects.end() - 1); ++ oit2)
+	{
+		Intersectable *obj = *oit2;
+		Intersectable *obj2 = *(oit2 + 1);
+		
+		const float areaDiff = 
+			fabs(obj->GetBox().SurfaceArea() - obj2->GetBox().SurfaceArea());
+
+		if (areaDiff > maxAreaDiff)
+		{
+			maxAreaDiff = areaDiff;
+			oit = oit2;
+		}
+	}
+}
+
+
+bool BvHierarchy::InitialTerminationCriteriaMet(BvhLeaf *leaf) const
+{
+	if (((int)leaf->mObjects.size() < mInititialObjectsSize) ||
+		(leaf->mObjects.back()->GetBox().SurfaceArea() < mMinInitialSurfaceArea))
+
+	{
+		return true; 
+	}
+
 	return false;
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1773)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1778)
@@ -129,4 +129,8 @@
 	{
 		mStrategies.push_back(SamplingStrategy::VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+
+		// ratio 3:1
+		mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
 		mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
 	}
@@ -405,4 +409,11 @@
 
 	// cast initial samples
+	
+	// mix of sampling strategies
+	vector<int>dummy;
+	//dummy.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+	//dummy.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+	//dummy.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+
 	CastPassSamples(mInitialSamples, mStrategies, initialSamples);
 
@@ -561,5 +572,4 @@
 	if (mShowVisualization)
 	{
-		cout << "************************\n*********************\n";
 		if (0)
 		{
@@ -5998,4 +6008,11 @@
 		Debug << "casting " << samplesPerPass << " samples ... ";
 
+		vector<int>dummyStrat;
+	
+		dummyStrat.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		dummyStrat.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
+		dummyStrat.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
+		//dummyStrat.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+
 		CastPassSamples(samplesPerPass, mStrategies, evaluationSamples);
 		
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1774)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1778)
@@ -404,5 +404,6 @@
 		mNumRays(0)
 		{
-			mSortedObjects[0] = mSortedObjects[1] = mSortedObjects[2] = NULL;
+			for (int i = 0; i < 4; ++ i)
+				mSortedObjects[i] = NULL;
 		}
 		
@@ -419,5 +420,6 @@
 		mNumRays(numRays)
 		{
-			mSortedObjects[0] = mSortedObjects[1] = mSortedObjects[2] = NULL;
+			for (int i = 0; i < 4; ++ i)
+				mSortedObjects[i] = NULL;
 		}
 
@@ -427,7 +429,6 @@
 		{
 			DEL_PTR(mNode);
-			DEL_PTR(mSortedObjects[0]);
-			DEL_PTR(mSortedObjects[1]);
-			DEL_PTR(mSortedObjects[2]);
+			for (int i = 0; i < 4; ++ i)
+				DEL_PTR(mSortedObjects[i]);
 		}
 
@@ -447,5 +448,5 @@
 		int mNumRays;
 		/// the sorted objects for the three dimensions
-		ObjectContainer *mSortedObjects[3];		
+		ObjectContainer *mSortedObjects[4];		
     };
 
@@ -895,10 +896,12 @@
 		some criteria (size, shader)
 	*/
-	void InititialSubdivision();
-
-	void ChooseSplitPlane(BvhLeaf *leaf);
-
-	bool InitialTerminationCriteriaMet(BvhLeaf *leaf);
-	float mMinInitialSuffaceArea;
+	void InititialSubdivision(ObjectContainer &objects);
+
+	void ChooseSplitIndex(const ObjectContainer &objects, 
+						  ObjectContainer::const_iterator &oit);
+
+	bool InitialTerminationCriteriaMet(BvhLeaf *leaf) const;
+	float mMinInitialSurfaceArea;
+int mInititialObjectsSize;
 protected:
 	
@@ -987,5 +990,5 @@
 	bool mUseBboxAreaForSah;
 
-	SortableEntryContainer *mSortedObjects[3];
+	SortableEntryContainer *mSortedObjects[4];
 
 	int mMinRaysForVisibility;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1764)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1778)
@@ -30,4 +30,5 @@
 
 
+
 /*******************************************************************/
 /*              class HierarchyManager implementation              */
@@ -1899,6 +1900,8 @@
 		float rc = 0;
         ObjectPvs pvs;
-		mVspTree->mViewCellsTree->GetPvs(vc, pvs);
-
+		
+		//mVspTree->mViewCellsTree->GetPvs(vc, pvs);
+		GetPvsIncrementally(vc, pvs);
+		
 		vc->SetPvs(pvs);
 
