Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1952)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1964)
@@ -59,15 +59,15 @@
 	virtual bool GenerateSample(SimpleRay &ray) = 0;
 
-  // true if the strategy keeps pointers to rays and thus they should get deleted
-  // outside, in that case the strategy has to use reference counting and deleting the rays
-  // by itself if the number of references drops to zero
-  virtual bool RequiresRays() { return false; }
-
-
-  virtual void Update(VssRayContainer &vssRays) {}
-
-  friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
-	return a->mRatio < b->mRatio;
-  }
+	// true if the strategy keeps pointers to rays and thus they should get deleted
+	// outside, in that case the strategy has to use reference counting and deleting the rays
+	// by itself if the number of references drops to zero
+	virtual bool RequiresRays() { return false; }
+
+
+	virtual void Update(VssRayContainer &vssRays) {}
+
+	friend bool LowerRatio(const SamplingStrategy *a, const SamplingStrategy *b) {
+		return a->mRatio < b->mRatio;
+	}
 
 public:
@@ -262,4 +262,19 @@
 
 
+class HwGlobalLinesDistribution: public SamplingStrategy
+{
+public:
+ 
+  HwGlobalLinesDistribution(Preprocessor &preprocessor):
+	SamplingStrategy(preprocessor) {
+	//mType = HW_GLOBAL_LINES_DISTRIBUTION;
+  }
+  
+private:
+
+	virtual bool GenerateSample(SimpleRay &ray);
+	static HaltonSequence sHalton;
+};
+
 /** This strategy generates samples inside of the objects, e.g.,
 	for sampling the inside of a colon.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp	(revision 1963)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp	(revision 1964)
@@ -28,11 +28,8 @@
 static CGprofile sCgFragmentProfile;
 static CGparameter sTextureParam;
+static CGparameter sTexWidthParam; 
+static CGparameter sStepSizeParam;
 
 GlobalLinesRenderer *globalLinesRenderer = NULL;
-
-//static int texWidth = 32;
-//static int texHeight = 32;
-static int texWidth = 256;
-static int texHeight = 256;
 
 static bool isDepth = true;
@@ -137,5 +134,5 @@
 
 			++ globalLinesRenderer->mMaxDepth;
-			globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0);
+			globalLinesRenderer->ApplyDepthPeeling(rays);
 
 			cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl;
@@ -150,5 +147,5 @@
 			cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl;
 			
-			globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0);
+			globalLinesRenderer->ApplyDepthPeeling(rays);
 			CLEAR_CONTAINER(rays);
 			return;
@@ -156,14 +153,10 @@
 	case '3':
 		{
-			//globalLinesRenderer->ApplyDepthPeeling(Beam(), 0);
 			globalLinesRenderer->ExportDepthBuffer();
-			
 			return;
 		}
 	case '4':
 		{
-			//globalLinesRenderer->ApplyDepthPeeling(Beam(), 0);
 			globalLinesRenderer->ExportItemBuffer();
-			
 			return;
 		}
@@ -176,5 +169,5 @@
 		{
 			VssRayContainer rays;
-			globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0);
+			globalLinesRenderer->ApplyDepthPeeling(rays);
 			VssRayContainer outRays;
 			VssRayContainer::const_iterator vit, vit_end = rays.end();
@@ -197,5 +190,5 @@
 		{
 			VssRayContainer rays;
-			globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0);
+			globalLinesRenderer->ApplyDepthPeeling(rays);
 			CLEAR_CONTAINER(rays);
 			return;
@@ -219,12 +212,31 @@
 
 GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor, 
-										 GlRenderer *renderer): 
+										 GlRenderer *renderer,
+										 const float mTexHeight,
+										 const float mTexWidth,
+										 const float eps): 
 mNewTexture(NULL), 
 mOldTexture(NULL), 
 mMaxDepth(0), 
 mRenderer(renderer), 
-mPreprocessor(preprocessor)
-{
-}
+mPreprocessor(preprocessor),
+mTexHeight(mTexHeight),
+mTexWidth(mTexWidth),
+mEpsilon(eps)
+{
+}
+
+
+GlobalLinesRenderer::GlobalLinesRenderer(Preprocessor *preprocessor, 
+										 GlRenderer *renderer):
+mNewTexture(NULL), 
+mOldTexture(NULL), 
+mMaxDepth(0), 
+mRenderer(renderer), 
+mPreprocessor(preprocessor),
+mTexHeight(128),
+mTexWidth(128),
+mEpsilon(0.0001)
+{}
 
 
@@ -279,202 +291,41 @@
 
  
-void GlobalLinesRenderer::CastGlobalLines(Beam &beam, const int samples)
-{
-	VssRayContainer rays;
-
-	// bind pixel shader implementing the front depth buffer functionality
-	ApplyDepthPeeling(rays, beam, samples);
-}
-
-
-void GlobalLinesRenderer::RenderObject(Intersectable *obj)
-{
-	mRenderer->RenderIntersectable(obj);
-}
-
-
-void GlobalLinesRenderer::DrawGeometry()
-{ 
-	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-	glMatrixMode(GL_MODELVIEW);
-
-	glPushMatrix();
-	{ 
-		//glLoadIdentity();
-		ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end();
-
-		Intersectable::NewMail();
-
-		for (oit = mPreprocessor->mObjects.begin(); oit != oit_end; ++ oit)
-		{
-			//cout << (*oit)->GetId() << " ";
-			RenderObject(*oit);
-		}
-	}
-	glPopMatrix();
-}
-
-
-void GlobalLinesRenderer::SwitchRenderTextures()
-{
-	RenderTexture *buffer = mOldTexture;
-	mOldTexture = mNewTexture;
-	mNewTexture = buffer;
-}
-
-
-void GlobalLinesRenderer::ComputeLookAt(const float alpha, 
-										const float beta,
-										Vector3 &eye, 
-										Vector3 &up, 
-										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(beta);
-
-	eye.RightHandedBase(up, left);
-}
-
-
-void GlobalLinesRenderer::InitGl()
-{
-	InitDevIl();
-
-    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
-	glutInitWindowPosition(50, 50);
-	glutInitWindowSize(512, 512);
-	glutCreateWindow("TestRenderDepthTexture");  
-
-	int err = glewInit();
-	if (GLEW_OK != err)
-	{
-		// problem: glewInit failed, something is seriously wrong
-		fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
-		exit(-1);
-	}  
-	
-	glutKeyboardFunc(Keyboard);
-	glutDisplayFunc(Display);
-	glutIdleFunc(Idle);
-	glutReshapeFunc(Reshape);
-
-	Reshape(512, 512);
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	// initialise the receiving buffers
-	mNewDepthBuffer = new float[texWidth * texHeight];
-	mNewItemBuffer = new unsigned char[texWidth * texHeight * 4];
-
-	mOldDepthBuffer = new float[texWidth * texHeight];
-    mOldItemBuffer = new unsigned char[texWidth * texHeight * 4];
-
-	for (int i = 0; i < texWidth * texHeight; ++ i)
-	{
-		mNewDepthBuffer[i] = 1;
-		mOldDepthBuffer[i] = 1;
-
-		mNewItemBuffer[i * 4]     = 255;
-		mNewItemBuffer[i * 4 + 1] = 255;
-		mNewItemBuffer[i * 4 + 2] = 255;
-		mNewItemBuffer[i * 4 + 3] = 255;
-
-		mOldItemBuffer[i * 4]     = 255;
-		mOldItemBuffer[i * 4 + 1] = 255;
-		mOldItemBuffer[i * 4 + 2] = 255;
-		mOldItemBuffer[i * 4 + 3] = 255;
-	}
-
+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();
 	
-	const float sceneSize = Magnitude(bbox.Diagonal());
-	mViewPoint = midPoint + Vector3(0.5 * sceneSize, 0, 0.5 * sceneSize);
-	
+	// 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;
 
-	mNear = 1;
-	mFar = sceneSize * 2;
-	mWidth = sceneSize;
-
-	mEyeVec = Normalize(midPoint - mViewPoint);
-	mEyeVec.RightHandedBase(mUpVec, mLeftVec);
-
-	/*gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
-			  midPoint.x, midPoint.y, midPoint.z, 
-			  0, 1, 0);
-*/
-	gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
-
-	//glDisable(GL_CULL_FACE);
-	glEnable(GL_CULL_FACE);
-	glDisable(GL_LIGHTING);
-	glDisable(GL_COLOR_MATERIAL);
-	glEnable(GL_DEPTH_TEST); 
-	glClearColor(0.1, 0.2, 0.3, 1);
-	
-	// A square, mipmapped, anisotropically filtered 8-bit RGBA texture with
-	// depth and stencil.
-	// Note that RT_COPY_TO_TEXTURE is required for depth textures on ATI hardware
-	
-	mNewTexture = new RenderTexture(texWidth, texHeight, true, true);
-	//mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE);
-	mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE);
-	
-	mOldTexture = new RenderTexture(texWidth, texHeight, true, true);
-	//mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE);
-	mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE);
-
-	// Setup Cg
-	cgSetErrorCallback(cgErrorCallback);
-
-	// Create cgContext.
-	sCgContext = cgCreateContext();
-
-	// get the best profile for this hardware
-	sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
-	
-	//assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN);
-	cgGLSetOptimalOptions(sCgFragmentProfile);
-
-	sCgDepthPeelingProgram = 
-		cgCreateProgramFromFile(sCgContext, 
-								CG_SOURCE,
-								mNewTexture->IsRectangleTexture() ? 
-								"../src/depth_peelingRect.cg" : "../src/depth_peeling2d.cg", 
-								GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30,
-								NULL,
-								NULL);
-
-	if(sCgDepthPeelingProgram != NULL)
-	{
-		cgGLLoadProgram(sCgDepthPeelingProgram);
-		sTextureParam = cgGetNamedParameter(sCgDepthPeelingProgram, "depthTex");  
-	}
-
-	sCgPassThroughProgram = 
-		cgCreateProgramFromFile(sCgContext, 
-								CG_SOURCE,
-								"../src/passthrough.cg", 
-								GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30,
-								NULL,
-								NULL);
-
-	if(sCgPassThroughProgram != NULL)
-	{
-		cgGLLoadProgram(sCgPassThroughProgram);
-	}
-
-    // setup the rendering context for the RenderTexture
+	 // setup the rendering context for the RenderTexture
 	mNewTexture->BeginCapture();
 	{
-		//Reshape(texWidth, texHeight);
-		glViewport(0, 0, texWidth, texHeight);
+		//Reshape(mTexWidth, mTexHeight);
+		glViewport(0, 0, mTexWidth, mTexHeight);
 		SetFrustum(mWidth, mWidth, mNear, mFar);
 
@@ -496,5 +347,5 @@
 		gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
 				  midPoint.x, midPoint.y, midPoint.z, 
-				  0, 1, 0);
+				  mUpVec.x, mUpVec.y, mUpVec.z);
 
 	}
@@ -507,6 +358,6 @@
 		glClearColor(1, 1, 1, 1);
        
-		//Reshape(texWidth, texHeight);
-		glViewport(0, 0, texWidth, texHeight);
+		//Reshape(mTexWidth, mTexHeight);
+		glViewport(0, 0, mTexWidth, mTexHeight);
 		SetFrustum(mWidth, mWidth, mNear, mFar);
 
@@ -525,9 +376,212 @@
 		gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
 				  midPoint.x, midPoint.y, midPoint.z, 
-				  0, 1, 0);
-
-		//SetFrustum(sceneSize, sceneSize, 1, sceneSize);
+				  mUpVec.x, mUpVec.y, mUpVec.z);
 	}
 	mOldTexture->EndCapture();
+
+	cout << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl;
+}
+
+
+void GlobalLinesRenderer::CastGlobalLines(const float alpha, 
+										  const float beta, 
+										  //const int samples,
+										  VssRayContainer &rays)
+{
+	InitScene(alpha, beta);
+
+	// bind pixel shader implementing the front depth buffer functionality
+	ApplyDepthPeeling(rays);
+}
+
+
+void GlobalLinesRenderer::RenderObject(Intersectable *obj)
+{
+	mRenderer->RenderIntersectable(obj);
+}
+
+
+void GlobalLinesRenderer::DrawGeometry()
+{ 
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+	glMatrixMode(GL_MODELVIEW);
+
+	glPushMatrix();
+	{ 
+		//glLoadIdentity();
+		ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end();
+
+		Intersectable::NewMail();
+
+		for (oit = mPreprocessor->mObjects.begin(); oit != oit_end; ++ oit)
+		{
+			//cout << (*oit)->GetId() << " ";
+			RenderObject(*oit);
+		}
+	}
+	glPopMatrix();
+}
+
+
+void GlobalLinesRenderer::SwitchRenderTextures()
+{
+	RenderTexture *buffer = mOldTexture;
+	mOldTexture = mNewTexture;
+	mNewTexture = buffer;
+}
+
+
+void GlobalLinesRenderer::ComputeLookAt(const float alpha, 
+										const float beta,
+										Vector3 &eye, 
+										Vector3 &up, 
+										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);
+}
+
+
+void GlobalLinesRenderer::InitGl()
+{
+	InitDevIl();
+
+    glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
+	glutInitWindowPosition(50, 50);
+	glutInitWindowSize(512, 512);
+	glutCreateWindow("TestRenderDepthTexture");  
+
+	int err = glewInit();
+	if (GLEW_OK != err)
+	{
+		// problem: glewInit failed, something is seriously wrong
+		fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
+		exit(-1);
+	}  
+	
+	glutKeyboardFunc(Keyboard);
+	glutDisplayFunc(Display);
+	glutIdleFunc(Idle);
+	glutReshapeFunc(Reshape);
+
+	Reshape(512, 512);
+	glMatrixMode(GL_MODELVIEW);
+	glLoadIdentity();
+
+	// initialise the receiving buffers
+	mNewDepthBuffer = new float[mTexWidth * mTexHeight];
+	mNewItemBuffer = new unsigned char[mTexWidth * mTexHeight * 4];
+
+	mOldDepthBuffer = new float[mTexWidth * mTexHeight];
+    mOldItemBuffer = new unsigned char[mTexWidth * mTexHeight * 4];
+
+	for (int i = 0; i < mTexWidth * mTexHeight; ++ i)
+	{
+		mNewDepthBuffer[i] = 1;
+		mOldDepthBuffer[i] = 1;
+
+		mNewItemBuffer[i * 4]     = 255;
+		mNewItemBuffer[i * 4 + 1] = 255;
+		mNewItemBuffer[i * 4 + 2] = 255;
+		mNewItemBuffer[i * 4 + 3] = 255;
+
+		mOldItemBuffer[i * 4]     = 255;
+		mOldItemBuffer[i * 4 + 1] = 255;
+		mOldItemBuffer[i * 4 + 2] = 255;
+		mOldItemBuffer[i * 4 + 3] = 255;
+	}
+
+	/*gluLookAt(mViewPoint.x, mViewPoint.y, mViewPoint.z, 
+			  midPoint.x, midPoint.y, midPoint.z, 
+			  0, 1, 0);
+*/
+	gluLookAt(0, 0, 3, 0, 0, 0, 0, 1, 0);
+
+	//glDisable(GL_CULL_FACE);
+	glEnable(GL_CULL_FACE);
+	glDisable(GL_LIGHTING);
+	glDisable(GL_COLOR_MATERIAL);
+	glEnable(GL_DEPTH_TEST); 
+	glClearColor(0.1, 0.2, 0.3, 1);
+	
+	// A square, mipmapped, anisotropically filtered 8-bit RGBA texture with
+	// depth and stencil.
+	// Note that RT_COPY_TO_TEXTURE is required for depth textures on ATI hardware
+	
+	mNewTexture = new RenderTexture(mTexWidth, mTexHeight, true, true);
+#ifdef ATI
+	mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE);
+#else
+	mNewTexture->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE);
+#endif
+
+	mOldTexture = new RenderTexture(mTexWidth, mTexHeight, true, true);
+
+#ifdef ATI
+	mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8, RenderTexture::RT_COPY_TO_TEXTURE);
+#else
+	mOldTexture ->Initialize(true, true, false, true, true, 8, 8, 8, 8);//, RenderTexture::RT_COPY_TO_TEXTURE);
+#endif
+
+	// Setup Cg
+	cgSetErrorCallback(cgErrorCallback);
+
+	// Create cgContext.
+	sCgContext = cgCreateContext();
+
+	// get the best profile for this hardware
+	sCgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
+	
+	//assert(sCgFragmentProfile != CG_PROFILE_UNKNOWN);
+	cgGLSetOptimalOptions(sCgFragmentProfile);
+
+	sCgDepthPeelingProgram = 
+		cgCreateProgramFromFile(sCgContext, 
+								CG_SOURCE,
+								mNewTexture->IsRectangleTexture() ? 
+								"../src/depth_peelingRect.cg" : "../src/depth_peeling2d.cg", 
+								GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30,
+								NULL,
+								NULL);
+
+	if(sCgDepthPeelingProgram != NULL)
+	{
+		cgGLLoadProgram(sCgDepthPeelingProgram);
+		sTextureParam = cgGetNamedParameter(sCgDepthPeelingProgram, "depthTex");  
+		
+		// we need size of texture for scaling
+		if (!mNewTexture->IsRectangleTexture()) 
+		{
+			sTexWidthParam = cgGetNamedParameter(sCgDepthPeelingProgram, "texWidth");
+		}
+
+		sStepSizeParam = cgGetNamedParameter(sCgDepthPeelingProgram, "stepSize"); 
+
+		cgGLSetParameter1f(sTexWidthParam, (float)mTexWidth);
+		cgGLSetParameter1f(sStepSizeParam, mEpsilon);
+	}
+
+	sCgPassThroughProgram = 
+		cgCreateProgramFromFile(sCgContext, 
+								CG_SOURCE,
+								"../src/passthrough.cg", 
+								GLEW_ARB_fragment_program ? CG_PROFILE_ARBFP1 : CG_PROFILE_FP30,
+								NULL,
+								NULL);
+
+	if(sCgPassThroughProgram != NULL)
+	{
+		cgGLLoadProgram(sCgPassThroughProgram);
+	}
+
+	const float alpha = 1.1;
+	const float beta = 0.9;
+	InitScene(alpha, beta);
 
 	PrintGLerror("init");
@@ -542,5 +596,5 @@
 													   const bool isFrontBuffer) const
 {
-	const int depthIndex = x + texWidth * y;
+	const int depthIndex = x + mTexWidth * y;
 	const int itemIndex = 4 * depthIndex;
 
@@ -548,12 +602,14 @@
 	const float eyeDist = mNear + (mFar - mNear) * depth;
 	
-	const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / texWidth;
-	//const float upDist = 0.5f * mWidth - (float)mWidth * ((float)y + 0.5f) / texHeight;
-	const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / texHeight;
-	
+	const float leftDist = -0.5f * mWidth + mWidth * ((float)x + 0.5f) / mTexWidth;
+	//const float leftDist = 0.5f * mWidth - mWidth * ((float)x + 0.5f) / mTexWidth;
+	
+	const float upDist = -0.5f * mWidth + mWidth * ((float)y + 0.5f) / mTexHeight;
+	//const float upDist = 0.5f * mWidth - mWidth * ((float)y + 0.5f) / mTexHeight;
+
 	hitPoint = mViewPoint + 
 		       eyeDist * mEyeVec + 
-			   leftDist * mUpVec + 
-			   upDist * mLeftVec;
+			   upDist * mUpVec +
+			   leftDist * mLeftVec;
 				
 	unsigned char r = itemBuffer[itemIndex];
@@ -595,5 +651,5 @@
 	else
 	{
-		for (int i = 0; i < texWidth * texHeight; ++ i)
+		for (int i = 0; i < mTexWidth * mTexHeight; ++ i)
 		{
 			mOldDepthBuffer[i] = 0;
@@ -606,9 +662,7 @@
 	}
 
-	//cout << "vp: " << "eye: " << mEyeVec << " left: " << mLeftVec << " up: " << mUpVec << endl;
-
-	for (int y = 0; y < texHeight; ++ y)
-	{
-		for (int x = 0; x < texWidth; ++ x)
+	for (int y = 0; y < mTexHeight; ++ y)
+	{
+		for (int x = 0; x < mTexWidth; ++ x)
 		{
 			Vector3 newPt, oldPt;
@@ -724,5 +778,5 @@
 		}
 
-		if (ray->mPass == 4)
+		//if (ray->mPass == 4)
 			outRays.push_back(ray);
 	}	
@@ -738,5 +792,4 @@
 	rt->BindDepth();
 	rt->EnableTextureTarget();
-	//cout << "depth: " << mNewTexture->GetDepthBits() << endl;
 
 	const int texFormat = GL_DEPTH_COMPONENT;
@@ -751,5 +804,4 @@
 	rt->Bind();
 	rt->EnableTextureTarget();
-	//cout << "depth: " << mNewTexture->GetDepthBits() << endl;
 
 	const int texFormat = GL_RGBA;
@@ -768,5 +820,5 @@
 	const int components = 1;//mNewTexture->GetDepthBits() / 8;
 
-	float *data = new float[texWidth * texHeight * components];
+	float *data = new float[mTexWidth * mTexHeight * components];
 	//const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV;
 	const int texFormat = GL_DEPTH_COMPONENT;
@@ -780,5 +832,5 @@
 	const int bpp = components;
 
-	ilTexImage(texWidth, texHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data);
+	ilTexImage(mTexWidth, mTexHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data);
 	ilSaveImage((char *const)filename.c_str());
 
@@ -799,5 +851,5 @@
 	const int components = 4;//mNewTexture->GetDepthBits() / 8;
 
-	unsigned char *data = new unsigned char [texWidth * texHeight * components];
+	unsigned char *data = new unsigned char [mTexWidth * mTexHeight * components];
 	//const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV;
 	const int texFormat = GL_RGBA;
@@ -810,5 +862,5 @@
 	const int bpp = components;
 
-	ilTexImage(texWidth, texHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data);
+	ilTexImage(mTexWidth, mTexHeight, depth, bpp, IL_RGBA, IL_UNSIGNED_BYTE, data);
 	ilSaveImage((char *const)filename.c_str());
 
@@ -821,7 +873,5 @@
 
 
-void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays,
-											Beam &beam, 
-											const int samples)
+void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays)
 {
 	mNewTexture->BeginCapture();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h	(revision 1963)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h	(revision 1964)
@@ -21,14 +21,22 @@
 {
 public:
-	/*GlobalLinesRenderer(RenderTexture *buffer1, 
-						RenderTexture *buffer2, 
-						Preprocessor *preprocessor,
-						GlRenderer *renderer);
-*/
+	
+	GlobalLinesRenderer(Preprocessor *preprocessor, 
+						GlRenderer *renderer,
+						const float texHeight,
+						const float mTexWidth,
+						const float eps);
+
 	GlobalLinesRenderer(Preprocessor *preprocessor, GlRenderer *renderer);
 
 	~GlobalLinesRenderer();
 
-	void CastGlobalLines(Beam &beam, const int samples);
+	/** Casts global lines in the angle specified by alpha and
+		beta. 
+		@returns Computed samples in the container rays
+	*/
+	void CastGlobalLines(const float alpha, 
+						 const float beta, 
+						 VssRayContainer &rays);
 
 	void InitGl();
@@ -51,8 +59,11 @@
 	void GrabDepthBuffer(float *data, RenderTexture *rt);
 	void GrabItemBuffer(unsigned char *data, RenderTexture *rt);
-	void ApplyDepthPeeling(VssRayContainer &rays, Beam &beam, const int samples);
+	void ApplyDepthPeeling(VssRayContainer &rays);
 	void ExportDepthBuffer();
 	void ExportItemBuffer();
-	void ProcessDepthBuffer(VssRayContainer &vssRays, const bool oldBufferInitialised, const int pass);
+	void ProcessDepthBuffer(VssRayContainer &vssRays, 
+							const bool oldBufferInitialised, 
+							const int pass);
+
 	void DisplayBuffer(const bool isDepth);
 	
@@ -93,17 +104,18 @@
 					   Vector3 &eye, 
 					   Vector3 &up, 
-					   Vector3 left);
+					   Vector3 &left);
 protected:
 
 	void SwitchRenderTextures();
 
-	void SetupProjection(const Vector3 &viewPoint, 
-						 const Beam &beam);
-
-	
+	void InitScene(const float alpha, const float beta);
 
 	Preprocessor *mPreprocessor;
 
 	GlRenderer *mRenderer;
+
+	int mTexWidth;
+	int mTexHeight;
+	float mEpsilon;
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp	(revision 1883)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp	(revision 1964)
@@ -29,5 +29,5 @@
 {
   if (simpleRay.mType == Ray::GLOBAL_RAY)
-	return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays);
+	  return CastGlobalRay(simpleRay, vssRays, box, pruneInvalidRays);
   
   //cout << "internal ray" << endl;
@@ -82,8 +82,8 @@
 int
 InternalRayCaster::CastGlobalRay(const SimpleRay &simpleRay,
-																 VssRayContainer &vssRays,
-																 const AxisAlignedBox3 &box,
-																 const bool pruneInvalidRays
-																 )
+								 VssRayContainer &vssRays,
+								 const AxisAlignedBox3 &box,
+								 const bool pruneInvalidRays
+								)
 {
   static Ray ray;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/depth_peeling2d.cg
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/depth_peeling2d.cg	(revision 1962)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/depth_peeling2d.cg	(revision 1964)
@@ -2,9 +2,11 @@
 float3 main(in float4 col : COL0,
 	    in float3 pos : WPOS,
+	    uniform float texWidth,
+	    uniform float stepSize,
 	    uniform sampler2D depthTex) : COLOR
 {
-   float zold = tex2D(depthTex, pos.xy / 256.0);
+   float zold = tex2D(depthTex, pos.xy / texWidth);
 
-   if(pos.z < (zold + 0.00001))
+   if(pos.z < (zold + stepSize))
       discard;
    else;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/depth_peelingRect.cg
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/depth_peelingRect.cg	(revision 1950)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/depth_peelingRect.cg	(revision 1964)
@@ -2,9 +2,10 @@
 float3 main(in float4 col : COL0,
 	    in float3 pos : WPOS,
+	    uniform float stepSize,
 	    uniform samplerRect depthTex) : COLOR
 {
    float zold = texRect(depthTex, pos.xy);
 
-   if(pos.z < (zold + 0.1))
+   if(pos.z < (zold + stepSize))
       discard;
    else;
