Index: GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SubdivisionCandidate.h	(revision 2224)
@@ -40,5 +40,5 @@
 	/** Evaluate this candidate and put results into queue for further traversal.
 	*/
-	virtual bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet) = 0;
+	virtual bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet, SubdivisionCandidateContainer &dirtyList) = 0;
 	
 	/** Returns true of the global termination criteria of this split were met,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2205)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2224)
@@ -125,4 +125,6 @@
 		float devRelPvsIncrease;
 		int viewcells;
+
+		float mem;
 	};
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2187)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2224)
@@ -377,5 +377,7 @@
 	bool ApplySubdivisionCandidate(SubdivisionCandidate *sc, 
 								   SplitQueue &splitQueue,
-								   const bool repairQueue);
+								   //const bool repairQueue,
+								   std::vector<SubdivisionCandidate *> &dirtyList
+								   );
 
 	/** Tests if hierarchy construction is finished.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h	(revision 2224)
@@ -264,5 +264,5 @@
 		}
 
-		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet)
+		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet, SubdivisionCandidateContainer &dirtyList)
 		{
 			KdNode *n = sOspTree->Subdivide(splitQueue ,this,  terminationCriteriaMet);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2210)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2224)
@@ -516,10 +516,15 @@
 		}
 
-		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet)
+		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet, SubdivisionCandidateContainer &dirtyList)
 		{
 			VspNode *n = sVspTree->Subdivide(splitQueue, this, terminationCriteriaMet);
 			
 			// local or global termination criteria failed
-			return !n->IsLeaf();		
+			const bool success = !n->IsLeaf();	
+
+			if (success)
+				CollectDirtyCandidates(dirtyList, true);
+
+			return success;
 		}
 
@@ -556,7 +561,5 @@
 		float mCorrectedFrontRenderCost;
 		float mCorrectedBackRenderCost;
-		//float mCorrectedFrontVolume;
-		//float mCorrectedBackVolume;
-
+		
 		float mFrontRenderCost;
 		float mBackRenderCost;
@@ -907,6 +910,5 @@
 	/** Evaluates contribution of min event to pvs
 	*/
-	inline int EvalMinEventContribution(
-		const VssRay &ray, const bool isTermination) const;
+	inline int EvalMinEventContribution(const VssRay &ray, const bool isTermination) const;
 
 	/** Evaluates contribution of max event to pvs
@@ -955,5 +957,5 @@
 				  RayInfoContainer &backRays) const;
 
-	void UpdatePvsEntriesContribution(
+	inline void UpdatePvsEntriesContribution(
 		const VssRay &ray,
 		const bool isTermination,
@@ -973,5 +975,5 @@
 	
 	*/
-	void UpdateContributionsToPvs(
+	inline void UpdateContributionsToPvs(
 		const VssRay &ray,
 		const bool isTermination,
@@ -983,5 +985,5 @@
 	/** Evaluates the contribution for objects.
 	*/
-	void UpdateContributionsToPvs(
+	inline void UpdateContributionsToPvs(
 		Intersectable *obj, 
 		const int cf, 
@@ -992,15 +994,15 @@
 	/** Evaluates the contribution for bounding volume leaves.
 	*/
-	void UpdateContributionsToPvs(
+	inline void UpdateContributionsToPvs(
 		BvhLeaf *leaf,
 		const int cf,
 		float &frontPvs,
 		float &backPvs,
-		float &totalPvsm,
+		float &totalPvs,
 		const bool countEntries) const;
 
 	/** Evaluates the contribution for kd leaves.
 	*/
-	void UpdateContributionsToPvs(
+	inline void UpdateContributionsToPvs(
 		KdLeaf *leaf,
 		const int cf,
@@ -1011,9 +1013,9 @@
 	/** Returns true if tree can be terminated.
 	*/
-	bool LocalTerminationCriteriaMet(const VspTraversalData &data) const;
+	inline bool LocalTerminationCriteriaMet(const VspTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const;
+	inline bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const;
 
 	/** Adds ray sample contributions to the PVS.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2210)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2224)
@@ -393,10 +393,4 @@
 	mNodeTimer.Entry();
 
-/*
-#if STORE_VIEWCELLS_WITH_BVH
-	AssociateViewCellsWithObjects(sc.mSampledFrontObjects);
-	AssociateViewCellsWithObjects(sc.mSampledBackObjects);
-#endif	
-*/
 	const BvhTraversalData &tData = sc.mParentData;
 	BvhLeaf *leaf = tData.mNode;
@@ -500,10 +494,5 @@
 		AssignSortedObjects(sc, frontData, backData);
 	}
-/*
-#if STORE_VIEWCELLS_WITH_BVH
-	ReleaseViewCells(sc.mSampledFrontObjects);
-	ReleaseViewCells(sc.mSampledBackObjects);
-#endif
-*/
+
 	mNodeTimer.Exit();
 
@@ -515,5 +504,7 @@
 BvhNode *BvHierarchy::Subdivide(SplitQueue &tQueue,
 								SubdivisionCandidate *splitCandidate,
-								const bool globalCriteriaMet)
+								const bool globalCriteriaMet
+								,vector<SubdivisionCandidate *> &dirtyList
+								)
 {
 	mSubdivTimer.Entry();
@@ -552,7 +543,13 @@
 				new BvhSubdivisionCandidate(tBackData);
 		
-		EvalSubdivisionCandidate(*frontCandidate);
-		EvalSubdivisionCandidate(*backCandidate);
-
+		// preprocess view cells
+		AssociateViewCellsWithObjects(*tData.mSampledObjects);
+
+		EvalSubdivisionCandidate(*frontCandidate, true, false);
+		EvalSubdivisionCandidate(*backCandidate, true, false);
+
+		CollectDirtyCandidates(sc, dirtyList, true);
+		ReleaseViewCells(*tData.mSampledObjects);
+		
 		// cross reference
 		tFrontData.mNode->SetSubdivisionCandidate(frontCandidate); 
@@ -638,11 +635,12 @@
 
 void BvHierarchy::EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitCandidate, 
-										   bool computeSplitPlane)
+										   const bool computeSplitPlane,
+										   const bool preprocessViewCells)
 {
 	mPlaneTimer.Entry();
 
 #if STORE_VIEWCELLS_WITH_BVH
-	// fill view cells cache
-	AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSampledObjects);
+	if (preprocessViewCells) // fill view cells cache
+		AssociateViewCellsWithObjects(*splitCandidate.mParentData.mSampledObjects);
 #endif
 
@@ -656,4 +654,6 @@
 		const bool sufficientSamples = 
 			splitCandidate.mParentData.mNumRays > mMinRaysForVisibility;
+
+		//if (!sufficientSamples) cout << splitCandidate.mParentData.mNumRays << " ";
 
 		const bool useVisibiliyBasedHeuristics = 
@@ -757,5 +757,6 @@
 
 #if STORE_VIEWCELLS_WITH_BVH
-	ReleaseViewCells(*splitCandidate.mParentData.mSampledObjects);
+	if (preprocessViewCells)
+		ReleaseViewCells(*splitCandidate.mParentData.mSampledObjects);
 #endif
 
@@ -1672,5 +1673,5 @@
 	VssRay::NewMail();
 
-	if ((mMaxTests < tData.mNumRays) &&	 mUseCostHeuristics && useVisibilityBasedHeuristics)
+	/*if ((mMaxTests < tData.mNumRays) && mUseCostHeuristics && useVisibilityBasedHeuristics)
 	{
 		VssRayContainer rays;
@@ -1692,5 +1693,5 @@
 			}
 		}		
-	}
+	}*/
 
 	////////////////////////////////////
@@ -1733,5 +1734,5 @@
 			}
 
-			// no good results for degenerate axis split
+			// avoid splits in degenerate axis with high penalty
 			if (1 &&
 				(tData.mNode->GetBoundingBox().Size(axis) < 0.0001))//Limits::Small))
@@ -2405,5 +2406,5 @@
 	///////////////////////////////////////
 	// start from root of tree
-	/*
+
 	if (node == NULL)
 		node = mRoot;
@@ -2449,5 +2450,4 @@
   
 	return leaf;
-	*/
 }
 #endif
@@ -2632,5 +2632,5 @@
 		
 		// evaluate priority
-		EvalSubdivisionCandidate(*oSubdivisionCandidate);
+		EvalSubdivisionCandidate(*oSubdivisionCandidate, true, true);
 		PrintSubdivisionStats(*oSubdivisionCandidate);
 
@@ -2646,5 +2646,5 @@
 			
 			// reevaluate priority
-			EvalSubdivisionCandidate(*sCandidate);
+			EvalSubdivisionCandidate(*sCandidate, true, true);
 			tQueue.Push(sCandidate);
 		}
@@ -2655,5 +2655,5 @@
 	{	
 		// evaluate priority
-		EvalSubdivisionCandidate(*oSubdivisionCandidate);
+		EvalSubdivisionCandidate(*oSubdivisionCandidate, true, true);
 		PrintSubdivisionStats(*oSubdivisionCandidate);
 
@@ -2794,5 +2794,5 @@
 		new BvhSubdivisionCandidate(oData);
 
-	EvalSubdivisionCandidate(*oSubdivisionCandidate);
+	EvalSubdivisionCandidate(*oSubdivisionCandidate, true, true);
 	bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate);
 
@@ -2929,5 +2929,5 @@
 		
 		// evaluate the changes in render cost and pvs entries
-		EvalSubdivisionCandidate(*sc, false);
+		EvalSubdivisionCandidate(*sc, false, true);
 
 		// create new interior node and two leaf node
@@ -3062,5 +3062,6 @@
 			const bool globalCriteriaMet = GlobalTerminationCriteriaMet(bsc->mParentData);
 		
-			BvhNode *node = Subdivide(tempQueue, bsc, globalCriteriaMet);
+			SubdivisionCandidateContainer dirtyList;
+			BvhNode *node = Subdivide(tempQueue, bsc, globalCriteriaMet, dirtyList);
 
 			// not needed anymore
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2206)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2224)
@@ -118,22 +118,7 @@
 	
 	mStats <<
-		"#Pass\n" << pass ++ << endl <<
-		"#Time\n" << time << endl <<
-		"#TotalSamples\n" << totalRays << endl;
-
-	float last = 0.0f;
-
-	for (int k=0; k < 6; ++ k) 
-	{
-		float ratio = 0.0f;
-
-		if (k < (int)mMixtureDistribution->mDistributions.size()) 
-		{
-			ratio = mMixtureDistribution->mDistributions[k]->mRatio - last;
-			last = mMixtureDistribution->mDistributions[k]->mRatio;
-		}
-
-		mStats <<  "#Distribution"<<k<<endl<< ratio<<endl;
-	}
+		"#Pass\n" << pass ++ <<endl<<
+		"#Time\n" << time <<endl<<
+		"#TotalSamples\n" <<totalRays<<endl;
 	
 
@@ -187,9 +172,8 @@
 	else
 	{
-		/*mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-		mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
+		mStrategies.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
+		//mStrategies.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
 		mStrategies.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
-		*/
-        
+		        
 		mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
 	}
@@ -2379,17 +2363,17 @@
 void ViewCellsManager::UpdatePvs()
 {
-  if (mViewCellPvsIsUpdated || !ViewCellsTreeConstructed())
-	return;
-  
-  mViewCellPvsIsUpdated = true;
-  
-  ViewCellContainer leaves;
-  mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
-  
-  ViewCellContainer::const_iterator it, it_end = leaves.end();
-  
-  for (it = leaves.begin(); it != it_end; ++ it)
-	{
-	  mViewCellsTree->PropagatePvs(*it);
+	if (mViewCellPvsIsUpdated || !ViewCellsTreeConstructed())
+		return;
+
+	mViewCellPvsIsUpdated = true;
+
+	ViewCellContainer leaves;
+	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
+
+	ViewCellContainer::const_iterator it, it_end = leaves.end();
+
+	for (it = leaves.begin(); it != it_end; ++ it)
+	{
+		mViewCellsTree->PropagatePvs(*it);
 	}
 }
@@ -2399,5 +2383,5 @@
 {
   // update pvs of view cells tree if necessary
-  UpdatePvs();
+  if (0) UpdatePvs();
   
   ViewCellContainer::const_iterator it = mViewCells.begin();
@@ -2416,4 +2400,5 @@
   stat.devRelPvsIncrease = 0.0f;
   stat.renderCost = 0.0f;
+  stat.mem = 0.0f;
 
   if (mPerViewCellStat.size() != mViewCells.size()) {
@@ -2431,83 +2416,85 @@
   const float vol = mViewSpaceBox.GetVolume();
 
-  for (i=0; it != mViewCells.end(); ++ it, i++) 
-	{
+  for (i = 0; it != mViewCells.end(); ++ it, ++ i) 
+  {
 	  ViewCell *viewcell = *it;
 	  if (viewcell->GetValid()) {
-		const float pvsCost = mViewCellsTree->GetPvsCost(viewcell);
-		const float renderCost = pvsCost * viewcell->GetVolume() / vol;
-
-		if (pvsCost < stat.minPvs)
-		  stat.minPvs = pvsCost;
-		if (pvsCost > stat.maxPvs)
-		  stat.maxPvs = pvsCost;
-		
-		stat.avgPvs += pvsCost;
-		stat.renderCost += renderCost;
-
-		const float pvsEntries = (float)mViewCellsTree->GetPvsEntries(viewcell);
-		stat.avgPvsEntries += pvsEntries;
-		
-		if (mPerViewCellStat[i].pvsSize > 0.0f)
-		  mPerViewCellStat[i].relPvsIncrease = (pvsCost - mPerViewCellStat[i].pvsSize)/mPerViewCellStat[i].pvsSize;
-		
-		stat.avgRelPvsIncrease += mPerViewCellStat[i].relPvsIncrease;
-		
-		// update the pvs size
-		mPerViewCellStat[i].pvsSize = pvsCost;
-		
-		
-		
-		if (evaluateFilter) {
-		  ObjectPvs filteredPvs;
-		  
-		  PvsFilterStatistics fstat = ApplyFilter2(viewcell,
-												   false,
-												   mFilterWidth,
-												   filteredPvs);
-		  
-		  float filteredCost = filteredPvs.EvalPvsCost();
-
-		  stat.avgFilteredPvs += filteredCost;
-		  stat.avgFilteredPvsEntries += filteredPvs.GetSize();
-		  
-		  stat.avgFilterContribution += filteredCost - pvsCost;
-		  
-		  stat.avgFilterRadius += fstat.mAvgFilterRadius;
-		  int sum = fstat.mGlobalFilterCount + fstat.mLocalFilterCount;
-		  if (sum) {
-			stat.avgFilterRatio += fstat.mLocalFilterCount /
-			  (float) sum;
+		  const float pvsCost = mViewCellsTree->GetPvsCost(viewcell);
+		  const float renderCost = pvsCost * viewcell->GetVolume() / vol;
+
+		  if (pvsCost < stat.minPvs)
+			  stat.minPvs = pvsCost;
+		  if (pvsCost > stat.maxPvs)
+			  stat.maxPvs = pvsCost;
+
+		  stat.avgPvs += pvsCost;
+		  stat.renderCost += renderCost;
+
+		  const float pvsEntries = (float)mViewCellsTree->GetPvsEntries(viewcell);
+		  stat.avgPvsEntries += pvsEntries;
+
+		  if (mPerViewCellStat[i].pvsSize > 0.0f)
+			  mPerViewCellStat[i].relPvsIncrease = (pvsCost - mPerViewCellStat[i].pvsSize) / mPerViewCellStat[i].pvsSize;
+
+		  stat.avgRelPvsIncrease += mPerViewCellStat[i].relPvsIncrease;
+
+		  // update the pvs size
+		  mPerViewCellStat[i].pvsSize = pvsCost;
+
+
+
+		  if (evaluateFilter) {
+			  ObjectPvs filteredPvs;
+
+			  PvsFilterStatistics fstat = ApplyFilter2(viewcell,
+				  false,
+				  mFilterWidth,
+				  filteredPvs);
+
+			  float filteredCost = filteredPvs.EvalPvsCost();
+
+			  stat.avgFilteredPvs += filteredCost;
+			  stat.avgFilteredPvsEntries += filteredPvs.GetSize();
+
+			  stat.avgFilterContribution += filteredCost - pvsCost;
+
+			  stat.avgFilterRadius += fstat.mAvgFilterRadius;
+			  int sum = fstat.mGlobalFilterCount + fstat.mLocalFilterCount;
+			  if (sum) {
+				  stat.avgFilterRatio += fstat.mLocalFilterCount /
+					  (float) sum;
+			  }
+
+		  } else {
+			  stat.avgFilteredPvs += pvsCost;
+			  stat.avgFilterContribution += 0;
 		  }
-		  
-		} else {
-		  stat.avgFilteredPvs += pvsCost;
-		  stat.avgFilterContribution += 0;
-		}
-		
-		++ stat.viewcells;
+
+		  ++ stat.viewcells;
 	  }
-	}
-
-  
-  
+  }
+
+
+
   if (stat.viewcells) {
-	stat.avgPvs/=stat.viewcells;
-	stat.avgPvsEntries/=stat.viewcells;
-	stat.avgFilteredPvsEntries/=stat.viewcells;
-	stat.avgFilteredPvs/=stat.viewcells;
-	stat.avgFilterContribution/=stat.viewcells;
-	stat.avgFilterRadius/=stat.viewcells;
-	stat.avgFilterRatio/=stat.viewcells; 
-	stat.avgRelPvsIncrease/=stat.viewcells;
-
-	// evaluate std deviation of relPvsIncrease
-	float sum=0.0f;
-	for (i=0; i < stat.viewcells; i++) {
-	  sum += sqr(mPerViewCellStat[i].relPvsIncrease - stat.avgRelPvsIncrease);
-	}
-	stat.devRelPvsIncrease = sqrt(sum/stat.viewcells);
+	  stat.mem = (float)(ObjectPvs::GetEntrySizeByte() * stat.avgPvsEntries + stat.viewcells * 16) / float(1024 * 1024); 
+
+	  stat.avgPvs/=stat.viewcells;
+	  stat.avgPvsEntries/=stat.viewcells;
+	  stat.avgFilteredPvsEntries/=stat.viewcells;
+	  stat.avgFilteredPvs/=stat.viewcells;
+	  stat.avgFilterContribution/=stat.viewcells;
+	  stat.avgFilterRadius/=stat.viewcells;
+	  stat.avgFilterRatio/=stat.viewcells; 
+	  stat.avgRelPvsIncrease/=stat.viewcells;
+	  
+	  // evaluate std deviation of relPvsIncrease
+	  float sum=0.0f;
+	  for (i=0; i < stat.viewcells; i++) {
+		  sum += sqr(mPerViewCellStat[i].relPvsIncrease - stat.avgRelPvsIncrease);
+	  }
+	  stat.devRelPvsIncrease = sqrt(sum/stat.viewcells);
   }
-  
+
 }
 
@@ -2520,4 +2507,5 @@
   s<<"#AVG_PVS\n"<<pvsStat.avgPvs<<endl;
   s<<"#AVG_ENTRIES_PVS\n"<<pvsStat.avgPvsEntries<<endl;
+  s<<"#RENDERCOST\n"<<pvsStat.renderCost<<endl;
   s<<"#AVG_FILTERED_PVS\n"<<pvsStat.avgFilteredPvs<<endl;
   s<<"#AVG_FILTERED_ENTRIES_PVS\n"<<pvsStat.avgFilteredPvsEntries<<endl;
@@ -2529,4 +2517,5 @@
   s<<"#AVG_REL_PVS_INCREASE\n"<<pvsStat.avgRelPvsIncrease<<endl;
   s<<"#DEV_REL_PVS_INCREASE\n"<<pvsStat.devRelPvsIncrease<<endl;
+  s<<"#MEMROY\n"<<pvsStat.mem<<endl;
 
   s<<"#CONTRIBUTING_RAYS\n"<<mSamplesStat.mContributingRays<<endl;
@@ -6863,30 +6852,4 @@
     cout << "Evaluating view cell partition ... " << endl;
 
-	vector<int> evalStrats;
-
-	// mix of sampling strategies
-	if (0)
-	{
-		evalStrats.push_back(SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION);
-	}
-	else
-	{
-		/*evalStrats.push_back(SamplingStrategy::OBJECT_BASED_DISTRIBUTION);
-		evalStrats.push_back(SamplingStrategy::REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION);
-		evalStrats.push_back(SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION);
-		*/
-		evalStrats.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
-	}
-			
-    Debug << "casting eval strategies: ";
-	for (int i = 0; i < (int)evalStrats.size(); ++ i)
-		Debug << evalStrats[i] << " ";
-	Debug << endl;
-
-	cout << "casting eval strategies: ";
-	for (int i = 0; i < (int)evalStrats.size(); ++ i)
-		cout << evalStrats[i] << " ";
-	cout << endl;
-
 	int pass = 0;
 
@@ -6905,35 +6868,13 @@
 		Debug << "casting " << samplesPerPass << " samples ... ";
 	
-		if (0)
-		{
-			CastPassSamples(samplesPerPass, evalStrats, evaluationSamples);
-
-			timeDiff = TimeDiff(startTime, GetTime());
-			cout << "finished in " << timeDiff * 1e-3f << " secs" << endl;
-			Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl;
+		// use mixed distributions
+		CastEvaluationSamples(samplesPerPass, evaluationSamples);
+
+		timeDiff = TimeDiff(startTime, GetTime());
+		cout << "finished in " << timeDiff * 1e-3f << " secs" << endl;
+		Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl;
 		
-			cout << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... ";
-			Debug << "computing sample contributions of " << (int)evaluationSamples.size()  << " samples ... ";
-
-			startTime = GetTime();
-
-			ComputeSampleContributions(evaluationSamples, true, false);
-
-			timeDiff = TimeDiff(startTime, GetTime());
-			cout << "finished in " << timeDiff * 1e-3 << " secs" << endl;
-			Debug << "finished in " << timeDiff * 1e-3 << " secs" << endl;
-		}
-		else
-		{
-			// use mixed distributions
-			CastEvaluationSamples(samplesPerPass, evaluationSamples);
-
-			timeDiff = TimeDiff(startTime, GetTime());
-			cout << "finished in " << timeDiff * 1e-3f << " secs" << endl;
-			Debug << "finished in " << timeDiff * 1e-3f << " secs" << endl;
+		// don't use sample contributions because already accounted for inside the mixture distribution!
 		
-			// don't use sample contributions because already accounted for inside the mixture distribution!
-		}
-
 		castSamples += samplesPerPass;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2210)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2224)
@@ -471,10 +471,10 @@
 		{
             mDirty = false;
-			sBvHierarchy->EvalSubdivisionCandidate(*this, computeSplitplane);
+			sBvHierarchy->EvalSubdivisionCandidate(*this, computeSplitplane, true);
 		}
 
-		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet)
+		bool Apply(SplitQueue &splitQueue, bool terminationCriteriaMet, SubdivisionCandidateContainer &dirtyList)
 		{
-			BvhNode *n = sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet);
+			BvhNode *n = sBvHierarchy->Subdivide(splitQueue, this, terminationCriteriaMet, dirtyList);
 
 			// local or global termination criteria failed
@@ -575,6 +575,7 @@
 	/** Evaluates candidate for splitting.
 	*/
-	void EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitData, 
-								  bool computeSplitPlane = true);
+	void EvalSubdivisionCandidate(BvhSubdivisionCandidate &splitData,
+								  const bool computeSplitPlane,
+								  const bool preprocessViewCells);
 
 	/** Returns vector of leaves.
@@ -754,5 +755,7 @@
 	BvhNode *Subdivide(SplitQueue &tQueue, 
 				 	   SubdivisionCandidate *splitCandidate,
-					   const bool globalCriteriaMet);
+					   const bool globalCriteriaMet
+					   ,vector<SubdivisionCandidate *> &dirtyList
+					   );
 	
 	/** Subdivides leaf.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2210)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2224)
@@ -837,4 +837,5 @@
 		return childPvs;
 	}
+
 	// assume pvs not sampled sufficiently => take total pvs
 	if (avgRayContri >= mMaxAvgRayContri)
@@ -852,5 +853,5 @@
 	const float newPvs = alpha * childPvs + (1.0f - alpha) * totalPvs;
 #endif
-
+cout<<"a";
 	//cout << "alpha " << alpha << " beta: " << beta << " child: " << childPvs << " parent: " << totalPvs << endl;
 	
@@ -863,8 +864,9 @@
 bool HierarchyManager::ApplySubdivisionCandidate(SubdivisionCandidate *sc, 
 												 SplitQueue &splitQueue,
-												 const bool repairQueue)
+												 //const bool repairQueue,
+												 SubdivisionCandidateContainer &dirtyList)
 {
 	const bool terminationCriteriaMet = GlobalTerminationCriteriaMet(sc);
-	const bool success = sc->Apply(splitQueue, terminationCriteriaMet);
+	const bool success = sc->Apply(splitQueue, terminationCriteriaMet, dirtyList);
 
 	if (sc->IsDirty())
@@ -934,14 +936,4 @@
 	// output stats
 	EvalSubdivisionStats();
-		
-	if (repairQueue) 
-	{
-		// reevaluate candidates affected by the split for view space splits, 
-		// this would be object space splits and other way round
-		vector<SubdivisionCandidate *> dirtyList;
-		sc->CollectDirtyCandidates(dirtyList, false);
-
-		RepairQueue(dirtyList, splitQueue, mRecomputeSplitPlaneOnRepair);
-	}
 
 	return true;
@@ -1046,4 +1038,6 @@
 									   AxisAlignedBox3 *forcedViewSpace)
 {
+	SubdivisionCandidate::NewMail();
+
 	while (!FinishedConstruction())
 	{
@@ -1053,6 +1047,15 @@
 		//-- subdivide leaf node
 
-		ApplySubdivisionCandidate(sc, mTQueue, repairQueue);
+		SubdivisionCandidateContainer dirtyList;
+
+		ApplySubdivisionCandidate(sc, mTQueue, dirtyList);
 				
+		if (repairQueue) 
+		{
+			// reevaluate candidates affected by the split for view space splits, 
+			// this would be object space splits and other way round
+			RepairQueue(dirtyList, mTQueue, mRecomputeSplitPlaneOnRepair);
+		}	
+
 		// we use objects for evaluating vsp tree construction until 
 		// a certain depth once a certain depth existiert ...
@@ -1103,6 +1106,12 @@
 		//-- subdivide leaf node of either type
 
-        ApplySubdivisionCandidate(sc, mTQueue, repairQueue);
+		SubdivisionCandidateContainer dirtyList;
+        ApplySubdivisionCandidate(sc, mTQueue, dirtyList);
 		
+		if (repairQueue)
+		{
+			RepairQueue(dirtyList, mTQueue, mRecomputeSplitPlaneOnRepair);
+		}
+
 		DEL_PTR(sc);
 	}
@@ -1140,10 +1149,9 @@
 		SubdivisionCandidate *sc = NextSubdivisionCandidate(splitQueue); 
 			
-		const bool repairQueue = false;
-		const bool success = ApplySubdivisionCandidate(sc, splitQueue, repairQueue);
+		const bool success = ApplySubdivisionCandidate(sc, splitQueue, dirtyCandidates);
 
 		if (success)
 		{
-			sc->CollectDirtyCandidates(dirtyCandidates, true);
+			//sc->CollectDirtyCandidates(dirtyCandidates, true);
 			++ steps;
 		}
