Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1248)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 1251)
@@ -167,13 +167,13 @@
 		</Configuration>
 		<Configuration
-			Name="Release_Internal|Win32"
-			OutputDirectory="$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="..\include;&quot;$(BOOST_INCLUDE)&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;&quot;$(CG_INC_PATH)&quot;;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing"
+			Name="Release Internal|Win32"
+			OutputDirectory="bin\Release"
+			IntermediateDirectory="bin\Release"
+			ConfigurationType="1"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\include;&quot;$(BOOST_INCLUDE)&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL"
 				RuntimeLibrary="2"
@@ -187,60 +187,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib"
-				OutputFile="$(OutDir)/Preprocessor.exe"
+				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib"
+				OutputFile="../bin/release/Preprocessor.exe"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="..\support\xercesc\lib\;..\support\zlib\lib\;..\support\devil\lib;..\include;..\src\GL;&quot;$(CG_LIB_PATH)&quot;;..\lib\release;..\..\Preprocessing\lib\release;&quot;$(BOOST_LIB)&quot;;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\..\Preprocessing\MultiLevelRayTracing\RTScene\Release;..\..\Preprocessing\MultiLevelRayTracing\RTWorld\Release"
-				GenerateDebugInformation="FALSE"
-				SubSystem="1"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
-				TargetMachine="1"
-				FixedBaseAddress="1"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCWebDeploymentTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release Internal|Win32"
-			OutputDirectory="$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
-			ConfigurationType="1"
-			CharacterSet="2">
-			<Tool
-				Name="VCCLCompilerTool"
-				Optimization="0"
-				AdditionalIncludeDirectories="..\include;&quot;$(BOOST_INCLUDE)&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;&quot;$(CG_INC_PATH)&quot;;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\MultiLevelRayTracing"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL"
-				RuntimeLibrary="2"
-				RuntimeTypeInfo="TRUE"
-				UsePrecompiledHeader="0"
-				WarningLevel="3"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLinkerTool"
-				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib cg.lib cgGL.lib Preprocessor.lib"
-				OutputFile="$(OutDir)/Preprocessor.exe"
-				LinkIncremental="1"
-				AdditionalLibraryDirectories="..\support\xercesc\lib\;..\support\zlib\lib\;..\support\devil\lib;..\include;..\src\GL;&quot;$(CG_LIB_PATH)&quot;;..\lib\release;..\..\Preprocessing\lib\release;&quot;$(BOOST_LIB)&quot;;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\..\Preprocessing\MultiLevelRayTracing\RTScene\Release;..\..\Preprocessing\MultiLevelRayTracing\RTWorld\Release"
+				AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;&quot;$(BOOST_LIB)&quot;;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release"
 				GenerateDebugInformation="FALSE"
 				SubSystem="1"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1233)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1251)
@@ -16,5 +16,5 @@
 #include "OspTree.h"
 #include "ObjParser.h"
-#ifdef INTEL_COMPILER
+#ifdef GTP_INTERNAL
 #include "ArchModeler2MLRT.hxx"
 #endif
@@ -123,5 +123,6 @@
 mVspBspTree(NULL),
 mViewCellsManager(NULL),
-mRenderSimulator(NULL)
+mRenderSimulator(NULL),
+mPass(0)
 {
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
@@ -757,5 +758,5 @@
 	{
 	case INTEL_RAYCASTER:
-#ifdef INTEL_COMPILER
+#ifdef GTP_INTERNAL
 		return mlrtaLoadAS(externKdTree.c_str());
 #endif
@@ -768,3 +769,282 @@
 }
 
-}
+
+int Preprocessor::CastIntelDoubleRay(
+									 const Vector3 &viewPoint,
+									 const Vector3 &direction,
+									 const float probability,
+									 VssRayContainer &vssRays,
+									 const AxisAlignedBox3 &box
+									 )
+{
+	VssRay *vssRay  = NULL;
+	int hits = 0;
+
+	Vector3 pointA, pointB;
+	
+	Intersectable *objectA = 
+		CastIntelSingleRay(viewPoint, direction, pointA, box);
+	
+	// cast ray into other direction
+	Intersectable *objectB = 
+		CastIntelSingleRay(viewPoint, -direction, pointB, box);
+
+	const bool validSample = (objectA != objectB);
+	
+	if (validSample) 
+	{	
+		if (objectA) 
+		{
+			vssRay = new VssRay(pointB,
+								pointA,
+								objectB,
+								objectA,
+								probability,
+								mPass);
+
+			vssRays.push_back(vssRay);
+			hits ++;
+		}
+
+		if (objectB) 
+		{
+			vssRay = new VssRay(pointA,
+								pointB,
+								objectA,
+								objectB,
+								probability,
+								mPass);
+
+			vssRays.push_back(vssRay);
+			hits ++;
+		}
+		//Debug << "intel ray: " << *vssRay << endl;
+	}
+	//cout << "a";
+	return hits;
+}
+
+
+Intersectable *Preprocessor::CastIntelSingleRay(const Vector3 &viewPoint,
+												const Vector3 &direction,
+												//const float probability,
+												Vector3 &tPoint,
+												const AxisAlignedBox3 &box
+												)
+{
+	AxisAlignedBox3 sbox = box;
+	sbox.Enlarge(Vector3(-Limits::Small));
+
+	if (!sbox.IsInside(viewPoint))
+		return 0;
+	
+	float pforg[3];
+	float pfdir[3];
+	double pfnorm[3];
+
+	pforg[0] = viewPoint[0]; pforg[1] = viewPoint[1]; pforg[2] = viewPoint[2];
+	pfdir[0] = direction[0]; pfdir[1] = direction[1]; pfdir[2] = direction[2];
+
+	float dist = 0;
+#ifdef GTP_INTERNAL
+	const int hittriangle = mlrtaIntersectAS(pforg, pfdir, pfnorm, dist);
+#else
+	const int hittriangle = -1;
+#endif
+
+	if (hittriangle == -1)
+	{
+		static Ray ray;
+		SetupRay(ray, viewPoint, direction);
+
+		float tmin = 0, tmax;
+		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
+		{
+			tPoint = ray.Extrap(tmax);
+		}
+
+		return NULL;
+	}
+	else
+	{
+		tPoint[0] = pforg[0] + pfdir[0] * dist;
+		tPoint[1] = pforg[1] + pfdir[1] * dist;
+		tPoint[2] = pforg[2] + pfdir[2] * dist;
+
+		return mFaceParents[hittriangle];
+	}
+}
+
+
+int Preprocessor::CastInternalRay(
+								  const Vector3 &viewPoint,
+								  const Vector3 &direction,
+								  const float probability,
+								  VssRayContainer &vssRays,
+								  const AxisAlignedBox3 &box
+								  )
+{
+    int hits = 0;
+	static Ray ray;
+
+	AxisAlignedBox3 sbox = box;
+	sbox.Enlarge(Vector3(-Limits::Small));
+
+	if (!sbox.IsInside(viewPoint))
+		return 0;
+	
+	SetupRay(ray, viewPoint, direction);
+	
+	// cast ray to KD tree to find intersection with other objects
+	Intersectable *objectA, *objectB;
+	
+	Vector3 pointA;
+	Vector3 pointB;
+
+	//float bsize = Magnitude(box.Size());
+	if (!mDetectEmptyViewSpace)
+		ray.mFlags &= ~Ray::CULL_BACKFACES;
+	else
+		ray.mFlags |= Ray::CULL_BACKFACES;
+
+	if (mKdTree->CastRay(ray)) 
+	{
+		objectA = ray.intersections[0].mObject;
+		pointA = ray.Extrap(ray.intersections[0].mT);
+	} 
+	else 
+	{
+		objectA = NULL;
+		// compute intersection with the scene bounding box
+		float tmin, tmax;
+		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
+			pointA = ray.Extrap(tmax);
+		else
+			return 0;
+	}
+
+	// matt: point A could be undefined?
+
+	// cast ray into opposite direction
+	if (1 && mDetectEmptyViewSpace) {
+		SetupRay(ray, pointA, -direction);
+	} else
+		SetupRay(ray, viewPoint, -direction);
+  
+	if (!mDetectEmptyViewSpace)
+		ray.mFlags &= ~Ray::CULL_BACKFACES;
+	else
+		ray.mFlags |= Ray::CULL_BACKFACES;
+
+	if (mKdTree->CastRay(ray)) 
+	{
+		objectB = ray.intersections[0].mObject;
+		pointB = ray.Extrap(ray.intersections[0].mT);
+	} 
+	else 
+	{
+		objectB = NULL;
+		float tmin, tmax;
+		
+		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
+			pointB = ray.Extrap(tmax);
+		else
+			return 0;
+	}
+  
+	//bool thesame = objectA && (objectA == objectB);
+	
+	//  if (objectA == NULL && objectB != NULL) {
+	if (1 && mDetectEmptyViewSpace) 
+	{
+		// cast again to ensure that there is no objectA
+		SetupRay(ray, pointB, direction);
+		ray.mFlags |= Ray::CULL_BACKFACES;
+		
+		if (mKdTree->CastRay(ray)) 
+		{
+	 		objectA = ray.intersections[0].mObject;
+			pointA = ray.Extrap(ray.intersections[0].mT);
+		}
+	}
+
+  
+	VssRay *vssRay  = NULL;
+
+	bool validSample = (objectA != objectB);
+	
+	//if (validSample && thesame) Debug << "warning!!" << endl;
+
+	if (0 && mDetectEmptyViewSpace) 
+	{   
+		// consider all samples valid
+		// check if the viewpoint lies on the line segment AB
+		if (Distance(pointA, pointB) <
+			Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) 
+		{
+			validSample = false;
+		}
+	}
+	
+	if (validSample) 
+	{	
+		if (objectA) 
+		{
+			vssRay = new VssRay(pointB,
+								pointA,
+								objectB,
+								objectA,
+								probability,
+								mPass);
+			vssRays.push_back(vssRay);
+			hits ++;
+		}
+
+		if (objectB) 
+		{
+			vssRay = new VssRay(pointA,
+								pointB,
+								objectA,
+								objectB,
+								probability,
+								mPass);
+			vssRays.push_back(vssRay);
+			hits ++;
+		}
+		//Debug << "internal ray: " << *vssRay << endl << endl;
+	}
+//cout << "b";
+	return hits;
+}
+
+
+int Preprocessor::CastRay(
+						  const Vector3 &viewPoint,
+						  const Vector3 &direction,
+						  const float probability,
+						  VssRayContainer &vssRays,
+						  const AxisAlignedBox3 &box
+						  )
+{
+	switch (mRayCastMethod)
+	{
+	case INTEL_RAYCASTER:
+		return CastIntelDoubleRay(viewPoint, direction, probability, vssRays, box);
+	case INTERNAL_RAYCASTER:
+	default:
+		return CastInternalRay(viewPoint, direction, probability, vssRays, box);
+	}
+}
+
+
+void Preprocessor::SetupRay(Ray &ray,
+							const Vector3 &point,
+							const Vector3 &direction
+							)
+{
+	ray.Clear();
+	// do not store anything else then intersections at the ray
+	ray.Init(point, direction, Ray::LOCAL_RAY);
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1248)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1251)
@@ -203,6 +203,6 @@
 				FavorSizeOrSpeed="0"
 				OptimizeForWindowsApplication="TRUE"
-				AdditionalIncludeDirectories="..\include;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\src;&quot;$(CG_INC_PATH)&quot;;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;&quot;$(BOOST_INCLUDE)&quot;;..\..\Preprocessing\MultiLevelRayTracing"
-				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+				AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;&quot;$(BOOST_INCLUDE)&quot;;..\MultiLevelRayTracing"
+				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL"
 				ExceptionHandling="TRUE"
 				RuntimeLibrary="2"
@@ -217,5 +217,6 @@
 				Name="VCCustomBuildTool"/>
 			<Tool
-				Name="VCLibrarianTool"/>
+				Name="VCLibrarianTool"
+				OutputFile="../lib/Release/$(ProjectName).lib"/>
 			<Tool
 				Name="VCMIDLTool"/>
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1251)
@@ -26,5 +26,4 @@
   
 RssPreprocessor::RssPreprocessor():
-  mPass(0),
   mVssRays()
 {
@@ -87,5 +86,5 @@
 {
   for (int i=0; i < rays.size(); i++) {
-	CastRay(rays[i].mOrigin, rays[i].mDirection, rays[i].mPdf, vssRays);
+	CastRay(rays[i].mOrigin, rays[i].mDirection, rays[i].mPdf, vssRays, mViewCellsManager->GetViewSpaceBox());
 	if (i % 10000 == 0)
 	  cout<<".";
@@ -101,15 +100,6 @@
 }
 
-void
-RssPreprocessor::SetupRay(Ray &ray, 
-						  const Vector3 &point, 
-						  const Vector3 &direction
-						  )
-{
-  ray.intersections.clear();
-  // do not store anything else then intersections at the ray
-  ray.Init(point, direction, Ray::LOCAL_RAY);
-}
-
+
+#if 0 //matt: this moved up to preprocessor
 int
 RssPreprocessor::CastRay(
@@ -212,5 +202,5 @@
   return hits;
 }
-
+#endif
 
 void
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1249)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1251)
@@ -13,7 +13,8 @@
 #include "Beam.h"
 #include "GlRenderer.h"
-//#include "ArchModeler2MLRT.hxx"
 #include "Intersectable.h"
-
+#ifdef GTP_INTERNAL
+#include "ArchModeler2MLRT.hxx"
+#endif
 
 namespace GtpVisibilityPreprocessor {
@@ -23,5 +24,4 @@
 
 VssPreprocessor::VssPreprocessor():
-  mPass(0),
   mVssRays(),
   mViewSpaceBox(NULL)
@@ -61,16 +61,4 @@
 
 void
-VssPreprocessor::SetupRay(Ray &ray,
-						  const Vector3 &point,
-						  const Vector3 &direction
-						  )
-{
-  ray.Clear();
-  // do not store anything else then intersections at the ray
-  ray.Init(point, direction, Ray::LOCAL_RAY);
-}
-
-
-void
 VssPreprocessor::CastRays(
 						  SimpleRayContainer &rays,
@@ -78,10 +66,11 @@
 						  )
 {
-	AxisAlignedBox3 &box =  mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox();
+	const AxisAlignedBox3 box =  mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox();
 	
 #if 1
-	for (int i=0; i < rays.size(); i++)
+	SimpleRayContainer::const_iterator rit, rit_end = rays.end();
+	for (rit = rays.begin(); rit != rit_end; ++ rit)
 	{
-		CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, box);
+		CastRay((*rit).mOrigin, (*rit).mDirection, 1, vssRays, box);
 	}
 #else
@@ -99,4 +88,5 @@
 								 const AxisAlignedBox3 &sbox)
 {
+#ifdef GTP_INTERNAL
 /*
 	mlrtaStoreRayAS16(const float* pforg, const float* pfdir, int j);
@@ -118,259 +108,5 @@
 
 	mlrtaTraverseGroupAS16(const float* bbmin, const float* bbmax, int* hit_triangles, float* dist);*/
-}
-
-
-int VssPreprocessor::CastIntelDoubleRay(
-										const Vector3 &viewPoint,
-										const Vector3 &direction,
-										VssRayContainer &vssRays,
-										const AxisAlignedBox3 &box)
-{
-	VssRay *vssRay  = NULL;
-	int hits = 0;
-
-	Vector3 pointA, pointB;
-	
-	Intersectable *objectA = 
-		CastIntelSingleRay(viewPoint, direction, pointA, box);
-	
-	// cast ray into other direction
-	Intersectable *objectB = 
-		CastIntelSingleRay(viewPoint, -direction, pointB, box);
-
-	const bool validSample = (objectA != objectB);
-	
-	if (validSample) 
-	{	
-		if (objectA) 
-		{
-			vssRay = new VssRay(pointB,
-								pointA,
-								objectB,
-								objectA,
-								mPass);
-			vssRays.push_back(vssRay);
-			hits ++;
-		}
-
-		if (objectB) 
-		{
-			vssRay = new VssRay(pointA,
-								pointB,
-								objectA,
-								objectB,
-								mPass);
-			vssRays.push_back(vssRay);
-			hits ++;
-		}
-		//Debug << "intel ray: " << *vssRay << endl;
-	}
-//cout << "a";
-	return hits;
-}
-
-
-Intersectable *VssPreprocessor::CastIntelSingleRay(const Vector3 &viewPoint,
-												   const Vector3 &direction,
-												   Vector3 &tPoint,
-												   const AxisAlignedBox3 &box
-												   )
-{
-	AxisAlignedBox3 sbox = box;
-	sbox.Enlarge(Vector3(-Limits::Small));
-
-	if (!sbox.IsInside(viewPoint))
-		return 0;
-	
-	float pforg[3];
-	float pfdir[3];
-	double pfnorm[3];
-
-	pforg[0] = viewPoint[0]; pforg[1] = viewPoint[1]; pforg[2] = viewPoint[2];
-	pfdir[0] = direction[0]; pfdir[1] = direction[1]; pfdir[2] = direction[2];
-
-	float dist = 0;
-	const int hittriangle = -1;//mlrtaIntersectAS(pforg, pfdir, pfnorm, dist);
-
-	if (hittriangle == -1)
-	{
-		static Ray ray;
-		SetupRay(ray, viewPoint, direction);
-
-		float tmin = 0, tmax;
-		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
-		{
-			tPoint = ray.Extrap(tmax);
-		}
-
-		return NULL;
-	}
-	else
-	{
-		tPoint[0] = pforg[0] + pfdir[0] * dist;
-		tPoint[1] = pforg[1] + pfdir[1] * dist;
-		tPoint[2] = pforg[2] + pfdir[2] * dist;
-
-		return mFaceParents[hittriangle];
-	}
-}
-
-
-int
-VssPreprocessor::CastInternalRay(
-								 const Vector3 &viewPoint,
-								 const Vector3 &direction,
-								 VssRayContainer &vssRays,
-								 const AxisAlignedBox3 &box 
-								 )
-{
-    int hits = 0;
-	static Ray ray;
-
-	AxisAlignedBox3 sbox = box;
-	sbox.Enlarge(Vector3(-Limits::Small));
-
-	if (!sbox.IsInside(viewPoint))
-		return 0;
-	
-	SetupRay(ray, viewPoint, direction);
-	
-	// cast ray to KD tree to find intersection with other objects
-	Intersectable *objectA, *objectB;
-	
-	Vector3 pointA;
-	Vector3 pointB;
-
-	//float bsize = Magnitude(box.Size());
-	if (!mDetectEmptyViewSpace)
-		ray.mFlags &= ~Ray::CULL_BACKFACES;
-	else
-		ray.mFlags |= Ray::CULL_BACKFACES;
-
-	if (mKdTree->CastRay(ray)) 
-	{
-		objectA = ray.intersections[0].mObject;
-		pointA = ray.Extrap(ray.intersections[0].mT);
-	} 
-	else 
-	{
-		objectA = NULL;
-		// compute intersection with the scene bounding box
-		float tmin, tmax;
-		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
-			pointA = ray.Extrap(tmax);
-		else
-			return 0;
-	}
-
-	// matt: point A could be undefined?
-
-	// cast ray into opposite direction
-	if (1 && mDetectEmptyViewSpace) {
-		SetupRay(ray, pointA, -direction);
-	} else
-		SetupRay(ray, viewPoint, -direction);
-  
-	if (!mDetectEmptyViewSpace)
-		ray.mFlags &= ~Ray::CULL_BACKFACES;
-	else
-		ray.mFlags |= Ray::CULL_BACKFACES;
-
-	if (mKdTree->CastRay(ray)) 
-	{
-		objectB = ray.intersections[0].mObject;
-		pointB = ray.Extrap(ray.intersections[0].mT);
-	} 
-	else 
-	{
-		objectB = NULL;
-		float tmin, tmax;
-		
-		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
-			pointB = ray.Extrap(tmax);
-		else
-			return 0;
-	}
-  
-	//bool thesame = objectA && (objectA == objectB);
-	
-	//  if (objectA == NULL && objectB != NULL) {
-	if (1 && mDetectEmptyViewSpace) 
-	{
-		// cast again to ensure that there is no objectA
-		SetupRay(ray, pointB, direction);
-		ray.mFlags |= Ray::CULL_BACKFACES;
-		
-		if (mKdTree->CastRay(ray)) 
-		{
-	 		objectA = ray.intersections[0].mObject;
-			pointA = ray.Extrap(ray.intersections[0].mT);
-		}
-	}
-
-  
-	VssRay *vssRay  = NULL;
-
-	bool validSample = (objectA != objectB);
-	
-	//if (validSample && thesame) Debug << "warning!!" << endl;
-
-	if (0 && mDetectEmptyViewSpace) 
-	{   
-		// consider all samples valid
-		// check if the viewpoint lies on the line segment AB
-		if (Distance(pointA, pointB) <
-			Distance(viewPoint, pointA) + Distance(viewPoint, pointB) - Limits::Small) 
-		{
-			validSample = false;
-		}
-	}
-	
-	if (validSample) 
-	{	
-		if (objectA) 
-		{
-			vssRay = new VssRay(pointB,
-								pointA,
-								objectB,
-								objectA,
-								mPass);
-			vssRays.push_back(vssRay);
-			hits ++;
-		}
-
-		if (objectB) 
-		{
-			vssRay = new VssRay(pointA,
-								pointB,
-								objectA,
-								objectB,
-								mPass);
-			vssRays.push_back(vssRay);
-			hits ++;
-		}
-		//Debug << "internal ray: " << *vssRay << endl << endl;
-	}
-//cout << "b";
-	return hits;
-}
-
-
-int
-VssPreprocessor::CastRay(
-						 const Vector3 &viewPoint,
-						 const Vector3 &direction,
-						 VssRayContainer &vssRays,
-						 const AxisAlignedBox3 &box
-						 )
-{
-	switch (mRayCastMethod)
-	{
-	case INTEL_RAYCASTER:
-		return CastIntelDoubleRay(viewPoint, direction, vssRays, box);
-	case INTERNAL_RAYCASTER:
-	default:
-		return CastInternalRay(viewPoint, direction, vssRays, box);
-	}
+#endif
 }
 
@@ -828,5 +564,5 @@
 			Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 
-			sampleContributions = CastRay(viewpoint, direction, mVssRays, vbox);
+			sampleContributions = CastRay(viewpoint, direction, 1, mVssRays, vbox);
 
 			if (sampleContributions) {
@@ -959,5 +695,5 @@
 
 	for (int i=0; i < rays.size(); i++)
-	  CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, vbox);
+	  CastRay(rays[i].mOrigin, rays[i].mDirection, 1, vssRays, vbox);
 
 	vssTree->AddRays(vssRays);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h	(revision 1239)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.h	(revision 1251)
@@ -568,9 +568,9 @@
 	/** Returns true if tree can be terminated.
 	*/
-	inline bool LocalTerminationCriteriaMet(const OspTraversalData &data) const;
+	bool LocalTerminationCriteriaMet(const OspTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	inline bool GlobalTerminationCriteriaMet(const OspTraversalData &data) const;
+	bool GlobalTerminationCriteriaMet(const OspTraversalData &data) const;
 
 	/** Selects an axis aligned for the next split.
@@ -579,7 +579,5 @@
 	float SelectSplitPlane(
 		const OspTraversalData &tData,
-		AxisAlignedPlane &plane,
-		float &pFront,
-		float &pBack);
+		AxisAlignedPlane &plane);
 	
 	/** Propagates valid flag up the tree.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1251)
@@ -150,9 +150,16 @@
   */
   ViewCellsManager *CreateViewCellsManager(const char *name);
-
    
   GlRendererBuffer *GetRenderer() { return renderer;}
 
   bool InitRayCast(const string externKdTree);
+
+  int CastRay(
+	  const Vector3 &viewPoint,
+	  const Vector3 &direction,
+	  const float probability,
+	  VssRayContainer &vssRays,
+	  const AxisAlignedBox3 &box
+	  );
 
   ////////////////////////////////////////////////
@@ -209,5 +216,29 @@
   void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
 
+  int mPass;
+
 protected:
+
+	void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction);
+
+	int CastInternalRay(
+		const Vector3 &viewPoint,
+		const Vector3 &direction,
+		const float probability,
+		VssRayContainer &vssRays,
+		const AxisAlignedBox3 &box);
+
+	int CastIntelDoubleRay(
+		const Vector3 &viewPoint,
+		const Vector3 &direction,
+		const float probability,
+		VssRayContainer &vssRays,
+		const AxisAlignedBox3 &box);
+
+	Intersectable *CastIntelSingleRay(
+			const Vector3 &viewPoint,
+			const Vector3 &direction,
+			Vector3 &tPoint,
+			const AxisAlignedBox3 &box);
 
   /////////////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1239)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 1251)
@@ -843,9 +843,9 @@
 	/** Returns true if tree can be terminated.
 	*/
-	inline bool LocalTerminationCriteriaMet(const VspTraversalData &data) const;
+	bool LocalTerminationCriteriaMet(const VspTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	inline bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const;
+	bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const;
 
 	/** Adds ray sample contributions to the PVS.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1237)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1251)
@@ -453,5 +453,5 @@
 
 
-bool BvHierarchy::LocalTerminationCriteriaMet(const BvhTraversalData &data) const
+inline bool BvHierarchy::LocalTerminationCriteriaMet(const BvhTraversalData &data) const
 {
 	// matt: TODO
@@ -464,5 +464,5 @@
 
 
-bool BvHierarchy::GlobalTerminationCriteriaMet(const BvhTraversalData &data) const
+inline bool BvHierarchy::GlobalTerminationCriteriaMet(const BvhTraversalData &data) const
 {
 	// matt: TODO
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1251)
@@ -36,8 +36,4 @@
 							  )
 {
-	//float *pforg;
-	//float *pfdir;
-	//mlrtaStoreRayAS4(pforg, pfdir, 4);
-	//////////////////////////////////
   static Ray ray;
   AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h	(revision 1112)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h	(revision 1251)
@@ -15,10 +15,10 @@
 
 
-/** Sampling based visibility preprocessing. The implementation is based on heuristical
-    sampling of view space */
+/** Sampling based visibility preprocessing. The implementation is 
+	based on heuristical sampling of view space 
+*/
 class RssPreprocessor : public Preprocessor {
   
 public:
-  int mPass;
   int mSamplesPerPass;
   int mRssSamplesPerPass;
@@ -56,13 +56,5 @@
   virtual bool ComputeVisibility();
 
-
-  void
-  SetupRay(Ray &ray, 
-		   const Vector3 &point, 
-		   const Vector3 &direction
-		   );
-
-
-	
+#if 0 // matt:: moved up into preprocessor
   int
   CastRay(
@@ -71,9 +63,6 @@
 		  const float probability,
 		  VssRayContainer &vssRays
-
 		  );
-		
-
-	
+#endif		
   virtual bool BuildBspTree() { return false; }
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h	(revision 1251)
@@ -19,5 +19,5 @@
 class VssPreprocessor : public Preprocessor {
 public:
-  int mPass;
+  
   int mSamplesPerPass;
   int mVssSamplesPerPass;
@@ -56,21 +56,4 @@
   void CastRays(SimpleRayContainer &rays, VssRayContainer &vssRays);
 
-  void
-  SetupRay(Ray &ray, 
-		   const Vector3 &point, 
-		   const Vector3 &direction
-		   );
-
-
-	
-  int
-  CastRay(
-		  const Vector3 &viewPoint,
-		  const Vector3 &direction,
-		  VssRayContainer &vssRays,
-		  const AxisAlignedBox3 &box
-		  );
-
-
   bool
   ExportRays(const char *filename,
@@ -107,6 +90,4 @@
 				);
   
-  void CastRay(const BspTree &tree, const VssRay & vssRay);
-
   void TestBeamCasting(VssTree *tre, ViewCellsManager *vm, const ObjectContainer &objects);
 
@@ -114,21 +95,6 @@
 
 protected:
-	int CastInternalRay(
-		const Vector3 &viewPoint,
-		const Vector3 &direction,
-		VssRayContainer &vssRays,
-		const AxisAlignedBox3 &sbox);
-
-	int CastIntelDoubleRay(
-		const Vector3 &viewPoint,
-		const Vector3 &direction,
-		VssRayContainer &vssRays,
-		const AxisAlignedBox3 &sbox);
-
-	Intersectable *CastIntelSingleRay(
-			const Vector3 &viewPoint,
-			const Vector3 &direction,
-			Vector3 &tPoint,
-			const AxisAlignedBox3 &abox);
+		
+ 
 
 	void CastRays16(SimpleRayContainer &rays, 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 1233)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h	(revision 1251)
@@ -616,9 +616,9 @@
 	/** Returns true if tree can be terminated.
 	*/
-	inline bool LocalTerminationCriteriaMet(const VspBspTraversalData &data) const;
+	bool LocalTerminationCriteriaMet(const VspBspTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	inline bool GlobalTerminationCriteriaMet(const VspBspTraversalData &data) const;
+	bool GlobalTerminationCriteriaMet(const VspBspTraversalData &data) const;
 
 	/** Computes accumulated ray lenght of this rays.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1239)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 1251)
@@ -515,9 +515,9 @@
 	/** Returns true if tree can be terminated.
 	*/
-	inline bool LocalTerminationCriteriaMet(const BvhTraversalData &data) const;
+	bool LocalTerminationCriteriaMet(const BvhTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	inline bool GlobalTerminationCriteriaMet(const BvhTraversalData &data) const;
+	bool GlobalTerminationCriteriaMet(const BvhTraversalData &data) const;
 
 	// --------------------------------------------------------------
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1237)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1251)
@@ -527,5 +527,5 @@
 
 
-bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const
+inline bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const
 {
 	const bool localTerminationCriteriaMet = (
@@ -552,5 +552,5 @@
 
 
-bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const
+inline bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const
 {
 	const bool terminationCriteriaMet = (
Index: GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp	(revision 1237)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/OspTree.cpp	(revision 1251)
@@ -490,12 +490,7 @@
 void OspTree::EvalSubdivisionCandidate(OspSubdivisionCandidate &splitCandidate)
 {
-	float frontProb;
-	float backProb;
-
 	// compute locally best split plane
 	const float ratio = SelectSplitPlane(splitCandidate.mParentData, 
-										 splitCandidate.mSplitPlane, 
-										 frontProb, 
-										 backProb);
+										 splitCandidate.mSplitPlane);
 
 	const bool success = ratio < mTermMaxCostRatio;
@@ -528,5 +523,5 @@
 
 
-bool OspTree::LocalTerminationCriteriaMet(const OspTraversalData &data) const
+inline bool OspTree::LocalTerminationCriteriaMet(const OspTraversalData &data) const
 {
 	// matt: TODO
@@ -539,5 +534,5 @@
 
 
-bool OspTree::GlobalTerminationCriteriaMet(const OspTraversalData &data) const
+inline  bool OspTree::GlobalTerminationCriteriaMet(const OspTraversalData &data) const
 {
 	// matt: TODO
@@ -920,6 +915,5 @@
 	{
 		ViewCell *vc = *vit;
-		//Debug << "here30 vc mail " << vc->mMailbox - ViewCell::sMailId << endl;
-
+	
 		// if obj not previously associated with this view cell => increase render cost
 		if (vc->Mailed(1) && !ViewCellHasMultipleReferences(obj, vc, false))
@@ -944,6 +938,4 @@
 	{
 		ViewCell *vc = *vit;
-
-		//Debug << "here6 " << vc->mMailbox - ViewCell::sMailId << endl;
 
 		// if obj was previously associated with this view cell but is not now 
@@ -1084,7 +1076,5 @@
 
 float OspTree::SelectSplitPlane(const OspTraversalData &tData,
-								AxisAlignedPlane &plane,
-								float &pFront,
-								float &pBack)
+								AxisAlignedPlane &plane)
 {
 	float nPosition[3];
@@ -1153,7 +1143,4 @@
 	// split plane position
     plane.mPosition = nPosition[bestAxis];
-
-	pFront = nProbFront[bestAxis];
-	pBack = nProbBack[bestAxis];
 
 	Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;
