Index: GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2210)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2353)
@@ -49,5 +49,5 @@
   //	cout<<mRays[i].mMutations<<" ";
   //  cout<<endl;
-  cerr<<"Muattion update..."<<endl;
+  cerr<<"Mutation update..."<<endl;
   cerr<<"rays = "<<mRays.size()<<endl;
   if ((int)mRays.size()) {
Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2347)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2353)
@@ -212,5 +212,5 @@
 				OptimizeForProcessor="1"
 				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;"
+				AdditionalIncludeDirectories="..\include;..\..\..\..\..\..\NonGTP\Boost;..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;NO_QT;USE_SSE"
 				RuntimeLibrary="2"
@@ -226,5 +226,5 @@
 				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"
-				OutputFile="../bin/release/Preprocessor2.exe"
+				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"
@@ -258,5 +258,5 @@
 		</Configuration>
 		<Configuration
-			Name="Release_Qt|Win32"
+			Name="Release_qt|Win32"
 			OutputDirectory="..\bin\Release"
 			IntermediateDirectory="..\obj\Release"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2353)
@@ -1225,8 +1225,7 @@
 };
 
-#define TEST_EVALUATION 0
-
-/**
-	Manages different higher order operations on the view cells.
+
+
+/**	Manages different higher order operations on the view cells.
 */
 class VspOspViewCellsManager: public ViewCellsManager
@@ -1301,13 +1300,10 @@
 
 #if TEST_PACKETS
-#ifdef USE_SSE
-
-	float ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays,
-		                                               const bool addContributions,
-													   const bool storeViewCells,
-													   const bool useHitObjects);
-
+
+	float ComputeSampleContributions(const VssRayContainer &rays,
+		                             const bool addContributions,
+									 const bool storeViewCells,
+									 const bool useHitObjects = false);
 #endif
-#endif
 
 protected:
@@ -1315,7 +1311,5 @@
 	VspOspViewCellsManager(ViewCellsTree *vcTree, HierarchyManager *hm);
 	
-#if 1//TEST_EVALUATION
 	virtual void EvalViewCellPartition();
-#endif
 
 	/** Exports view cell geometry.
@@ -1349,6 +1343,4 @@
 	static HierarchyManager *CreateHierarchyManager(const string &name);
 
-	//void ExportStats(const string &mergeStats);
-
 	/** collect objects intersecting a given spatial box 
 	*/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2342)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2353)
@@ -80,50 +80,4 @@
 				UsePrecompiledHeader="0"
 				BrowseInformation="1"
-				WarningLevel="2"
-				Detect64BitPortabilityProblems="TRUE"
-				DebugInformationFormat="3"/>
-			<Tool
-				Name="VCCustomBuildTool"/>
-			<Tool
-				Name="VCLibrarianTool"/>
-			<Tool
-				Name="VCMIDLTool"/>
-			<Tool
-				Name="VCPostBuildEventTool"/>
-			<Tool
-				Name="VCPreBuildEventTool"/>
-			<Tool
-				Name="VCPreLinkEventTool"/>
-			<Tool
-				Name="VCResourceCompilerTool"/>
-			<Tool
-				Name="VCWebServiceProxyGeneratorTool"/>
-			<Tool
-				Name="VCXMLDataGeneratorTool"/>
-			<Tool
-				Name="VCManagedWrapperGeneratorTool"/>
-			<Tool
-				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
-		</Configuration>
-		<Configuration
-			Name="Release_Internal|Win32"
-			OutputDirectory="$(ConfigurationName)"
-			IntermediateDirectory="$(ConfigurationName)"
-			ConfigurationType="4"
-			CharacterSet="2">
-			<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;;..\..\Preprocessing\MultiLevelRayTracing"
-				PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
-				ExceptionHandling="TRUE"
-				RuntimeLibrary="2"
-				DisableLanguageExtensions="FALSE"
-				ForceConformanceInForLoopScope="FALSE"
-				RuntimeTypeInfo="TRUE"
-				UsePrecompiledHeader="0"
 				WarningLevel="2"
 				Detect64BitPortabilityProblems="TRUE"
@@ -270,5 +224,5 @@
 		</Configuration>
 		<Configuration
-			Name="Release_Qt|Win32"
+			Name="Release_qt|Win32"
 			OutputDirectory="..\lib\Release"
 			IntermediateDirectory="..\obj\Release"
@@ -627,12 +581,4 @@
 				<FileConfiguration
 					Name="Release|Win32">
-					<Tool
-						Name="VCCustomBuildTool"
-						Description=""
-						CommandLine=""
-						Outputs=""/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Release_Internal|Win32">
 					<Tool
 						Name="VCCustomBuildTool"
@@ -658,5 +604,5 @@
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release_Qt|Win32">
+					Name="Release_qt|Win32">
 					<Tool
 						Name="VCCustomBuildTool"
@@ -679,12 +625,4 @@
 				<FileConfiguration
 					Name="Release|Win32">
-					<Tool
-						Name="VCCustomBuildTool"
-						Description=""
-						CommandLine=""
-						Outputs=""/>
-				</FileConfiguration>
-				<FileConfiguration
-					Name="Release_Internal|Win32">
 					<Tool
 						Name="VCCustomBuildTool"
@@ -710,5 +648,5 @@
 				</FileConfiguration>
 				<FileConfiguration
-					Name="Release_Qt|Win32">
+					Name="Release_qt|Win32">
 					<Tool
 						Name="VCCustomBuildTool"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2347)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2353)
@@ -318,7 +318,5 @@
 						const bool useMailboxing = true);
 
-#ifdef USE_SSE
 	int CastLineSegment(RayPacket &packet);
-#endif
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2347)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2353)
@@ -1128,31 +1128,75 @@
 	int CompressObjects(VspLeaf *leaf);
 
+	int TraverseRayPacket(RayPacket &rp, const bool useMailboxing);
 
 #ifdef USE_SSE
 	struct PacketTraversalData
 	{
+		PacketTraversalData () {}
+	
+		PacketTraversalData (VspNode *n, 
+			                 const __m128 &px, const __m128 &py, const __m128 &pz, 
+							 const __m128 &maxt,
+							 const __m128 &mask):
+		mNode(n), 
+		mExitPointX4(px), mExitPointY4(py), mExitPointZ4(pz),
+		mMaxT4(maxt),
+		mMask4(mask)
+		{}
+
 		VspNode *mNode;
 
-		union { float mExitPointX[4]; __m128 mExitPointX4; };
-		union { float mExitPointY[4]; __m128 mExitPointY4; };
-		union { float mExitPointZ[4]; __m128 mExitPointZ4; };
-
-		union { float mMaxT[4]; __m128 mMaxT4; };
-		union { float mMask[4]; __m128 mMask4; };
-
-		PacketTraversalData () {}
-		PacketTraversalData (VspNode *n, 
-			const __m128 &px, const __m128 &py, const __m128 &pz, 
-			const __m128 &maxt,
-			const __m128 &mask):
-		mNode(n), 
-			mExitPointX4(px), mExitPointY4(py), mExitPointZ4(pz),
-			mMaxT4(maxt),
-			mMask4(mask)
-		{}
+		union { __m128 mExitPointX4; float mExitPointX[4]; };
+		union { __m128 mExitPointY4; float mExitPointY[4]; };
+		union { __m128 mExitPointZ4; float mExitPointZ[4]; };
+
+		union { __m128 mMaxT4; float mMaxT[4]; };
+		union { __m128 mMask4; float mMask[4]; };
 	};
 
 
-	int TraverseRayPacket(RayPacket &rp, const bool useMailboxing);
+	struct __declspec(align(16)) PacketTraversalStack
+	{
+		// for performance
+		friend class VspTree;
+
+	public:
+		PacketTraversalStack(const int depth):
+		mStackPtr(0), 
+		//mDepth(depth)
+		mDepth(1000)
+		{
+			//mData = new PacketTraversalData[mDepth];
+		}
+
+		~PacketTraversalStack()
+		{
+			//delete [] mData;
+		}
+		
+		//PacketTraversalStack() {}
+
+		void Pop() {-- mStackPtr;}
+		const PacketTraversalData &Top() const { return mData[mStackPtr - 1];}
+		
+		void Push(const PacketTraversalData &tData) 
+		{
+			// note: faster with direct assignments
+			mData[mStackPtr ++] = tData;
+			//if (mStackPtr == mDepth) std::cerr << "this can never happen!!" << std::endl;
+		}
+
+		bool Empty() const {return mStackPtr <= 0;}
+
+	protected:
+
+		// static array to avoid using operator new
+		//PacketTraversalData *mData;
+		PacketTraversalData mData[1000];
+
+		int mStackPtr;
+		int mDepth;
+
+	};
 
 #endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2351)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2353)
@@ -6652,4 +6652,5 @@
 	stream << "</ViewCells>" << endl;
 
+
 	//////////////////////
 	//-- export the view space hierarchy
@@ -6808,6 +6809,4 @@
 }
 
-
-#if 1
 
 void VspOspViewCellsManager::EvalViewCellPartition()
@@ -6898,41 +6897,4 @@
 			Debug << "statistics computed in " << timeDiff * 1e-3 << " secs" << endl;
 
-#if 0
-			//////////////
-			// filtered stats
-
-			sprintf(suffix, "-%09d-eval-filter.log", castSamples);
-			const string filename2 = string(statsPrefix) + string(suffix);
-
-			startTime = GetTime();
-			
-			cout << "compute new statistics for filtered pvs ... " << endl;
-
-			ofstream ofstr2(filename2.c_str());
-			mHierarchyManager->EvaluateSubdivision2(ofstr2, splitsStepSize, true);
-
-			timeDiff = TimeDiff(startTime, GetTime());
-			cout << "finished in " << timeDiff * 1e-3 << " secs" << endl;
-			cout << "*************************************" << endl;
-			Debug << "filtered statistics computed in " << timeDiff * 1e-3 << " secs" << endl;
-#endif
-
-			// only for debugging purpose
-			if (0)
-			{
-				ViewCellContainer viewCells;
-				mViewCellsTree->CollectLeaves(mViewCellsTree->GetRoot(), viewCells);
-
-				ViewCellContainer::const_iterator vit, vit_end = viewCells.end();
-				int pvsSize = 0;
-
-				for (vit = viewCells.begin(); vit != vit_end; ++ vit)
-				{
-					pvsSize += (*vit)->GetPvs().GetSize();
-				}
-
-				cout << "debug entries: " << pvsSize << ", memcost: " 
-					 << (float)pvsSize * ObjectPvs::GetEntrySize() << endl;
-			}
 			++ pass;
 		}
@@ -6959,24 +6921,21 @@
 
 		//for (int pass = histoStepSize; pass <= numLeaves; pass += histoStepSize)
-		if (1)
-		{
-			string filename;
-
-			cout << "computing histogram for " << pass << " view cells" << endl;
-
-			//////////////////////////////////////////
-            //-- evaluate histogram for pvs size
-
-			cout << "computing pvs histogram for " << pass << " view cells" << endl;
-
-			sprintf(str, "-%09d-histo-pvs2.log", pass);
-			filename = string(statsPrefix) + string(str);
-
-			EvalViewCellHistogramForPvsSize(filename, pass);
-		}
-	}
-}
-
-#endif
+
+		string filename;
+
+		cout << "computing histogram for " << pass << " view cells" << endl;
+
+		/////////////////////////////
+		//-- evaluate histogram for pvs size
+
+		cout << "computing pvs histogram for " << pass << " view cells" << endl;
+
+		sprintf(str, "-%09d-histo-pvs2.log", pass);
+		filename = string(statsPrefix) + string(str);
+
+		EvalViewCellHistogramForPvsSize(filename, pass);
+	}
+}
+
 
 void VspOspViewCellsManager::FinalizeViewCells(const bool createMesh)
@@ -6993,53 +6952,47 @@
 
 #if TEST_PACKETS
-#ifdef USE_SSE
-
-float ViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays,
-												   const bool addContributions,
-												   const bool storeViewCells,
-												   const bool useHitObjects)
-{
+
+float VspOspViewCellsManager::ComputeSampleContributions(const VssRayContainer &rays,
+														 const bool addContributions,
+														 const bool storeViewCells,
+														 const bool useHitObjects)
+{
+	if (!ViewCellsConstructed()) 
+		return 0;
+	
 	float sum = 0.0f;
-
 	VssRayContainer::const_iterator it, it_end = rays.end();
 
 	VssRayContainer tmpRays;	
-	RayPacket packet;
 
 	for (it = rays.begin(); it != it_end; ++ it) 
 	{
-		if (!ViewCellsConstructed()) 
-		{
-			// view cells not yet constructed
-			// just take the lenghts of the rays as contributions
-			if ((*it)->mTerminationObject)
+		sum += ComputeSampleContribution(*(*it), addContributions, storeViewCells, useHitObjects);
+
+		tmpRays.push_back(new VssRay(*(*it)));
+		
+		if (tmpRays.size() == 4)
+		{
+			// cast packets of 4 rays
+			RayPacket packet(tmpRays);
+			mHierarchyManager->CastLineSegment(packet);
+		
+			for (int i = 0; i < 4; ++ i)
 			{
-				sum += (*it)->Length();
+				ComputeSampleContribution(*tmpRays[i], addContributions, true, useHitObjects);
+
+				//////////
+				// compare results
+
+				cout << "ray " << i << ": " << (int)tmpRays[i]->mViewCells.size() << " " << (int)packet.mViewCells[i].size() << endl;
 			}
-		} 
-		else 
-		{
-			sum += ComputeSampleContribution(*(*it), addContributions, storeViewCells, useHitObjects);
-
-			tmpRays.push_back(new VssRay(*it));
+
 			
-			if (tmpRays.size() == 4)
-			{
-				// cast packets of 4 rays
-				RayPacket packet(tmpRays);
-				mHierarchyManager->CastLineSegment(packet);
-
-				for (int i = 0; i < 4; ++ i)
-				{
-					ComputeSampleContribution(tmpRays[i], addContributions, true, useHitObjects);
-				}
-
-				// compare results
-				//////////
-
-				CLEAR_CONTAINER(tmpRays);
-			}
-		}
-	}
+			
+			CLEAR_CONTAINER(tmpRays);
+		}
+	}
+cout << "=================\nhere6"<<endl;
+	CLEAR_CONTAINER(tmpRays);
 
 	cout << "view cell cast time: " << viewCellCastTimer.TotalTime() << " s" << endl;
@@ -7053,5 +7006,5 @@
 
 #endif
-#endif
-
-}
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2351)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2353)
@@ -1623,6 +1623,5 @@
 
 	const float oldRenderCost = penaltyOld * pOverall;
-	const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront + 
-								sc.mCorrectedBackRenderCost * pBack;
+	const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront + sc.mCorrectedBackRenderCost * pBack;
 
 
@@ -1634,5 +1633,6 @@
 
 #if GTP_DEBUG
-	Debug << "old: " << normalizedOldRenderCost << " new: " << newRenderCost / viewSpaceVol << " corr: " << tData.mCorrectedRenderCost << " ratio: " << oldRenderCostRatio << endl;
+	Debug << "old: " << normalizedOldRenderCost << " new: " << newRenderCost / viewSpaceVol 
+		  << " corr: " << tData.mCorrectedRenderCost << " ratio: " << oldRenderCostRatio << endl;
 #endif
 
@@ -2425,4 +2425,5 @@
 			tStack.push(LineTraversalData(farChild, extp, maxt)); //TODO
 
+			// new exit point for near child
 			extp = origin + dir * tdist;
 			maxt = tdist;
@@ -2453,4 +2454,5 @@
 				break;
 
+			// set new entry point for far child
 			entp = extp;
 			mint = maxt;
@@ -2469,8 +2471,7 @@
 
 
+int VspTree::TraverseRayPacket(RayPacket &rp, const bool useMailboxing)
+{
 #ifdef USE_SSE
-int VspTree::TraverseRayPacket(RayPacket &rp,
-							   const bool useMailboxing)
-{
 	int hits = 0;
 
@@ -2479,20 +2480,14 @@
 	float zero = 0.0f;
 
-	__m128 one4 = _mm_load_ps(&one);
-	__m128 zero4 = _mm_load_ps(&zero);
-
-	__m128 *entp4;
-	__m128 *extp4;
-
-	union { float mask[4]; __m128 mask4; };
+	__m128 one4 = _mm_load1_ps(&one);
+	__m128 zero4 = _mm_load1_ps(&zero);
+
+	union { __m128 mask4; float mask[4];};
+	union { __m128 mask4_2; float mask_2[4];};
+
 	mask4 = one4;
 
-	__m128 entpX4 = rp.mOriginX4;
-	__m128 entpY4 = rp.mOriginY4;
-	__m128 entpZ4 = rp.mOriginZ4;
-	
-	__m128 extpX4 = rp.mTerminationX4;
-	__m128 extpY4 = rp.mTerminationY4;
-	__m128 extpZ4 = rp.mTerminationZ4;
+	__declspec(align(16)) __m128 entp4[] = {rp.mOriginX4, rp.mOriginY4, rp.mOriginZ4};
+	__declspec(align(16)) __m128 extp4[] = {rp.mTerminationX4, rp.mTerminationY4, rp.mTerminationZ4};
 
 	__m128 *origin = &rp.mOriginX4;
@@ -2511,6 +2506,5 @@
 	__m128 minT4 = zero4;
 
-	stack<PacketTraversalData *> tStack;
-
+	PacketTraversalStack tStack(1000);
 
 	VspNode *node = mRoot;
@@ -2527,12 +2521,9 @@
 		{
 			VspInterior *in = static_cast<VspInterior *>(node);
-			
-			entp4 = &entpX4;
-			extp4 = &extpX4;
-
+		
 			position = in->GetPosition();
 			axis = in->GetAxis();
 
-			position4 = _mm_load_ps(&position);
+			position4 = _mm_load1_ps(&position);
 
 			// are the entry points all in near leaf?
@@ -2540,5 +2531,5 @@
 			{
 				// are the exit points all in near leaf?
-				if (_mm_movemask_ps(_mm_and_ps(_mm_cmpgt_ps(extp4[axis], position4), mask4)))
+				if (_mm_movemask_ps(_mm_and_ps(_mm_cmple_ps(extp4[axis], position4), mask4)))
 				{
 					node = in->GetBack();
@@ -2555,5 +2546,6 @@
 			else
 			{
-				if (_mm_movemask_ps(_mm_and_ps(_mm_cmpgt_ps(position4, extp4[axis]), mask4)))
+				if (_mm_movemask_ps(_mm_and_ps(_mm_cmple_ps(position4, entp4[axis]), mask4)) &&
+					_mm_movemask_ps(_mm_and_ps(_mm_cmple_ps(position4, extp4[axis]), mask4)))
 				{
 					node = in->GetFront();
@@ -2573,15 +2565,16 @@
 			const __m128 tDist4 = _mm_mul_ps(_mm_sub_ps(position4, origin[axis]), termination[axis]);
 			
+			mask4 = _mm_and_ps(_mm_cmplt_ps(tDist4, minT4), mask4);
+            mask4_2 = _mm_and_ps(_mm_cmpgt_ps(tDist4, minT4), mask4);
+
 			// push far child for further processing
-			tStack.push(new PacketTraversalData(farChild, extpX4, extpY4, extpZ4, maxT4, mask4));
+			tStack.Push(PacketTraversalData(farChild, extp4[0], extp4[1], extp4[2], maxT4, mask4_2));
 
 			// compute new exit point
-			extpX4 = _mm_add_ps(_mm_mul_ps(dirX4, tDist4), rp.mOriginX4);
-			extpY4 = _mm_add_ps(_mm_mul_ps(dirY4, tDist4), rp.mOriginY4);
-			extpZ4 = _mm_add_ps(_mm_mul_ps(dirZ4, tDist4), rp.mOriginZ4);
+			extp4[0] = _mm_add_ps(_mm_mul_ps(dirX4, tDist4), rp.mOriginX4);
+			extp4[1] = _mm_add_ps(_mm_mul_ps(dirY4, tDist4), rp.mOriginY4);
+			extp4[2] = _mm_add_ps(_mm_mul_ps(dirZ4, tDist4), rp.mOriginZ4);
 
 			maxT4 = tDist4;
-
-			mask4 = _mm_cmplt_ps( maxT4, minT4);
 		}
 		else
@@ -2602,4 +2595,5 @@
 				for (int i = 0; i < 4; ++i)
 				{
+					// push view cells for all valid rays
 					if (mask[i]) 
 						rp.mViewCells[i].push_back(viewCell);
@@ -2610,76 +2604,35 @@
 
 			// get the next node from the stack
-			if (tStack.empty())
+			if (tStack.Empty())
 				break;
-
-			entpX4 = extpX4;
-			entpY4 = extpY4;
-			entpZ4 = extpZ4;
+			
+			// use memcopy?
+			entp4[0] = extp4[0];
+			entp4[1] = extp4[1];
+			entp4[2] = extp4[2];
 
 			minT4 = maxT4;
+
+			const PacketTraversalData &s = tStack.Top();
+			node = s.mNode;
 			
-			PacketTraversalData *s  = tStack.top();
-			node = s->mNode;
+			extp4[0] = s.mExitPointX4;
+			extp4[1] = s.mExitPointY4;
+			extp4[2] = s.mExitPointZ4;
+
+			maxT4 = s.mMaxT4;
+			mask4 = s.mMask4;
 			
-			extpX4 = s->mExitPointX4;
-			extpY4 = s->mExitPointY4;
-			extpZ4 = s->mExitPointZ4;
-
-			maxT4 = s->mMaxT4;
-
-			mask4 = s->mMask4;
-
-			tStack.pop();
-			delete s;
-		}
-	}
-
+			tStack.Pop();
+		}
+	}
+	
 	return hits;
 
-/*
-	const int offs[4] = {(rp.dx[0] >= 0) ? 1 : 0,  (rp.dy[0] >= 0)? 1 : 0,  (rp.dz[0] >= 0)? 1 : 0, 0};
-
-	while (!node->IsLeaf())
-	{
-		PacketTraversalData *tData = tStack.top();
-		tStack.pop();
-
-		node = tData->node;
-		VspInterior *interior = static_cast<VspInterior *>(node);
-		tn4 = tData->tn4;
-		tf4 = tData->tf4;
-		mask = tData->mask4;
-
-		position = interior->GetPosition();
-		const __m128 position4 = _mm_load_ps(&pos);
-
-		const int axis = interior->GetAxis();
-		const __m128 d4 = _mm_mul_ps(_mm_sub_ps(splitPos, origin[axis]), termination[axis]);
-
-		VspNode* ln = offs[axis] ? interior->GetFront() : interior->GetBack();
-
-		if (!_mm_movemask_ps(_mm_and_ps(_mm_cmpgt_ps(d4, tn4), mask)))
-		{ 
-			node = ln; 
-			continue; 
-		}
-
-		node = offs[axis]^1 ? interior->GetFront() : interior->GetBack();// + (offs[aidx]^1);
-
-		if (_mm_movemask_ps( _mm_and_ps( _mm_cmplt_ps(d4, tf4), mask)))
-		{
-			const __m128 mask2 = _mm_cmpgt_ps(d4, tn4);
-			const __m128 mask3 = _mm_cmplt_ps(d4, tf4);
-
-
-			tData->tf4 = tf4 = _mm_or_ps(_mm_and_ps(mask3, d4), _mm_andnot_ps( mask3, tf4));
-			tData->node = (VspNode *)ln;
-			tData->mask4 = mask;
-			tData->tn4 = _mm_or_ps( _mm_and_ps( mask2, d4 ), _mm_andnot_ps( mask2, tn4 ) );
-			mask = _mm_cmplt_ps( tn4, tf4 );
-		}
-	}*/
-}
+#else
+
+	return 0;
 #endif
+}
 
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 2342)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 2353)
@@ -22,21 +22,4 @@
 #define VSS_STORE_VIEWCELLS 1
 
-#ifdef USE_SSE
-
-struct RayPacket
-{
-	union { float mOriginX[4]; __m128 mOriginX4; };
-	union { float mOriginY[4]; __m128 mOriginY4; };
-	union { float mOriginZ[4]; __m128 mOriginZ4; };
-
-	union { float mTerminationX[4]; __m128 mTerminationX4; };
-	union { float mTerminationY[4]; __m128 mTerminationY4; };
-	union { float mTerminationZ[4]; __m128 mTerminationZ4; };
-
-	ViewCellContainer mViewCells[4];
-};
-
-
-#endif
 
 
@@ -345,28 +328,44 @@
   void PrintStatistics(std::ostream &s);
   int SelectRays(const int number, VssRayContainer &selected, const bool copy=false) const;
-  int
-  GetContributingRays(VssRayContainer &selected,
-					  const int minPass
-					  ) const;
-  
-};
-
-/*
-struct VssRayDistribution {
-  VssRayDistribution() { mContribution = -1.0f; }
-  SimpleRayContainer mRays;
-  vector<VssRayContainer> mVssRays;
-  float mContribution;
-  float mTime;
-};
-
-struct VssRayDistributionMixture {
-  VssRayDistributionMixture() {}
-  
-  vector<VssRayDistribution> distributions;
-};
-*/
-
-};
-
-#endif
+  int GetContributingRays(VssRayContainer &selected, const int minPass) const;
+  
+};
+
+
+struct RayPacket
+{
+	RayPacket(const VssRayContainer &rays)
+	{
+		for (int i = 0; i < 4; ++ i)
+			mOriginX[i] = rays[i]->mOrigin[0];
+
+		for (int i = 0; i < 4; ++ i)
+			mOriginY[i] = rays[i]->mOrigin[1];
+
+		for (int i = 0; i < 4; ++ i)
+			mOriginZ[i] = rays[i]->mOrigin[2];
+	}
+#ifdef USE_SSE	
+	union { float mOriginX[4]; __m128 mOriginX4; };
+	union { float mOriginY[4]; __m128 mOriginY4; };
+	union { float mOriginZ[4]; __m128 mOriginZ4; };
+
+	union { float mTerminationX[4]; __m128 mTerminationX4; };
+	union { float mTerminationY[4]; __m128 mTerminationY4; };
+	union { float mTerminationZ[4]; __m128 mTerminationZ4; };
+#else
+	float mOriginX[4];
+	float mOriginY[4];
+	float mOriginZ[4];
+
+	float mTerminationX[4];
+	float mTerminationY[4];
+	float mTerminationZ[4];
+#endif
+	ViewCellContainer mViewCells[4];
+};
+
+
+};
+
+#endif
Index: GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 2353)
@@ -184,5 +184,5 @@
 	}
 #endif
-	
+
 	Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
 	MeshKdTree::ParseEnvironment();
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2342)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2353)
@@ -285,5 +285,7 @@
 
 	// split was not reevaluated before => do it now
-	if (splitCandidate->IsDirty())
+	// matt: for new evaluation method, we cannot be sure if the candidate is dirty,
+	// so ALWAYS reevaluate
+	if (1 || splitCandidate->IsDirty())
 	{
 		splitCandidate->EvalCandidate();
@@ -2509,5 +2511,5 @@
 }
 
-#ifdef USE_SSE
+
 int HierarchyManager::CastLineSegment(RayPacket &packet)
 {
@@ -2515,5 +2517,4 @@
 }
 
-#endif
-
-}
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2227)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2353)
@@ -496,61 +496,113 @@
 }
 
-  // add contributions of the sample to the strategies
+
+#if TEST_PACKETS
+
+// add contributions of the sample to the strategies
+void MixtureDistribution::ComputeContributions(VssRayContainer &vssRays)
+{
+	int i;
+
+	mPreprocessor.mViewCellsManager->ComputeSampleContributions(vssRays, true, false);
+
+	VssRayContainer::iterator it = vssRays.begin();
+
+	for (i=0; i < mDistributions.size(); i++) {
+		mDistributions[i]->mContribution = 0;
+		mDistributions[i]->mRays = 0;
+	}
+
+	for(; it != vssRays.end(); ++ it) 
+	{
+		VssRay *ray = *it;
+
+		for (i = 0; i < mDistributions.size() - 1; ++ i) 
+		{
+			if (mDistributions[i]->mType == ray->mDistribution)
+				break;
+		}
+
+		float contribution =
+			mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray, true, false);
+
+		mDistributions[i]->mContribution += contribution;
+		mDistributions[i]->mRays ++;
+
+		mDistributions[i]->mTotalContribution += contribution;
+		mDistributions[i]->mTotalRays ++;
+	}
+
+	UpdateRatios();
+
+
+	const float vcTime = viewCellCastTimer.TotalTime();
+	const float pvsTime = pvsTimer.TotalTime();
+	const float haltonTime = haltonTimer.TotalTime();
+
+	cout << "view cell cast time: " << vcTime << " s" << endl;
+	cout << "pvs time: " << pvsTime << " s" << endl;
+	cout << "halton time: "<< haltonTime << " s" << endl;
+
+	Debug << "view cell cast time: " << vcTime << " s" << endl;
+	Debug << "pvs time: " << pvsTime << " s" << endl;
+	Debug << "halton time: "<< haltonTime << " s" << endl;
+}
+
+
+#else
+
+// add contributions of the sample to the strategies
 void
 MixtureDistribution::ComputeContributions(VssRayContainer &vssRays)
 {
-  int i;
-  
-  VssRayContainer::iterator it = vssRays.begin();
-
-  for (i=0; i < mDistributions.size(); i++) {
-	mDistributions[i]->mContribution = 0;
-	mDistributions[i]->mRays = 0;
-  }
-
-  for(; it != vssRays.end(); ++it) {
-	VssRay *ray = *it;
-	for (i=0; i < mDistributions.size()-1; i++) {
-	  if (mDistributions[i]->mType == ray->mDistribution)
-		break;
-	}
- 
-	float contribution =
-	  mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray,
-																 true,
-																 false);
-
-	mDistributions[i]->mContribution += contribution;
-	mDistributions[i]->mRays ++;
-	
-	mDistributions[i]->mTotalContribution += contribution;
-	mDistributions[i]->mTotalRays ++;
-  }
-
-#if 0
-  pvsTimer.Entry();
-  // resort pvss
-  mPreprocessor.mViewCellsManager->SortViewCellPvs();
-  pvsTimer.Exit();
+	int i;
+
+	VssRayContainer::iterator it = vssRays.begin();
+
+	for (i=0; i < mDistributions.size(); i++) {
+		mDistributions[i]->mContribution = 0;
+		mDistributions[i]->mRays = 0;
+	}
+
+	for(; it != vssRays.end(); ++it) {
+		VssRay *ray = *it;
+		for (i=0; i < mDistributions.size()-1; i++) {
+			if (mDistributions[i]->mType == ray->mDistribution)
+				break;
+		}
+
+		float contribution =
+			mPreprocessor.mViewCellsManager->ComputeSampleContribution(*ray,
+			true,
+			false);
+
+		mDistributions[i]->mContribution += contribution;
+		mDistributions[i]->mRays ++;
+
+		mDistributions[i]->mTotalContribution += contribution;
+		mDistributions[i]->mTotalRays ++;
+	}
+
+	UpdateRatios();
+
+
+  if (1)
+  {
+	  const float vcTime = viewCellCastTimer.TotalTime();
+	  const float pvsTime = pvsTimer.TotalTime();
+	  const float haltonTime = haltonTimer.TotalTime();
+
+	  cout << "view cell cast time: " << vcTime << " s" << endl;
+	  cout << "pvs time: " << pvsTime << " s" << endl;
+	  cout << "halton time: "<< haltonTime << " s" << endl;
+
+	  Debug << "view cell cast time: " << vcTime << " s" << endl;
+	  Debug << "pvs time: " << pvsTime << " s" << endl;
+	  Debug << "halton time: "<< haltonTime << " s" << endl;
+  }
+}
+
 #endif
 
-  
-  UpdateRatios();
-
-#if 1
-  const float vcTime = viewCellCastTimer.TotalTime();
-  const float pvsTime = pvsTimer.TotalTime();
-  const float haltonTime = haltonTimer.TotalTime();
-
-  cout << "view cell cast time: " << vcTime << " s" << endl;
-  cout << "pvs time: " << pvsTime << " s" << endl;
-  cout << "halton time: "<< haltonTime << " s" << endl;
-  // cout<<"obj time:"<<objTimer.TotalTime()<<" s"<<endl;
-
-  Debug << "view cell cast time: " << vcTime << " s" << endl;
-  Debug << "pvs time: " << pvsTime << " s" << endl;
-  Debug << "halton time: "<< haltonTime << " s" << endl;
-#endif
-}
 
 void
