Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h	(revision 1520)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.h	(revision 1520)
@@ -0,0 +1,62 @@
+#ifndef _IntelRayCaster_H__
+#define _IntelRayCaster_H__
+
+#include "RayCaster.h"
+#include <vector>
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+class Intersectable;
+class VssRay;
+class KdTree;
+class Ray;
+class SimpleRayContainer;
+class AxisAlignedBox3;
+class Vector3;
+struct VssRayContainer;
+class Preprocessor;
+
+
+/** This class provides an interface for ray casting.
+*/
+class IntelRayCaster: public RayCaster
+{
+public:
+	/** Default constructor initialising e.g., KD tree and BSP tree.
+	*/
+	IntelRayCaster(
+		const Preprocessor &preprocessor,
+		const string externKdTree);
+
+	virtual ~IntelRayCaster();
+
+	int Type() const { return INTEL_RAYCASTER; }
+
+	virtual int CastRay(
+		const Vector3 &viewPoint,
+		const Vector3 &direction,
+		const float probability,
+        VssRayContainer &vssRays,
+		const AxisAlignedBox3 &box,
+		const bool castDoubleRay
+		);
+
+	 virtual void CastRays16(
+		 const int i,
+		 SimpleRayContainer &rays, 
+		 VssRayContainer &vssRays,
+		 const AxisAlignedBox3 &sbox,
+		 const bool castDoubleRay
+		 );
+	 
+protected:
+
+	bool InitRayCast(const string externKdTree);
+};
+
+
+}
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h	(revision 1520)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.h	(revision 1520)
@@ -0,0 +1,62 @@
+#ifndef _InternalRayCaster_H__
+#define _InternalRayCaster_H__
+
+#include "RayCaster.h"
+#include "Containers.h"
+#include <string>
+using namespace std;
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+class Intersectable;
+class VssRay;
+class KdTree;
+class Ray;
+class SimpleRayContainer;
+class AxisAlignedBox3;
+class Vector3;
+struct VssRayContainer;
+class Preprocessor;
+
+
+
+/** This class provides an interface for ray casting.
+*/
+class InternalRayCaster: public RayCaster
+{
+public:
+	/** Default constructor initialising e.g., KD tree
+	*/
+	InternalRayCaster(const Preprocessor &preprocessor, KdTree *kdTree);
+	virtual ~InternalRayCaster();
+
+	int Type() const { return INTERNAL_RAYCASTER; }
+
+	virtual int CastRay(
+		const Vector3 &viewPoint,
+		const Vector3 &direction,
+		const float probability,
+        VssRayContainer &vssRays,
+		const AxisAlignedBox3 &box,
+		const bool castDoubleRay
+		);
+
+	 virtual void CastRays16(
+		 const int i,
+		 SimpleRayContainer &rays, 
+		 VssRayContainer &vssRays,
+		 const AxisAlignedBox3 &sbox,
+		 const bool castDoubleRay
+		 );
+
+protected:
+
+	KdTree *mKdTree;
+};
+
+
+}
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.cpp	(revision 1457)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtPreprocessorThread.cpp	(revision 1520)
@@ -1,4 +1,4 @@
+#ifdef GTP_INTERNAL
 #include <QApplication>
-
 #include "QtPreprocessorThread.h"
 #include "Camera.h"
@@ -17,5 +17,7 @@
 {
   if (p->mQuitOnFinish)
-	connect(this, SIGNAL(finished()), qApp, SLOT(closeAllWindows(void)));
+  {
+	  connect(this, SIGNAL(finished()), qApp, SLOT(closeAllWindows(void)));
+  }
 }
 
@@ -28,2 +30,3 @@
 }
 
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 1520)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 1520)
@@ -0,0 +1,78 @@
+#ifndef _RayCaster_H__
+#define _RayCaster_H__
+
+#include "Containers.h"
+#include <string>
+using namespace std;
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+class Intersectable;
+class VssRay;
+class SimpleRayContainer;
+class AxisAlignedBox3;
+class Vector3;
+struct VssRayContainer;
+class Preprocessor;
+
+/** This class provides an interface for ray casting.
+*/
+class RayCaster
+{
+public:
+	
+	enum {
+	  INTERNAL_RAYCASTER = 0,
+	  INTEL_RAYCASTER
+	};
+
+	RayCaster(const Preprocessor &preprocessor);
+
+	virtual ~RayCaster() = 0;
+
+	virtual int Type() const = 0;
+
+	virtual int CastRay(
+		const Vector3 &viewPoint,
+		const Vector3 &direction,
+		const float probability,
+        VssRayContainer &vssRays,
+		const AxisAlignedBox3 &box,
+		const bool castDoubleRay
+		) = 0;
+
+	 virtual void CastRays16(
+		 const int i,
+		 SimpleRayContainer &rays, 
+		 VssRayContainer &vssRays,
+		 const AxisAlignedBox3 &sbox,
+		 const bool castDoubleRay
+		 ) = 0;
+	
+
+protected:
+
+	int ProcessRay(
+			 const Vector3 &viewPoint,
+			 const Vector3 &direction,
+			 Intersectable *objectA,
+			 Vector3 &pointA,
+			 const Vector3 &normalA,
+			 Intersectable *objectB,
+			 Vector3 &pointB,
+			 const Vector3 &normalB,
+			 const float probability,
+			 VssRayContainer &vssRays,
+			 const AxisAlignedBox3 &box
+			 );
+
+	
+  	const Preprocessor &mPreprocessor;
+};
+
+
+}
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1500)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1520)
@@ -1281,4 +1281,5 @@
 
 
+
   /***********************************************************************************/
   /*                         View cells related options                              */
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.vcproj	(revision 1270)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtGlRenderer/QtGlRenderer.vcproj	(revision 1520)
@@ -103,5 +103,7 @@
 				Name="VCMIDLTool"/>
 			<Tool
-				Name="VCPostBuildEventTool"/>
+				Name="VCPostBuildEventTool"
+				Description="&quot;copy dll to preprocessor dir&quot;"
+				CommandLine="copy $(OutDir)\*.dll ..\..\bin\"/>
 			<Tool
 				Name="VCPreBuildEventTool"/>
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1520)
@@ -19,9 +19,8 @@
 #include "HierarchyManager.h"
 #include "VssRay.h"
-
-
-#ifdef GTP_INTERNAL
-#include "ArchModeler2MLRT.hxx"
-#endif
+#include "IntelRayCaster.h"
+#include "InternalRayCaster.h"
+
+
 
 #define DEBUG_RAYCAST 0
@@ -31,6 +30,4 @@
 
 const static bool ADDITIONAL_GEOMETRY_HACK = false;
-
-//Preprocessor *preprocessor;
 
 
@@ -135,6 +132,6 @@
 mRenderSimulator(NULL),
 mPass(0),
-mRayCastMethod(0),
-mSceneGraph(NULL)
+mSceneGraph(NULL),
+mRayCaster(NULL)
 {
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.useGlRenderer", mUseGlRenderer);
@@ -149,6 +146,5 @@
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.exportVisibility", mExportVisibility );
-	Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", mRayCastMethod);
-
+	
 	char buffer[256];
 	Environment::GetSingleton()->GetStringValue("Preprocessor.visibilityFile",  buffer);
@@ -162,9 +158,4 @@
 	Debug << "detect empty view space=" << mDetectEmptyViewSpace << endl;
 	Debug << "load meshes: " << mLoadMeshes << endl;
-
-	if (mRayCastMethod == 0)
-		cout << "ray cast method: internal" << endl;
-	else
-		cout << "ray cast method: intel" << endl;
 }
 
@@ -237,5 +228,7 @@
 
 	// intel ray caster can only trace triangles
-	vector<FaceParentInfo> *fi = (mRayCastMethod == Preprocessor::INTEL_RAYCASTER) ?
+	int rayCastMethod;
+	Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod);
+	vector<FaceParentInfo> *fi = (rayCastMethod == RayCaster::INTEL_RAYCASTER) ?
 		&mFaceParents : NULL;
 
@@ -759,13 +752,13 @@
 	switch (strategyId)
 	{
-	case OBJECT_BASED_DISTRIBUTION: 
+	case SamplingStrategy::OBJECT_BASED_DISTRIBUTION: 
 		return new ObjectBasedDistribution(*this);
-	case OBJECT_DIRECTION_BASED_DISTRIBUTION:
+	case SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION:
 		return new ObjectDirectionBasedDistribution(*this);
-	case DIRECTION_BASED_DISTRIBUTION:
+	case SamplingStrategy::DIRECTION_BASED_DISTRIBUTION:
 		return new DirectionBasedDistribution(*this);
-	case DIRECTION_BOX_BASED_DISTRIBUTION: 
+	case SamplingStrategy::DIRECTION_BOX_BASED_DISTRIBUTION: 
 		return new DirectionBoxBasedDistribution(*this);
-	case SPATIAL_BOX_BASED_DISTRIBUTION:
+	case SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION:
 		return new SpatialBoxBasedDistribution(*this);
 	//case OBJECTS_INTERIOR_DISTRIBUTION:
@@ -819,14 +812,16 @@
 	}
 
-	switch (mRayCastMethod) // use intel ray tracing
-	{
-	case INTEL_RAYCASTER:
-#ifdef GTP_INTERNAL
-	  cout<<"Ray Cast file: " << externKdTree << endl;
-	  return mlrtaLoadAS(externKdTree.c_str());
-#endif
-	case INTERNAL_RAYCASTER:
-	default:
-		break;
+	int rayCastMethod;
+	Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", rayCastMethod);
+
+	if (rayCastMethod == 0)
+	{
+		mRayCaster = new InternalRayCaster(*this, mKdTree);
+		cout << "ray cast method: internal" << endl;
+	}
+	else
+	{
+		mRayCaster = new IntelRayCaster(*this, externKdTree);
+		cout << "ray cast method: intel" << endl;
 	}
 
@@ -834,560 +829,52 @@
 }
 
-
-int Preprocessor::CastIntelDoubleRay(
-									 const Vector3 &viewPoint,
-									 const Vector3 &direction,
-									 const float probability,
-									 VssRayContainer &vssRays,
-									 const AxisAlignedBox3 &box
-									 )
-{
-#ifdef GTP_INTERNAL
-	//cout << "intel ray" << endl;
-	VssRay *vssRay  = NULL;
-	int hits = 0;
-	int hittriangle;
-	Vector3 pointA, pointB;
-	Vector3 normalA, normalB;
-	Intersectable *objectA = NULL, *objectB = NULL;
-	float dist;
-	double normal[3];
-
-	hittriangle = mlrtaIntersectAS(&viewPoint.x,
-		&direction.x,
-		normal,
-		dist);
-
-	if (hittriangle != -1 ) {
-		if (hittriangle >= mFaceParents.size())
-			cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
-		else {
-			objectA = mFaceParents[hittriangle].mObject;
-			normalA = Vector3(normal[0], normal[1], normal[2]);
-			// Get the normal of that face
-			//		Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
-			//		normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
-			//-rays[index+i].mDirection; // $$ temporary
-			pointA = viewPoint + direction*dist;
-		}
-	}
-
-
-	Vector3 dir = -direction;
-	hittriangle = mlrtaIntersectAS(&viewPoint.x,
-		&dir.x,
-		normal,
-		dist);
-
-	if (hittriangle != -1 ) {
-		if (hittriangle >= mFaceParents.size())
-			cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
-		else {
-			objectB = mFaceParents[hittriangle].mObject;
-			normalB = Vector3(normal[0], normal[1], normal[2]);
-			// Get the normal of that face
-			//		Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
-			//		normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
-			//-rays[index+i].mDirection; // $$ temporary
-			pointB = viewPoint + dir * dist;
-		}
-	}
-
-	return ProcessRay(viewPoint,
-		direction,
-		objectA, pointA, normalA,
-		objectB, pointB, normalB,
-		probability,
-		vssRays,
-		box
-		);
-#else
-	return -1;
-#endif
-}
-
-
-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;
-	
-#ifdef GTP_INTERNAL
-	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;
-	const int hittriangle = 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 {
-	  if (hittriangle >= mFaceParents.size()) {
-		cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
-		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].mObject;
-	  }
-	}
-
-#else
-	const int hittriangle = -1;
-	return NULL;
-#endif
-
-}
-
-
-int Preprocessor::CastInternalRay(
-								  const Vector3 &viewPoint,
-								  const Vector3 &direction,
-								  const float probability,
-								  VssRayContainer &vssRays,
-								  const AxisAlignedBox3 &box
-								  )
-{
-  //cout << "internal ray" << endl;
-  int hits = 0;
-  static Ray ray;
-  Intersectable *objectA, *objectB;
-  Vector3 pointA, pointB;
-
-  //  AxisAlignedBox3 box = Union(mKdTree->GetBox(), mViewCellsManager->GetViewSpaceBox());
-  AxisAlignedBox3 sbox = box;
-  sbox.Enlarge(Vector3(-Limits::Small));
-  if (!sbox.IsInside(viewPoint))
-	return 0;
-	
-  SetupRay(ray, viewPoint, direction);
-  ray.mFlags &= ~Ray::CULL_BACKFACES;
-
-  // cast ray to KD tree to find intersection with other objects
-  float bsize = Magnitude(box.Size());
-  
-  
-  if (mKdTree->CastRay(ray)) {
-	objectA = ray.intersections[0].mObject;
-	pointA = ray.Extrap(ray.intersections[0].mT);
-	if (mDetectEmptyViewSpace)
-	  if (DotProd(ray.intersections[0].mNormal, direction) >= 0) {
-		// discard the sample
-		return 0;
-	  }
-	
-  } 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;
-  }
-
-  SetupRay(ray, viewPoint, -direction);
-  ray.mFlags &= ~Ray::CULL_BACKFACES;
-  
-  if (mKdTree->CastRay(ray)) {
-	objectB = ray.intersections[0].mObject;
-	pointB = ray.Extrap(ray.intersections[0].mT);
-	if (mDetectEmptyViewSpace)
-	  if (DotProd(ray.intersections[0].mNormal, direction) <= 0) {
-		// discard the sample
-		return 0;
-	  }
-  } else {
-	objectB = NULL;
-	float tmin, tmax;
-	if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
-	  pointB = ray.Extrap(tmax);
-	else
-	  return 0;
-  }
-  
-  
-  VssRay *vssRay  = NULL;
-  bool validSample = (objectA != objectB);
-  if (validSample) {
-	if (objectA) {
-	  vssRay = new VssRay(pointB,
-						  pointA,
-						  objectB,
-						  objectA,
-						  mPass,
-						  probability
-						  );
-	  vssRays.push_back(vssRay);
-	  //cout << "ray: " << *vssRay << endl;
-	  hits ++;
-	}
-	
-	if (objectB) {
-	  vssRay = new VssRay(pointA,
-						  pointB,
-						  objectA,
-						  objectB,
-						  mPass,
-						  probability
-						  );
-	  vssRays.push_back(vssRay);
-	  //cout << "ray: " << *vssRay << endl;
-	  hits ++;
-	}
-  }
-  
-  return hits;
-}
-
-
-int
-Preprocessor::ProcessRay(
-						 const Vector3 &viewPoint,
-						 const Vector3 &direction,
-						 Intersectable *objectA,
-						 Vector3 &pointA,
-						 const Vector3 &normalA,
-						 Intersectable *objectB,
-						 Vector3 &pointB,
-						 const Vector3 &normalB,
-						 const float probability,
-						 VssRayContainer &vssRays,
-						 const AxisAlignedBox3 &box
-						 )
-{
-  int hits=0;
-#if DEBUG_RAYCAST
-  Debug<<"PR ";
-#endif
-  if (objectA == NULL && objectB == NULL)
-	return 0;
-  
-  AxisAlignedBox3 sbox = box;
-  sbox.Enlarge(Vector3(-Limits::Small));
-
-  if (!sbox.IsInside(viewPoint))
-	return 0;
-
-  if (objectA == NULL) {
-	// compute intersection with the scene bounding box
-	static Ray ray;
-	SetupRay(ray, viewPoint, direction);
-	
-	float tmin, tmax;
-	if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
-	  pointA = ray.Extrap(tmax);
-	else
-	  return 0;
-  } else {
-	if (mDetectEmptyViewSpace)
-	  if (DotProd(normalA, direction) >= 0) {
-		// discard the sample
-		return 0;
-	  }
-  }
-
-  if (objectB == NULL) {
-	// compute intersection with the scene bounding box
-	static Ray ray;
-	SetupRay(ray, viewPoint, -direction);
-
-	float tmin, tmax;
-	if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
-	  pointB = ray.Extrap(tmax);
-	else
-	  return 0;
-  } else {
-	if (mDetectEmptyViewSpace)
-	  if (DotProd(normalB, direction) <= 0) {
-		// discard the sample
-		return 0;
-	  }
-  }
-  
-  VssRay *vssRay  = NULL;
-  bool validSample = (objectA != objectB);
-  if (validSample) {
-	if (objectA) {
-	  vssRay = new VssRay(pointB,
-						  pointA,
-						  objectB,
-						  objectA,
-						  mPass,
-						  probability
-						  );
-	  vssRays.push_back(vssRay);
-	  //cout << "ray: " << *vssRay << endl;
-	  hits ++;
-	}
-	
-	if (objectB) {
-	  vssRay = new VssRay(pointA,
-						  pointB,
-						  objectA,
-						  objectB,
-						  mPass,
-						  probability
-						  );
-	  vssRays.push_back(vssRay);
-	  //cout << "ray: " << *vssRay << endl;
-	  hits ++;
-	}
-  }
-
-
-  return hits;
-}
-
-void
-Preprocessor::CastRays16(const int index,
-						 SimpleRayContainer &rays, 
-						 VssRayContainer &vssRays,
-						 const AxisAlignedBox3 &sbox)
-{
-  int i;
-  const int num = 16;
-
-#if DEBUG_RAYCAST
-  Debug<<"C16 "<<flush;
-#endif
-  if (mRayCastMethod == INTEL_RAYCASTER) {
-#ifdef GTP_INTERNAL
-
-  int forward_hit_triangles[16];
-  float forward_dist[16];
-
-  int backward_hit_triangles[16];
-  float backward_dist[16];
-
-
-  Vector3 min = sbox.Min();
-  Vector3 max = sbox.Max();
-  
-  for (i=0; i < num; i++) {
-	mlrtaStoreRayAS16(&rays[index + i].mOrigin.x,
-					  &rays[index + i].mDirection.x,
-					  i);
-  }
-  
-  mlrtaTraverseGroupAS16(&min.x,
-						 &max.x,
-						 forward_hit_triangles,
-						 forward_dist);
-
-  for (i=0; i < num; i++) {
-	Vector3 dir = -rays[index + i].mDirection;
-	mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
-					  &dir.x,
-					  i);
-  }
-  
-  mlrtaTraverseGroupAS16(&min.x,
-						 &max.x,
-						 backward_hit_triangles,
-						 backward_dist);
-  
-
-  for (i=0; i < num; i++) {
-	Intersectable *objectA = NULL, *objectB = NULL;
-	Vector3 pointA, pointB;
-	Vector3 normalA, normalB;
-
-	if (forward_hit_triangles[i] != -1 ) {
-	  if (forward_hit_triangles[i] >= mFaceParents.size())
-		cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl;
-	  else { 
-		objectA = mFaceParents[forward_hit_triangles[i]].mObject;
-		// Get the normal of that face
-		normalA = objectA->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex);
-		//-rays[index+i].mDirection; // $$ temporary
-		pointA = rays[index+i].Extrap(forward_dist[i]);
-	  }
-	}
-	 
-	if (backward_hit_triangles[i]!=-1) {
-	  if (backward_hit_triangles[i] >= mFaceParents.size())
-		cerr<<"Warning: triangle  index out of range! "<<backward_hit_triangles[i]<<endl;
-	  else { 
-		objectB = mFaceParents[backward_hit_triangles[i]].mObject;
-		normalB = objectB->GetNormal(mFaceParents[forward_hit_triangles[i]].mFaceIndex);
-		
-		// normalB = rays[index+i].mDirection; // $$ temporary
-		pointB = rays[index+i].Extrap(-backward_dist[i]);
-	  }
-	}
- 
-	ProcessRay(rays[index+i].mOrigin,
-			   rays[index+i].mDirection,
-			   objectA, pointA, normalA,
-			   objectB, pointB, normalB,
-			   rays[index+i].mPdf,
-			   vssRays,
-			   sbox
-			   );
-  }
-  
-#endif
-  
-  } else {
-
-	for (i=index; i < index + num; i++) {
-	  CastRay(rays[i].mOrigin,
-			  rays[i].mDirection,
-			  rays[i].mPdf,
-			  vssRays,
-			  sbox);
-	}
-  }
-#if DEBUG_RAYCAST
-  Debug<<"C16F\n"<<flush;
-#endif
-}
 
 void
 Preprocessor::CastRays(
 					   SimpleRayContainer &rays,
-					   VssRayContainer &vssRays
+					   VssRayContainer &vssRays,
+					   const bool castDoubleRays
 					   )
 {
-  long t1 = GetTime();
-  
-  for (int i = 0; i < (int)rays.size(); ) {
-	  // method only available for intel raycaster yet
-	if (i + 16 < (int)rays.size()) {
-
-	  CastRays16(
-				 i,
-				 rays,
-				 vssRays,
-				 mViewCellsManager->GetViewSpaceBox());
-	  i += 16;
-	} else {
-	  CastRay(rays[i].mOrigin,
-			  rays[i].mDirection,
-			  rays[i].mPdf,
-			  vssRays,
-			  mViewCellsManager->GetViewSpaceBox());
-	  i++;
-	}
-	if (i % 10000 == 0)
-	  cout<<".";
-  }
-
-  long t2 = GetTime();
-  cout<<2*rays.size()/(1e3*TimeDiff(t1, t2))<<"M rays/s"<<endl;
-}
-
-Intersectable *
-Preprocessor::CastSimpleRay(
-							const Vector3 &viewPoint,
-							const Vector3 &direction,
-							const AxisAlignedBox3 &box,
-							Vector3 &point,
-							Vector3 &normal
-							)
-{
-  Intersectable *result = NULL;
-  switch (mRayCastMethod)
-	{
-	case INTEL_RAYCASTER: {
-	 
-	  int hittriangle;
-
-#ifdef GTP_INTERNAL
-	  float dist; 
-	  double n[3];
-
-	  hittriangle = mlrtaIntersectAS(&viewPoint.x,
-									 &direction.x,
-									 n,
-									 dist);
-
-	   if (hittriangle !=-1 ) {
-		if (hittriangle >= mFaceParents.size())
-		  cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
-		else {
-		  result = mFaceParents[hittriangle].mObject;
-		  normal = Vector3(n[0], n[1], n[2]);
-		  point = viewPoint + direction*dist;
-		}
-	  }
-#else
-	  hittriangle = -1;
-#endif
-
-	  break;
-	}
-	case INTERNAL_RAYCASTER:
-	default: {
-	  static Ray ray;
-	  
-	  ray.intersections.clear();
-	  // do not store anything else then intersections at the ray
-	  ray.Init(viewPoint, direction, Ray::LOCAL_RAY);
-	  
-	  ray.mFlags &= ~Ray::CULL_BACKFACES;
-	  
-	  if (mKdTree->CastRay(ray)) {
-		result = ray.intersections[0].mObject;
-		point = ray.Extrap(ray.intersections[0].mT);
-		normal = ray.intersections[0].mNormal;
-	  }
-	  break;
-	}
-	}
-  return result;
-}
-
-int
-Preprocessor::CastRay(
-					  const Vector3 &viewPoint,
-					  const Vector3 &direction,
-					  const float probability,
-					  VssRayContainer &vssRays,
-					  const AxisAlignedBox3 &box
-					  )
-{
-#if DEBUG_RAYCAST
-  Debug<<"CR "<<flush;
-#endif
-  switch (mRayCastMethod)
-	{
-	case INTEL_RAYCASTER:
-		return CastIntelDoubleRay(viewPoint, direction, probability, vssRays, box);
-	case INTERNAL_RAYCASTER:
-	default:
-		return CastInternalRay(viewPoint, direction, probability, vssRays, box);
-	}
-#if DEBUG_RAYCAST	
-  Debug<<"CRF "<<flush;
-#endif	
+	long t1 = GetTime();
+
+	if (castDoubleRays)
+	{
+		for (int i = 0; i < (int)rays.size(); ) 
+		{
+			if (i + 16 < (int)rays.size()) 
+			{
+				mRayCaster->CastRays16(
+					i,
+					rays,				
+					vssRays,
+					mViewCellsManager->GetViewSpaceBox(),
+					castDoubleRays);
+				i += 16;
+			} 
+			else 
+			{
+				mRayCaster->CastRay(
+					rays[i].mOrigin,
+					rays[i].mDirection,
+					rays[i].mPdf,
+					vssRays,
+					mViewCellsManager->GetViewSpaceBox(),
+					castDoubleRays);
+				i++;
+			}
+			
+			if (i % 10000 == 0)
+				cout<<".";
+		}
+
+		long t2 = GetTime();
+
+		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;
+	}
+	
 }
 
@@ -1429,5 +916,5 @@
 							const Vector3 &point,
 							const Vector3 &direction
-							)
+							) const
 {
 	ray.Clear();
@@ -1436,3 +923,4 @@
 }
 
-}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1501)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 1520)
@@ -217,5 +217,5 @@
 				OptimizeForProcessor="3"
 				OptimizeForWindowsApplication="TRUE"
-				AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;&quot;$(QTDIR)\include\QtCore&quot;"
+				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;"
 				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL"
 				ExceptionHandling="TRUE"
@@ -364,4 +364,16 @@
 			<File
 				RelativePath=".\HierarchyManager.h">
+			</File>
+			<File
+				RelativePath=".\IntelRayCaster.cpp">
+			</File>
+			<File
+				RelativePath=".\IntelRayCaster.h">
+			</File>
+			<File
+				RelativePath=".\InternalRayCaster.cpp">
+			</File>
+			<File
+				RelativePath=".\InternalRayCaster.h">
 			</File>
 			<File
@@ -556,8 +568,20 @@
 			</File>
 			<File
+				RelativePath=".\QtPreprocessorThread.cpp">
+			</File>
+			<File
+				RelativePath=".\QtPreprocessorThread.h">
+			</File>
+			<File
 				RelativePath="..\src\Ray.cpp">
 			</File>
 			<File
 				RelativePath="..\src\Ray.h">
+			</File>
+			<File
+				RelativePath=".\RayCaster.cpp">
+			</File>
+			<File
+				RelativePath=".\RayCaster.h">
 			</File>
 			<File
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1454)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp	(revision 1520)
@@ -12,4 +12,6 @@
 #include "RenderSimulator.h"
 #include "GlRenderer.h"
+#include "SamplingStrategy.h"
+
 
 namespace GtpVisibilityPreprocessor {
@@ -62,6 +64,6 @@
 
   switch (sampleType) {
-  case RSS_BASED_DISTRIBUTION:
-  case RSS_SILHOUETTE_BASED_DISTRIBUTION:
+  case SamplingStrategy::RSS_BASED_DISTRIBUTION:
+  case SamplingStrategy::RSS_SILHOUETTE_BASED_DISTRIBUTION:
 	if (mRssTree) {
 	  GenerateImportanceRays(mRssTree, number, rays);
@@ -554,15 +556,15 @@
 
 	if (mUseImportanceSampling) {
-	  GenerateRays(mInitialSamples/3, SPATIAL_BOX_BASED_DISTRIBUTION, rays);
-	  GenerateRays(mInitialSamples/3, OBJECT_BASED_DISTRIBUTION, rays);
-	  GenerateRays(mInitialSamples/3, DIRECTION_BASED_DISTRIBUTION, rays);
+	  GenerateRays(mInitialSamples/3, SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION, rays);
+	  GenerateRays(mInitialSamples/3, SamplingStrategy::OBJECT_BASED_DISTRIBUTION, rays);
+	  GenerateRays(mInitialSamples/3, SamplingStrategy::DIRECTION_BASED_DISTRIBUTION, rays);
 	  //	GenerateRays(mInitialSamples/4, OBJECT_DIRECTION_BASED_DISTRIBUTION, rays);
 	} else {
-	  int rayType = SPATIAL_BOX_BASED_DISTRIBUTION;
+		int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION;
 	  if (mObjectBasedSampling)
-		rayType = OBJECT_BASED_DISTRIBUTION;
+		rayType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION;
 	  else
 		if (mDirectionalSampling)
-		  rayType = DIRECTION_BASED_DISTRIBUTION;
+		  rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION;
 	  cout<<"Generating rays..."<<endl;
 	  GenerateRays(mRssSamplesPerPass, rayType, rays);
@@ -571,5 +573,5 @@
 	
 	cout<<"Casting initial rays..."<<endl<<flush;
-	CastRays(rays, mVssRays);
+	CastRays(rays, mVssRays, true);
 
 	ExportObjectRays(mVssRays, 1546);
@@ -690,9 +692,9 @@
 	  t1 = GetTime();
 	  
-	  GenerateRays(int(mRssSamplesPerPass*ratios[0]), RSS_BASED_DISTRIBUTION, rays);
+	  GenerateRays(int(mRssSamplesPerPass*ratios[0]), SamplingStrategy::RSS_BASED_DISTRIBUTION, rays);
 
 	  rays.NormalizePdf((float)rays.size());
 	  
-	  CastRays(rays, tmpVssRays);
+	  CastRays(rays, tmpVssRays, true);
 	  castRays += (int)rays.size();
 #if ADD_RAYS_IN_PLACE 
@@ -711,6 +713,6 @@
 	  if (ratios[1]!=0.0f) {
 		t1 = GetTime();
-		GenerateRays(int(mRssSamplesPerPass*ratios[1]), SPATIAL_BOX_BASED_DISTRIBUTION, rays);
-		CastRays(rays, tmpVssRays);
+		GenerateRays(int(mRssSamplesPerPass*ratios[1]), SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION, rays);
+		CastRays(rays, tmpVssRays, true);
 		castRays += (int)rays.size();
 #if ADD_RAYS_IN_PLACE 
@@ -733,6 +735,6 @@
 	  if (ratios[2]!=0.0f) {
 		t1 = GetTime();
-		GenerateRays(int(mRssSamplesPerPass*ratios[2]), DIRECTION_BASED_DISTRIBUTION, rays);
-		CastRays(rays, tmpVssRays);
+		GenerateRays(int(mRssSamplesPerPass*ratios[2]), SamplingStrategy::DIRECTION_BASED_DISTRIBUTION, rays);
+		CastRays(rays, tmpVssRays, true);
 		castRays += (int)rays.size();
 #if ADD_RAYS_IN_PLACE 
@@ -775,10 +777,10 @@
 	}
 	else {
-	  int rayType = SPATIAL_BOX_BASED_DISTRIBUTION;
+		int rayType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION;
 	  if (mObjectBasedSampling)
-		rayType = OBJECT_BASED_DISTRIBUTION;
+		  rayType = SamplingStrategy::OBJECT_BASED_DISTRIBUTION;
 	  else
 		if (mDirectionalSampling)
-		  rayType = DIRECTION_BASED_DISTRIBUTION;
+			rayType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION;
 
 	  cout<<"Generating rays..."<<endl;
@@ -788,5 +790,5 @@
 
 	  cout<<"Casting rays..."<<endl;
-	  CastRays(rays, vssRays);
+	  CastRays(rays, vssRays, true);
 	  cout<<"done."<<endl;
 	  castRays += (int)rays.size();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1520)
@@ -8,6 +8,5 @@
 #include "KdTree.h"
 
-// matt: remove qt dependencies
-//#include <QObject>
+
 
 namespace GtpVisibilityPreprocessor {
@@ -29,4 +28,6 @@
 class Intersectable;
 class VssRay;
+class RayCaster;
+
 
 /** Namespace for the external visibility preprocessor
@@ -45,5 +46,8 @@
 {
   //Q_OBJECT
-
+	friend class RayCaster;
+	friend class IntelRayCaster;
+	friend class InternalRayCaster;
+	
 public:
 	/** Default constructor initialising e.g., KD tree and BSP tree.
@@ -51,5 +55,5 @@
 	Preprocessor();
 
-   virtual ~Preprocessor();
+	virtual ~Preprocessor();
 
   /** Load the input scene. 
@@ -123,24 +127,4 @@
   bool ExportKdTree(const string filename);
 
-  /** Get Sample rays of particular type, returns false if this
-	  type of rays is not supported by the preprocessor
-  */
-  enum {
-	OBJECT_BASED_DISTRIBUTION,
-	DIRECTION_BASED_DISTRIBUTION,
-	DIRECTION_BOX_BASED_DISTRIBUTION,
-	SPATIAL_BOX_BASED_DISTRIBUTION,
-	RSS_BASED_DISTRIBUTION,
-	RSS_SILHOUETTE_BASED_DISTRIBUTION,
-	VSS_BASED_DISTRIBUTION,
-	OBJECT_DIRECTION_BASED_DISTRIBUTION,
-	OBJECTS_INTERIOR_DISTRIBUTION
-  };
-  
-  enum {
-	  INTERNAL_RAYCASTER = 0,
-	  INTEL_RAYCASTER
-  };
-
   virtual bool
   GenerateRays(
@@ -157,5 +141,6 @@
 
   virtual void CastRays(SimpleRayContainer &rays,
-						VssRayContainer &vssRays);
+						VssRayContainer &vssRays,
+						const bool castDoubleRays);
 
   /** Returns a view cells manager of the given name.
@@ -178,12 +163,4 @@
 	  );
 
-  Intersectable *
-  CastSimpleRay(
-				const Vector3 &viewPoint,
-				const Vector3 &direction,
-				const AxisAlignedBox3 &box,
-				Vector3 &point,
-				Vector3 &normal
-				);
   
   ////////////////////////////////////////////////
@@ -234,6 +211,6 @@
   float mVisibilityFilterWidth;
  
-  int GetRayCastMethod() { return mRayCastMethod; }
-  void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
+  //int GetRayCastMethod() { return mRayCastMethod; }
+  //void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
 
   int mPass;
@@ -241,43 +218,12 @@
 protected:
 
-	void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction);
-
-  int
-  ProcessRay(
-			 const Vector3 &viewPoint,
-			 const Vector3 &direction,
-			 Intersectable *objectA,
-			 Vector3 &pointA,
-			 const Vector3 &normalA,
-			 Intersectable *objectB,
-			 Vector3 &pointB,
-			 const Vector3 &normalB,
-			 const float probability,
-			 VssRayContainer &vssRays,
-			 const AxisAlignedBox3 &box);
-  
-  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);
-  
-  /////////////////////////
-
-  int mRayCastMethod;
+	void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const;
+
+	// matt: previously was a signal
+	void EvalPvsStat();
+
+	/////////////////////////
+
+  RayCaster *mRayCaster;
   /// samples used for construction of the BSP view cells tree.
   int mBspConstructionSamples;
@@ -287,24 +233,12 @@
   */
   RenderSimulator *mRenderSimulator;
-
   
   vector<FaceParentInfo> mFaceParents;
-  
+
   GlRendererBuffer *renderer;
-// matt: remove qt dependencies 
-//signals:
-  void EvalPvsStat();
-
-  protected:
-
-  
-  void CastRays16(const int i,
-				  SimpleRayContainer &rays, 
-				  VssRayContainer &vssRays,
-				  const AxisAlignedBox3 &sbox);
+
   
 };
 
-//extern Preprocessor *preprocessor;
 
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1021)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.h	(revision 1520)
@@ -15,10 +15,24 @@
  public:
 
+	 /** Sample rays of particular type
+	 */
+	 enum 
+	 {
+		 OBJECT_BASED_DISTRIBUTION,
+		 DIRECTION_BASED_DISTRIBUTION,
+		 DIRECTION_BOX_BASED_DISTRIBUTION,
+		 SPATIAL_BOX_BASED_DISTRIBUTION,
+		 RSS_BASED_DISTRIBUTION,
+		 RSS_SILHOUETTE_BASED_DISTRIBUTION,
+		 VSS_BASED_DISTRIBUTION,
+		 OBJECT_DIRECTION_BASED_DISTRIBUTION,
+		 OBJECTS_INTERIOR_DISTRIBUTION
+	 };
+
 	 /** Default constructor
      */
-	 SamplingStrategy(const Preprocessor &preprocessor): mPreprocessor(preprocessor)
-	 {}
+	 SamplingStrategy(const Preprocessor &preprocessor);
 
-	 virtual ~SamplingStrategy() {};
+	 virtual ~SamplingStrategy();
 
 	 /** Each strategy has to implement this function.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1520)
@@ -47,4 +47,5 @@
 
   // cast ray to KD tree to find intersection with other objects
+#if 0
   object = CastSimpleRay(origin,
 						 direction,
@@ -53,5 +54,6 @@
 						 normal
 						 );
-  
+#endif
+
   if (mDetectEmptyViewSpace && DotProd(normal, direction) >= 0) {
 	object = NULL;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1486)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1520)
@@ -22,4 +22,5 @@
 #include "OspTree.h"
 #include "BvHierarchy.h"
+#include "SamplingStrategy.h"
 
 
@@ -110,13 +111,13 @@
 	if (strcmp(buf, "box") == 0)
 	{
-		mSamplingType = Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION;
+		mSamplingType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION;
 	}
 	else if (strcmp(buf, "directional") == 0)
 	{
-		mSamplingType = Preprocessor::DIRECTION_BASED_DISTRIBUTION;
+		mSamplingType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION;
 	}
 	else if (strcmp(buf, "object_directional") == 0)
 	{
-		mSamplingType = Preprocessor::OBJECT_DIRECTION_BASED_DISTRIBUTION;
+		mSamplingType = SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION;
 	}
 	/*else if (strcmp(buf, "interior") == 0)
@@ -135,17 +136,17 @@
 	if (strcmp(buf, "box") == 0)
 	{
-		mEvaluationSamplingType = Preprocessor::SPATIAL_BOX_BASED_DISTRIBUTION;
+		mEvaluationSamplingType = SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION;
 	}
 	else if (strcmp(buf, "directional") == 0)
 	{
-		mEvaluationSamplingType = Preprocessor::DIRECTION_BASED_DISTRIBUTION;
+		mEvaluationSamplingType = SamplingStrategy::DIRECTION_BASED_DISTRIBUTION;
 	}
 	else if (strcmp(buf, "object_directional") == 0)
 	{
-		mEvaluationSamplingType = Preprocessor::OBJECT_DIRECTION_BASED_DISTRIBUTION;
+		mEvaluationSamplingType = SamplingStrategy::OBJECT_DIRECTION_BASED_DISTRIBUTION;
 	}
 	/*else if (strcmp(buf, "interior") == 0)
 	{
-		mEvaluationSamplingType = Preprocessor::OBJECTS_INTERIOR_DISTRIBUTION;
+		mEvaluationSamplingType = SamplingStrategy::OBJECTS_INTERIOR_DISTRIBUTION;
 	}*/
 	else
@@ -271,5 +272,5 @@
 
 	// shoot simple ray and add it to importance samples
-	mPreprocessor->CastRays(simpleRays, passSamples);
+	mPreprocessor->CastRays(simpleRays, passSamples, true);
 	Debug << "cast " <<  samplesPerPass << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
@@ -394,5 +395,5 @@
 	const int n = mConstructionSamples; //+initialSamples;
 	// should we use directional samples?
-	bool dirSamples = (mSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION);
+	bool dirSamples = (mSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION);
 
 	while (numSamples < n)
@@ -489,7 +490,8 @@
 		VssRayContainer visualizationSamples;
 
+		////////
 		//-- visualization rays, e.g., to show some samples in the scene
 		CastPassSamples(mVisualizationSamples,
-					    Preprocessor::DIRECTION_BASED_DISTRIBUTION, 
+					    SamplingStrategy::DIRECTION_BASED_DISTRIBUTION, 
 						visualizationSamples);
 
@@ -841,5 +843,5 @@
 
 	// should directional sampling be used?
-	bool dirSamples = (mEvaluationSamplingType == Preprocessor::DIRECTION_BASED_DISTRIBUTION);
+	bool dirSamples = (mEvaluationSamplingType == SamplingStrategy::DIRECTION_BASED_DISTRIBUTION);
 
 	cout << "reseting pvs ... ";
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 1520)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 1520)
@@ -0,0 +1,210 @@
+#include "IntelRayCaster.h"
+#include "VssRay.h"
+#include "Preprocessor.h"
+
+#ifdef GTP_INTERNAL
+#include "ArchModeler2MLRT.hxx"
+
+#define DEBUG_RAYCAST 0
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+IntelRayCaster::IntelRayCaster(const Preprocessor &preprocessor, const string externKdTree):
+RayCaster(preprocessor)
+{
+	InitRayCast(externKdTree);
+}
+
+
+IntelRayCaster::~IntelRayCaster()
+{
+}
+
+
+bool IntelRayCaster::InitRayCast(const string externKdTree)
+{
+	cout<<"Ray Cast file: " << externKdTree << endl;
+	return mlrtaLoadAS(externKdTree.c_str());
+}
+
+
+int IntelRayCaster::CastRay(
+							const Vector3 &viewPoint,
+							const Vector3 &direction,
+							const float probability,
+							VssRayContainer &vssRays,
+							const AxisAlignedBox3 &box,
+							const bool castDoubleRay,
+							const int pass
+							)
+{
+	//cout << "intel ray" << endl;
+	VssRay *vssRay  = NULL;
+	int hits = 0;
+	int hittriangle;
+	Vector3 pointA, pointB;
+	Vector3 normalA, normalB;
+	Intersectable *objectA = NULL, *objectB = NULL;
+	float dist;
+	double normal[3];
+
+	hittriangle = mlrtaIntersectAS(
+		&viewPoint.x,
+		&direction.x,
+		normal,
+		dist);
+
+	if (hittriangle != -1 ) {
+		if (hittriangle >= mPreprocessor.mFaceParents.size())
+			cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
+		else {
+			objectA = mPreprocessor.mFaceParents[hittriangle].mObject;
+			normalA = Vector3(normal[0], normal[1], normal[2]);
+			// Get the normal of that face
+			//		Mesh *mesh = ((MeshInstance *)objectA)->GetMesh();
+			//		normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
+			//-rays[index+i].mDirection; // $$ temporary
+			pointA = viewPoint + direction*dist;
+		}
+	}
+
+	if (castDoubleRay)
+	{
+		Vector3 dir = -direction;
+		hittriangle = mlrtaIntersectAS(
+			&viewPoint.x,
+			&dir.x,
+			normal,
+			dist);
+
+		if (hittriangle != -1 ) {
+			if (hittriangle >= mPreprocessor.mFaceParents.size())
+				cerr<<"Warning: triangle index out of range! "<<hittriangle<<endl;
+			else 
+			{
+				objectB = mPreprocessor.mFaceParents[hittriangle].mObject;
+				normalB = Vector3(normal[0], normal[1], normal[2]);
+				// Get the normal of that face
+				//		Mesh *mesh = ((MeshInstance *)objectB)->GetMesh();
+				//		normalA = mesh->GetFacePlane(mFaceParents[forward_hit_triangles[i]].mFaceIndex).mNormal;
+				//-rays[index+i].mDirection; // $$ temporary
+				pointB = viewPoint + dir * dist;
+			}
+		}
+	}
+
+	return ProcessRay(
+		viewPoint,
+		direction,
+		objectA, pointA, normalA,
+		objectB, pointB, normalB,
+		probability,
+		vssRays,
+		box
+		);
+}
+
+
+void IntelRayCaster::CastRays16(
+								const int index,
+								SimpleRayContainer &rays, 
+								VssRayContainer &vssRays,
+								const AxisAlignedBox3 &sbox,
+								const bool castDoubleRay,
+								const int pass)
+{
+	int i;
+	const int num = 16;
+
+#if DEBUG_RAYCAST
+	Debug<<"C16 "<<flush;
+#endif
+
+	int forward_hit_triangles[16];
+	float forward_dist[16];
+
+	int backward_hit_triangles[16];
+	float backward_dist[16];
+
+
+	Vector3 min = sbox.Min();
+	Vector3 max = sbox.Max();
+
+	for (i=0; i < num; i++) {
+		mlrtaStoreRayAS16(&rays[index + i].mOrigin.x,
+			&rays[index + i].mDirection.x,
+			i);
+	}
+
+	mlrtaTraverseGroupAS16(&min.x,
+		&max.x,
+		forward_hit_triangles,
+		forward_dist);
+
+	if (castDoubleRay)
+	{
+		for (i=0; i < num; i++) 
+		{
+			Vector3 dir = -rays[index + i].mDirection;
+			mlrtaStoreRayAS16(&rays[index+i].mOrigin.x,
+				&dir.x,
+				i);
+		}
+
+		mlrtaTraverseGroupAS16(&min.x,
+			&max.x,
+			backward_hit_triangles,
+			backward_dist);
+	}
+
+	for (i=0; i < num; i++) 
+	{
+		Intersectable *objectA = NULL, *objectB = NULL;
+		Vector3 pointA, pointB;
+		Vector3 normalA, normalB;
+
+		if (forward_hit_triangles[i] != -1 ) {
+			if (forward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
+				cerr<<"Warning: triangle index out of range! "<<forward_hit_triangles[i]<<endl;
+			else { 
+				objectA = mPreprocessor.mFaceParents[forward_hit_triangles[i]].mObject;
+				// Get the normal of that face
+				normalA = objectA->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
+				//-rays[index+i].mDirection; // $$ temporary
+				pointA = rays[index+i].Extrap(forward_dist[i]);
+			}
+		}
+
+		if (castDoubleRay && (backward_hit_triangles[i] != -1)) {
+			if (backward_hit_triangles[i] >= mPreprocessor.mFaceParents.size())
+				cerr<<"Warning: triangle  index out of range! "<<backward_hit_triangles[i]<<endl;
+			else { 
+				objectB = mPreprocessor.mFaceParents[backward_hit_triangles[i]].mObject;
+				normalB = objectB->GetNormal(mPreprocessor.mFaceParents[forward_hit_triangles[i]].mFaceIndex);
+
+				// normalB = rays[index+i].mDirection; // $$ temporary
+				pointB = rays[index+i].Extrap(-backward_dist[i]);
+			}
+		}
+
+		ProcessRay(
+			rays[index+i].mOrigin,
+			rays[index+i].mDirection,
+			objectA, pointA, normalA,
+			objectB, pointB, normalB,
+			rays[index+i].mPdf,
+			vssRays,
+			sbox
+			);
+	}
+
+#if DEBUG_RAYCAST
+	Debug<<"C16F\n"<<flush;
+#endif
+}
+
+}
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 1520)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 1520)
@@ -0,0 +1,116 @@
+#include "RayCaster.h"
+#include "VssRay.h"
+#include "Ray.h"
+#include "Preprocessor.h"
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+#define DEBUG_RAYCAST 0
+
+
+RayCaster::RayCaster(const Preprocessor &preprocessor):
+mPreprocessor(preprocessor)
+{
+}
+
+
+int RayCaster::ProcessRay(const Vector3 &viewPoint,
+						  const Vector3 &direction,
+						  Intersectable *objectA,
+						  Vector3 &pointA,
+						  const Vector3 &normalA,
+						  Intersectable *objectB,
+						  Vector3 &pointB,
+						  const Vector3 &normalB,
+						  const float probability,
+						  VssRayContainer &vssRays,
+						  const AxisAlignedBox3 &box
+						  )
+{
+	int hits = 0;
+#if DEBUG_RAYCAST
+	Debug<<"PR ";
+#endif
+	if (objectA == NULL && objectB == NULL)
+		return 0;
+
+	AxisAlignedBox3 sbox = box;
+	sbox.Enlarge(Vector3(-Limits::Small));
+
+	if (!sbox.IsInside(viewPoint))
+		return 0;
+
+	if (objectA == NULL) {
+		// compute intersection with the scene bounding box
+		static Ray ray;
+		mPreprocessor.SetupRay(ray, viewPoint, direction);
+
+		float tmin, tmax;
+		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
+			pointA = ray.Extrap(tmax);
+		else
+			return 0;
+	} else {
+		if (mPreprocessor.mDetectEmptyViewSpace)
+			if (DotProd(normalA, direction) >= 0) {
+				// discard the sample
+				return 0;
+			}
+	}
+
+	if (objectB == NULL) {
+		// compute intersection with the scene bounding box
+		static Ray ray;
+		mPreprocessor.SetupRay(ray, viewPoint, -direction);
+
+		float tmin, tmax;
+		if (box.ComputeMinMaxT(ray, &tmin, &tmax) && tmin < tmax)
+			pointB = ray.Extrap(tmax);
+		else
+			return 0;
+	} else {
+		if (mPreprocessor.mDetectEmptyViewSpace)
+			if (DotProd(normalB, direction) <= 0) {
+				// discard the sample
+				return 0;
+			}
+	}
+
+	VssRay *vssRay  = NULL;
+	bool validSample = (objectA != objectB);
+	if (validSample) {
+		if (objectA) {
+			vssRay = new VssRay(
+				pointB,
+				pointA,
+				objectB,
+				objectA,
+				mPreprocessor.mPass,
+				probability
+				);
+			
+			vssRays.push_back(vssRay);
+			hits ++;
+		}
+
+		if (objectB) {
+			vssRay = new VssRay(
+				pointA,
+				pointB,
+				objectA,
+				objectB,
+				mPreprocessor.mPass,
+				probability
+				);
+			
+			vssRays.push_back(vssRay);
+			hits ++;
+		}
+	}
+
+	return hits;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp	(revision 1520)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/InternalRayCaster.cpp	(revision 1520)
@@ -0,0 +1,108 @@
+#include "InternalRayCaster.h"
+#include "VssRay.h"
+#include "KdTree.h"
+#include "Preprocessor.h"
+
+#define DEBUG_RAYCAST 0
+
+
+namespace GtpVisibilityPreprocessor {
+
+
+InternalRayCaster::InternalRayCaster(const Preprocessor &preprocessor, KdTree *kdTree):
+RayCaster(preprocessor), mKdTree(kdTree)
+{
+}
+
+
+InternalRayCaster::~InternalRayCaster()
+{
+}
+
+
+int InternalRayCaster::CastRay(
+							   const Vector3 &viewPoint,
+							   const Vector3 &direction,
+							   const float probability,
+							   VssRayContainer &vssRays,
+							   const AxisAlignedBox3 &box,
+							   const bool castDoubleRay
+							   )
+{
+	//cout << "internal ray" << endl;
+	int hits = 0;
+	static Ray ray;
+	Intersectable *objectA = NULL, *objectB = NULL;
+	Vector3 pointA, pointB;
+	Vector3 normalA, normalB;
+
+#if 0
+	AxisAlignedBox3 sbox = box;
+	sbox.Enlarge(Vector3(-Limits::Small));
+	if (!sbox.IsInside(viewPoint))
+		return 0;
+#endif
+
+	mPreprocessor.SetupRay(ray, viewPoint, direction);
+	ray.mFlags &= ~Ray::CULL_BACKFACES;
+
+	if (mKdTree->CastRay(ray)) 
+	{
+		objectA = ray.intersections[0].mObject;
+		pointA = ray.Extrap(ray.intersections[0].mT);
+		normalA = ray.intersections[0].mNormal;
+	}
+	
+	mPreprocessor.SetupRay(ray, viewPoint, -direction);
+	ray.mFlags &= ~Ray::CULL_BACKFACES;
+
+	if (castDoubleRay && mKdTree->CastRay(ray)) 
+	{
+		objectB = ray.intersections[0].mObject;
+		pointB = ray.Extrap(ray.intersections[0].mT);
+		normalB = ray.intersections[0].mNormal;
+	}
+	
+	return ProcessRay(
+		viewPoint,
+		direction,
+		objectA, pointA, normalA,
+		objectB, pointB, normalB,
+		probability,
+		vssRays,
+		box
+		);
+}
+
+
+void InternalRayCaster::CastRays16(
+								   const int index,
+								   SimpleRayContainer &rays, 
+								   VssRayContainer &vssRays,
+								   const AxisAlignedBox3 &sbox,
+								   const bool castDoubleRays)
+{
+	int i;
+	const int num = 16;
+
+#if DEBUG_RAYCAST
+	Debug<<"C16 "<<flush;
+#endif
+
+	// no acceleration for ray bundles implemented right now
+	for (i=index; i < index + num; i++) 
+	{
+		CastRay(rays[i].mOrigin,
+			rays[i].mDirection,
+			rays[i].mPdf,
+			vssRays,
+			sbox,
+			castDoubleRays);
+	}
+
+#if DEBUG_RAYCAST
+	Debug<<"C16F\n"<<flush;
+#endif
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1501)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1520)
@@ -198,5 +198,5 @@
 	// establish visibility
 	VssRayContainer vssRays;
-	CastRays(simpleRays, vssRays);
+	CastRays(simpleRays, vssRays, false);
 	// add to ray queue
 	EnqueueRays(vssRays);
@@ -273,5 +273,5 @@
 	// generate vss rays
 	VssRayContainer samples;
-	CastRays(simpleRays, samples);
+	CastRays(simpleRays, samples, true);
 	
 	// add to ray queue
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1297)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 1520)
@@ -8,4 +8,16 @@
 
 namespace GtpVisibilityPreprocessor {
+
+
+SamplingStrategy::SamplingStrategy(const Preprocessor &preprocessor): 
+mPreprocessor(preprocessor)
+{
+}
+
+
+SamplingStrategy::~SamplingStrategy() 
+{
+}
+
 
 
@@ -142,5 +154,5 @@
 }
 
-/*
+#if 0
 bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray) const
 {
@@ -170,5 +182,5 @@
 
 	return true;
-}*/
-
 }
+#endif
+}
