Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/IVReader.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/IVReader.vcproj	(revision 2532)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/IVReader/src/IVReader.vcproj	(revision 2560)
@@ -142,5 +142,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;IVREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;IVREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODUL"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj	(revision 2555)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/src/GtpVisibility.vcproj	(revision 2560)
@@ -123,5 +123,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="..\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODUL"
 				RuntimeLibrary="2"
 				EnableEnhancedInstructionSet="2"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2557)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/Plugin_VisibilitySceneManager.vcproj	(revision 2560)
@@ -164,5 +164,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;..\include;..\..\..\OnlineCullingCHC\include;..\..\..\Preprocessing\src;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\include"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE;PLUGIN_KD_TERRAIN_EXPORTS"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODUL;PLUGIN_KD_TERRAIN_EXPORTS"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
@@ -186,5 +186,5 @@
 				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\Release&quot;;&quot;$(OGRE_PATH)\OgreMain\lib\Release&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\Release&quot;;..\..\..\Preprocessing\lib\Release;..\..\..\Preprocessing\src\GL;..\..\GtpVisibility\lib\Release;..\..\lib\Release;..\lib\Release;..\..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\Lib\Vis\Preprocessing\MultiLevelRayTracing\RTWorld\Release;..\..\..\..\..\Lib\Vis\Preprocessing\MultiLevelRayTracing\RTScene\Release;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\lib\Release;..\..\..\..\..\Lib\Vis\OnlineCullingCHC\ObjReader\lib\Release;&quot;$(CG_LIB_PATH)&quot;"
 				ModuleDefinitionFile="..\misc\OgreVisibilitySceneManager.def"
-				GenerateDebugInformation="TRUE"
+				GenerateDebugInformation="FALSE"
 				SubSystem="2"
 				OptimizeReferences="2"
Index: GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2532)
+++ GTP/trunk/Lib/Vis/OnlineCullingCHC/ObjReader/src/ObjReader.vcproj	(revision 2560)
@@ -141,5 +141,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include;..\..\..\Preprocessing\src"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODULE"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;OBJREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE;GAMETOOLS_ILLUMINATION_MODUL"
 				StringPooling="TRUE"
 				RuntimeLibrary="2"
Index: GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena	(revision 2543)
+++ GTP/trunk/Lib/Vis/Preprocessing/scripts/run_demo_arena	(revision 2560)
@@ -4,5 +4,4 @@
 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+"
 COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=100000000"
-
 
 SCENE=../data/Arena/arena-high-lods.obj
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2559)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2560)
@@ -145,5 +145,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(QTDIR)\include\Qt&quot;;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include&quot;;QtInterface;..\src\sparsehash\src\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;$(NOINHERIT)"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_VERBOSE_PV"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;USE_QT;USE_CG;USE_VERBOSE_PVS;QT_OPENGL_LIB;QT_DLL"
 				StringPooling="TRUE"
 				MinimalRebuild="TRUE"
@@ -160,8 +160,8 @@
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib QtCore4.lib qtmain.lib cg.lib cgGL.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtInterface.lib"
+				AdditionalDependencies="xerces-c_2.lib glew32.lib zdll.lib zziplib.lib devil.lib glut32.lib OpenGL32.Lib glu32.lib Preprocessor.lib RTScene.lib RTWorld.lib cg.lib cgGL.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtInterface.lib QtOpenGL4.lib QtCore4.lib qtmain.lib"
 				OutputFile="../bin/release/Preprocessor.exe"
 				LinkIncremental="1"
-				AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;&quot;$(QTDIR)\lib&quot;;.\QtInterface\Release;&quot;$(CG_LIB_PATH)&quot;"
+				AdditionalLibraryDirectories="&quot;$(QTDIR)\lib&quot;;..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;.\QtInterface\Release;&quot;$(CG_LIB_PATH)&quot;"
 				GenerateDebugInformation="FALSE"
 				SubSystem="1"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.h	(revision 2548)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.h	(revision 2560)
@@ -10,16 +10,20 @@
 
 
-
 /** This sampling strategy utilizes the spatial filter to find 
 	areas that are likely to be visible.
 
-	First the filter is applied. The difference set of objects (filtered pvs - unfiltered pvs) gives you the objects 
-	which are not found visible yet but have a good probability that they are in fact visible, based on the current 
-	state of the sampling and the size of the filter. In fact the difference set is a probably visible set.
-    
-	Idea:
-	We apply the filter for n times, each time with a higher filter radius. The difference set gives you the probable visible set. 
-	Then we use a certain #random samples for sampling the view cell border + the object border. 
-	We can use different filter sizes to estimate the probablility distribution. The objects shouldreceived samples 
+	First the filter is applied. The difference set of objects 
+	(filtered pvs - unfiltered pvs) gives you the objects which 
+	are not found visible yet but have a good probability that they 
+	are in fact visible, based on the current 
+	state of the sampling and the size of the filter. In fact the 
+	difference set is a probably visible set.
+
+	Algorithm overview:
+	We apply the filter for n times, each time with a higher filter radius. 
+	The difference set gives you the probable visible set. 
+	Then we use a certain #random samples for sampling the view cell border + 
+	the object border. We can use different filter sizes to estimate the probability 
+	distribution. The objects shouldreceived samples 
 	roughly according to their probability of becoming invisible.
 */	
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2546)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2560)
@@ -126,5 +126,5 @@
 				OptimizeForWindowsApplication="TRUE"
 				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;;&quot;$(QTDIR)\include\QtOpenGl&quot;;&quot;$(CG_INC_PATH)&quot;;Timer;..\src\sparsehash\src\google\sparsehash;..\src\sparsehash\src\windows;..\src\sparsehash\src\google;..\src\sparsehash\src;..\src\ootl\;..\src\ootl\src\;..\src\ootl\src\cpp;..\src\ootl\src\cpp\include\;..\src\ootl\src\include\ootl;..\src\ootl\src\include\ootl\sandbox;..\src\ootl\src\cpp\include\ootl\mswin"
-				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_VERBOSE_PV"
+				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;USE_QT;USE_VERBOSE_PVS;USE_CG"
 				StringPooling="TRUE"
 				MinimalRebuild="TRUE"
@@ -1053,8 +1053,8 @@
 			</File>
 			<File
+				RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h">
+			</File>
+			<File
 				RelativePath=".\sparsehash\src\windows\hash_fun.h">
-			</File>
-			<File
-				RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h">
 			</File>
 			<File
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2543)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2560)
@@ -690,11 +690,15 @@
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
-	if (1) {
+	if (1) 
+	{
 		SetupCameraProjection(width(), height());
 		SetupCamera();
 
-		if (mRenderErrors) {
+		if (mRenderErrors) 
+		{
 			RenderErrors();
-		} else {
+		} 
+		else 
+		{
 			glColor3f(0.6f, 0.6f, 0.6f);
 			RenderPvs();
@@ -845,4 +849,5 @@
 	mShowRenderCost = false;
 	mShowPvsSizes = false;
+	mShowPiercingRays = false;
 	mSpatialFilterSize = 0.01;
 	mPvsSize = 0;
@@ -883,4 +888,5 @@
 	connect(mControlWidget, SIGNAL(SetUseSpatialFilter(bool)),
 		this, SLOT(SetUseSpatialFilter(bool)));
+	connect(mControlWidget, SIGNAL(SetShowPiercingRays(bool)), this, SLOT(SetShowPiercingRays(bool)));
 
 	connect(mControlWidget,
@@ -1146,5 +1152,6 @@
 	eq[3] = mSceneCutPlane.mD;
 
-	if (mCutViewCells) {
+	if (mCutViewCells) 
+	{
 		glClipPlane(GL_CLIP_PLANE0, eq);
 		glEnable(GL_CLIP_PLANE0);
@@ -1154,5 +1161,7 @@
 	ViewCellContainer &viewcells = mViewCellsManager->GetViewCells();
 	int maxPvs = -1;
-	for (i=0; i < viewcells.size(); i++) 
+	int maxPiercingRays = 0;
+
+	for (i = 0; i < viewcells.size(); ++ i) 
 	{
 		ViewCell *vc = viewcells[i];
@@ -1162,8 +1171,12 @@
 		if (p > maxPvs)
 			maxPvs = p;
-	}
-
-
-	for (i=0; i < viewcells.size(); i++) {
+		const int piercingRays = vc->GetNumPiercingRays();
+		if (piercingRays > maxPiercingRays)
+			maxPiercingRays = piercingRays;
+	}
+
+
+	for (i = 0; i < viewcells.size(); ++ i) 
+	{
 		ViewCell *vc = viewcells[i];
 		//	Mesh *m = vc->GetMesh();
@@ -1171,15 +1184,26 @@
 		RgbColor c;
 
-		if (!mShowPvsSizes) {
+		if (!mShowPvsSizes && !mShowPiercingRays)
+		{
 			mWireFrame = true;
 			c = vc->GetColor();
-		} else {
-			//	  const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
-			const float importance = 5.0f*mTransferFunction *
+		} 
+		else if (mShowPiercingRays)
+		{
+			// const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
+			const float importance = 5.0f * mTransferFunction *
+				((float)vc->GetNumPiercingRays() / (float)maxPiercingRays);
+			// c = RgbColor(importance, 1.0f - importance, 0.0f);
+			c = RainbowColorMapping(importance);
+		}
+		else
+		{
+			// const float importance = 5.0f*mTransferFunction * ((float)vc->GetPvs().CountObjectsInPvs() / (float)maxPvs);
+			const float importance = 5.0f * mTransferFunction *
 				((float)vc->GetPvs().GetSize() / (float)maxPvs);
-			//	  c = RgbColor(importance, 1.0f - importance, 0.0f);
+			// c = RgbColor(importance, 1.0f - importance, 0.0f);
 			c = RainbowColorMapping(importance);
-
 		}
+
 		glColor3f(c.r, c.g, c.b);
 
@@ -1191,5 +1215,4 @@
 
 	glPopAttrib();
-
 }
 
@@ -1318,5 +1341,11 @@
 	connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowRays(bool)));
 
-	vbox->resize(800,100);
+	
+	cb = new QCheckBox("Show piercing rays", hbox);
+	hlayout->addWidget(cb);
+	cb->setChecked(false);
+	connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowPiercingRays(bool)));
+
+	vbox->resize(800,150);
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2543)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.h	(revision 2560)
@@ -112,8 +112,8 @@
   void SetShowRenderCost(bool);
   void SetShowPvsSizes(bool);
+  void SetShowPiercingRays(bool);
   void SetTopView(bool);
   void SetCutViewCells(bool);
   void SetCutScene(bool);
-
 };
 
@@ -137,4 +137,5 @@
 	bool mUseSpatialFilter;
 	bool mShowRenderCost;
+	bool mShowPiercingRays;
 	bool mShowRays;
 
@@ -293,4 +294,9 @@
 	void SetShowPvsSizes(bool b) {
 		mShowPvsSizes = b;
+		updateGL();
+	}
+
+	void SetShowPiercingRays(bool b) {
+		mShowPiercingRays = b;
 		updateGL();
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtInterface.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtInterface.vcproj	(revision 2530)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtInterface.vcproj	(revision 2560)
@@ -166,5 +166,5 @@
 				Name="VCCLCompilerTool"
 				AdditionalIncludeDirectories="..\..\src;&quot;$(QTDIR)\include\QtCore&quot;;&quot;$(QTDIR)\include\QtGui&quot;;&quot;$(QTDIR)\include&quot;;&quot;$(QTDIR)\include\QtOpenGl&quot;;..\..\..\..\..\..\..\NonGTP\Zlib\include;&quot;$(CG_INC_PATH)&quot;"
-				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;QTGLRENDERER_EXPORTS;USE_VERBOSE_PVS"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;QTGLRENDERER_EXPORTS;USE_VERBOSE_PVS;USE_QT;USE_CG;GTP_INTERNAL"
 				RuntimeLibrary="2"
 				UsePrecompiledHeader="0"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2538)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2560)
@@ -52,5 +52,5 @@
 	if (mRenderer->mRenderViewCells) 
 	  mRenderer->RenderViewCells();
-
+	
 	glColor3f(0.8f, 0.8f, 0.8f);
 	mRenderer->RenderPvs();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2543)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2560)
@@ -473,7 +473,4 @@
 	{
 		ViewCell *vc = *vit;
-
-		int vcTri;
-		int vcObj;
 
 		int oldVcTri = (int)vc->GetTrianglesInPvs();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2548)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2560)
@@ -2833,5 +2833,5 @@
 	// check if last ray was not same ray with reverse direction
 	if (1) 
-		// tmp matt: don't use that before origin objects are accounted for, currently the second ray is lost!!
+		// tmp matt: don't use when origin objects are not accounted for, currently the second ray is lost!!
 		//!lastVssRay ||
 		//!(ray.mOrigin == lastVssRay->mTermination) ||
@@ -2883,4 +2883,5 @@
 									ray.mTermination, 
 									addRays);
+		(*it)->IncNumPiercingRays();
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2552)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2560)
@@ -76,5 +76,6 @@
 mData(NULL),
 mIndices(NULL),
-mUseVbos(true),
+//mUseVbos(true),
+mUseVbos(false),
 mCurrentFrame(-1)
 {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2544)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2560)
@@ -129,5 +129,6 @@
 mEntriesInPvs(0),
 mPvsSizeValid(false),
-mFilteredPvsSize(0)
+mFilteredPvsSize(0),
+mNumPiercingRays(0)
 {
 	mId = -100;
@@ -144,5 +145,6 @@
 mPvsCost(0),
 mPvsSizeValid(false),
-mFilteredPvsSize(0)
+mFilteredPvsSize(0),
+mNumPiercingRays(0)
 {
 	mId = -100;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 2544)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 2560)
@@ -253,21 +253,26 @@
 	float GetMergeCost() const;
 
-	void UpdatePvsCost() {
+	void UpdatePvsCost() 
+	{
 		mPvsCost = GetPvs().EvalPvsCost();
 	}
 
-	void SetTrianglesInPvs(const float c) {
+	void SetTrianglesInPvs(const float c) 
+	{
 		mPvsCost = c;
 	}
 
-	void SetEntriesInPvs(const int e) {
+	void SetEntriesInPvs(const int e) 
+	{
 		mEntriesInPvs = e;
 	}
 
-	float GetTrianglesInPvs() const {
+	float GetTrianglesInPvs() const 
+	{
 		return mPvsCost;
 	}
 
-	int GetEntriesInPvs() const {
+	int GetEntriesInPvs() const 
+	{
 		return mEntriesInPvs;
 	}
@@ -278,9 +283,24 @@
 	}
 
-	void SetFilteredPvsSize(const int s) {
+	void SetFilteredPvsSize(const int s) 
+	{
 		mFilteredPvsSize = s;
 	}
 
-	//virtual int ViewCellType;
+	void IncNumPiercingRays()
+	{
+		++ mNumPiercingRays;
+	}
+	
+	void ResetNumPiercingRays()
+	{
+		mNumPiercingRays = 0;
+	}
+
+	int GetNumPiercingRays()
+	{
+		return mNumPiercingRays;
+	}
+
 
 protected:
@@ -311,6 +331,8 @@
 	/// Filter cost of the pvs
 	int mFilteredPvsSize;
-
+	/// number of rays piercing this view cell
+	int mNumPiercingRays;
 };
+
 
 inline bool SmallerPvs(const ViewCell *a, const ViewCell *b) 
@@ -357,9 +379,11 @@
 	bool IsLeaf() const;
 
-	void SetCost(const float c) {
+	void SetCost(const float c) 
+	{
 		mCost = c;
 	}
 
-	float GetCost() const {
+	float GetCost() const 
+	{
 		return mCost;
 	}
@@ -580,7 +604,6 @@
 
 
-	//////////////////////////////////////////////////////////////
-	//                    merge related stuff                   //
-	//////////////////////////////////////////////////////////////
+	////////////////////////////////////////////
+	//-- merge related stuff                   
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp	(revision 2559)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/DifferenceSampling.cpp	(revision 2560)
@@ -103,5 +103,5 @@
 		// n samples per object
 		const int n = 50;
-		mNumSamples = mPvsDifference.size() * n;
+		mNumSamples = (int)mPvsDifference.size() * n;
 	}
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2543)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2560)
@@ -21,16 +21,17 @@
 #include "GlobalLinesRenderer.h"
 
-
 #include "ViewCellsManager.h"
 
-#ifdef USE_QT  
+//#ifdef USE_QT  
 	#include "QtPreprocessorThread.h"
 	#include "QtGlViewer.h"
 	#include "QtGlRenderer.h"
-#else
+	#include <QGLWidget>
+
+//#else
 	#if USE_THREADS
 		#include "BoostPreprocessorThread.h"
 	#endif
-#endif
+//#endif
 
 #include "ResourceManager.h"
@@ -155,4 +156,6 @@
 main(int argc, char **argv)
 {
+	int returnCode = 0;
+
 	//Now just call this function at the start of your program and if you're
 	//compiling in debug mode (F5), any leaks will be displayed in the Output
@@ -160,11 +163,7 @@
 	//be ignored. Use it as you will!
 	//note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
-#if 1
-  _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
-  _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
-  _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 
-#endif
-
-	int returnCode = 0;
+	_CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
+	_CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
+	_CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR); 
 
 	InitTiming();
@@ -185,5 +184,4 @@
 	}
 
-
 	Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
 	string filename(buff);
@@ -216,4 +214,5 @@
 	}
 	
+
 	////////////
 	//-- initialize external ray caster
@@ -292,20 +291,98 @@
 	// create a preprocessor thread (note: capsulates calls to boost fuctions!)
 	PreprocessorThread *pt = NULL;
-
-#ifdef TRY_GLOBAL_LINES
-	
-	preprocessor->PrepareHwGlobalLines();
-	globalLinesRenderer->Run();
-
-#else
+	
+	//preprocessor->PrepareHwGlobalLines();
+	//globalLinesRenderer->Run();
+
+
+	bool guiSupported = false;
+	const bool useRendererBuffer = true;
+
+	int frames;
+	Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", frames);
 
 #ifdef USE_QT
-	
+
 	// create a qt application first (must be created before any opengl widget ...)
 	QApplication *app = new QApplication(argc, NULL);
-
-	pt = new QtPreprocessorThread(preprocessor);
-
-#else
+	pt = new QtPreprocessorThread(preprocessor);	
+	
+	if (0 && preprocessor->mUseGlRenderer && (importRandomViewCells || frames))
+	{
+		QGLFormat f;
+		f.setStencil(true);
+		QGLFormat::setDefaultFormat(f);
+
+		// NOTE: render texture should be power of 2 and square
+		// renderer must be initialised
+		// $$matt
+		preprocessor->renderer = 
+			new QtGlRendererBuffer(1024, 1024,
+			preprocessor->mSceneGraph,
+			preprocessor->mViewCellsManager,
+			preprocessor->mKdTree);
+	}
+
+	if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
+	{
+		////////
+		//-- create and run the preprocessor application in a parallel thread
+
+		cout << "using gl widget" << endl;
+
+		pt->InitThread();
+		pt->RunThread();
+
+		// display the render widget
+		if (!rendererWidget) 
+		{
+			if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
+				cout << "damn" << endl;
+				QMessageBox::information(0, "OpenGL pbuffers", 
+					"This system does not support OpenGL/pbuffers.",
+					QMessageBox::Ok);
+				return NULL;
+			}
+
+			rendererWidget = 
+				new QtGlRendererWidget(preprocessor->mSceneGraph,
+				preprocessor->mViewCellsManager,
+				preprocessor->mKdTree);
+
+			rendererWidget->Show();
+
+			if (1) // not working with vbo
+			{
+				QtGlViewer *viewer = 
+					new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget);
+				viewer->show();
+			}
+
+			guiSupported = true; 
+		}
+
+		bool exportRandomViewCells;
+		Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells",
+			exportRandomViewCells);
+
+		if (exportRandomViewCells)
+		{
+			cout << "exporting random view cells" << endl;
+			preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile);
+			cout << "finished" << endl;
+		}
+
+		/*bool evaluatePixelError;
+		Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError",  evaluatePixelError);
+
+		if (evaluatePixelError)
+		{
+		cout << "evaluating pixel error" << endl;
+		preprocessor->ComputeRenderError();
+		}*/
+
+		qApp->exec();
+	}
+#else // USE_QUT
 
 	//#if USE_THREADS
@@ -319,118 +396,26 @@
 	preprocessor->SetThread(pt);
 
-	bool guiSupported = false;
-	bool useRendererBuffer = true;
-
-	int frames;
-	Environment::GetSingleton()->GetIntValue("Preprocessor.pvsRenderErrorSamples", frames);
-	
-	
-#ifdef USE_QT
-
-	if (0 && preprocessor->mUseGlRenderer && (importRandomViewCells || frames))
-	{
-		QGLFormat f;
-		f.setStencil(true);
-		QGLFormat::setDefaultFormat(f);
-
-		// NOTE: render texture should be power of 2 and square
-		// renderer must be initialised
-		// $$matt
-		preprocessor->renderer = 
-			new QtGlRendererBuffer(1024, 1024,
-			                       preprocessor->mSceneGraph,
-								   preprocessor->mViewCellsManager,
-								   preprocessor->mKdTree);
-	}
-#endif
-
-	  if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
-	  {
-#ifdef USE_QT
-
-		  ////////
-		  // create and run the preprocessor application in a parallel thread
-
-		  cout << "using gl widget" << endl;
-
-		  pt->InitThread();
-		  pt->RunThread();
-
-		  // display the render widget
-		  if (!rendererWidget) 
-		  {
-
-			  if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
-				  QMessageBox::information(0, "OpenGL pbuffers", 
-					  "This system does not support OpenGL/pbuffers.",
-					  QMessageBox::Ok);
-				  return NULL;
-			  }
-
-			  rendererWidget = 
-				  new QtGlRendererWidget(preprocessor->mSceneGraph,
-				                         preprocessor->mViewCellsManager,
-				                         preprocessor->mKdTree);
-
-			  rendererWidget->Show();
-
-			  if (0)
-			  {
-				  QtGlViewer *viewer = 
-					  new QtGlViewer(NULL, (QtGlRendererWidget *)rendererWidget);
-				  viewer->show();
-			  }
-
-			  guiSupported = true; 
-		  }
-
-
-		  bool exportRandomViewCells;
-		  Environment::GetSingleton()->GetBoolValue("ViewCells.exportRandomViewCells",
-			  exportRandomViewCells);
-
-		  if (exportRandomViewCells)
-		  {
-			  cout << "exporting random view cells" << endl;
-			  preprocessor->mViewCellsManager->ExportRandomViewCells(viewCellPointsFile);
-			  cout << "finished" << endl;
-		  }
-
-		  /*bool evaluatePixelError;
-		  Environment::GetSingleton()->GetBoolValue("Preprocessor.evaluatePixelError",  evaluatePixelError);
-
-		  if (evaluatePixelError)
-		  {
-		  cout << "evaluating pixel error" << endl;
-		  preprocessor->ComputeRenderError();
-		  }*/
-
-		  qApp->exec();
-#endif
-	  }
-
-	  // no gui available
-	  if (!guiSupported) 
-	  {
-		  if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
-			  cout << "warning: gui not supported!" << endl;
-
-		  preprocessor->mUseGlRenderer = false;
-		  preprocessor->mUseGlDebugger = false;
-	  }
-
-	  if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) 
-	  {
-		  cout << "executing main thread" << endl;
-		  // just call the mail method -> will be executed in the main thread
-		  pt->Main();
-	  }	
-#endif
-
-	  // release memory
-	  Cleanup();
-	  delete pt;
-
-	  return returnCode;
+	// no gui available
+	if (!guiSupported) 
+	{
+		if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
+			cout << "warning: gui not supported!" << endl;
+
+		preprocessor->mUseGlRenderer = false;
+		preprocessor->mUseGlDebugger = false;
+	}
+
+	if (!(preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)) 
+	{
+		cout << "executing main thread" << endl;
+		// just call the mail method -> will be executed in the main thread
+		pt->Main();
+	}	
+
+	// release memory
+	Cleanup();
+	delete pt;
+
+	return returnCode;
 }
 
