Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2342)
@@ -229,5 +229,5 @@
 				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"
-				GenerateDebugInformation="TRUE"
+				GenerateDebugInformation="FALSE"
 				SubSystem="1"
 				OptimizeReferences="2"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2307)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2342)
@@ -229,5 +229,5 @@
 
 
-bool Preprocessor::ExportBinaryObj(const string filename, SceneGraphNode *root)
+bool Preprocessor::ExportBinaryObj(const string &filename, SceneGraphNode *root)
 {
 	ogzstream samplesOut(filename.c_str());
@@ -266,5 +266,5 @@
 
 
-bool Preprocessor::ExportObj(const string filename, const ObjectContainer &objects)
+bool Preprocessor::ExportObj(const string &filename, const ObjectContainer &objects)
 {
 	ofstream samplesOut(filename.c_str());
@@ -320,5 +320,5 @@
 }
 
-static string ReplaceSuffix(string filename, string a, string b)
+static string ReplaceSuffix(const string &filename, string a, string b)
 {
 	string result = filename;
@@ -381,5 +381,5 @@
 
 bool
-Preprocessor::LoadScene(const string filename)
+Preprocessor::LoadScene(const string &filename)
 {
     // use leaf nodes of the original spatial hierarchy as occludees
@@ -533,5 +533,5 @@
 
 bool
-Preprocessor::ExportPreprocessedData(const string filename)
+Preprocessor::ExportPreprocessedData(const string &filename)
 {
 	mViewCellsManager->ExportViewCells(filename, true, mObjects);
@@ -605,5 +605,5 @@
 
 bool
-Preprocessor::Export( const string filename,
+Preprocessor::Export( const string &filename,
 					  const bool scene,
 					  const bool kdtree
@@ -813,5 +813,5 @@
 
 
-bool Preprocessor::LoadKdTree(const string filename)
+bool Preprocessor::LoadKdTree(const string &filename)
 {
 	mKdTree = new KdTree();
@@ -821,5 +821,5 @@
 
 
-bool Preprocessor::ExportKdTree(const string filename)
+bool Preprocessor::ExportKdTree(const string &filename)
 {
 	return mKdTree->ExportBinTree(filename.c_str());
@@ -1034,49 +1034,49 @@
 
 
-bool Preprocessor::LoadInternKdTree( const string internKdTree)
-{
-  bool mUseKdTree = true;
-  
-  if (!mUseKdTree) {
-	// create just a dummy KdTree
-	mKdTree = new KdTree;
+bool Preprocessor::LoadInternKdTree(const string &internKdTree)
+{
+	bool mUseKdTree = true;
+
+	if (!mUseKdTree) {
+		// create just a dummy KdTree
+		mKdTree = new KdTree;
+		return true;
+	}
+
+	// always try to load the kd tree
+	cout << "loading kd tree file " << internKdTree << " ... " << endl;
+
+	if (!LoadKdTree(internKdTree)) {
+		cout << "error loading kd tree with filename " 
+			<< internKdTree << ", rebuilding it instead ... " << endl;
+		// build new kd tree from scene geometry
+		BuildKdTree();
+
+		// export kd tree?
+		const long startTime = GetTime();
+		cout << "exporting kd tree ... ";
+
+		if (!ExportKdTree(internKdTree))
+		{
+			cout << " error exporting kd tree with filename " 
+				<< internKdTree << endl;
+		}
+		else
+		{
+			cout << "finished in " 
+				<< TimeDiff(startTime, GetTime()) * 1e-3 
+				<< " secs" << endl;
+		}
+	}
+
+	KdTreeStatistics(cout);
+	cout << mKdTree->GetBox() << endl;
+
 	return true;
-  }
-  
-  // always try to load the kd tree
-  cout << "loading kd tree file " << internKdTree << " ... " << endl;
-  
-  if (!LoadKdTree(internKdTree)) {
-	cout << "error loading kd tree with filename " 
-		 << internKdTree << ", rebuilding it instead ... " << endl;
-	// build new kd tree from scene geometry
-	BuildKdTree();
-	
-	// export kd tree?
-	const long startTime = GetTime();
-	cout << "exporting kd tree ... ";
-	
-	if (!ExportKdTree(internKdTree))
-	  {
-		cout << " error exporting kd tree with filename " 
-			 << internKdTree << endl;
-	  }
-	else
-	  {
-		cout << "finished in " 
-			 << TimeDiff(startTime, GetTime()) * 1e-3 
-			 << " secs" << endl;
-	  }
-  }
-  
-  KdTreeStatistics(cout);
-  cout << mKdTree->GetBox() << endl;
-  
-  return true;
-}
-
-
-bool Preprocessor::InitRayCast(const string externKdTree, 
-							   const string internKdTree)
+}
+
+
+bool Preprocessor::InitRayCast(const string &externKdTree, 
+							   const string &internKdTree)
 {
 	// always try to load the kd tree
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2342)
@@ -106,5 +106,4 @@
 				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
 		</Configuration>
-	
 		<Configuration
 			Name="Release_Internal|Win32"
@@ -454,7 +453,4 @@
 			</File>
 			<File
-				RelativePath=".\HashPvs2.h">
-			</File>
-			<File
 				RelativePath=".\HierarchyManager.cpp">
 			</File>
@@ -637,5 +633,4 @@
 						Outputs=""/>
 				</FileConfiguration>
-			
 				<FileConfiguration
 					Name="Release_Internal|Win32">
@@ -690,5 +685,4 @@
 						Outputs=""/>
 				</FileConfiguration>
-				
 				<FileConfiguration
 					Name="Release_Internal|Win32">
@@ -1109,8 +1103,8 @@
 			</File>
 			<File
+				RelativePath=".\sparsehash\src\windows\hash_fun.h">
+			</File>
+			<File
 				RelativePath=".\sparsehash\src\google\sparsehash\hash_fun.h">
-			</File>
-			<File
-				RelativePath=".\sparsehash\src\windows\hash_fun.h">
 			</File>
 			<File
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2342)
@@ -321,5 +321,10 @@
 						ViewCellContainer &viewcells,
 						const bool useMailboxing = true);
-	
+
+#ifdef USE_SSE
+	int CastLineSegment(RayPacket &packet);
+#endif
+
+
 protected:
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2187)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2342)
@@ -9,7 +9,8 @@
 #include "SimpleRay.h"
 
+
 namespace GtpVisibilityPreprocessor {
-  class PreprocessorThread;
-  
+
+class PreprocessorThread;  
 class RenderSimulator;
 class SceneGraph;
@@ -60,5 +61,5 @@
 		@return true on success
 	*/
-	virtual bool LoadScene(const string filename);
+	virtual bool LoadScene(const string &filename);
 
 	/** Export all preprocessed data in a XML format understandable by the
@@ -67,5 +68,5 @@
 		@return true on successful export
 	*/
-	virtual bool ExportPreprocessedData(const string filename);
+	virtual bool ExportPreprocessedData(const string &filename);
 
 	/** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
@@ -102,5 +103,5 @@
 	/** Export preprocessor data.
 	*/
-	bool Export(const string filename, const bool scene, const bool kdtree);  
+	bool Export(const string &filename, const bool scene, const bool kdtree);  
 
 	virtual void KdTreeStatistics(ostream &s);
@@ -119,6 +120,6 @@
 	bool ExportSamples(const VssRayContainer &samples) const;
 
-	bool LoadKdTree(const string filename);
-	bool ExportKdTree(const string filename);
+	bool LoadKdTree(const string &filename);
+	bool ExportKdTree(const string &filename);
 
 	virtual bool
@@ -150,11 +151,11 @@
 						  const bool pruneInvalidRays = true);
 
-  virtual void
-  CastRaysWithHwGlobalLines(
-							SimpleRayContainer &rays,
-							VssRayContainer &vssRays,
-							const bool castDoubleRays,
-							const bool pruneInvalidRays
-							);
+	virtual void
+		CastRaysWithHwGlobalLines(
+		SimpleRayContainer &rays,
+		VssRayContainer &vssRays,
+		const bool castDoubleRays,
+		const bool pruneInvalidRays
+		);
 
 	/** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
@@ -168,9 +169,9 @@
 	GlRendererBuffer *GetRenderer();
 
-	bool InitRayCast(const string externKdTree, const string internKdTree);
-
-	bool LoadInternKdTree(const string internKdTree);
-
-	bool ExportObj(const string filename, const ObjectContainer &objects);
+	bool InitRayCast(const string &externKdTree, const string &internKdTree);
+
+	bool LoadInternKdTree(const string &internKdTree);
+
+	bool ExportObj(const string &filename, const ObjectContainer &objects);
 
 	Intersectable *GetParentObject(const int index) const;
@@ -192,8 +193,9 @@
 
 	static bool LoadObjects(const string &filename,
-							ObjectContainer &pvsObjects, 
+		                    ObjectContainer &pvsObjects, 
 							const ObjectContainer &preprocessorObject);
 
-	////////////////////////////////////////////////
+
+	/////////////////////////
 
 	/// scene graph loaded from file
@@ -223,5 +225,5 @@
 	bool mUseGlRenderer;
 	bool mUseGlDebugger;
-	
+
 	bool mUseHwGlobalLines;
 	bool mLoadViewCells;
@@ -242,7 +244,7 @@
 
 	int mPass;
- 
+
 	bool mStopComputation;
-  
+
 	bool mExportObj;
 
@@ -254,5 +256,5 @@
 
 	GlRendererBuffer *renderer;
-  
+
 	int mTotalSamples;
 	int mTotalTime;
@@ -260,5 +262,5 @@
 	int mSamplesPerEvaluation;
 
-  	RayCaster *mRayCaster;
+	RayCaster *mRayCaster;
 
 
@@ -266,8 +268,8 @@
 
 	bool LoadBinaryObj(const std::string &filename,
-					   SceneGraphNode *root,
+                       SceneGraphNode *root,
 					   std::vector<FaceParentInfo> *parents);
 
-	bool ExportBinaryObj(const std::string filename, SceneGraphNode *root);
+	bool ExportBinaryObj(const std::string &filename, SceneGraphNode *root);
 
 	void SetupRay(Ray &ray, const Vector3 &point, const Vector3 &direction) const;
@@ -276,4 +278,5 @@
 
 	virtual void EvalViewCellHistogram();
+
 
 	/////////////////////////
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2342)
@@ -14,8 +14,8 @@
 #include "Timer/PerfTimer.h"
 
+
 #ifdef USE_SSE
 #include <xmmintrin.h>
 #endif
-
 
 
@@ -797,7 +797,7 @@
 	float EvalRenderCostDecrease(VspSubdivisionCandidate &splitData, 
 								 float &normalizedOldRenderCost,
-								 const float totalPvs,
-								 const float pvsFront,
-								 const float pvsBack) const;
+								 const float totalRenderCost,
+								 const float frontRenderCost,
+								 const float backRenderCost) const;
 
 	/** Collects view cells in the subtree under root.
@@ -1113,19 +1113,6 @@
 	int CompressObjects(VspLeaf *leaf);
 
+
 #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];
-	};
-
 	struct PacketTraversalData
 	{
@@ -1141,19 +1128,19 @@
 		PacketTraversalData () {}
 		PacketTraversalData (VspNode *n, 
-							 const __m128 &px, const __m128 &py, const __m128 &pz, 
-							 const __m128 &maxt,
-							 const __m128 &mask):
+			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)
+			mExitPointX4(px), mExitPointY4(py), mExitPointZ4(pz),
+			mMaxT4(maxt),
+			mMask4(mask)
 		{}
 	};
 
-	
-	int TraverseRayPacket(RayPacket &rp,
-						  const bool useMailboxing);
+
+	int TraverseRayPacket(RayPacket &rp, const bool useMailboxing);
 
 #endif
+
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2342)
@@ -400,4 +400,5 @@
 	ViewCell::NewMail(3);
 
+	// mail view cells which can see front object
 	ViewCellContainer::const_iterator fit, fit_end = frontViewCells.end();
 
@@ -408,4 +409,5 @@
 	}
 
+	// mail view cells which can see back or both objects
 	ViewCellContainer::const_iterator bit, bit_end = backViewCells.end();
 
@@ -429,8 +431,9 @@
 		int vcObj;
 
-		float oldVcTri = vc->GetPvsCost();
+		float oldVcTri = vc->GetTrianglesInPvs();
 		int oldVcObj = vc->GetEntriesInPvs();
 
-		// both objects in view cell
+		// both objects seen from view cell
+		// => no reduction, but an additional pvs entry
 		if (vc->Mailed(2))
 		{
@@ -438,4 +441,6 @@
 			vcObj = oldVcObj + 1;   
 		}
+		// only back object seen from view cell 
+		// => reduction in triangles
 		else if (vc->Mailed(1))
 		{
@@ -443,5 +448,5 @@
 			vcObj = oldVcObj;   
 		}
-		else // (vc->Mailed(0))
+		else // front object
 		{
 			vcTri = oldVcTri - totalTri + frontTri; 
@@ -449,5 +454,5 @@
 		}
 
-		vc->SetPvsCost(vcTri);
+		vc->SetTrianglesInPvs(vcTri);
 		vc->SetEntriesInPvs(vcObj);
 
@@ -567,5 +572,6 @@
 	}
 
-	// compute e.g., new render cost decrease after this split
+	// compute new stats for the view cells which see this object, 
+	// e.g. new render cost decrease after the split
 	UpdateViewCells(sc);
 
@@ -870,5 +876,5 @@
 		int vcObj;
 
-		float oldVcTri = vc->GetPvsCost();
+		float oldVcTri = vc->GetTrianglesInPvs();
 		int oldVcObj = vc->GetEntriesInPvs();
 
@@ -2228,22 +2234,19 @@
 								  const bool onlyUnmailedRays)// const
 {
+	// view cells not cached
 	if (obj->GetOrCreateViewCells()->empty())
 	{
-		//cerr << "g";//CollectViewCells: view cells empty, view cells cache not working" << endl;
 		return CollectViewCellsFromRays(obj, viewCells, useMailBoxing, setCounter, onlyUnmailedRays);
 	}
-
-	mCollectTimer.Entry();
-
-	ViewCellContainer *objViewCells = obj->GetOrCreateViewCells();
 
 	///////////
 	//-- use view cells cache
 
-	// fastest way: just copy to the end
-	//if (!useMailBoxing)	viewCells.insert(viewCells.end(), objViewCells->begin(), objViewCells->end());
+	mCollectTimer.Entry();
+
+	ViewCellContainer *objViewCells = obj->GetOrCreateViewCells();
 
 	// loop through view cells
-	// matt: probably slow to insert  view cells one by one
+	// matt: probably slow to insert view cells one by one
 	ViewCellContainer::const_iterator vit, vit_end = objViewCells->end();
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2342)
@@ -169,6 +169,6 @@
 	Environment::GetSingleton()->GetFloatValue("ViewCells.objectWeight", mObjectWeight);
 
-	// mix of sampling strategies
-	if (1)
+	// choose mix of sampling strategies
+	if (0)
 	{
 		mStrategies.push_back(SamplingStrategy::SPATIAL_BOX_BASED_DISTRIBUTION);
@@ -1317,5 +1317,5 @@
 			(*it)->UpdatePvsCost();
 		else
-			(*it)->SetPvsCost((float)(*it)->GetFilteredPvsSize());
+			(*it)->SetTrianglesInPvs((float)(*it)->GetFilteredPvsSize());
 	}
 
@@ -1325,5 +1325,5 @@
 	sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs);
 
-	maxPvs = viewCells.back()->GetPvsCost();
+	maxPvs = viewCells.back()->GetTrianglesInPvs();
 	minVal = 0;
 
@@ -1369,5 +1369,5 @@
 
 		while ((i < (int)viewCells.size()) && 
-			   (viewCells[i]->GetPvsCost() < currentPvs))
+			   (viewCells[i]->GetTrianglesInPvs() < currentPvs))
 		{
 			volDif += viewCells[i]->GetVolume();
@@ -1380,5 +1380,5 @@
 		
 		//		if (0 && (i < (int)viewCells.size()))
-		//		  Debug << "new pvs cost increase: " << mViewCellsTree->GetPvsCost(viewCells[i]) 
+		//		  Debug << "new pvs cost increase: " << mViewCellsTree->GetTrianglesInPvs(viewCells[i]) 
 		//				<< " " << currentPvs << endl;
 		
@@ -1412,5 +1412,5 @@
 	sort(viewCells.begin(), viewCells.end(), ViewCell::SmallerPvs);
 
-	maxPvs = viewCells.back()->GetPvsCost();
+	maxPvs = viewCells.back()->GetTrianglesInPvs();
 	minVal = 0;
 
@@ -1456,5 +1456,5 @@
 
 		while ((i < (int)viewCells.size()) && 
-			   (viewCells[i]->GetPvsCost() < currentPvs))
+			   (viewCells[i]->GetTrianglesInPvs() < currentPvs))
 		{
 			volDif += viewCells[i]->GetVolume();
@@ -1467,5 +1467,5 @@
 		
 		//		if (0 && (i < (int)viewCells.size()))
-		//		  Debug << "new pvs cost increase: " << mViewCellsTree->GetPvsCost(viewCells[i]) 
+		//		  Debug << "new pvs cost increase: " << mViewCellsTree->GetTrianglesInPvs(viewCells[i]) 
 		//				<< " " << currentPvs << endl;
 		
@@ -2418,5 +2418,5 @@
 	  ViewCell *viewcell = *it;
 	  if (viewcell->GetValid()) {
-		  const float pvsCost = mViewCellsTree->GetPvsCost(viewcell);
+		  const float pvsCost = mViewCellsTree->GetTrianglesInPvs(viewcell);
 		  const float renderCost = pvsCost * viewcell->GetVolume() / vol;
 
@@ -2908,5 +2908,5 @@
 float ViewCellsManager::GetRendercost(ViewCell *viewCell) const
 {
-	return (float)mViewCellsTree->GetPvsCost(viewCell);
+	return (float)mViewCellsTree->GetTrianglesInPvs(viewCell);
 }
 
@@ -3603,5 +3603,5 @@
 			if (mCurrentViewCellsStats.maxPvs)
 			{
-				importance = (float)mViewCellsTree->GetPvsCost(vc) / 700;
+				importance = (float)mViewCellsTree->GetTrianglesInPvs(vc) / 700;
 							 //(float)mCurrentViewCellsStats.maxPvs;
 			}
@@ -4105,5 +4105,5 @@
 		Exporter *exporter = Exporter::GetExporter(s);
 		
-		cout << "view cell " << idx << ": pvs cost=" << (int)mViewCellsTree->GetPvsCost(vc) << endl;
+		cout << "view cell " << idx << ": pvs cost=" << (int)mViewCellsTree->GetTrianglesInPvs(vc) << endl;
 
 		if (exportRays)
@@ -5430,5 +5430,5 @@
 		Exporter *exporter = Exporter::GetExporter(s);
 		
-		const float pvsCost = mViewCellsTree->GetPvsCost(vc);
+		const float pvsCost = mViewCellsTree->GetTrianglesInPvs(vc);
 		cout << "view cell " << vc->GetId() << ": pvs cost=" << pvsCost << endl;
 
@@ -6482,5 +6482,5 @@
 		Exporter *exporter = Exporter::GetExporter(s);
 		
-		cout << "view cell " << vc->GetId() << ": pvs cost=" << mViewCellsTree->GetPvsCost(vc) << endl;
+		cout << "view cell " << vc->GetId() << ": pvs cost=" << mViewCellsTree->GetTrianglesInPvs(vc) << endl;
 
 		if (exportPvs)
@@ -7028,6 +7028,6 @@
 			if (tmpRays.size() == 4)
 			{
+				// cast packets of 4 rays
 				RayPacket packet(tmpRays);
-
 				mHierarchyManager->CastLineSegment(packet);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.cpp	(revision 2342)
@@ -34,7 +34,6 @@
 					   myless<vector<ViewCell *>::value_type> > TraversalQueue;
 
-  int ViewCell::sMailId = 10000;//2147483647;
-  int ViewCell::sReservedMailboxes = 1;
-
+int ViewCell::sMailId = 10000;//2147483647;
+int ViewCell::sReservedMailboxes = 1;
 
 float MergeCandidate::sRenderCostWeight = 0;
@@ -1305,5 +1304,5 @@
 	{
 		const float penalty = 
-			EvalPvsPenalty(GetPvsCost(vc), lower, upper);
+			EvalPvsPenalty(GetTrianglesInPvs(vc), lower, upper);
 
 		return (mAvgRenderCost - penalty) * (mAvgRenderCost - penalty) / 
@@ -1323,5 +1322,5 @@
 	if (1)
 	{
-		const float penalty = EvalPvsPenalty(GetPvsCost(vc), lower, upper);
+		const float penalty = EvalPvsPenalty(GetTrianglesInPvs(vc), lower, upper);
 		return fabs(mAvgRenderCost - penalty) / (float)mNumActiveViewCells;
 	}
@@ -1515,5 +1514,5 @@
 	const float vol = box.GetVolume();
 
-	const float rootPvs = GetPvsCost(mRoot);
+	const float rootPvs = GetTrianglesInPvs(mRoot);
 	const int rootEntries = GetPvsEntries(mRoot);
 	
@@ -1550,5 +1549,5 @@
 			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
-			const float parentCost = GetPvsCost(interior);
+			const float parentCost = GetTrianglesInPvs(interior);
 			const int parentPvsEntries = GetPvsEntries(interior);
             const float parentExpCost = (float)parentCost * interior->GetVolume();
@@ -1566,5 +1565,5 @@
 				ViewCell *vc = *it;
 
-				const float pvsCost = GetPvsCost(vc);
+				const float pvsCost = GetTrianglesInPvs(vc);
 				const int pvsEntries = GetPvsEntries(vc);
 
@@ -1953,5 +1952,5 @@
 
 
-float ViewCellsTree::GetPvsCost(ViewCell *vc) const
+float ViewCellsTree::GetTrianglesInPvs(ViewCell *vc) const
 {
 	float pvsCost = 0;
@@ -2159,5 +2158,5 @@
 
 	const float vol = mViewCellsManager->GetViewSpaceBox().GetVolume();
-	const float rootPvs = GetPvsCost(mRoot);
+	const float rootPvs = GetTrianglesInPvs(mRoot);
 	
 	float totalRenderCost;
@@ -2182,5 +2181,5 @@
 			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
-			const float parentCost = GetPvsCost(interior);
+			const float parentCost = GetTrianglesInPvs(interior);
 			const float parentExpCost = parentCost * interior->GetVolume();
 
@@ -2196,5 +2195,5 @@
 				ViewCell *vc = *it;
 
-				const float pvsCost = GetPvsCost(vc);
+				const float pvsCost = GetTrianglesInPvs(vc);
 				
 				childExpCost += (float) pvsCost * vc->GetVolume();
@@ -2248,5 +2247,5 @@
 			ViewCellInterior *interior = static_cast<ViewCellInterior *>(vc);
 
-			const float parentPvsCost = GetPvsCost(interior);
+			const float parentPvsCost = GetTrianglesInPvs(interior);
 			const int parentPvsEntries = GetPvsEntries(interior);
             const float parentExpCost = (float)parentPvsCost * interior->GetVolume();
@@ -2288,5 +2287,5 @@
 	++ vcStat.viewCells;
 		
-	const float pvsCost = GetPvsCost(vc);
+	const float pvsCost = GetTrianglesInPvs(vc);
 
 	vcStat.pvsCost += pvsCost;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCell.h	(revision 2342)
@@ -287,5 +287,5 @@
 	}
 
-	void SetPvsCost(const float c) {
+	void SetTrianglesInPvs(const float c) {
 		mPvsCost = c;
 	}
@@ -295,5 +295,5 @@
 	}
 
-	float GetPvsCost() const {
+	float GetTrianglesInPvs() const {
 		return mPvsCost;
 	}
@@ -508,5 +508,5 @@
 	/** Returns pvs size (i.e. the render cost of the stored objects)
 	*/
-	float GetPvsCost(ViewCell *vc) const;
+	float GetTrianglesInPvs(ViewCell *vc) const;
   
 	/** Returns number of entries associated with this view cell. 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2342)
@@ -568,7 +568,7 @@
 	else
 	{
-		// todo: set correct scalars
-		viewCell->SetPvsCost(renderCost);
+		viewCell->SetTrianglesInPvs(renderCost);
 		viewCell->SetEntriesInPvs(pvs);
+		
 		//cout << "create view cell with tri=" << (int)renderCost << " pvs=" << pvs << endl; 
 	}
@@ -753,7 +753,6 @@
 	RayInfoContainer::const_iterator rit, rit_end = splitCandidate.mParentData.mRays->end();
 
-	float frontRenderCost = 0, backRenderCost = 0, totalRenderCost = 0;
 	float frontTriangles = 0, backTriangles = 0, totalTriangles = 0;
-	int  frontObjects = 0, backObjects = 0, totalObjects = 0;
+	int frontObjects = 0, backObjects = 0, totalObjects = 0;
 
 	Intersectable::NewMail(3);
@@ -803,9 +802,9 @@
 	}
 
-	totalRenderCost = mViewCellsManager->ComputeRenderCost((int)totalTriangles, totalObjects);
-	backRenderCost = mViewCellsManager->ComputeRenderCost((int)backTriangles, backObjects);
-	frontRenderCost = mViewCellsManager->ComputeRenderCost((int)frontTriangles, frontObjects);
-
-	
+	const float totalRenderCost = mViewCellsManager->ComputeRenderCost((int)totalTriangles, totalObjects);
+	const float backRenderCost = mViewCellsManager->ComputeRenderCost((int)backTriangles, backObjects);
+	const float frontRenderCost = mViewCellsManager->ComputeRenderCost((int)frontTriangles, frontObjects);
+	
+
 	/////////////
 	// avg ray contri
@@ -843,7 +842,5 @@
 	// take render cost of node into account 
 	// otherwise danger of being stuck in a local minimum!
-	const float factor = mRenderCostDecreaseWeight;
-
-	float priority = factor * renderCostDecr + (1.0f - factor) * oldRenderCost;
+	float priority = mRenderCostDecreaseWeight * renderCostDecr + (1.0f - mRenderCostDecreaseWeight) * oldRenderCost;
 
 	if (mHierarchyManager->mConsiderMemory)
@@ -854,5 +851,5 @@
 	splitCandidate.SetPriority(priority);
 
-	//cout << "vsp render cost decrease=" << renderCostDecr<<endl;
+	//cout << "vsp render cost decrease=" << renderCostDecr << endl;
 	mEvalTimer.Exit();
 }
@@ -883,13 +880,9 @@
 	splitCandidate.mBackPvs = (float)bPvsSize;
 
-	if (0)
-	cout << "vsp pvs"
-		 << " avg ray contri: " << splitCandidate.GetAvgRayContribution() << " ratio: " << oldPvsRatio 
-		 << " parent: " << correctedOldPvs << " " << " old vol: " << oldPvsSize
-		 << " frontpvs: " << fPvsSize << " corr. " << splitCandidate.mCorrectedFrontPvs 
-		 << " backpvs: " << bPvsSize << " corr. " << splitCandidate.mCorrectedBackPvs << endl;
-
-
+#if TODO
 	return (int)(splitCandidate.mCorrectedFrontPvs + splitCandidate.mCorrectedBackPvs - correctedOldPvs);
+#else
+	return fPvsSize + bPvsSize - oldPvsSize;
+#endif
 }
 
@@ -1633,7 +1626,7 @@
 float VspTree::EvalRenderCostDecrease(VspSubdivisionCandidate &sc,
 									  float &normalizedOldRenderCost,
-									  const float totalPvs,
-									  const float pvsFront,
-									  const float pvsBack) const
+									  const float totalRenderCost,
+									  const float frontRenderCost,
+									  const float backRenderCost) const
 {
 	const float viewSpaceVol = mBoundingBox.GetVolume();
@@ -1643,11 +1636,5 @@
 	const float avgRaysPerObject = sc.GetAvgRaysPerObject();
 
-	/////////////////////////
-	// mark objects in the front / back / both using mailboxing
-	// then count pvs sizes
-
-	Intersectable::NewMail(3);
-	KdLeaf::NewMail(3);
-    
+
 	AxisAlignedBox3 frontBox;
 	AxisAlignedBox3 backBox;
@@ -1667,18 +1654,28 @@
 	//-- evaluate render cost heuristics
 
-	const float oldRenderCostRatio = (tData.mRenderCost > 0)? (totalPvs / tData.mRenderCost) : 1;
+	// ratio of how render cost changed since last evaluation
+	const float oldRenderCostRatio = (tData.mRenderCost > 0)? (totalRenderCost / tData.mRenderCost) : 1;
 	const float penaltyOld = tData.mCorrectedRenderCost * oldRenderCostRatio;
 
-	sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsFront, penaltyOld, avgRaysPerObject);
-	sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(pvsBack, penaltyOld, avgRaysPerObject);
-
-	sc.mFrontRenderCost = pvsFront;
-	sc.mBackRenderCost = pvsBack;
-
-	const float oldRenderCost = pOverall * penaltyOld;
+	sc.mCorrectedFrontRenderCost = mHierarchyManager->EvalCorrectedPvs(frontRenderCost, penaltyOld, avgRaysPerObject);
+	sc.mCorrectedBackRenderCost = mHierarchyManager->EvalCorrectedPvs(backRenderCost, penaltyOld, avgRaysPerObject);
+
+	sc.mFrontRenderCost = frontRenderCost;
+	sc.mBackRenderCost = backRenderCost;
+
+#if TODO // undersampling evalution does not work yet
+
+	const float oldRenderCost = penaltyOld * pOverall;
 	const float newRenderCost = sc.mCorrectedFrontRenderCost * pFront + 
 								sc.mCorrectedBackRenderCost * pBack;
 
-	// we also return the old render cost
+#else
+
+	const float oldRenderCost = totalRenderCost * pOverall;
+	const float newRenderCost = frontRenderCost * pFront + backRenderCost * pBack;
+
+#endif
+
+	// the normalized old render cost is needed for the priority
 	normalizedOldRenderCost = oldRenderCost / viewSpaceVol;
 
@@ -3255,5 +3252,5 @@
     leaf->SetViewCell(viewCell);
 
-	viewCell->SetPvsCost((float)objects.size());
+	viewCell->SetTrianglesInPvs((float)objects.size());
 	viewCell->SetEntriesInPvs(1);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 2234)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssRay.h	(revision 2342)
@@ -7,5 +7,7 @@
 #include "Containers.h"
 
-//
+#ifdef USE_SSE
+#include <xmmintrin.h>
+#endif
 
 
@@ -19,5 +21,24 @@
 #define ABS_CONTRIBUTION_WEIGHT 0.0f
 #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
+
+
 class VssRay {
 public:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2332)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2342)
@@ -559,9 +559,16 @@
 		
 		/// Repair split queue
-		cout << "repairing queue ... " << endl;
+		cout << "repairing object space queue ... " << endl;
 		RepairQueue(dirtyList, objectSpaceQueue, true);
 		cout << "repaired " << (int)dirtyList.size() << " candidates" << endl;
 
 		dirtyList.clear();
+
+		/// also repair some candidates from view space queue
+		/*cout << "repairing view space queue ... " << endl;
+		CollectRandomCandidates(dirtyList);
+		RepairQueue(dirtyList, viewSpaceQueue, true);
+		cout << "repaired " << (int)dirtyList.size() << " candidates" << endl;
+		dirtyList.clear();*/
 		//PrintTimings(false);
 	}
@@ -743,9 +750,9 @@
 	mVspTree->PrepareConstruction(tQueue, sampleRays, *viewSpaceRays);
 
-	/////////
-	//-- new stats
-
 	if (0)
 	{
+		/////////
+		//-- new render cost
+
 		mHierarchyStats.mTotalCost = mVspTree->mTotalCost;
 		cout << "\nreseting cost for vsp construction, new total cost: " << mHierarchyStats.mTotalCost << endl;
@@ -2278,5 +2285,5 @@
 		{
 			ComputePvs(vc->GetPvs(), triangles, entries);
-			vc->SetPvsCost(triangles);
+			vc->SetTrianglesInPvs(triangles);
 		}
 
@@ -2502,4 +2509,11 @@
 }
 
-
-}
+#ifdef USE_SSE
+int HierarchyManager::CastLineSegment(RayPacket &packet)
+{
+	return mVspTree->TraverseRayPacket(packet, true);
+}
+
+#endif
+
+}
