Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.sh
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.sh	(revision 1744)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/generate_viewcells.sh	(revision 1982)
@@ -17,5 +17,5 @@
 ############################################################################
 
- METHOD=gradient
+ METHOD=interleaved
  echo "$SCENE $METHOD"
 
@@ -28,2 +28,18 @@
   -hierarchy_construction_type=2 \
   -hierarchy_construction_consider_memory=true
+
+############################################################################
+
+#  METHOD=fast
+#  echo "$SCENE $METHOD"
+
+#  $PROGRAM $ENVIRONMENT \
+#  -view_cells_filename=$LOG_PREFIX-$METHOD-viewcells.xml.gz \
+#   -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=0 \
+#   -hierarchy_construction_consider_memory=true \
+#   -bvh_term_max_leaves=10000 \
+#   -hierarchy_term_max_leaves=20000 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1980)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1982)
@@ -194,5 +194,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\Qt&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include&quot;;QtInterface"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;TRY_GLOBAL_LINES"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT"
 				RuntimeLibrary="2"
 				RuntimeTypeInfo="TRUE"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1977)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1982)
@@ -172,4 +172,13 @@
 							const VssRay &oldRay) const;
 
+	bool NextViewCell();
+
+	void GlobalComputation();
+
+	void PerViewCellComputation();
+
+	void VisualizeViewCells();
+
+
 	//////////////////////
 
@@ -203,4 +212,6 @@
 
 	ViewCell *mCurrentViewCell;
+
+	int mNumViewCells;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1981)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1982)
@@ -171,6 +171,7 @@
 						   const VssRayContainer &sampleRays) = 0;
 
-  /** collect objects intersecting a given spatial box */
-  virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects);
+	/** collect objects intersecting a given spatial box.
+	*/
+	virtual void CollectObjects(const AxisAlignedBox3 &box, ObjectContainer &objects);
 
 	/** type of the view cell container.
@@ -185,6 +186,6 @@
 		@param filename file to load
 		@return true on success
-    */
-    virtual bool LoadViewCellsGeometry(const string filename, const bool extrudeBaseTriangle);
+	*/
+	virtual bool LoadViewCellsGeometry(const string filename, const bool extrudeBaseTriangle);
 	
 	/** Merges two view cells.
@@ -210,7 +211,5 @@
 	ViewCell *ExtrudeViewCell(const Triangle3 &baseTri, const float height) const;
 
-
-  virtual Intersectable *
-  GetIntersectable(const VssRay &ray, const bool isTermination) const;
+	virtual Intersectable *GetIntersectable(const VssRay &ray, const bool isTermination) const;
 
 	/** Sets maximal number of samples used for the 
@@ -272,4 +271,6 @@
 	virtual ViewCell *GetViewCell(const Vector3 &point, const bool active = false) const = 0;
   
+	ViewCell *GetViewCell(const int idx) const {return mViewCells[idx];}
+
 	virtual void PrintPvsStatistics(ostream &s);
 
@@ -324,5 +325,5 @@
 	virtual bool GetViewPoint(Vector3 &viewPoint) const;
   
-  virtual bool GetViewPoint(Vector3 &viewPoint, const Vector3 &params) const;
+	virtual bool GetViewPoint(Vector3 &viewPoint, const Vector3 &params) const;
 
 	/** Returns true if this view point is in the valid view space.
@@ -489,4 +490,6 @@
 
 	virtual void CompressViewCells();
+
+	int GetNumViewCells() const;
 
 	/////////////////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1981)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1982)
@@ -2282,4 +2282,10 @@
 
 
+int ViewCellsManager::GetNumViewCells() const
+{
+	return (int)mViewCells.size();
+}
+
+
 float ViewCellsManager::ComputeSampleContribution(VssRay &ray,
 												  const bool addRays,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1981)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1982)
@@ -28,6 +28,7 @@
 GvsPreprocessor::GvsPreprocessor(): 
 Preprocessor(), 
-//mSamplingType(SamplingStrategy::DIRECTION_BASED_DISTRIBUTION),
-mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION)
+mSamplingType(SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION),
+mNumViewCells(0),
+mCurrentViewCell(NULL)
 {
 	Environment::GetSingleton()->GetIntValue("GvsPreprocessor.totalSamples", mTotalSamples);
@@ -55,6 +56,19 @@
 		mOnlyRandomSampling = false;
 
-	//mGvsStatsStream.open("gvspreprocessor.log");
 	mGvsStats.Reset();
+}
+
+
+bool GvsPreprocessor::NextViewCell()
+{
+	if (mViewCellsManager->GetNumViewCells() == mNumViewCells)
+		return false; // no more view cells
+
+	mCurrentViewCell = mViewCellsManager->GetViewCell(mNumViewCells);
+	mViewCellsManager->CreateMesh(mCurrentViewCell);
+
+	++ mNumViewCells;
+    
+	return true;
 }
 
@@ -350,23 +364,4 @@
 
 
-/*Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay,
-										 const Triangle3 &hitTriangle,
-										 const VssRay &oldRay) const
-{
-	//-- intersect triangle plane with plane spanned by current samples
-	Plane3 plane(currentRay.GetOrigin(), currentRay.GetTermination(), oldRay.GetTermination());
-	Plane3 triPlane(hitTriangle.GetNormal(), hitTriangle.mVertices[0]);
-
-	SimpleRay intersectLine = GetPlaneIntersection(plane, triPlane);
-
-	// Evaluate new hitpoint just outside the triangle
-	const float factor = 0.95f;
-	const float t = triPlane.FindT(intersectLine);
-	const Vector3 newPoint = intersectLine.mOrigin + t * factor * intersectLine.mDirection;
-
-	return newPoint;
-}*/
-
-
 Vector3 GvsPreprocessor::GetPassingPoint(const VssRay &currentRay,
 										 const Triangle3 &occluder,
@@ -532,4 +527,92 @@
 	
 	return castSamples;
+}
+
+
+void GvsPreprocessor::VisualizeViewCells()
+{
+	char str[64]; sprintf(str, "tmp/pass%06d_%04d-", mNumViewCells, mPass);
+			
+	// visualization
+	if (mGvsStats.mPassContribution > 0)
+	{
+		const bool exportRays = true;
+		const bool exportPvs = true;
+
+		mViewCellsManager->ExportSingleViewCells(mObjects, 
+												 10, 
+												 false, 
+												 exportPvs, 
+												 exportRays, 
+												 1000, 
+												 str);
+	}
+
+	// remove pass samples
+	ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
+
+	for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
+	{
+		(*vit)->DelRayRefs();
+	}
+}
+
+
+void GvsPreprocessor::PerViewCellComputation()
+{
+	const int maxViewCells = 5;
+
+	while (NextViewCell() && mNumViewCells < maxViewCells)
+	{
+		cout << "processing view cell " << mNumViewCells << endl;
+
+		while (mGvsStats.mTotalSamples < mTotalSamples) 
+		{
+			++ mPass;
+
+			mGvsStats.mTotalSamples += Pass();
+				
+			////////
+			//-- stats
+
+			cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples 
+				 << " of " << mTotalSamples << endl;
+
+			mGvsStats.mPass = mPass;
+			mGvsStats.Stop();
+			mGvsStats.Print(mGvsStatsStream);
+			//mViewCellsManager->PrintPvsStatistics(mGvsStats);
+
+			if (GVS_DEBUG)
+				VisualizeViewCells();
+		}
+
+		// ComputeRenderError();
+	}
+}
+
+
+void GvsPreprocessor::GlobalComputation()
+{
+	while (mGvsStats.mTotalSamples < mTotalSamples) 
+	{
+		++ mPass;
+
+		mGvsStats.mTotalSamples += Pass();
+				
+		////////
+		//-- stats
+
+		cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples 
+			 << " of " << mTotalSamples << endl;
+
+		mGvsStats.mPass = mPass;
+		mGvsStats.Stop();
+		mGvsStats.Print(mGvsStatsStream);
+		//mViewCellsManager->PrintPvsStatistics(mGvsStats);
+
+		if (GVS_DEBUG)
+			VisualizeViewCells();
+	}
 }
 
@@ -564,47 +647,11 @@
 	mGvsStats.Print(mGvsStatsStream);
 
-	while (mGvsStats.mTotalSamples < mTotalSamples) 
-	{
-		++ mPass;
-
-		mGvsStats.mTotalSamples += Pass();
-				
-		////////
-		//-- stats
-
-		cout << "\nPass " << mPass << " #samples: " << mGvsStats.mTotalSamples << " of " << mTotalSamples << endl;
-		mGvsStats.mPass = mPass;
-		mGvsStats.Stop();
-		mGvsStats.Print(mGvsStatsStream);
-		//mViewCellsManager->PrintPvsStatistics(mGvsStats);
-
-		if (GVS_DEBUG)
-		{
-			char str[64]; sprintf(str, "tmp/pass%04d-", mPass);
-		
-			// visualization
-			if (mGvsStats.mPassContribution > 0)
-			{
-				const bool exportRays = true;
-				const bool exportPvs = true;
-
-				mViewCellsManager->ExportSingleViewCells(mObjects, 
-														 10, 
-														 false, 
-														 exportPvs, 
-														 exportRays, 
-														 1000, 
-														 str);
-			}
-
-			// remove pass samples
-			ViewCellContainer::const_iterator vit, vit_end = mViewCellsManager->GetViewCells().end();
-			for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit)
-			{
-				(*vit)->DelRayRefs();
-			}
-		}
-
-		// ComputeRenderError();
+	if (mPerViewCell)
+	{
+		PerViewCellComputation();
+	}
+	else
+	{
+		GlobalComputation();
 	}
 
