Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1414)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1415)
@@ -1946,5 +1946,5 @@
 }
 
-
+// matt: todo
 void ViewCellsManager::ExportViewCellsForViz(Exporter *exporter) const
 {
@@ -2640,8 +2640,19 @@
 		mViewCellsTree->SetRoot(root);
 
-		// compute pvs
+		// recompute pvs in the whole hierarchy
 		ObjectPvs pvs;
 		UpdatePvsForEvaluation(root, pvs);
 	}
+
+	cout << "finished" << endl;
+	cout << "merged view cells in "
+		 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
+
+	Debug << "Postprocessing: Merged view cells in "
+		<< TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl << endl;
+
+	
+	/////////////////////////////////////////
+	//-- visualization and statistics
 
 	// export statistics after merge
@@ -2653,16 +2664,5 @@
 	}
 
-	//-- stats and visualizations
-	cout << "finished" << endl;
-	cout << "merged view cells in "
-		 << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
-
-	Debug << "Postprocessing: Merged view cells in "
-		<< TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl << endl;
-	
-
-	//-- visualization and statistics
-    // reset view cells and stats
-	ResetViewCells();
+	ResetViewCells(); // reset view cells
 	Debug << "\nView cells after merge:\n" << mCurrentViewCellsStats << endl;
 
@@ -2763,5 +2763,5 @@
 	{
 		mColorCode = 1; // hack color code
-		Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d");
+		Exporter *exporter = Exporter::GetExporter("final_view_cells.wrl");
 	
 		cout << "exporting view cells after merge (pvs size) ... ";	
@@ -3815,5 +3815,5 @@
 	SimulationStatistics ss;
 	dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);
-    Debug << "render time before refine\n" << ss << endl;
+    Debug << "render time before refine\n\n" << ss << endl;
 
 	const long startTime = GetTime();
@@ -3898,5 +3898,5 @@
 	//-- render simulation after merge + refine
 
-	cout << "\nview cells partition render time before compress";
+	cout << "\nview cells partition render time before compress" << endl << endl;;
 	dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene();
 	SimulationStatistics ss;
@@ -4449,4 +4449,5 @@
 	//    find view cells associated with the samples
 	//    store the sample pvs with the pvs associated with the view cell
+	//
 	// for each view cell:
 	//    compute difference point sampled pvs - view cell pvs
@@ -4490,20 +4491,18 @@
 		m.mDiffuseColor.b = 1.0f;
 		//exporter->SetForcedMaterial(m);
-
-//		ExportViewCellGeometry(exporter, vc, mClipPlane);
-
-/*	// counting the pvss
-	for (rit = samples.begin(); rit != rit_end; ++ rit)
-	{
-		RenderCostSample sample = *rit;
-
-		ViewCell *vc = GetViewCell(sample.mPosition);
-		
-		AxisAlignedBox3 box(sample.mPosition - Vector3(1, 1, 1), sample.mPosition + Vector3(1, 1, 1));
-		Mesh *hMesh = CreateMeshFromBox(box);
-		
-		DEL_PTR(hMesh);
-
-*/
+		//ExportViewCellGeometry(exporter, vc, mClipPlane);
+
+		/*	// counting the pvss
+		for (rit = samples.begin(); rit != rit_end; ++ rit)
+		{
+			RenderCostSample sample = *rit;
+			ViewCell *vc = GetViewCell(sample.mPosition);
+
+			AxisAlignedBox3 box(sample.mPosition - Vector3(1, 1, 1), sample.mPosition + Vector3(1, 1, 1));
+			Mesh *hMesh = CreateMeshFromBox(box);
+
+			DEL_PTR(hMesh);
+		}
+		*/
 	}
 }
@@ -4801,4 +4800,5 @@
 
 	// print subdivision statistics
+	Debug << endl << endl;
 	mHierarchyManager->PrintHierarchyStatistics(Debug);
 
@@ -4815,5 +4815,4 @@
 
 	const long startTime = GetTime();
-
 	cout << "Computing remaining ray contributions ... ";
 
@@ -4822,14 +4821,10 @@
 		ComputeSampleContributions(savedRays, true, false);
 
-	cout << "finished" << endl;
-
-	Debug << "Computed remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3
+	Debug << "finished computing remaining ray contribution in " << TimeDiff(startTime, GetTime()) * 1e-3
 		  << " secs" << endl;
 
-	cout << "construction finished" << endl;
-
-	// real meshes are contructed at this stage
 	if (0)
 	{
+		// real meshes are constructed at this stage
 		cout << "finalizing view cells ... ";
 		FinalizeViewCells(true);
@@ -4908,5 +4903,5 @@
 	//-- render simulation after merge + refine
 
-	cout << "\nview cells partition render time before compress";
+	cout << "\nview cells partition render time before compress" << endl << endl;
 	dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene();
 	SimulationStatistics ss;
@@ -5028,5 +5023,10 @@
 	
 	if (clipPlane)
+	{
 		plane = clipPlane->GetPlane();
+	}
+
+	AxisAlignedBox3 bbox = GetViewSpaceBox();
+	bbox.Scale(Vector3(0.5, 1, 0.5));			
 
 	for (it = leaves.begin(); it != it_end; ++ it)
@@ -5037,4 +5037,7 @@
 		const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(vspVc->mLeaf);
 		
+		if (!Overlap(box, bbox))
+			continue;
+
 		if (clipPlane)
 		{
@@ -5081,7 +5084,8 @@
 	if (1) 
 	{	
+		/////////////////////////////
 		//-- export final view cells
 
-		// hack pvs
+		// hack color code (show pvs size)
 		const int savedColorCode = mColorCode;
 		mColorCode = 0;
@@ -5091,5 +5095,6 @@
 		if (exporter)
 		{
-			cout << "exporting view cells after post process ... ";
+			const long starttime = GetTime();
+			cout << "exporting final view cells (after initial construction + post process) ... ";
 
 			if (mExportGeometry)
@@ -5113,5 +5118,5 @@
 			delete exporter;
 
-			cout << "finished" << endl;
+			cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl;
 		}
 
@@ -5126,9 +5131,11 @@
 		if (exporter)
 		{
+			const long starttime = GetTime();
+
 			cout << "exporting object space hierarchy ... ";
 			mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects);
 		
 			delete exporter;
-			cout << "finished" << endl;
+			cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl;
 		}
 	}
@@ -5153,16 +5160,15 @@
 	const bool sortViewCells = true;
 
-	// sort view cells to visualize the largest view cells
 	if (sortViewCells)
 	{
 		//stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::SmallerPvs);
+		// sort view cells to visualize the view cells with highest render cost
 		stable_sort(mViewCells.begin(), mViewCells.end(), ViewCell::LargerRenderCost);
 	}
 
 	int limit = min(leafOut, (int)mViewCells.size());
-
 	int raysOut = 0;
 
-
+	///////////////////////////
 	//-- some rays for output
 	
@@ -5249,9 +5255,11 @@
 				}	
 				
-				//-- export rays piercing this view cell
+				// export rays piercing this view cell
 				exporter->ExportRays(vcRays, RgbColor(1, 1, 0));
 			}
 		}
 
+
+		/////////////////
 		//-- export view cell geometry
 
@@ -5267,4 +5275,5 @@
 
 #if 0	
+		//////////
 		//-- export pvs
 
@@ -5336,4 +5345,5 @@
 		return false;
 
+	const long starttime = GetTime();
 	cout << "exporting view cells to xml ... ";
 	
@@ -5349,4 +5359,6 @@
 	//////////////////////////////////////////////////////////////
 	//-- export bounding boxes
+	//-- The bounding boxes are used to identify 
+	//-- the objects in the rendering engine
 
 	stream << "<BoundingBoxes>" << endl;
@@ -5356,14 +5368,12 @@
 	{
 			const AxisAlignedBox3 box = (*oit)->GetBox();
-
-			//-- the bounding boxes
 			stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\""
 				   << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\""
 				   << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl;
 	}
-
 	stream << "</BoundingBoxes>" << endl;
 
-	////////////////////////////////////////////////////////////////
+
+	//////////////////////////
 	//-- export the view cells and the pvs
 
@@ -5374,5 +5384,5 @@
 	stream << "</ViewCells>" << endl;
 
-
+	//////////////////////
 	//-- export the view space hierarchy
 	
@@ -5384,5 +5394,5 @@
 	stream << "</ViewSpaceHierarchy>" << endl;
 
-	
+	//////////////////////	
 	//-- export the object space partition
 	
@@ -5392,6 +5402,5 @@
 	stream.close();
 	
-	cout << "finished" << endl;
-
+	cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3 << " secs" << endl;
 	return true;
 }
