Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1977)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 1981)
@@ -141,9 +141,4 @@
 									 const bool storeViewCells);
 
-	/** Add sample contributions to the viewcells they intersect 
-	*/
-	//void AddSampleContributions(const VssRayContainer &rays);
-  
-
 	/** Computes sample contribution of a simgle ray to the view cells PVS.
 		@param ray finds intersections with view cells and holds the contribution
@@ -153,5 +148,5 @@
 	*/
 	virtual float ComputeSampleContribution(VssRay &ray, 
-											const bool addRays,
+											const bool addContributions,
 											const bool storeViewCells);
 
@@ -159,5 +154,5 @@
 	*/
 	virtual float ComputeSampleContribution(VssRay &ray, 
-											const bool addRays,
+											const bool addContributions,
 											ViewCell *currentViewCell);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1977)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1981)
@@ -2292,26 +2292,4 @@
 		return 0.0f;
 
-	static Ray hray;
-	hray.Init(ray);
-
-	float tmin = 0, tmax = 1.0;
-
-	if (!GetViewSpaceBox().GetRaySegment(hray, tmin, tmax) || (tmin > tmax))
-	{
-		// cerr<<"ray outside view space box\n";
-		return 0;
-	}
-
-	Vector3 origin = hray.Extrap(tmin);
-	Vector3 termination = hray.Extrap(tmax);
-
-	// traverse the view space subdivision
-	if (!LineSegmentIntersects(origin, 
-							   termination, 
-							   currentViewCell))
-	{
-		return 0;
-	}
-	
 	// optain pvs entry (can be different from hit object)
 	Intersectable *terminationObj = GetIntersectable(ray, true);
@@ -2326,5 +2304,6 @@
 	float c = 0.0f;
 	if (terminationObj) 
-	  c = ray.Length();
+		c = ray.Length();
+
 	ray.mRelativePvsContribution = ray.mPvsContribution = c;
 	return c;
@@ -5942,4 +5921,5 @@
 		mColorCode = 0; // 0 = random, 1 = export pvs
 
+		if (0)
 		mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, 
 													  CLAMP_TO_BOX ? &bbox : NULL, maxRenderCost, false);
@@ -5979,4 +5959,5 @@
 		const float maxRenderCost = -1;
 
+		if (0)
 		mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, 
 													  CLAMP_TO_BOX ? &bbox : NULL, maxRenderCost, false);
@@ -5992,30 +5973,5 @@
 	}
 
-#if 0
-	// export final object partition
-	exporter = Exporter::GetExporter("final_object_partition.wrl");
-
-	if (exporter)
-	{
-		if (CLAMP_TO_BOX)
-		{	
-			exporter->mClampToBox = true; 	
-		}
-
-		const long starttime = GetTime();
-
-		// matt: hack for making visualization smaller in size
-		AxisAlignedBox3 bbox = mHierarchyManager->GetObjectSpaceBox();
-		bbox.Scale(scale);
-
-		cout << "exporting object space hierarchy ... ";
-		mHierarchyManager->ExportObjectSpaceHierarchy(exporter, objects, CLAMP_TO_BOX ? &bbox : NULL, -1);
-
-		delete exporter;
-		cout << "finished in " << TimeDiff(starttime, GetTime()) * 1e-3f << " secs" << endl;
-	}
-#endif
-
-	// visualization of the view cells
+	// visualization of the merged view cells
     if (0) 
 	{	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1977)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1981)
@@ -445,4 +445,11 @@
 	const float offset = 0.5f;
 	const Vector3 newOrigin = newPoint - newDir * offset;
+
+	static Ray ray(newOrigin, newDir, Ray::LOCAL_RAY);
+	ray.Precompute();
+
+	// check if ray intersects view cell
+	if (mPerViewCell && !mCurrentViewCell->CastRay(ray))
+		return NULL;
 
 	const SimpleRay simpleRay(newOrigin, newDir, SamplingStrategy::GVS, 1.0f);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 1951)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/AxisAlignedBox3.cpp	(revision 1981)
@@ -2353,5 +2353,57 @@
 }
 
-
-}
-
+/*
+int inline GetIntersection(const float fDst1, 
+						   const float fDst2, 
+						   const Vector3 p1, 
+						   const Vector3 p2, 
+						   const Vector3 &hit) 
+{
+	if ((fDst1 * fDst2) >= 0.0f) 
+		return 0;
+    
+	if (fDst1 == fDst2) 
+		return 0; 
+    
+	hit = p1 + (p2 - p1) * (-fDst1 / (fDst2 - fDst1));
+	
+	return 1;
+}
+
+
+int inline InBox( CVec3 Hit, CVec3 B1, CVec3 B2, const int Axis) {
+if ( Axis==1 && Hit.z > B1.z && Hit.z < B2.z && Hit.y > B1.y && Hit.y < B2.y) return 1;
+if ( Axis==2 && Hit.z > B1.z && Hit.z < B2.z && Hit.x > B1.x && Hit.x < B2.x) return 1;
+if ( Axis==3 && Hit.x > B1.x && Hit.x < B2.x && Hit.y > B1.y && Hit.y < B2.y) return 1;
+return 0;
+}
+
+// returns true if line (L1, L2) intersects with the box (B1, B2)
+// returns intersection point in Hit
+int CheckLineBox( CVec3 B1, CVec3 B2, CVec3 L1, CVec3 L2, CVec3 &Hit)
+{
+if (L2.x < B1.x && L1.x < B1.x) return false;
+if (L2.x > B2.x && L1.x > B2.x) return false;
+if (L2.y < B1.y && L1.y < B1.y) return false;
+if (L2.y > B2.y && L1.y > B2.y) return false;
+if (L2.z < B1.z && L1.z < B1.z) return false;
+if (L2.z > B2.z && L1.z > B2.z) return false;
+if (L1.x > B1.x && L1.x < B2.x &&
+    L1.y > B1.y && L1.y < B2.y &&
+    L1.z > B1.z && L1.z < B2.z) 
+    {Hit = L1; 
+    return true;}
+if ( (GetIntersection( L1.x-B1.x, L2.x-B1.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 ))
+  || (GetIntersection( L1.y-B1.y, L2.y-B1.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 )) 
+  || (GetIntersection( L1.z-B1.z, L2.z-B1.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 )) 
+  || (GetIntersection( L1.x-B2.x, L2.x-B2.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 )) 
+  || (GetIntersection( L1.y-B2.y, L2.y-B2.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 )) 
+  || (GetIntersection( L1.z-B2.z, L2.z-B2.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 )))
+	return true;
+
+return false;
+}
+*/
+
+}
+
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 1867)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mesh.cpp	(revision 1981)
@@ -220,9 +220,9 @@
 		faceIndex++) {
     hits += CastRayToFace(faceIndex,
-													ray,
-													nearestT,
-													nearestNormal,
-													nearestFace,
-													instance);
+						  ray,
+						  nearestT,
+						  nearestNormal,
+						  nearestFace,
+						  instance);
     if (mIsConvex && nearestFace != -1)
       break;
