Index: /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 557)
+++ /trunk/VUT/GtpVisibilityPreprocessor/scripts/default.env	(revision 558)
@@ -29,5 +29,5 @@
 VssPreprocessor {
 	samplesPerPass  100000
-	initialSamples 1000000
+	initialSamples 800000
 	vssSamples 0
 	vssSamplesPerPass 500000
@@ -259,5 +259,5 @@
 VspBspTree {
 	Construction {
-		samples 500000
+		samples 300000
 		epsilon 0.005
 		randomize false
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 557)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp	(revision 558)
@@ -2557,10 +2557,12 @@
 	else // throw them into old view cells container
 	{
-		fVc->mMailbox = -1;
-		bVc->mMailbox = -1;
+		//fVc->mMailbox = -1;
+		//bVc->mMailbox = -1;
+		fVc->SetId(-2);
+		bVc->SetId(-2);
 
 		mOldViewCells.push_back(fVc);
 		mOldViewCells.push_back(bVc);
-
+		
 		mNewViewCells.push_back(vc);
 	}
@@ -2816,5 +2818,6 @@
 	int pass = 0;
 	const int nextPass = 200;
-
+for (int k = 0; k < (int)viewCells.size(); ++ k)
+						Debug << "vc mailid4: " << viewCells[k]->mMailbox << endl;
 	cout << "starting merge ... ";
 
@@ -2873,25 +2876,35 @@
 				
 					ViewCellContainer::const_iterator vit, vit_end = viewCells.end();
-
-					Debug << "here2111 " << viewCells.size() << endl;
-					for (int i = 0; i < viewCells.size(); ++ i)
+					
+					// find all already merged view cells and remove them from view cells
+					int i = 0;
+					while (1)
 					{
-						while (!viewCells.empty() && (viewCells.back()->mMailbox == -1))
+						//while (!viewCells.empty() && (viewCells.back()->mMailbox == -1))
+						while (!viewCells.empty() && (viewCells.back()->GetId() == -2))
 						{
-							Debug << "here244" << endl;
+							DEL_PTR(viewCells.back());
 							viewCells.pop_back();
 						}
+						// all merged view cells have been found
+						if (i >= viewCells.size()) 
+							break;
 
 						// already merged view cell, put it to end of vector
-						if ((i < viewCells.size()) && (viewCells[i]->mMailbox == -1))
-						{
-							Debug << "here2" << endl;
+						//if (viewCells[i]->mMailbox == -1)
+						if (viewCells[i]->GetId() == -2)
 							swap(viewCells[i], viewCells.back());
-						}
+						
+						++ i;
 					}
 				
+					for (int k = 0; k < (int)viewCells.size(); ++ k)
+						//Debug << "vc mailid: " << viewCells[k]->mMailbox << endl;
+						Debug << "vc id: " << viewCells[k]->GetId() << endl;
+
 					cout << "finished" << endl;
 					// not part of any leaf
-					CLEAR_CONTAINER(mOldViewCells);
+					//CLEAR_CONTAINER(mOldViewCells);
+					mOldViewCells.clear();
 
 					int newVcSize = (int)mNewViewCells.size();
@@ -2913,14 +2926,24 @@
 						ViewCellContainer::const_iterator it, it_end = viewCells.end();
 		
+						// new view cells are on the back
 						int i = (int)viewCells.size();
 						for (it = viewCells.begin(); it != it_end; ++ it)
 						{
-							Material m = RandomMaterial();
-							if (i-- == newVcSize)
+							Material m;
+
+							if (i -- < newVcSize)
 							{
-								m.mDiffuseColor.r = 1;
+								m.mDiffuseColor.r = RandomValue(0.5, 1.0);
 								m.mDiffuseColor.g = 0;
 								m.mDiffuseColor.b = 0;
 							}
+							else
+							{
+								float col = RandomValue(0.5, 1.0);
+								m.mDiffuseColor.r = col;
+								m.mDiffuseColor.g = col;
+								m.mDiffuseColor.b = col;
+							}
+
 							exporter->SetForcedMaterial(m);
 							mViewCellsManager->ExportVcGeometry(exporter, *it);
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 557)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp	(revision 558)
@@ -2221,7 +2221,7 @@
 				lm = vm;
 					
-				vm.mDiffuseColor.r -= 0.3f;
-				vm.mDiffuseColor.g -= 0.3f;
-				vm.mDiffuseColor.b -= 0.3f;
+				vm.mDiffuseColor.r -= 0.45f;
+				vm.mDiffuseColor.g -= 0.45f;
+				vm.mDiffuseColor.b -= 0.45f;
 
 				vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end();
