Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1966)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1968)
@@ -1188,4 +1188,34 @@
 				 "1000000");
 
+  RegisterOption("Preprocessor.useHwGlobalLines",
+				 optBool,
+				 "preprocessor_use_hw_global_lines=",
+				 "false");
+
+   RegisterOption("Preprocessor.HwGlobalLines.texHeight",
+				  optInt,
+				  "preprocessor_hw_global_lines_texheight=",
+				  "128");
+
+    RegisterOption("Preprocessor.HwGlobalLines.texWidth",
+				   optInt,
+				   "preprocessor_hw_global_lines_texwidth=",
+				   "128");
+
+	RegisterOption("Preprocessor.HwGlobalLines.stepSize",
+				   optFloat,
+				   "preprocessor_hw_global_lines_stepsize=",
+				   "0.0001");
+
+	RegisterOption("Preprocessor.HwGlobalLines.maxDepth",
+				   optInt,
+				   "preprocessor_hw_global_lines_max_depth=",
+				   "50");
+
+	RegisterOption("Preprocessor.HwGlobalLines.sampleReverse",
+				   optBool,
+				   "preprocessor_hw_global_lines_sample_reverse=",
+				   "true");
+
   RegisterOption("RenderSampler.samples",
 				 optInt,
@@ -1198,5 +1228,4 @@
 				 "0");
 
-
    RegisterOption("RenderSampler.useOcclusionQueries",
 				 optBool,
@@ -1252,7 +1281,7 @@
 
 
-   /************************************************************************************/
-   /*                         GvsPrerpocessor related options                          */
-   /************************************************************************************/
+   /*************************************************************************/
+   /*                       GvsPrerpocessor related options                 */
+   /*************************************************************************/
 
 
@@ -1287,7 +1316,8 @@
 					"gvsStats.log");
 
-  /***********************************************************************************/
-  /*                         View cells related options                              */
-  /***********************************************************************************/
+	
+  /**********************************************************************/
+  /*                     View cells related options                     */
+  /**********************************************************************/
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1966)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1968)
@@ -21,5 +21,5 @@
 #include "IntelRayCaster.h"
 #include "InternalRayCaster.h"
-
+#include "GlobalLinesRenderer.h"
 
 
@@ -134,5 +134,6 @@
 mRayCaster(NULL),
 mStopComputation(false),
-mThread(NULL)
+mThread(NULL),
+mGlobalLinesRenderer(NULL)
 {
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
@@ -174,5 +175,4 @@
 											 mSamplesPerEvaluation);
 
-	
 	Debug << "******* Preprocessor Options **********" << endl;
 	Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
@@ -211,4 +211,6 @@
 	DEL_PTR(renderer);
 	DEL_PTR(mRayCaster);
+
+	DEL_PTR(mGlobalLinesRenderer);
 }
 
@@ -1074,5 +1076,6 @@
 
 
-bool Preprocessor::InitRayCast(const string externKdTree, const string internKdTree)
+bool Preprocessor::InitRayCast(const string externKdTree, 
+							   const string internKdTree)
 {
 	// always try to load the kd tree
@@ -1081,5 +1084,6 @@
 	if (!LoadKdTree(internKdTree))
 	{
-		cout << "error loading kd tree with filename " << internKdTree << ", rebuilding it instead ... " << endl;
+		cout << "error loading kd tree with filename " 
+			 << internKdTree << ", rebuilding it instead ... " << endl;
 		// build new kd tree from scene geometry
 		BuildKdTree();
@@ -1091,9 +1095,12 @@
 		if (!ExportKdTree(internKdTree))
 		{
-			cout << " error exporting kd tree with filename " << internKdTree << endl;
+			cout << " error exporting kd tree with filename " 
+				 << internKdTree << endl;
 		}
 		else
 		{
-			cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
+			cout << "finished in " 
+				 << TimeDiff(startTime, GetTime()) * 1e-3 
+				 << " secs" << endl;
 		}
 	}
@@ -1114,5 +1121,6 @@
 
 	int rayCastMethod;
-	Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod);
+	Environment::GetSingleton()->
+		GetIntValue("Preprocessor.rayCastMethod", rayCastMethod);
 
 	if (rayCastMethod == 0)
@@ -1145,4 +1153,12 @@
 	for (int i = 0; i < (int)rays.size();)
 	{
+		// HACK: does not really go together with the 16 ray bundles
+		if (rays[i].mDistribution == SamplingStrategy::HW_GLOBAL_LINES_DISTRIBUTION)
+		{
+			mGlobalLinesRenderer->CastGlobalLines(rays[i], vssRays);
+			i ++;
+			continue;
+		}
+
 		if (i + 16 < (int)rays.size()) 
 		{
@@ -1173,13 +1189,13 @@
 	if (rays.size() > 10000) 
 	{
-	  cout<<endl;
-	
-	long t2 = GetTime();
+		cout << endl;
+
+		long t2 = GetTime();
 
 #if SHOW_RAYCAST_TIMING
-	if (castDoubleRays)
-		cout << 2 * rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
-	else
-		cout << rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
+		if (castDoubleRays)
+            cout << 2 * rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
+		else
+			cout << rays.size() / (1e3f * TimeDiff(t1, t2)) << "M rays/s" << endl;
 #endif
 	}
@@ -1230,4 +1246,5 @@
 	ray.Init(point, direction, Ray::LOCAL_RAY);	
 }
+
 
 void Preprocessor::EvalViewCellHistogram()
@@ -1326,3 +1343,28 @@
 }
 
-}
+
+void Preprocessor::PrepareHwGlobalLines()
+{
+	int texHeight, texWidth;
+	float eps;
+	int maxDepth;
+	bool sampleReverse;
+
+	Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.texHeight", texHeight);
+	Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.texHeight", texWidth);
+	Environment::GetSingleton()->GetFloatValue("Preprocessor.HwGlobalLines.stepSize", eps);
+	Environment::GetSingleton()->GetIntValue("Preprocessor.HwGlobalLines.maxDepth", maxDepth);
+	Environment::GetSingleton()->GetBoolValue("Preprocessor.HwGlobalLines.sampleReverse", sampleReverse);
+
+	mGlobalLinesRenderer = 
+		new GlobalLinesRenderer(this,
+								texHeight,
+								texWidth,
+								eps,
+								maxDepth,
+								sampleReverse);
+
+	mGlobalLinesRenderer->InitGl();
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1958)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1968)
@@ -316,5 +316,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(CG_INC_PATH)&quot;"
-				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_QT"
+				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;USE_QT;ATI"
 				ExceptionHandling="TRUE"
 				RuntimeLibrary="2"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1966)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1968)
@@ -29,5 +29,5 @@
 class VssRay;
 class RayCaster;
-
+class GlobalLinesRenderer;
 
 
@@ -174,5 +174,5 @@
 	Intersectable *GetObjectById(const int id);
 
-
+	void PrepareHwGlobalLines();
 	////////////////////////////////////////////////
 
@@ -234,6 +234,6 @@
   
 	int mTotalSamples;
-  int mSamplesPerPass;
-  int mSamplesPerEvaluation;
+	int mSamplesPerPass;
+	int mSamplesPerEvaluation;
 
 protected:
@@ -253,4 +253,5 @@
 	/////////////////////////
 
+	GlobalLinesRenderer *mGlobalLinesRenderer;
 	RayCaster *mRayCaster;
 	/// samples used for construction of the BSP view cells tree.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1966)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1968)
@@ -25,6 +25,6 @@
 	enum 
 	{
-	  DUMMY_DISTRIBUTION = 0,
-	  DIRECTION_BASED_DISTRIBUTION,
+		DUMMY_DISTRIBUTION = 0,
+		DIRECTION_BASED_DISTRIBUTION,
 		OBJECT_BASED_DISTRIBUTION,
 		DIRECTION_BOX_BASED_DISTRIBUTION,
@@ -39,8 +39,8 @@
 		VIEWSPACE_BORDER_BASED_DISTRIBUTION,
 		REVERSE_VIEWSPACE_BORDER_BASED_DISTRIBUTION,
-	  GLOBAL_LINES_DISTRIBUTION,
-	  GVS,
-	  MUTATION_BASED_DISTRIBUTION
-
+		GLOBAL_LINES_DISTRIBUTION,
+		GVS,
+		MUTATION_BASED_DISTRIBUTION,
+		HW_GLOBAL_LINES_DISTRIBUTION
 	};
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp	(revision 1964)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp	(revision 1968)
@@ -200,43 +200,40 @@
 
 
-/*GlobalLinesRenderer::GlobalLinesRenderer(RenderTexture *buffer1, 
-										 RenderTexture *buffer2, 
-										 Preprocessor *preprocessor,
-										 GlRenderer *renderer)
-: mNewTexture(buffer1), mOldTexture(buffer2), mPreprocessor(preprocessor), mMaxDepth(100),
-mRenderer(renderer)
-{
-}
-*/
-
-
 GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor, 
-										 GlRenderer *renderer,
-										 const float mTexHeight,
-										 const float mTexWidth,
-										 const float eps): 
+										 const int texHeight,
+										 const int texWidth,
+										 const float eps,
+										 const int maxDepth,
+										 const bool sampleReverse):
 mNewTexture(NULL), 
 mOldTexture(NULL), 
-mMaxDepth(0), 
-mRenderer(renderer), 
 mPreprocessor(preprocessor),
 mTexHeight(mTexHeight),
 mTexWidth(mTexWidth),
-mEpsilon(eps)
-{
-}
-
-
-GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor, 
-										 GlRenderer *renderer):
+mEpsilon(eps),
+mMaxDepth(maxDepth),
+mSampleReverse(sampleReverse)
+{
+	mRenderer = new GlRenderer(mPreprocessor->mSceneGraph,
+							   mPreprocessor->mViewCellsManager,
+							   mPreprocessor->mKdTree);
+
+}
+
+
+GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor):
 mNewTexture(NULL), 
 mOldTexture(NULL), 
-mMaxDepth(0), 
-mRenderer(renderer), 
+mMaxDepth(40), 
 mPreprocessor(preprocessor),
 mTexHeight(128),
 mTexWidth(128),
-mEpsilon(0.0001)
-{}
+mEpsilon(0.0001),
+mSampleReverse(true)
+{
+	mRenderer = new GlRenderer(mPreprocessor->mSceneGraph,
+							   mPreprocessor->mViewCellsManager,
+							   mPreprocessor->mKdTree);
+}
 
 
@@ -288,41 +285,13 @@
 	delete mNewItemBuffer;
 	delete mOldItemBuffer;
+
+	DEL_PTR(mRenderer);
 }
 
  
-void GlobalLinesRenderer::InitScene(const float alpha, const float beta)
-{
-	AxisAlignedBox3 bbox = globalLinesRenderer->mPreprocessor->mKdTree->GetBox();
-	
-	const float sceneSize = Magnitude(bbox.Diagonal());
-
-	// compute the center of the scene
-	Vector3 midPoint = bbox.Center();
-	
-	// add a small offset to provide some randomness in the sampling
-	Vector3 offset(Random(sceneSize * 1e-3f), 
-				   Random(sceneSize * 1e-3f), 
-				   Random(sceneSize * 1e-3f));
-
-	midPoint += offset;
-		
-	mNear = 1;
-	mFar = sceneSize * 2;
-	mWidth = sceneSize;
-
-	ComputeLookAt(alpha, 
-				  beta,
-				  mEyeVec, 
-				  mUpVec,
-				  mLeftVec);
-	
-	mViewPoint = midPoint - 0.5f * sceneSize * mEyeVec;
-
-	cout << "mid point: " << midPoint << endl;
-	cout << "view point: " << mViewPoint << endl;
-	cout << "scene: " << bbox << endl;
-
+void GlobalLinesRenderer::InitRenderTexture(RenderTexture *rt)
+{
 	 // setup the rendering context for the RenderTexture
-	mNewTexture->BeginCapture();
+	rt->BeginCapture();
 	{
 		//Reshape(mTexWidth, mTexHeight);
@@ -346,38 +315,83 @@
 		glLoadIdentity();
 		gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
-				  midPoint.x, midPoint.y, midPoint.z, 
+				  mTermination.x, mTermination.y, mTermination.z, 
 				  mUpVec.x, mUpVec.y, mUpVec.z);
 
 	}
-	mNewTexture->EndCapture();
-
-	// setup the rendering context for the other depth buffer
-	mOldTexture->BeginCapture();
-	{
-		// for item buffer: white means no color
-		glClearColor(1, 1, 1, 1);
-       
-		//Reshape(mTexWidth, mTexHeight);
-		glViewport(0, 0, mTexWidth, mTexHeight);
-		SetFrustum(mWidth, mWidth, mNear, mFar);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
+	rt->EndCapture();
+}
+
+
+void GlobalLinesRenderer::InitScene(const float alpha, const float beta)
+{
+	AxisAlignedBox3 bbox = 
+		globalLinesRenderer->mPreprocessor->mKdTree->GetBox();
+	
+	const float sceneSize = Magnitude(bbox.Diagonal());
+
+	// compute the center of the scene
+	mTermination = bbox.Center();
+	
+	// add a small offset to provide some randomness in the sampling
+	if (0)
+	{
+		Vector3 offset(
+			Random(sceneSize * 1e-3f), 
+			Random(sceneSize * 1e-3f), 
+			Random(sceneSize * 1e-3f));
+
+		mTermination += offset;
+	}
 		
-		glFrontFace(GL_CCW);
-		glCullFace(GL_BACK);
-		
-		glDisable(GL_CULL_FACE);
-		//glEnable(GL_CULL_FACE);
-		
-		glShadeModel(GL_FLAT);
-		glEnable(GL_DEPTH_TEST);
-		
-		gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
-				  midPoint.x, midPoint.y, midPoint.z, 
-				  mUpVec.x, mUpVec.y, mUpVec.z);
-	}
-	mOldTexture->EndCapture();
-
+	mNear = 1;
+	mFar = sceneSize * 2;
+	mWidth = sceneSize;
+
+	ComputeLookAt(alpha, 
+				  beta,
+				  mEyeVec, 
+				  mUpVec,
+				  mLeftVec);
+	
+	mViewPoint = mTermination - 0.5f * sceneSize * mEyeVec;
+
+	cout << "termination point: " << mTermination << endl;
+	cout << "view point: " << mViewPoint << endl;
+	cout << "scene: " << bbox << endl;
+
+	InitRenderTexture(mNewTexture);
+	InitRenderTexture(mOldTexture);
+	
+	cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl;
+}
+
+
+void GlobalLinesRenderer::InitScene(const SimpleRay &ray)
+{
+	AxisAlignedBox3 bbox = 
+		globalLinesRenderer->mPreprocessor->mKdTree->GetBox();
+	
+	const float sceneSize = Magnitude(bbox.Diagonal());
+
+	// compute the center of the scene
+	mViewPoint = ray.mOrigin;
+	mTermination = ray.mOrigin + ray.mDirection;
+
+	mEyeVec = Normalize(ray.mDirection);
+
+	mNear = 1;
+	mFar = sceneSize * 2;
+	mWidth = sceneSize;
+
+	mEyeVec.RightHandedBase(mUpVec, mLeftVec);
+    mViewPoint = mTermination - 0.5f * sceneSize * mEyeVec;
+
+	cout << "termination point: " << mTermination << endl;
+	cout << "view point: " << mViewPoint << endl;
+	cout << "scene: " << bbox << endl;
+
+	InitRenderTexture(mNewTexture);
+	InitRenderTexture(mOldTexture);
+	
 	cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl;
 }
@@ -395,4 +409,13 @@
 }
 
+
+void GlobalLinesRenderer::CastGlobalLines(const SimpleRay &ray, 
+										  VssRayContainer &rays)
+{
+	InitScene(ray);
+
+	// bind pixel shader implementing the front depth buffer functionality
+	ApplyDepthPeeling(rays);
+}
 
 void GlobalLinesRenderer::RenderObject(Intersectable *obj)
@@ -438,11 +461,8 @@
 										Vector3 &left)
 {
-	//float x = cos(alpha);
-	//float y = sin(alpha);
 	eye.x = sin(alpha) * cos(beta);
 	eye.y = sin(alpha) * sin(beta);
 	eye.z = cos(alpha);
 
-	//eye = Normalize(eye);
 	eye.RightHandedBase(up, left);
 }
@@ -637,5 +657,5 @@
 
 
-void GlobalLinesRenderer::ProcessDepthBuffer(VssRayContainer &vssRays, 
+bool GlobalLinesRenderer::ProcessDepthBuffer(VssRayContainer &vssRays, 
 											 const bool oldBufferInitialised,
 											 const int pass)
@@ -660,4 +680,45 @@
 			mOldItemBuffer[i * 4 + 3] = 255;
 		}
+	}
+
+	/////////////////
+	// test for validity
+
+	bool buffersEqual = true;
+	bool bufferEmpty = true;
+
+	for (int y = 0; y < mTexHeight; ++ y)
+	{
+		for (int x = 0; x < mTexWidth; ++ x)
+		{
+			const int depthIndex = x + mTexWidth * y;   
+			const int itemIndex = 4 * depthIndex;
+		
+			if (mOldItemBuffer[itemIndex] != mNewItemBuffer[itemIndex])
+			{
+				buffersEqual = false;
+			}
+
+			unsigned char r = mNewItemBuffer[itemIndex];
+			unsigned char g = mNewItemBuffer[itemIndex + 1];
+			unsigned char b = mNewItemBuffer[itemIndex + 2];
+
+			// 3 times 255 means no valid object
+			if (!((r == 255) && (g == 255) && (b == 255)))
+			{
+				bufferEmpty = false;
+			}
+		}
+		
+		// early exit
+		if (!buffersEqual && !bufferEmpty)
+			break;
+	}
+
+	// depth buffer not valid
+	if (buffersEqual || bufferEmpty)
+	{
+		cout << "stopped at layer " << pass << endl;
+		return false;
 	}
 
@@ -698,5 +759,5 @@
 			}
 
-			if (termObj2)
+			if (mSampleReverse && termObj2)
 			{
 				vssRays.push_back(new VssRay(clippedNewPt, clippedOldPt, NULL, termObj2, pass));
@@ -705,4 +766,6 @@
 		}
 	}
+
+	return true;
 }
 
@@ -912,5 +975,7 @@
 
 		// process the buffers for following layer
-		ProcessDepthBuffer(rays, true, i);
+		// jump out of loop for the first invalid buffer
+		if (!ProcessDepthBuffer(rays, true, i))
+			break;
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h	(revision 1964)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h	(revision 1968)
@@ -15,4 +15,5 @@
 class Preprocessor;
 class GlRenderer;
+struct SimpleRay;
 
 struct VssRayContainer;
@@ -23,10 +24,11 @@
 	
 	GlobalLinesRenderer(Preprocessor *preprocessor, 
-						GlRenderer *renderer,
-						const float texHeight,
-						const float mTexWidth,
-						const float eps);
+						const int texHeight,
+						const int mTexWidth,
+						const float eps,
+						const int maxDepth,
+						const bool sampleReverse);
 
-	GlobalLinesRenderer(Preprocessor *preprocessor, GlRenderer *renderer);
+	GlobalLinesRenderer(Preprocessor *preprocessor);
 
 	~GlobalLinesRenderer();
@@ -39,4 +41,12 @@
 						 const float beta, 
 						 VssRayContainer &rays);
+
+	/** Casts global lines using the given ray as origin and 
+		direction vector.
+		@returns Computed samples in the container rays
+	*/
+	void CastGlobalLines(const SimpleRay &ray, 
+						 VssRayContainer &rays);
+
 
 	void InitGl();
@@ -62,5 +72,5 @@
 	void ExportDepthBuffer();
 	void ExportItemBuffer();
-	void ProcessDepthBuffer(VssRayContainer &vssRays, 
+	bool ProcessDepthBuffer(VssRayContainer &vssRays, 
 							const bool oldBufferInitialised, 
 							const int pass);
@@ -83,7 +93,10 @@
 
 	int mMaxDepth;
+	
 	Vector3 mEyeVec;
 	Vector3 mLeftVec;
 	Vector3 mUpVec;
+	Vector3 mTermination;
+
 	float mFar;
 	float mNear;
@@ -94,4 +107,5 @@
 	float *mNewDepthBuffer;
 	float *mOldDepthBuffer;
+
 	unsigned char *mNewItemBuffer;
 	unsigned char *mOldItemBuffer;
@@ -105,4 +119,5 @@
 					   Vector3 &up, 
 					   Vector3 &left);
+
 protected:
 
@@ -110,4 +125,7 @@
 
 	void InitScene(const float alpha, const float beta);
+	void InitScene(const SimpleRay &ray);
+
+	void InitRenderTexture(RenderTexture *rt);
 
 	Preprocessor *mPreprocessor;
@@ -118,4 +136,6 @@
 	int mTexHeight;
 	float mEpsilon;
+
+	bool mSampleReverse;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1949)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1968)
@@ -258,16 +258,22 @@
 	}
 	
+	
+	bool useHwGlobalLines;
+	Environment::GetSingleton()->GetBoolValue("Preprocessor.useHwGlobalLines",
+											   useHwGlobalLines);
+
+	if (useHwGlobalLines)
+		preprocessor->PrepareHwGlobalLines();
+
 	// create a preprocessor thread (note: capsulates calls to boost fuctions!)
 	PreprocessorThread *pt = NULL;
 
 #ifdef TRY_GLOBAL_LINES
-	GlRenderer *renderer = new GlRenderer(preprocessor->mSceneGraph,
-										  preprocessor->mViewCellsManager,
-										  preprocessor->mKdTree);
-
-	globalLinesRenderer = new GlobalLinesRenderer(preprocessor, renderer);
+	
+	globalLinesRenderer = new GlobalLinesRenderer(preprocessor);
 	globalLinesRenderer->InitGl();
 	globalLinesRenderer->Run();
 
+	//delete renderer;
 #else
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1960)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.h	(revision 1968)
@@ -224,97 +224,95 @@
 public:
 
-GlRendererBuffer(SceneGraph *sceneGraph,
-				 ViewCellsManager *viewcells,
-				 KdTree *tree);
-
-  virtual ~GlRendererBuffer();
+	GlRendererBuffer(SceneGraph *sceneGraph,
+		ViewCellsManager *viewcells,
+		KdTree *tree);
+
+	virtual ~GlRendererBuffer();
 
 	/** Evaluates render cost of a point sample.
-		@param sample the render cost sample to be evaluated
-		@param useOcclusionQueries if occlusion queries should be used or item buffer
-		@param threshold number of pixels / samples from where an object is considered visible.
-	*/
-  virtual void EvalRenderCostSample(RenderCostSample &sample,
-							  const bool useOcclusionQueries,
-							  const int threshold);
+	@param sample the render cost sample to be evaluated
+	@param useOcclusionQueries if occlusion queries should be used or item buffer
+	@param threshold number of pixels / samples from where an object is considered visible.
+	*/
+	virtual void EvalRenderCostSample(RenderCostSample &sample,
+		const bool useOcclusionQueries,
+		const int threshold);
 
 	/** Evaluates render cost of a number of point samples. The point samples
-		are distributed uniformly over the defined view space.
-
-		@param numSamples the number of point samples taken
-		@param samples stores the taken point samples in a container
-		@param useOcclusionQueries if occlusion queries should be used or item buffer
-		@param threshold number of pixels / samples from where an object is considered visible.
-	*/
-  virtual void SampleRenderCost(const int numSamples, 
-								vector<RenderCostSample> &samples,
-								const bool useOcclusionQueries,
-								const int threshold = 0);
-  
+	are distributed uniformly over the defined view space.
+
+	@param numSamples the number of point samples taken
+	@param samples stores the taken point samples in a container
+	@param useOcclusionQueries if occlusion queries should be used or item buffer
+	@param threshold number of pixels / samples from where an object is considered visible.
+	*/
+	virtual void SampleRenderCost(const int numSamples, 
+		vector<RenderCostSample> &samples,
+		const bool useOcclusionQueries,
+		const int threshold = 0);
+
 
 	/** Implerment in subclasses.
 	*/
-  virtual void EvalPvsStat();
-
-
-  virtual int GetWidth() const = 0;
-  virtual int GetHeight() const  = 0; 
-
-  virtual void MakeCurrent() = 0;
-  virtual void DoneCurrent() = 0;
-  
-
-  virtual void SampleBeamContributions(
-							   Intersectable *sourceObject,
-							   Beam &beam,
-							   const int samples,
-							   BeamSampleStatistics &stat
-							   );
-
-  virtual void
-  SampleViewpointContributions(
-							   Intersectable *sourceObject,
-							   const Vector3 viewPoint,
-							   Beam &beam,
-							   const int desiredSamples,
-							   BeamSampleStatistics &stat
-							   );
-
-  virtual void InitGL();
-
-  /** Computes rays from information gained with hw sampling-
-  */
-  virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
-
-  virtual int ComputePvs() const = 0;
-
-  
-  virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
-
-
-
-  
+	virtual void EvalPvsStat();
+
+
+	virtual int GetWidth() const = 0;
+	virtual int GetHeight() const  = 0; 
+
+	virtual void MakeCurrent() = 0;
+	virtual void DoneCurrent() = 0;
+
+
+	virtual void SampleBeamContributions(
+		Intersectable *sourceObject,
+		Beam &beam,
+		const int samples,
+		BeamSampleStatistics &stat
+		);
+
+	virtual void
+		SampleViewpointContributions(
+		Intersectable *sourceObject,
+		const Vector3 viewPoint,
+		Beam &beam,
+		const int desiredSamples,
+		BeamSampleStatistics &stat
+		);
+
+	virtual void InitGL();
+
+	/** Computes rays from information gained with hw sampling-
+	*/
+	virtual void ComputeRays(Intersectable *sourceObj, VssRayContainer &rays);
+
+	virtual int ComputePvs() const = 0;
+
+	virtual int ComputePvs(ObjectContainer &objects, ObjectContainer &pvs) const = 0;
+
+
 protected:
-  unsigned int *mPixelBuffer;
-  
-  static void GenQueries(const int numQueries);
-	
-  virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint, 
-									 const Beam &beam, 
-
-									 Intersectable *sourceObject);
+
+	unsigned int *mPixelBuffer;
+
+	static void GenQueries(const int numQueries);
+
+	virtual void SetupProjectionForViewPoint(const Vector3 &viewPoint, 
+		const Beam &beam, 
+
+		Intersectable *sourceObject);
 
 	/** Evaluates query for one direction using item buffer.
 	*/
-  virtual void EvalQueryWithItemBuffer();
+	virtual void EvalQueryWithItemBuffer();
 
 	/** Evaluates query for one direction using occlusion queries.
 	*/
-  virtual void EvalQueryWithOcclusionQueries();
+	virtual void EvalQueryWithOcclusionQueries();
 
 public:
 	// matt: remove qt dependencies
- // signals:
-//	void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
+	// signals:
+	//	void UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &);
 };
 
@@ -325,23 +323,23 @@
 {
 public:
-	
+
 	GlRendererWidget(SceneGraph *sceneGraph, ViewCellsManager *vcm, KdTree *kdTree):
 	  GlRenderer(sceneGraph, vcm, kdTree)
-	{}
-
-    GlRendererWidget() {}
-
-    virtual ~GlRendererWidget() {}
-
-	//virtual void Create() {}
-	virtual void Show() {}
-	
+	  {}
+
+	  GlRendererWidget() {}
+
+	  virtual ~GlRendererWidget() {}
+
+	  //virtual void Create() {}
+	  virtual void Show() {}
+
 
 protected:
 
 
-  //	SceneGraph *mSceneGraph;
-  //	ViewCellsManager *mViewCellsManager;
-  //	KdTree *mKdTree;
+	//	SceneGraph *mSceneGraph;
+	//	ViewCellsManager *mViewCellsManager;
+	//	KdTree *mKdTree;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1966)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1968)
@@ -18,10 +18,13 @@
 HaltonSequence ObjectDirectionBasedDistribution::sHalton;
 HaltonSequence DirectionBasedDistribution::sHalton;
+HaltonSequence HwGlobalLinesDistribution::sHalton;
 
 
 SamplingStrategy::SamplingStrategy(Preprocessor &preprocessor): 
-  mPreprocessor(preprocessor), mRatio(1.0f),  mTotalRays(0), mTotalContribution(0.0f)
-{
-  
+mPreprocessor(preprocessor), 
+mRatio(1.0f),  
+mTotalRays(0), 
+mTotalContribution(0.0f)
+{  
 }
 
@@ -415,6 +418,4 @@
 	return true;
 }
-
-
 
 
@@ -839,5 +840,68 @@
 }
 
-}
-
-
+
+bool HwGlobalLinesDistribution::GenerateSample(SimpleRay &ray) 
+{
+	Vector3 origin, termination, direction; 
+
+	float radius = 0.5f * 
+		Magnitude(mPreprocessor.mViewCellsManager->GetViewSpaceBox().Size());
+
+	Vector3 center = mPreprocessor.mViewCellsManager->GetViewSpaceBox().Center();
+
+	const int tries = 1000;
+	int i;
+	for (i=0; i < tries; i++) 
+	{
+		float r[2];
+		sHalton.GetNext(2, r);
+
+		origin = center + (radius * UniformRandomVector(r[0], r[1]));
+		termination = center;
+		
+		if (0)
+		{
+			// add a small offset to provide some more randomness in the sampling
+			Vector3 offset(Random(radius * 1e-3f), 
+						   Random(radius * 1e-3f), 
+						   Random(radius * 1e-3f));
+			termination += offset;
+		}
+
+		direction = termination - origin;
+
+		// $$ jb the pdf is yet not correct for all sampling methods!
+		const float c = Magnitude(direction);
+
+		if (c <= Limits::Small) 
+			return false;
+
+		direction *= 1.0f / c;
+
+		// check if the ray intersects the view space box
+		static Ray ray;
+		ray.Init(origin, direction, Ray::LOCAL_RAY);	
+
+		float tmin, tmax;
+		if (mPreprocessor.mViewCellsManager->
+			GetViewSpaceBox().ComputeMinMaxT(ray, &tmin, &tmax) && (tmin < tmax))
+			break;
+	}
+
+	if (i != tries) 
+	{
+		// $$ jb the pdf is yet not correct for all sampling methods!
+		const float pdf = 1.0f;
+
+		ray = SimpleRay(origin, direction, HW_GLOBAL_LINES_DISTRIBUTION, pdf);
+		ray.mType = Ray::GLOBAL_RAY;
+		return true;
+	}
+
+	return false;
+}
+
+
+}
+
+
