Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 938)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h	(revision 1221)
@@ -64,5 +64,5 @@
 	/** Override pass so we can do the z-fail pass. 
 	*/
-	const Pass* _setPass(Pass* pass);
+	virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
 
 	/** Override from SceneManager so we can skip all but first pass for depth pass. 
@@ -124,14 +124,4 @@
 	*/
 	void InitVisibilityCulling(Camera *cam);
-#if 0
-	/** Finds object corresponding to this bounding box in the scene.
-	*/
-	Entity *FindCorrespondingObject(const AxisAlignedBox &box);
-
-	/** Identifies objects in the scene and gives them unique ids that
-		correspond to preprocessor ids.
-	*/
-	void IdentifyObjects(GtpVisibilityPreprocessor::ObjectContainer &objects);
-#endif
 	/** Loads / unloads pvs of the view cell to set the visibility in the scene.
 	*/
@@ -145,4 +135,7 @@
 	*/
 	void SetObjectsVisible(const bool visible);
+
+	
+	//////////////////////////////////////////
 
 	/// the interface to the scene hierarchy.
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1214)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h	(revision 1221)
@@ -92,5 +92,5 @@
 	/** Override pass so we can do the z-fail pass.
 	*/
-	const Pass* _setPass(Pass* pass);
+	virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
 
 	/** Render a queue group. 
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 1206)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/scripts/Plugin_VisibilitySceneManager.vcproj	(revision 1221)
@@ -109,5 +109,5 @@
 				LinkIncremental="1"
 				SuppressStartupBanner="TRUE"
-				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;&quot;$(QTDIR)\lib&quot;;..\..\..\Preprocessing\src\GL;&quot;$(CG_LIB_PATH)&quot;;..\..\..\..\..\..\..\NonGTP\Zlib\lib"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;;&quot;..\..\..\Preprocessing\lib\$(ConfigurationName)&quot;;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\Preprocessing\src\GL;&quot;$(CG_LIB_PATH)&quot;;..\..\..\..\..\..\..\NonGTP\Zlib\lib"
 				ModuleDefinitionFile="..\misc\OgreVisibilitySceneManager.def"
 				GenerateDebugInformation="TRUE"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1220)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreOcclusionCullingSceneManager.cpp	(revision 1221)
@@ -207,5 +207,5 @@
 }
 //-----------------------------------------------------------------------
-const Pass *OcclusionCullingSceneManager::_setPass(Pass* pass)
+const Pass *OcclusionCullingSceneManager::_setPass(Pass* pass, bool evenIfSuppressed)
 {
 	if (NORMAL_RENDER_HACK)
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1220)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTreeSceneManager.cpp	(revision 1221)
@@ -1109,5 +1109,5 @@
 }
 //-----------------------------------------------------------------------
-const Pass *KdTreeSceneManager::_setPass(Pass* pass)
+const Pass *KdTreeSceneManager::_setPass(Pass* pass, bool evenIfSuppressed)
 {
 	if (mRenderMethod == KdTree::KDRM_INTERNAL)
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp	(revision 944)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreBoundingBoxConverter.cpp	(revision 1221)
@@ -19,5 +19,4 @@
 	GtpVisibilityPreprocessor::IndexedBoundingBoxContainer::
 		const_iterator iit, iit_end = iboxes.end();
-
   
 	for (iit = iboxes.begin(); iit != iit_end; ++ iit)
@@ -25,5 +24,4 @@
 		const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second;
 		const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box);
-
    
 		Entity *ent = FindCorrespondingObject(currentBox);
@@ -42,4 +40,5 @@
 	const float eps = 1e-3f;
 	const Vector3 veps(eps, eps, eps);
+
 	Vector3 max = box.getMaximum();
 	Vector3 min = box.getMinimum();
@@ -54,5 +53,5 @@
 	//AxisAlignedBox dummy(Vector3(-50000, -50000, -50000), Vector3(50000, 50000, 50000));
 	
-	//-- get intersecting scene nodes
+	// get intersecting scene nodes
 	mSceneMgr->findNodesIn(mybox, sceneNodeList, NULL);
 	
@@ -99,5 +98,5 @@
 				 bestFittingObj = static_cast<Entity *>(mo);
 
-				 // perfect fit => object found, eraly exit
+				 // perfect fit => object found, early exit
 				 if (overlap >= thresh)
 					 return bestFittingObj;				
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj	(revision 1184)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/Preprocessor.vcproj	(revision 1221)
@@ -61,9 +61,10 @@
 			<Tool
 				Name="VCCLCompilerTool"
+				Optimization="0"
 				InlineFunctionExpansion="0"
 				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;"
-				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
+				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"
 				ExceptionHandling="TRUE"
 				RuntimeLibrary="2"
@@ -245,4 +246,10 @@
 			</File>
 			<File
+				RelativePath="..\src\ObjParser.cpp">
+			</File>
+			<File
+				RelativePath="..\src\ObjParser.h">
+			</File>
+			<File
 				RelativePath="..\src\OcclusionQuery.cpp">
 			</File>
@@ -459,4 +466,7 @@
 			</File>
 			<File
+				RelativePath="..\src\VssRay.cpp">
+			</File>
+			<File
 				RelativePath="..\src\VssRay.h">
 			</File>
@@ -535,7 +545,4 @@
 			<File
 				RelativePath="..\src\Renderer.h">
-			</File>
-			<File
-				RelativePath="..\src\VssRay.cpp">
 			</File>
 		</Filter>
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj	(revision 1163)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/TestPreprocessor.vcproj	(revision 1221)
@@ -70,5 +70,6 @@
 			<Tool
 				Name="VCCLCompilerTool"
-				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"
+				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"
 				RuntimeLibrary="2"
@@ -82,8 +83,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"
+				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 RTWorld.lib RTScene.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"
+				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"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h	(revision 1001)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.h	(revision 1221)
@@ -17,5 +17,6 @@
   virtual bool ParseFile(const std::string filename, 
 						 SceneGraphNode **root, 
-						 const bool loadPolygonsAsMeshes = false);
+						 const bool loadPolygonsAsMeshes = false,
+						 vector<Intersectable *> *parents = NULL);
   
 };
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1112)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.cpp	(revision 1221)
@@ -655,5 +655,6 @@
 X3dParser::ParseFile(const string filename,
 					 SceneGraphNode **root,
-					 const bool loadPolygonsAsMeshes)
+					 const bool loadPolygonsAsMeshes,
+					 vector<Intersectable *> *parents)
 {
   // Initialize the XML4C system
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h	(revision 1004)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.h	(revision 1221)
@@ -18,8 +18,8 @@
   
   //bool ParseFile(const string filename, ViewCellsManager &viewCells);
-  bool ParseFile(const string filename, 
-				 ViewCellsManager **viewCells,
-				 ObjectContainer *objectsm,
-				 BoundingBoxConverter *bconverter);
+  bool ParseViewCellsFile(const string filename, 
+	  ViewCellsManager **viewCells,
+	  ObjectContainer *objects,
+	  BoundingBoxConverter *bconverter);
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1221)
@@ -1093,5 +1093,4 @@
 				 "atlanta2.x3d");
 
-  
   RegisterOption("Unigraphics.meshGrouping",
 				 optInt,
@@ -1099,4 +1098,8 @@
 				 "0");
   
+   RegisterOption("ObjParser.meshGrouping",
+				 optInt,
+				 "objparser_mesh_grouping=",
+				 "0");
 
   RegisterOption("KdTree.Termination.minCost",
@@ -1737,4 +1740,9 @@
 					"1000");
 
+	RegisterOption("Preprocessor.rayCastMethod", 
+					optInt,
+					"preprocessor_ray_cast_method=",
+					"0");
+
 	RegisterOption("Preprocessor.histogram.intervals", 
 					optInt,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1221)
@@ -14,5 +14,6 @@
 #include "SamplingStrategy.h"
 #include "VspOspTree.h"
-
+#include "ObjParser.h"
+#include "ArchModeler2MLRT.hxx"
 
 
@@ -93,8 +94,8 @@
 	scene->mRoot->UpdateBox();
 	}
-	
-	// plane separating view space regions
+		
 	if (1)
 	{
+		// plane separating view space regions
 		const Vector3 scale(1.0f, 0.0, 0);
 
@@ -133,4 +134,5 @@
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.detectEmptyViewSpace", mDetectEmptyViewSpace);
 	Environment::GetSingleton()->GetBoolValue("Preprocessor.exportVisibility", mExportVisibility );
+	Environment::GetSingleton()->GetIntValue("Preprocessor.rayCastMethod", mRayCastMethod);
 
 	char buffer[256];
@@ -220,9 +222,15 @@
 		  if (strstr(filename.c_str(), ".ply") || strstr(filename.c_str(), ".plb"))
 			parser = new PlyParser;
-		  else
-			parser = new UnigraphicsParser;
+		  else if (strstr(filename.c_str(), ".obj"))
+			  parser = new ObjParser;
+		  else 
+			  parser = new UnigraphicsParser;
 
 		cout<<filename<<endl;
-		result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes);
+
+		if (mRayCastMethod == Preprocessor::INTEL_RAYCASTER)
+			result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes, &mFaceParents);
+		else
+			result = parser->ParseFile(filename, &mSceneGraph->mRoot, mLoadPolygonsAsMeshes);
 
 		delete parser;
@@ -234,7 +242,7 @@
 			if (strstr(filenames[i].c_str(), ".x3d"))
 				parser = new X3dParser;
-			else
+			else 
 				parser = new UnigraphicsParser;
-			
+						
 			SceneGraphNode *node;
 			if (parser->ParseFile(filenames[i], &node)) {
@@ -736,4 +744,5 @@
 		return NULL;
 	}
+
 	// should never come here
 	return NULL;
@@ -741,3 +750,17 @@
 
 
-}
+bool Preprocessor::InitRayCast(const string externKdTree)
+{
+	switch (mRayCastMethod) // use intel ray tracing
+	{
+	case INTEL_RAYCASTER:
+		return mlrtaLoadAS(externKdTree.c_str());
+	case INTERNAL_RAYCASTER:
+	default:
+		break;
+	}
+
+	return true;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h	(revision 1197)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dExporter.h	(revision 1221)
@@ -24,6 +24,6 @@
 class VspBspTree;
 class BspNode;
-//class VspKdViewCell;
 class Beam;
+
 
 class X3dExporter : public Exporter
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1145)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 1221)
@@ -13,5 +13,7 @@
 #include "Beam.h"
 #include "GlRenderer.h"
-#include "ViewCellBsp.h"
+#include "ArchModeler2MLRT.hxx"
+#include "Intersectable.h"
+
 
 namespace GtpVisibilityPreprocessor {
@@ -76,25 +78,157 @@
 						  )
 {
-  for (int i=0; i < rays.size(); i++)
-	CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);
+	AxisAlignedBox3 &box =  mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox();
+	
+#if 1
+	for (int i=0; i < rays.size(); i++)
+	{
+		CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, box);
+	}
+#else
+	for (int i = 0; i < rays.size(); i += 16)
+	{
+		CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, box);
+	}
+
+#endif
+}
+
+
+void VssPreprocessor::CastRays16(SimpleRayContainer &rays, 
+								 VssRayContainer &vssRays,
+								 const AxisAlignedBox3 &sbox)
+{
+/*
+	mlrtaStoreRayAS16(const float* pforg, const float* pfdir, int j);
+
+
+	// input parameters
+	const RTVec3f& org = *reinterpret_cast<const RTVec3f*> (pforg);
+	const RTVec3f& rd  = *reinterpret_cast<const RTVec3f*> (pfdir);
+
+	int ri = j/4;
+	int ci = j%4;
+	*((float*)&ibp4.ray4X[ri].m_origin.t[0] + ci) = org[0];
+	*((float*)&ibp4.ray4X[ri].m_origin.t[1] + ci) = org[1];
+	*((float*)&ibp4.ray4X[ri].m_origin.t[2] + ci) = org[2];
+
+	*((float*)&ibp4.ray4X[ri].m_direction.t[0] + ci) = rd[0];
+	*((float*)&ibp4.ray4X[ri].m_direction.t[1] + ci) = rd[1];
+	*((float*)&ibp4.ray4X[ri].m_direction.t[2] + ci) = rd[2];
+
+	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 = 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::CastRay(
-						 Vector3 &viewPoint,
-						 Vector3 &direction,
-						 VssRayContainer &vssRays
-						 )
-{
-
+VssPreprocessor::CastInternalRay(
+								 const Vector3 &viewPoint,
+								 const Vector3 &direction,
+								 VssRayContainer &vssRays,
+								 const AxisAlignedBox3 &box 
+								 )
+{
     int hits = 0;
 	static Ray ray;
-	
-	AxisAlignedBox3 box =  mViewSpaceBox ? *mViewSpaceBox : mKdTree->GetBox();
+
 	AxisAlignedBox3 sbox = box;
-    
 	sbox.Enlarge(Vector3(-Limits::Small));
-	
+
 	if (!sbox.IsInside(viewPoint))
 		return 0;
@@ -109,5 +243,4 @@
 
 	//float bsize = Magnitude(box.Size());
-
 	if (!mDetectEmptyViewSpace)
 		ray.mFlags &= ~Ray::CULL_BACKFACES;
@@ -132,4 +265,6 @@
 
 	// matt: point A could be undefined?
+
+	// cast ray into opposite direction
 	if (1 && mDetectEmptyViewSpace) {
 		SetupRay(ray, pointA, -direction);
@@ -215,7 +350,27 @@
 			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);
+	}
 }
 
@@ -565,9 +720,11 @@
 	box.SetMax(1, box.Min(1));
 
-  cout << "use view space box=" << mUseViewSpaceBox<<endl;
+  cout << "use view space box=" << mUseViewSpaceBox << endl;
 
   
   if (mUseViewSpaceBox)
   {
+	//mViewSpaceBox = ConstructViewSpaceBox();
+
 	  if (!mEnlargeViewSpace)
 	  {
@@ -671,5 +828,5 @@
 			Vector3 direction = GetDirection(viewpoint, mViewSpaceBox);
 
-			sampleContributions = CastRay(viewpoint, direction, mVssRays);
+			sampleContributions = CastRay(viewpoint, direction, mVssRays, vbox);
 
 			if (sampleContributions) {
@@ -802,5 +959,5 @@
 
 	for (int i=0; i < rays.size(); i++)
-	  CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays);
+	  CastRay(rays[i].mOrigin, rays[i].mDirection, vssRays, vbox);
 
 	vssTree->AddRays(vssRays);
@@ -842,14 +999,11 @@
   }
 
-  if (0)
-	  Debug << vssTree->stat << endl;
+  if (0)  Debug << vssTree->stat << endl;
 
   if (0)
   {
 	VssRayContainer viewCellRays;
-  
-	// compute rays used for view cells construction
+ 	// compute rays used for view cells construction
 	const int numRays = mViewCellsManager->GetVisualizationSamples();
-
 	vssTree->CollectRays(viewCellRays, numRays);
   }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.h	(revision 1221)
@@ -16,5 +16,6 @@
   bool ParseFile(const string filename,
 				 SceneGraphNode **root,
-				 const bool loadPolygonsAsMeshes = false);
+				 const bool loadPolygonsAsMeshes = false,
+				 vector<Intersectable *> *parents = NULL);
 
   bool ParseFile(const string filename, ViewCellsManager &viewCells) { return false; }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1197)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 1221)
@@ -26,4 +26,5 @@
 class VspTree;
 class OspTree;
+class Intersectable;
 
 /** Namespace for the external visibility preprocessor
@@ -131,4 +132,9 @@
   };
   
+  enum {
+	  INTERNAL_RAYCASTER,
+	  INTEL_RAYCASTER
+  };
+
   virtual bool
   GenerateRays(
@@ -144,4 +150,11 @@
   */
   ViewCellsManager *CreateViewCellsManager(const char *name);
+
+   
+  GlRendererBuffer *GetRenderer() { return renderer;}
+
+  bool InitRayCast(const string externKdTree);
+
+  ////////////////////////////////////////////////
 
   /// scene graph loaded from file
@@ -192,11 +205,13 @@
 
   float mVisibilityFilterWidth;
-  
-  GlRendererBuffer *GetRenderer() { return renderer;}
-  
+ 
+  int GetRayCastMethod() { return mRayCastMethod; }
+  void SetRayCastMethod(int rayCastMethod) { mRayCastMethod = rayCastMethod; }
+
 protected:
 
   /////////////////////////
 
+	int mRayCastMethod;
   /// samples used for construction of the BSP view cells tree.
   int mBspConstructionSamples;
@@ -207,4 +222,5 @@
   RenderSimulator *mRenderSimulator;
 
+  vector<Intersectable *> mFaceParents;
   GlRendererBuffer *renderer;
 // matt: remove qt dependencies 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.cpp	(revision 1221)
@@ -581,5 +581,5 @@
 
 
-bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const
+inline bool VspTree::LocalTerminationCriteriaMet(const VspTraversalData &data) const
 {
 	const bool localTerminationCriteriaMet = (
@@ -606,5 +606,5 @@
 
 
-bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const
+inline bool VspTree::GlobalTerminationCriteriaMet(const VspTraversalData &data) const
 {
 	const bool terminationCriteriaMet = (
@@ -2931,10 +2931,10 @@
 
 
-void VspTree::GetViewCells(VssRay &ray, ViewCellContainer &viewCells)
-{
-	mViewCellsManager->ComputeSampleContribution(ray, false, true);
+void VspTree::GetViewCells(const VssRay &ray, ViewCellContainer &viewCells)
+{
+	/*mViewCellsManager->ComputeSampleContribution(ray, false, true);
 	viewCells = ray.mViewCells;
 	ray.mViewCells.clear();
-	/*
+	*/
 	static Ray hray;
 	hray.Init(ray);
@@ -2951,5 +2951,5 @@
 
 	// if no precomputation of view cells
-	CastLineSegment(origin, termination, viewCells);*/
+	CastLineSegment(origin, termination, viewCells);
 }
 
@@ -3368,5 +3368,5 @@
 
 
-bool OspTree::LocalTerminationCriteriaMet(const OspTraversalData &data) const
+inline bool OspTree::LocalTerminationCriteriaMet(const OspTraversalData &data) const
 {
 	// matt: TODO
@@ -3379,5 +3379,5 @@
 
 
-bool OspTree::GlobalTerminationCriteriaMet(const OspTraversalData &data) const
+inline bool OspTree::GlobalTerminationCriteriaMet(const OspTraversalData &data) const
 {
 	// matt: TODO
@@ -3537,5 +3537,5 @@
 		{
 			float currentPos;
-			Debug << "here29 : " << minRenderCost / viewSpaceVol << endl;
+			//Debug << "here29 : " << minRenderCost / viewSpaceVol << endl;
 
 			// HACK: current positition is BETWEEN visibility events
@@ -3677,5 +3677,5 @@
 	// collect view cells and set mail + counter
 	ViewCellContainer viewCells;
-	mVspTree->GetViewCells(VssRay(ray), viewCells);
+	mVspTree->GetViewCells(ray, viewCells);
     	
 	ViewCellContainer::const_iterator vit, vit_end = viewCells.end();
@@ -3798,11 +3798,9 @@
 
 
-void OspTree::EvalRayContribution(KdLeaf *leaf,
-								  const VssRay &ray, 
-								  float &renderCost)
+void OspTree::EvalRayContribution(KdLeaf *leaf, const VssRay &ray, float &renderCost)
 {
 	ViewCellContainer viewCells;
 
-	mVspTree->GetViewCells(VssRay(ray), viewCells);
+	mVspTree->GetViewCells(ray, viewCells);
 
 	// classify view cells and compute volume contri accordingly
@@ -3994,6 +3992,6 @@
     plane.mPosition = nPosition[bestAxis];
 
-	pFront = nProbFront[bestAxis];
-	pBack = nProbBack[bestAxis];
+	//pFront = nProbFront[bestAxis];
+	//pBack = nProbBack[bestAxis];
 
 	Debug << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp	(revision 1221)
@@ -11,4 +11,5 @@
 
 
+
 namespace GtpVisibilityPreprocessor {
 
@@ -35,5 +36,8 @@
 							  )
 {
-
+	//float *pforg;
+	//float *pfdir;
+	//mlrtaStoreRayAS4(pforg, pfdir, 4);
+	//////////////////////////////////
   static Ray ray;
   AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h	(revision 860)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h	(revision 1221)
@@ -66,8 +66,8 @@
   int
   CastRay(
-		  Vector3 &viewPoint,
-		  Vector3 &direction,
-		  VssRayContainer &vssRays
-
+		  const Vector3 &viewPoint,
+		  const Vector3 &direction,
+		  VssRayContainer &vssRays,
+		  const AxisAlignedBox3 &box
 		  );
 
@@ -112,4 +112,27 @@
 
   bool mTestBeamSampling;
+
+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, 
+					VssRayContainer &vssRays,
+					const AxisAlignedBox3 &sbox);
 };
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1221)
@@ -239,6 +239,6 @@
 }
 
-AxisAlignedBox3
-ViewCellsManager::GetViewCellBox(ViewCell *vc)
+
+AxisAlignedBox3 ViewCellsManager::GetViewCellBox(ViewCell *vc)
 {
   Mesh *m = vc->GetMesh();
@@ -349,14 +349,17 @@
 	SimpleRayContainer simpleRays;
 
-	mPreprocessor->GenerateRays(samplesPerPass,
-							   sampleType,
-							   simpleRays);
+	const long startTime = GetTime();
+
+	mPreprocessor->GenerateRays(samplesPerPass, sampleType, simpleRays);
+
+	Debug << "generated " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
 	// shoot simple ray and add it to importance samples
 	mPreprocessor->CastRays(simpleRays, passSamples);
+	
+	Debug << "cast " <<  mInitialSamples << " samples in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
 	return (int)passSamples.size();
 }
-
 
 
@@ -408,9 +411,7 @@
 
 	//-- construction rays => we use uniform samples for this
-	CastPassSamples(mInitialSamples, 
-					mSamplingType,
-					initialSamples);
-	
-	cout << "finished" << endl;
+	CastPassSamples(mInitialSamples, mSamplingType,	initialSamples);
+	
+	cout << "finished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl;
 
 	
@@ -677,5 +678,5 @@
 	ViewCellsManager *vm = NULL;
 
-	if (parser.ParseFile(filename, &vm, objects, bconverter))
+	if (parser.ParseViewCellsFile(filename, &vm, objects, bconverter))
 	{
 		long startTime = GetTime();
@@ -3672,7 +3673,11 @@
 
 	if (1)
+	{
 		mVspBspTree->Construct(constructionRays, &mViewSpaceBox);
+	}
 	else
+	{
 		mVspBspTree->Construct(rays, &mViewSpaceBox);
+	}
 
 	// collapse invalid regions
@@ -3685,5 +3690,6 @@
     cout << "finished" << endl;
 
-	//-- stats
+	//-- stats after construction
+
 	Debug << mVspBspTree->GetStatistics() << endl;
 
@@ -5798,25 +5804,25 @@
 	Debug << "compute new statistics ... ";
 
-	//-- propagate pvs or pvs size information
+	// propagate pvs or pvs size information
 	ObjectPvs pvs;
 	UpdatePvsForEvaluation(mViewCellsTree->GetRoot(), pvs);
 
-	//-- output stats
-
-	sprintf(s, "-%09d-eval.log", castSamples);
-	string fileName = string(statsPrefix) + string(s);
-
-	ViewCellContainer leaves;
-
-	mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
+
+//-- test render cost
+
+sprintf(s, "-%09d-eval.log", castSamples);
+string fileName = string(statsPrefix) + string(s);
+
+ViewCellContainer leaves;
+
+mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), leaves);
 float rc = 0;
-	ViewCellContainer::const_iterator vit, vit_end = leaves.end();
-	for (vit = leaves.begin(); vit != vit_end; ++ vit)
-	{
-		ViewCell *vc = *vit;
-
+ViewCellContainer::const_iterator vit, vit_end = leaves.end();
+for (vit = leaves.begin(); vit != vit_end; ++ vit)
+{
+	ViewCell *vc = *vit;
 		int pvs = vc->GetPvs().CountObjectsInPvs();
-		float vol = vc->GetVolume();
-		rc += pvs * vol;
+	float vol = vc->GetVolume();
+	rc += pvs * vol;
 
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 1221)
@@ -32,5 +32,5 @@
 					   myless<vector<ViewCell *>::value_type> > TraversalQueue;
 
-int ViewCell::sMailId = 21843194198;
+int ViewCell::sMailId = 0;//21843194198;
 int ViewCell::sReservedMailboxes = 1;
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspOspTree.h	(revision 1221)
@@ -774,5 +774,5 @@
 		or by recomputation.
 	*/
-	void GetViewCells(VssRay &ray, ViewCellContainer &viewCells);
+	void GetViewCells(const VssRay &ray, ViewCellContainer &viewCells);
 
 
@@ -1001,9 +1001,9 @@
 	/** Returns true if tree can be terminated.
 	*/
-	inline bool LocalTerminationCriteriaMet(const VspTraversalData &data) const;
+	/*inline*/ bool LocalTerminationCriteriaMet(const VspTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	inline bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const;
+	/*inline*/ bool GlobalTerminationCriteriaMet(const VspTraversalData &data) const;
 
 	/** Adds ray sample contributions to the PVS.
@@ -1587,17 +1587,18 @@
 	
 	*/
-	void UpdateObjPvsContri(Intersectable *obj, 
-					 const int cf, 
-					 float &frontPvs, 
-					 float &backPvs, 
-					 float &totalPvs) const;
+	void UpdateObjPvsContri(
+		Intersectable *obj, 
+		const int cf, 
+		float &frontPvs, 
+		float &backPvs, 
+		float &totalPvs) const;
 	
 	/** Returns true if tree can be terminated.
 	*/
-	inline bool LocalTerminationCriteriaMet(const OspTraversalData &data) const;
+	/*inline*/ bool LocalTerminationCriteriaMet(const OspTraversalData &data) const;
 
 	/** Returns true if global tree can be terminated.
 	*/
-	inline bool GlobalTerminationCriteriaMet(const OspTraversalData &data) const;
+	/*inline*/ bool GlobalTerminationCriteriaMet(const OspTraversalData &data) const;
 
 	float SelectSplitPlane(const OspTraversalData &tData,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1076)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/UnigraphicsParser.cpp	(revision 1221)
@@ -44,5 +44,6 @@
 UnigraphicsParser::ParseFile(const string filename,
 			     SceneGraphNode **proot,
-				 const bool loadPolygonsAsMeshese)
+				 const bool loadPolygonsAsMeshes,
+				 vector<Intersectable *> *parents)
 {
   map<string, Vector3, ltstr> vht; // hash table for vectors
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h	(revision 1020)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Parser.h	(revision 1221)
@@ -3,9 +3,11 @@
 
 #include <string>
+#include <vector>
+
 
 namespace GtpVisibilityPreprocessor {
 
 class SceneGraphNode;
-
+class Intersectable;
 
 
@@ -17,5 +19,6 @@
   virtual bool ParseFile(const std::string filename, 
 						 SceneGraphNode **root, 
-						 const bool loadPolygonsAsMeshes = false) 
+						 const bool loadPolygonsAsMeshes = false,
+						 std::vector<Intersectable *> *parents = NULL) 
   {return false;};
 	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.h	(revision 1221)
@@ -0,0 +1,27 @@
+#ifndef __OBJPARSER_H
+#define __OBJPARSER_H
+
+#include <string>
+#include "Parser.h"
+
+namespace GtpVisibilityPreprocessor {
+
+class SceneGraphNode;
+
+class ObjParser: public Parser
+{
+public:
+
+  ObjParser(): Parser() {}
+  
+  virtual bool ParseFile(const std::string filename, 
+						 SceneGraphNode **root, 
+						 const bool loadPolygonsAsMeshes = false,
+						 vector<Intersectable *> *parents = NULL);
+  
+};
+
+}
+
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 1133)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 1221)
@@ -282,5 +282,6 @@
     return SqrMagnitude(diff);
   }
-
+  friend ostream& operator<< (ostream &s, const VssRay &vssRay);
+    
 };
 
@@ -297,4 +298,13 @@
 										  const float overlap
 										  );
+
+// Overload << operator for C++-style output
+inline ostream&
+operator<< (ostream &s, const VssRay &vssRay)
+{
+	return s 
+		<< "(" << vssRay.mPass << ", " << vssRay.mOrigin << ", " << vssRay.mTermination 
+		<< ", " << vssRay.mOriginObject << ", " << vssRay.mTerminationObject << ", " << vssRay.mPdf << ")";
+}
 
 // --------------------------------------------------------------
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1221)
@@ -161,9 +161,20 @@
 	preprocessor->LoadScene(filename);
 
+	//-- initialize external ray casters
+	if (preprocessor->InitRayCast("../data/grandcanyon1_RotXmin90.kdf"))
+	{
+		cout << "ray casting initialized!" << endl;
+	}
+	else
+	{
+		cout << "ray casting initialization failed" << endl;
+		exit(1);
+	}
+
 	//-- build kd tree from scene geometry
 	preprocessor->BuildKdTree();
 	preprocessor->KdTreeStatistics(cout);
-	preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
-	
+	
+	/*preprocessor->mKdTree->ExportBinTree("kd.bin.gz");
 	MeshManager::GetSingleton()->ExportEntries("meshes.bin");
 
@@ -188,5 +199,5 @@
 
 	DEL_PTR(kdTree2);
-
+*/
 	// parse view cells related options
 	preprocessor->PrepareViewCells();
@@ -209,6 +220,5 @@
 		// create and run the preprocessor application in a parallel thread
 		pt.InitThread();
-		//pt.RunThread();
-
+	
 		// display the render widget
 		DisplayWidget();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.h	(revision 1199)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.h	(revision 1221)
@@ -13,5 +13,6 @@
 
 /** Sampling based visibility preprocessing. The implementation is based on heuristical
-    sampling of view space */
+    sampling of view space 
+	*/
 class SamplingPreprocessor : public Preprocessor {
 public:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1221)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ObjParser.cpp	(revision 1221)
@@ -0,0 +1,237 @@
+#include  <stdlib.h>
+#include <iostream>
+#include <list>
+#include <map>
+using namespace std;
+
+#include "Vector3.h"
+#include "Mesh.h"
+#include "SceneGraph.h"
+
+#include "ObjParser.h"
+//#include "Material.h"
+#include "Environment.h"
+#include "ResourceManager.h"
+
+
+namespace GtpVisibilityPreprocessor {
+
+#define ROTATE_SCENE 0
+// HACK
+	static void RotateMesh(Mesh *mesh)
+	{
+		VertexContainer::iterator it, it_end = mesh->mVertices.end();
+
+		const float angle = 30.0f * PI / 180.0f;
+		const Matrix4x4 rot = RotationYMatrix(angle);
+
+		for (it = mesh->mVertices.begin(); it != it_end; ++ it)
+		{
+			(*it) = rot * (*it);        
+		}
+	}
+
+
+	struct ltstr
+	{
+		bool operator()(const string s1, const string s2) const
+		{
+			return s1 < s2;
+		}
+	};
+
+const static int nMaxFaces = 6;
+
+
+Face *LoadFace(char *str, 
+			   const VertexContainer &vertices, 
+			   map<int, Vector3> &hashTable)
+{
+	cout << "f";
+
+	char *pch;
+	
+	pch = strtok(str + 1, " ");
+	
+	VertexIndexContainer indices;
+	while (pch != NULL)
+	{
+	   	const int index = (int)strtol(pch, NULL, 10) - 1;
+
+		//Debug << index << " x ";
+		
+		// store vertex in hash table
+		hashTable[index] = vertices[index];
+		indices.push_back(index);
+		
+		pch = strtok(NULL, " ");
+	}
+	//if (indices.size() > 4) return NULL;
+
+	return new Face(indices); 
+}
+
+
+Mesh *CreateMesh(FaceContainer &faces, const map<int, Vector3> &hashTable)
+{
+	Mesh *mesh = MeshManager::GetSingleton()->CreateResource();
+	
+	FaceContainer::const_iterator fit, fit_end = faces.end();
+
+	for (fit = faces.begin(); fit != fit_end; ++ fit)
+	{
+		Face *face = *fit;
+		VertexIndexContainer::iterator vit, vit_end = face->mVertexIndices.end();
+		
+		for (vit = face->mVertexIndices.begin(); vit != vit_end; ++ vit)
+		{
+			// go through indices
+			const int index = *vit;            
+			//Debug << "old idx: " << (*vit) << endl;
+			map<int, Vector3>::const_iterator hit = hashTable.find(index);
+
+			// correct face index (nust be relative to start of verices)
+			(*vit) = distance(hashTable.begin(), hit);
+			//Debug << "new idx: " << (*vit) << endl;
+		}
+	}
+
+	VertexContainer vertices;
+
+	map<int, Vector3>::const_iterator hit, hit_end = hashTable.end();
+
+	// store vertices in given order
+	for (hit = hashTable.begin(); hit != hit_end; ++ hit)
+	{
+		mesh->mVertices.push_back((*hit).second);
+	}
+
+	mesh->mFaces = faces;
+	mesh->Preprocess();
+
+	/*for (int i = 0; i < faces.size(); ++ i)
+	{
+		Debug << "face: ";
+
+		for (int j = 0; j < faces[i]->mVertexIndices.size(); ++ j)
+		{
+			Debug << "i " << faces[i]->mVertexIndices[j] << " " << endl;	
+			Debug << "v " << mesh->mVertices[faces[i]->mVertexIndices[j]] << " ";
+		}
+		Debug << endl;
+	}*/
+
+	return mesh;
+}
+
+
+// HACK: associate mesh instances with triangles
+void AssociateFacesWithInstance(MeshInstance *mi, vector<Intersectable *> &parents)
+{
+	Mesh *mesh = mi->GetMesh();
+
+	FaceContainer::const_iterator fit, fit_end = mesh->mFaces.end();
+	
+	for (fit = mesh->mFaces.begin(); fit != fit_end; ++ fit)
+	{
+        parents.push_back(mi);
+	}
+}
+
+
+bool ObjParser::ParseFile(const string filename,
+						  SceneGraphNode **proot,
+						  const bool loadPolygonsAsMeshes,
+						  vector<Intersectable *> *parents)
+{
+	FILE *file;
+	if ((file = fopen(filename.c_str(), "rt")) == NULL)
+		return false;
+	
+	VertexContainer vertices; // table for vertices
+	map<int, Vector3> hashTable; // table associating indices with vectors
+	FaceContainer faces;
+
+	char str[100];
+	
+	float x,y,z;
+	int i;
+
+	SceneGraphNode *root = new SceneGraphNode;
+	
+	int meshGrouping;
+	Environment::GetSingleton()->GetIntValue("ObjParser.meshGrouping", meshGrouping);
+
+	while (fgets(str, 80, file) != NULL)
+	{
+		switch (str[0]) 
+		{
+		case 'v':
+			cout << "v";
+
+			// vertex 
+			sscanf(str + 1, "%f %f %f", &x, &y, &z);
+			vertices.push_back(Vector3(x,y,z));
+			
+			//Debug << "vertex: " << vertices.back() << endl;
+			break;
+
+		case 'f': 
+			{
+				Face *face = LoadFace(str, vertices, hashTable);
+				if (!face) break;
+				
+				faces.push_back(face);
+
+				if (faces.size() >= nMaxFaces)
+				{
+					Mesh *mesh = CreateMesh(faces, hashTable);
+
+					// make an instance of this mesh
+					MeshInstance *mi = new MeshInstance(mesh);
+					root->mGeometry.push_back(mi);
+					
+					if (parents) 
+					{
+						AssociateFacesWithInstance(mi, *parents);
+					}
+
+					// reset tables
+					hashTable.clear();
+					faces.clear();
+				}
+				break;
+			}      // end face
+		default:
+			break;
+		}
+
+	}
+
+	// there could be faces remaining
+	if (1 && !faces.empty())
+	{	
+		Mesh *mesh = CreateMesh(faces, hashTable);
+
+		// make an instance of this mesh
+		MeshInstance *mi = new MeshInstance(mesh);
+		
+		if (parents) 
+		{
+			AssociateFacesWithInstance(mi, *parents);
+		}
+
+		root->mGeometry.push_back(mi);	
+	}
+
+	// reset tables
+	hashTable.clear();
+	faces.clear();
+
+	fclose(file);
+	*proot = root;
+
+	return true;
+}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1201)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp	(revision 1221)
@@ -964,8 +964,8 @@
 
 
-bool ViewCellsParser::ParseFile(const string filename, 
-								ViewCellsManager **viewCells,
-								ObjectContainer *objects,
-								BoundingBoxConverter *bconverter)
+bool ViewCellsParser::ParseViewCellsFile(const string filename, 
+										 ViewCellsManager **viewCells,
+										 ObjectContainer *objects,
+										 BoundingBoxConverter *bconverter)
 {
   // Initialize the XML4C system
Index: GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h	(revision 971)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/X3dParser.h	(revision 1221)
@@ -15,5 +15,10 @@
 	X3dParser();
   
-	bool ParseFile(const string filename, SceneGraphNode **root, const bool loadPolygonsAsMeshes = false);
+	bool ParseFile(
+		const string filename, 
+		SceneGraphNode **root, 
+		const bool loadPolygonsAsMeshes = false,
+		vector<Intersectable *> *parents = NULL);
+
 	bool ParseFile(const string filename, ViewCellsManager &viewCells);
  
Index: GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp	(revision 863)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/PlyParser.cpp	(revision 1221)
@@ -260,5 +260,6 @@
 PlyParser::ParseFile(const string filename,
 					 SceneGraphNode **root,
-					 const bool loadPolygonsAsMeshes)
+					 const bool loadPolygonsAsMeshes,
+					 vector<Intersectable *> *parents)
 {
   vector<string> filelist;
Index: GTP/trunk/Lib/Vis/README_ONLINE_MODULE.txt
===================================================================
--- GTP/trunk/Lib/Vis/README_ONLINE_MODULE.txt	(revision 944)
+++ GTP/trunk/Lib/Vis/README_ONLINE_MODULE.txt	(revision 1221)
@@ -53,9 +53,11 @@
 FileSystem=d:/svn/gametools/OGRE/trunk/resources/models/trees
 
+6) add VisisibilitySceneManager as PlugIn in Plugins.cfg in 
 
-5) Set preprocessor flag GTP_VISIBILITY_MODIFIED_OGRE to the example projects you want to use
+D:\svn\gametools\OGRE\trunk\ogrenew\Samples\Common\bin\Release
 
-6) open scripts GTP\trunk\Lib\Vis\shared\GtpVisibility.sln and build all
+7) Set preprocessor flag GTP_VISIBILITY_MODIFIED_OGRE to the example projects you want to use
 
+8) open scripts GTP\trunk\Lib\Vis\shared\GtpVisibility.sln and build all
 
-7) start TerrainExampleApplication for testing
+9) start TerrainExampleApplication for testing
Index: GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln
===================================================================
--- GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln	(revision 1165)
+++ GTP/trunk/Lib/Vis/shared/scripts/GtpVisibility.sln	(revision 1221)
@@ -34,8 +34,4 @@
 	EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QtGlRenderer", "..\..\QtRenderer\QtRenderer.vcproj", "{B85DC7B1-58B6-4912-BD64-8B452630A368}"
-	ProjectSection(ProjectDependencies) = postProject
-	EndProjectSection
-EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestKdTree", "..\..\..\..\App\Demos\Vis\KdTreeDemo\OGRE\scripts\TestKdTree.vcproj", "{17F2C6F9-6101-430E-ABF4-71383868EF24}"
 	ProjectSection(ProjectDependencies) = postProject
@@ -44,46 +40,88 @@
 	EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiLevelRayTracing", "..\..\Preprocessing\MultiLevelRayTracing\MultiLevelRayTracing.vcproj", "{F72B85F3-FA3A-4939-8196-596B1250B36E}"
+	ProjectSection(ProjectDependencies) = postProject
+	EndProjectSection
+EndProject
 Global
 	GlobalSection(SolutionConfiguration) = preSolution
 		Debug = Debug
+		Debug Static = Debug Static
 		Release = Release
+		Release Static = Release Static
 	EndGlobalSection
 	GlobalSection(ProjectConfiguration) = postSolution
 		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Debug.ActiveCfg = Debug|Win32
 		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Debug.Build.0 = Debug|Win32
+		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Debug Static.ActiveCfg = Debug|Win32
+		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Debug Static.Build.0 = Debug|Win32
 		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Release.ActiveCfg = Release|Win32
 		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Release.Build.0 = Release|Win32
+		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Release Static.ActiveCfg = Release|Win32
+		{EABCE292-D598-4600-A1C9-2591E7D62FDA}.Release Static.Build.0 = Release|Win32
 		{101A7691-74F3-48B4-96A3-CF35578F5900}.Debug.ActiveCfg = Debug|Win32
 		{101A7691-74F3-48B4-96A3-CF35578F5900}.Debug.Build.0 = Debug|Win32
+		{101A7691-74F3-48B4-96A3-CF35578F5900}.Debug Static.ActiveCfg = Debug|Win32
+		{101A7691-74F3-48B4-96A3-CF35578F5900}.Debug Static.Build.0 = Debug|Win32
 		{101A7691-74F3-48B4-96A3-CF35578F5900}.Release.ActiveCfg = Release|Win32
 		{101A7691-74F3-48B4-96A3-CF35578F5900}.Release.Build.0 = Release|Win32
+		{101A7691-74F3-48B4-96A3-CF35578F5900}.Release Static.ActiveCfg = Release|Win32
+		{101A7691-74F3-48B4-96A3-CF35578F5900}.Release Static.Build.0 = Release|Win32
 		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Debug.ActiveCfg = Debug|Win32
 		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Debug.Build.0 = Debug|Win32
+		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Debug Static.ActiveCfg = Debug|Win32
+		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Debug Static.Build.0 = Debug|Win32
 		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Release.ActiveCfg = Release|Win32
 		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Release.Build.0 = Release|Win32
+		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Release Static.ActiveCfg = Release|Win32
+		{248F19A6-2FE0-4F5D-8928-E0EA10609887}.Release Static.Build.0 = Release|Win32
 		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Debug.ActiveCfg = Debug|Win32
 		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Debug.Build.0 = Debug|Win32
+		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Debug Static.ActiveCfg = Debug|Win32
+		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Debug Static.Build.0 = Debug|Win32
 		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Release.ActiveCfg = Release|Win32
 		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Release.Build.0 = Release|Win32
+		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Release Static.ActiveCfg = Release|Win32
+		{80DECC17-BDDD-4412-8CF8-F7C1C17A7436}.Release Static.Build.0 = Release|Win32
 		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Debug.ActiveCfg = Debug|Win32
 		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Debug.Build.0 = Debug|Win32
+		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Debug Static.ActiveCfg = Debug|Win32
+		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Debug Static.Build.0 = Debug|Win32
 		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Release.ActiveCfg = Release|Win32
 		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Release.Build.0 = Release|Win32
+		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Release Static.ActiveCfg = Release|Win32
+		{935D1BDD-41B0-49F1-A86C-EB49B94DDB20}.Release Static.Build.0 = Release|Win32
 		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Debug.ActiveCfg = Debug|Win32
 		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Debug.Build.0 = Debug|Win32
+		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Debug Static.ActiveCfg = Debug|Win32
+		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Debug Static.Build.0 = Debug|Win32
 		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Release.ActiveCfg = Release|Win32
 		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Release.Build.0 = Release|Win32
+		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Release Static.ActiveCfg = Release|Win32
+		{69BC58F0-C7EB-4B43-B782-B6F047EF0528}.Release Static.Build.0 = Release|Win32
 		{7319E499-473D-4CE5-9983-725D6E68A55D}.Debug.ActiveCfg = Debug|Win32
 		{7319E499-473D-4CE5-9983-725D6E68A55D}.Debug.Build.0 = Debug|Win32
+		{7319E499-473D-4CE5-9983-725D6E68A55D}.Debug Static.ActiveCfg = Debug|Win32
+		{7319E499-473D-4CE5-9983-725D6E68A55D}.Debug Static.Build.0 = Debug|Win32
 		{7319E499-473D-4CE5-9983-725D6E68A55D}.Release.ActiveCfg = Release|Win32
 		{7319E499-473D-4CE5-9983-725D6E68A55D}.Release.Build.0 = Release|Win32
-		{B85DC7B1-58B6-4912-BD64-8B452630A368}.Debug.ActiveCfg = Debug|Win32
-		{B85DC7B1-58B6-4912-BD64-8B452630A368}.Debug.Build.0 = Debug|Win32
-		{B85DC7B1-58B6-4912-BD64-8B452630A368}.Release.ActiveCfg = Release|Win32
-		{B85DC7B1-58B6-4912-BD64-8B452630A368}.Release.Build.0 = Release|Win32
+		{7319E499-473D-4CE5-9983-725D6E68A55D}.Release Static.ActiveCfg = Release|Win32
+		{7319E499-473D-4CE5-9983-725D6E68A55D}.Release Static.Build.0 = Release|Win32
 		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Debug.ActiveCfg = Debug|Win32
 		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Debug.Build.0 = Debug|Win32
+		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Debug Static.ActiveCfg = Debug|Win32
+		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Debug Static.Build.0 = Debug|Win32
 		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Release.ActiveCfg = Release|Win32
 		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Release.Build.0 = Release|Win32
+		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Release Static.ActiveCfg = Release|Win32
+		{17F2C6F9-6101-430E-ABF4-71383868EF24}.Release Static.Build.0 = Release|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Debug.ActiveCfg = Debug|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Debug.Build.0 = Debug|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Debug Static.ActiveCfg = Debug|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Debug Static.Build.0 = Debug|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Release.ActiveCfg = Release|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Release.Build.0 = Release|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Release Static.ActiveCfg = Release|Win32
+		{F72B85F3-FA3A-4939-8196-596B1250B36E}.Release Static.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
Index: GTP/trunk/Lib/Vis/QtRenderer/QtRenderer.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/QtRenderer/QtRenderer.vcproj	(revision 1178)
+++ GTP/trunk/Lib/Vis/QtRenderer/QtRenderer.vcproj	(revision 1221)
@@ -143,6 +143,5 @@
 						Name="VCCustomBuildTool"
 						Description="Performing moc on $(InputName).h"
-						CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp
-"
+						CommandLine="%qtdir%\bin\moc.exe $(InputDir)$(InputName).h -o $(InputDir)moc_$(InputName).cpp&#xA;"
 						Outputs="$(InputDir) moc_$(InputName).cpp"/>
 				</FileConfiguration>
