Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2187)
@@ -256,12 +256,17 @@
 				GlobalOptimizations="TRUE"
 				InlineFunctionExpansion="2"
-				FavorSizeOrSpeed="1"
+				EnableIntrinsicFunctions="TRUE"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="TRUE"
 				EnableFiberSafeOptimizations="TRUE"
-				OptimizeForProcessor="3"
+				OptimizeForProcessor="0"
 				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;"
 				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;GTP_INTERNAL;NO_QT"
-				RuntimeLibrary="2"
-				RuntimeTypeInfo="TRUE"
+				StringPooling="TRUE"
+				MinimalRebuild="FALSE"
+				RuntimeLibrary="2"
+				EnableEnhancedInstructionSet="2"
+				RuntimeTypeInfo="FALSE"
 				UsePrecompiledHeader="0"
 				WarningLevel="3"
@@ -275,9 +280,11 @@
 				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;;.\QtGlRenderer\Release"
-				GenerateDebugInformation="FALSE"
-				SubSystem="1"
-				OptimizeReferences="2"
-				EnableCOMDATFolding="2"
+				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="FALSE"
+				SubSystem="1"
+				LargeAddressAware="0"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				OptimizeForWindows98="1"
 				TargetMachine="1"
 				FixedBaseAddress="1"/>
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.h	(revision 2187)
@@ -108,5 +108,4 @@
   };
 
-  
   VssRayPool mVssRayPool;
 
@@ -121,4 +120,12 @@
 
 protected:
+
+	VssRay *RequestRay(const Vector3 &origin, 
+					   const Vector3 &termination, 
+					   Intersectable *originObject, 
+					   Intersectable *terminationObject, 
+					   const int pass, 
+					   const float pdf);
+
   void _SortRays(SimpleRayContainer &rays,
 				 const int l,
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2183)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2187)
@@ -32,97 +32,7 @@
 namespace GtpVisibilityPreprocessor {
 
-  const static bool ADDITIONAL_GEOMETRY_HACK = false;
-
-  Preprocessor *preprocessor = NULL;
-  
-// HACK: Artificially modify scene to watch rendercost changes
-static void AddGeometry(SceneGraph *scene)
-{
-	scene->GetRoot()->UpdateBox();
-
-	AxisAlignedBox3 sceneBox = scene->GetBox();
-
-	int n = 200;
-
-	if (0)
-	{
-		// form grid of boxes
-		for (int i = 0; i < n; ++ i)
-		{
-			for (int j = 0; j < n; ++ j)
-			{
-				const Vector3 scale2((float)j * 0.8f / n + 0.1f,  0.05f, (float)i * 0.8f  / (float)n + 0.1f);
-
-				const Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
-
-				const Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
-				AxisAlignedBox3 box(pt2, pt2 + boxSize);
-				Mesh *mesh = CreateMeshFromBox(box);
-
-				mesh->Preprocess();
-
-				MeshInstance *mi = new MeshInstance(mesh);
-				scene->GetRoot()->mGeometry.push_back(mi);
-			}
-		}
-
-		for (int i = 0; i < n; ++ i)
-		{
-			for (int j = 0; j < n; ++ j)
-			{
-				const Vector3 scale2(0.15f, (float)j * 0.8f / n + 0.1f, (float)i * 0.8f  / (float)n + 0.1f);
-
-				Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
-
-				Vector3 boxSize = sceneBox.Size() * Vector3(0.0025f, 0.01f, 0.0025f);
-				AxisAlignedBox3 box(pt2, pt2 + boxSize);
-				Mesh *mesh = CreateMeshFromBox(box);
-
-				mesh->Preprocess();
-
-				MeshInstance *mi = new MeshInstance(mesh);
-				scene->GetRoot()->mGeometry.push_back(mi);
-			}
-		}
-
-		for (int i = 0; i < n; ++ i)
-		{
-			const Vector3 scale2(2, 0.2f, (float)i * 0.8f  / (float)n + 0.1f);
-
-			Vector3 pt2 = sceneBox.Min() + scale2 * (sceneBox.Max() - sceneBox.Min());
-			Vector3 boxSize = sceneBox.Size() * Vector3(0.005f, 0.02f, 0.005f);
-
-			AxisAlignedBox3 box(pt2 + 0.1f, pt2 + boxSize);
-			Mesh *mesh = CreateMeshFromBox(box);
-
-			mesh->Preprocess();
-
-			MeshInstance *mi = new MeshInstance(mesh);
-			scene->GetRoot()->mGeometry.push_back(mi);
-		}
-
-		scene->GetRoot()->UpdateBox();
-	}
-
-	if (1)
-	{
-		// plane separating view space regions
-		const Vector3 scale(1.0f, 0.0, 0);
-
-		Vector3 pt = sceneBox.Min() + scale * (sceneBox.Max() - sceneBox.Min());
-
-		Plane3 cuttingPlane(Vector3(1, 0, 0), pt);
-		Mesh *planeMesh = new Mesh();
-
-		Polygon3 *poly = sceneBox.CrossSection(cuttingPlane);
-		IncludePolyInMesh(*poly, *planeMesh);
-
-		planeMesh->Preprocess();
-
-		MeshInstance *planeMi = new MeshInstance(planeMesh);
-		scene->GetRoot()->mGeometry.push_back(planeMi);
-	}	
-}
-
+
+Preprocessor *preprocessor = NULL;
+  
 
 Preprocessor::Preprocessor():
@@ -599,7 +509,4 @@
 	if (result) 
 	{ 
-	  // HACK 
-		if (ADDITIONAL_GEOMETRY_HACK)
-			AddGeometry(mSceneGraph);
 
 		mSceneGraph->AssignObjectIds();
@@ -1228,28 +1135,36 @@
 	Environment::GetSingleton()->GetBoolValue("ViewCells.loadFromFile", loadViewCells);
 
-	int reserveRays;
+	int reserveRays;	
+	int constructionSamples;
 
 	if (!loadViewCells)
 	{
-		cout << "setting ray pool size to view cell construction ize" << endl;
+		cout << "hack: setting ray pool size to view cell construction or evaluation size" << endl;
+
+		constructionSamples = 1000000;
 
 		char buf[100];
 		Environment::GetSingleton()->GetStringValue("ViewCells.type", buf);	
-		
+
 		if (strcmp(buf, "vspBspTree") == 0)
 		{
-			Environment::GetSingleton()->GetIntValue("VspBspTree.Construction.samples", reserveRays);
-			reserveRays *= 2;
+			Environment::GetSingleton()->GetIntValue("VspBspTree.Construction.samples", constructionSamples);
+			
 		}
 		else if (strcmp(buf, "vspOspTree") == 0)
 		{
-			Environment::GetSingleton()->GetIntValue("Hierarchy.Construction.samples", reserveRays);
-			reserveRays *= 2;			
-		}
+			Environment::GetSingleton()->GetIntValue("Hierarchy.Construction.samples", constructionSamples);		
+		}
+
+		int evalSamplesPerPass;
+
+		Environment::GetSingleton()->GetIntValue("ViewCells.Evaluation.samplesPerPass", evalSamplesPerPass);
+
+		reserveRays = max(constructionSamples, evalSamplesPerPass);
+		reserveRays *= 2;
 	}
 	else
 	{
-		cout << "setting ray pool size to samples per pass" << endl;
-        
+		cout << "setting ray pool size to samples per pass" << endl;       
 		reserveRays = mSamplesPerPass * 2;
 	}
@@ -1274,5 +1189,6 @@
 	const long t1 = GetTime();
 	
-	if ((int)rays.size() > 10000) {
+	if (1 && (rays.size() > 10000))
+	{
 	
 		mRayCaster->SortRays(rays);
@@ -1298,4 +1214,5 @@
 
 	if (mUseHwGlobalLines) 
+	{
 	  CastRaysWithHwGlobalLines(
 								rays,
@@ -1304,5 +1221,7 @@
 								pruneInvalidRays
 								);
+	}
 	else
+	{
 	  mRayCaster->CastRays(
 						 rays,				
@@ -1311,6 +1230,7 @@
 						 castDoubleRays,
 						 pruneInvalidRays);
-  
-	if ((int)rays.size() > 10000) 
+	}
+
+	if (rays.size() > 10000) 
 	{
 		cout << endl;
@@ -1328,13 +1248,11 @@
 }
 
-
   
 void
 Preprocessor::CastRaysWithHwGlobalLines(
 										SimpleRayContainer &rays,
-									  VssRayContainer &vssRays,
-									  const bool castDoubleRays,
-									  const bool pruneInvalidRays
-									  )
+										VssRayContainer &vssRays,
+										const bool castDoubleRays,
+										const bool pruneInvalidRays)
 {
   SimpleRayContainer::const_iterator rit, rit_end = rays.end();
@@ -1352,20 +1270,20 @@
 		}
 #endif
-	  rayBucket.push_back(ray);
-	  
-	  // 16 rays gathered => do ray casting
-	  if ((int)rayBucket.size() >= 16)
-		{
-		  mRayCaster->CastRays16(
-								 rayBucket,				
-								 vssRays,
-								 mViewCellsManager->GetViewSpaceBox(),
-								 castDoubleRays,
-								 pruneInvalidRays);
-		  
-		  rayBucket.clear();
-		}
-	
-		if ((int)rays.size() > 100000 && i % 100000 == 0)
+		rayBucket.push_back(ray);
+
+		// 16 rays gathered => do ray casting
+		if (rayBucket.size() >= 16)
+		{
+			mRayCaster->CastRays16(
+				rayBucket,				
+				vssRays,
+				mViewCellsManager->GetViewSpaceBox(),
+				castDoubleRays,
+				pruneInvalidRays);
+
+			rayBucket.clear();
+		}
+
+		if (rays.size() > 100000 && i % 100000 == 0)
 			cout<<"\r"<<i<<"/"<<(int)rays.size()<<"\r";
 	}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj	(revision 2187)
@@ -267,15 +267,21 @@
 				Name="VCCLCompilerTool"
 				Optimization="3"
+				GlobalOptimizations="TRUE"
 				InlineFunctionExpansion="0"
-				FavorSizeOrSpeed="0"
-				OptimizeForProcessor="3"
+				EnableIntrinsicFunctions="TRUE"
+				FavorSizeOrSpeed="1"
+				OmitFramePointers="TRUE"
+				EnableFiberSafeOptimizations="TRUE"
+				OptimizeForProcessor="0"
 				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;"
+				AdditionalIncludeDirectories="..\src;..\..\..\..\..\..\NonGTP\Devil\include;..\..\..\..\..\..\NonGTP\Zlib\include;..\..\..\..\..\..\NonGTP\Xerces;..\..\..\..\..\..\NonGTP\Boost;..\MultiLevelRayTracing;Timer"
 				PreprocessorDefinitions="WIN32;NDEBUG;_LIB;GTP_INTERNAL;NO_QT"
+				StringPooling="TRUE"
 				ExceptionHandling="TRUE"
 				RuntimeLibrary="2"
+				EnableEnhancedInstructionSet="2"
 				DisableLanguageExtensions="FALSE"
 				ForceConformanceInForLoopScope="FALSE"
-				RuntimeTypeInfo="TRUE"
+				RuntimeTypeInfo="FALSE"
 				UsePrecompiledHeader="0"
 				BrowseInformation="1"
@@ -1160,8 +1166,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/HierarchyManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h	(revision 2187)
@@ -323,4 +323,6 @@
 protected:
 
+	void PrintTimings(const bool osp);
+
 	/** Returns true if the global termination criteria were met.
 	*/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 2116)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp	(revision 2187)
@@ -623,8 +623,8 @@
 void VssPreprocessor::DeterminePvsObjects(VssRayContainer &rays)
 {
-	//Preprocessor::DeterminePvsObjects(rays);
-	mViewCellsManager->DeterminePvsObjects(rays, true);
-}
-
-
-}
+	// store higher order object
+	mViewCellsManager->DeterminePvsObjects(rays, false);
+}
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2183)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h	(revision 2187)
@@ -57,35 +57,36 @@
 
 	/** Load the input scene. 
-	@param filename file to load
-	@return true on success
+		@param filename file to load
+		@return true on success
 	*/
 	virtual bool LoadScene(const string filename);
 
 	/** Export all preprocessed data in a XML format understandable by the
-	PreprocessingInterface of the GtpVisibilityPreprocessor Module. 
-	The file can be compressed depending on the environement settings.
-	@return true on successful export
+		PreprocessingInterface of the GtpVisibilityPreprocessor Module. 
+		The file can be compressed depending on the environement settings.
+		@return true on successful export
 	*/
 	virtual bool ExportPreprocessedData(const string filename);
 
 	/** Build the KdTree of currently loaded occluders/occludees/viewcells. The construction
-	is driven by the environment settings, which also sais which of the three types of
-	entities should be used to drive the heuristical construction (only occluders by default)
+		is driven by the environment settings, which also sais which of the three types of
+		entities should be used to drive the heuristical construction (only occluders by default)
 	*/
 	virtual bool BuildKdTree();
 
 	/** Compute visibility method. This method has to be reimplemented by the actual
-	Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
-	GlobalSamplingpreprocessor)
+		Preprocessor implementation (e.g. SamplingPreprocessor, ExactPreprocessor,
+		GlobalSamplingpreprocessor)
 	*/
 	virtual bool ComputeVisibility() = 0;
 
 	/** Post Process the computed visibility. By default applys the visibility filter
-	(if specified in the environment and export the preprocessed data */
+		(if specified in the environment and export the preprocessed data 
+		*/
 	virtual bool PostProcessVisibility();
 
 	/** View cells are either loaded or prepared for generation, according to the chosen environment
-	object. Important evironment options are, e.g, the view cell type.
-	Should be done after scene loading (i.e., some options are based on scene type).
+		object. Important evironment options are, e.g, the view cell type.
+		Should be done after scene loading (i.e., some options are based on scene type).
 	*/
 	bool PrepareViewCells();
@@ -111,9 +112,8 @@
 	@returns true if samples were loaded successfully
 	*/
-	bool LoadSamples(VssRayContainer &samples,
-		ObjectContainer &objects) const;
+	bool LoadSamples(VssRayContainer &samples, ObjectContainer &objects) const;
 
 	/** Exports samples to file.
-	@returns true if samples were written successfully
+		@returns true if samples were written successfully
 	*/
 	bool ExportSamples(const VssRayContainer &samples) const;
@@ -158,5 +158,5 @@
 							);
 
-	/** Compute pixel error of the current PVS solution by sampling given number of viewpoints .
+	/** Compute pixel error of the current PVS solution by sampling given number of viewpoints.
 	*/
 	virtual void ComputeRenderError();
@@ -223,5 +223,6 @@
 	bool mUseGlRenderer;
 	bool mUseGlDebugger;
-  bool mUseHwGlobalLines;
+	
+	bool mUseHwGlobalLines;
 	bool mLoadViewCells;
 
@@ -261,4 +262,5 @@
   	RayCaster *mRayCaster;
 
+
 protected:
 
@@ -288,6 +290,4 @@
 	vector<FaceParentInfo> mFaceParents;
 
-
-  
 	/// if box around view space should be used
 	bool mUseViewSpaceBox;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.h	(revision 2187)
@@ -12,4 +12,5 @@
 #include "SubdivisionCandidate.h"
 #include "HierarchyManager.h"
+#include "PerfTimer.h"
 
 
@@ -535,6 +536,5 @@
 		float GetPriority() const
 		{
-			return (float)-mParentData.mDepth;
-			//return mPriority;
+			return mPriority;
 		}
 
@@ -723,4 +723,9 @@
 	VspNode *SubdivideAndCopy(SplitQueue &tQueue, SubdivisionCandidate *splitCandidate);
 
+	PerfTimer mSortTimer;
+	PerfTimer mSplitTimer;
+	PerfTimer mNodeTimer;
+	PerfTimer mSubdivTimer;
+	PerfTimer mEvalTimer;
 
 protected:
@@ -985,5 +990,5 @@
 		float &backPvs,
 		float &totalPvsm,
-		const bool countEntries = false) const;
+		const bool countEntries) const;
 
 	/** Evaluates the contribution for kd leaves.
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2124)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2187)
@@ -384,4 +384,5 @@
 										BvhTraversalData &backData)
 { 
+	mNodeTimer.Entry();
 	const BvhTraversalData &tData = sc.mParentData;
 	BvhLeaf *leaf = tData.mNode;
@@ -480,4 +481,6 @@
 	}
 	
+	mNodeTimer.Exit();
+
 	// return the new interior node
 	return node;
@@ -489,4 +492,6 @@
 								const bool globalCriteriaMet)
 {
+	mSubdivTimer.Entry();
+
 	BvhSubdivisionCandidate *sc = 
 		static_cast<BvhSubdivisionCandidate *>(splitCandidate);
@@ -505,5 +510,5 @@
 		// create new interior node and two leaf node
 		currentNode = SubdivideNode(*sc, tFrontData, tBackData);
-	
+
 		// decrease the weighted average cost of the subdivisoin
 		mTotalCost -= sc->GetRenderCostDecrease();
@@ -524,5 +529,5 @@
 		EvalSubdivisionCandidate(*frontCandidate);
 		EvalSubdivisionCandidate(*backCandidate);
-	
+
 		// cross reference
 		tFrontData.mNode->SetSubdivisionCandidate(frontCandidate); 
@@ -550,4 +555,6 @@
 	}
 	
+	mSubdivTimer.Exit();
+
 	return currentNode;
 }
@@ -608,4 +615,5 @@
 										   bool computeSplitPlane)
 {
+	mEvalTimer.Entry();
 	if (computeSplitPlane)
 	{
@@ -697,4 +705,5 @@
   	// compute global decrease in render cost
 	splitCandidate.SetPriority(priority);
+	mEvalTimer.Exit();
 }
 
@@ -1549,4 +1558,6 @@
 										 bool useVisibilityBasedHeuristics)
 {
+	mSplitTimer.Entry();
+
 	if (mIsInitialSubdivision)
 	{
@@ -1653,4 +1664,6 @@
 	backObjects = nBackObjects[bestAxis];
 
+	mSplitTimer.Exit();
+
 	//cout << "val: " << nCostRatio[bestAxis] << " axis: " << bestAxis << endl;
 	return nCostRatio[bestAxis];
@@ -2312,4 +2325,8 @@
 												const ObjectContainer &objects)
 {
+	mSortTimer.Entry();
+
+	const bool doSort = true;
+
 	// we sort the objects as a preprocess so they don't have
 	// to be sorted for each split
@@ -2320,5 +2337,5 @@
 		CreateLocalSubdivisionCandidates(objects, 
 									     &sortedObjects, 
-										 true, 
+										 doSort, 
 										 i);
 		
@@ -2342,6 +2359,9 @@
 
 	*(tData.mSortedObjects[3]) = objects;
-	//stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize);
-	sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize);
+	
+	stable_sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize);
+	//sort(tData.mSortedObjects[3]->begin(), tData.mSortedObjects[3]->end(), smallerSize);
+
+	mSortTimer.Exit();
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2187)
@@ -969,10 +969,4 @@
 	if (mShowVisualization)
 	{
-		if (0)
-		{
-			mStrategies.clear();
-			mStrategies.push_back(SamplingStrategy::VIEWCELL_BORDER_BASED_DISTRIBUTION);
-		}
-
 		///////////////
 		//-- visualization rays, e.g., to show some samples in the scene
@@ -2712,4 +2706,5 @@
 	if (!useHitObjects) 
 	{
+		// store higher order object (e.g., bvh node) instead of object itself
 		VssRayContainer::const_iterator it, it_end = rays.end();
         
@@ -2717,8 +2712,7 @@
 		{
 			VssRay *vssRay = *it;
+
 			// set only the termination object
-			vssRay->mTerminationObject = GetIntersectable(
-				*vssRay,
-				true);
+			vssRay->mTerminationObject = GetIntersectable(*vssRay, true);
 		}
 	}
@@ -2771,5 +2765,5 @@
 	ray.mRelativePvsContribution = 0.0f;
 
-	mSamplesStat.mRays++;
+	++ mSamplesStat.mRays;
 	
 	if (!ray.mTerminationObject)
@@ -2796,4 +2790,5 @@
 	static VssRay *lastVssRay = NULL;
 	
+	// check if last ray was not same ray with reverse direction
 	if (lastVssRay == NULL ||
 		!(ray.mOrigin == lastVssRay->mTermination) ||
@@ -2819,5 +2814,5 @@
 	  ray.mViewCells = viewCells;
 #else
-	  cerr<<"Vss store viewcells not supported."<<endl;
+	  cerr << "Vss store viewcells not supported." << endl;
 	  exit(1);
 #endif
@@ -2850,5 +2845,5 @@
 	mSamplesStat.mPvsContributions += ray.mPvsContribution;
 	if (ray.mPvsContribution)
-	  mSamplesStat.mContributingRays++;
+		++ mSamplesStat.mContributingRays;
 	
 #if AVG_RAY_CONTRIBUTIONS
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.h	(revision 2187)
@@ -14,4 +14,5 @@
 #include "IntersectableWrapper.h"
 #include "HierarchyManager.h"
+#include "PerfTimer.h"
 
 
@@ -495,6 +496,6 @@
 		float GetPriority() const
 		{
-			return (float)-mParentData.mDepth;
-			//return mPriority;
+			//return (float)-mParentData.mDepth;
+			return mPriority;
 		}
 
@@ -656,4 +657,10 @@
 	void Compress();
 	void CreateUniqueObjectIds();
+
+	PerfTimer mSortTimer;
+	PerfTimer mNodeTimer;
+	PerfTimer mSubdivTimer;
+	PerfTimer mEvalTimer;
+	PerfTimer mSplitTimer;
 
 protected:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 2105)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 2187)
@@ -115,5 +115,5 @@
 								const bool pruneInvalidRays)
 {
-  CastRays16(rays, 0, vssRays, sbox, castDoubleRay, pruneInvalidRays);
+	CastRays16(rays, 0, vssRays, sbox, castDoubleRay, pruneInvalidRays);
 }
 
@@ -322,5 +322,5 @@
   }
 
-  for (; offset < rays.size(); offset++)
+  for (; offset < (int)rays.size(); offset++)
   	CastRay(rays[offset], vssRays, sbox, castDoubleRay, pruneInvalidRays);
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2187)
@@ -668,4 +668,6 @@
 							const bool globalCriteriaMet)
 {
+	mSubdivTimer.Entry();
+
 	// todo remove dynamic cast
 	VspSubdivisionCandidate *sc = 
@@ -686,8 +688,6 @@
 		const int maxCostMisses = sc->GetMaxCostMisses();
 
-		newNode = SubdivideNode(*sc,
-								tFrontData, 
-								tBackData);
-	
+		newNode = SubdivideNode(*sc, tFrontData, tBackData);
+
 		// how often was max cost ratio missed in this branch?
 		tFrontData.mMaxCostMisses = maxCostMisses;
@@ -766,4 +766,6 @@
 	}
 
+	mSubdivTimer.Exit();
+
 	return newNode;
 }
@@ -773,4 +775,6 @@
 									   bool computeSplitPlane)
 {
+	mEvalTimer.Entry();
+
 	if (computeSplitPlane)
 	{
@@ -825,4 +829,6 @@
 
 	splitCandidate.SetPriority(priority);
+
+	mEvalTimer.Exit();
 }
 
@@ -887,4 +893,6 @@
 									VspTraversalData &backData)
 {
+	mNodeTimer.Entry();
+	
 	VspLeaf *leaf = static_cast<VspLeaf *>(sc.mParentData.mNode);
 
@@ -993,4 +1001,6 @@
 	AddViewCellReferences(backLeaf->GetViewCell());
 #endif
+
+	mNodeTimer.Exit();
 
 	return interior;
@@ -1023,5 +1033,5 @@
 
 		if (entry) 
-		{cout<<"a";
+		{
 			madeContrib = 
 				vc->GetPvs().AddSample(entry, ray->mPdf);
@@ -1052,8 +1062,10 @@
 
 void VspTree::SortSubdivisionCandidates(const RayInfoContainer &rays,
-								  const int axis, 
-								  float minBand, 
-								  float maxBand)
-{
+										const int axis, 
+										float minBand, 
+										float maxBand)
+{
+	mSortTimer.Entry();
+
 	mLocalSubdivisionCandidates->clear();
 
@@ -1102,4 +1114,6 @@
 	stable_sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end());
 	//sort(mLocalSubdivisionCandidates->begin(), mLocalSubdivisionCandidates->end());
+
+	mSortTimer.Exit();
 }
 
@@ -1408,4 +1422,6 @@
 								float &pBack)
 {
+	mSplitTimer.Entry();
+
 	float nPosition[3];
 	float nCostRatio[3];
@@ -1502,4 +1518,6 @@
 	pFront = nProbFront[bestAxis];
 	pBack = nProbBack[bestAxis];
+
+	mSplitTimer.Exit();
 
 	return nCostRatio[bestAxis];
@@ -3191,5 +3209,5 @@
 		{
 			BvhLeaf *leaf = mHierarchyManager->mBvHierarchy->GetLeaf(obj);
-			UpdateContributionsToPvs(leaf, cf, frontPvs, backPvs, totalPvs);
+			UpdateContributionsToPvs(leaf, cf, frontPvs, backPvs, totalPvs, false);
 			break;
 		}
@@ -3242,5 +3260,5 @@
 	int pvs = 0;
 
-	switch(mHierarchyManager->GetObjectSpaceSubdivisionType())
+	switch (mHierarchyManager->GetObjectSpaceSubdivisionType())
 	{
 	case HierarchyManager::NO_OBJ_SUBDIV:
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 2105)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 2187)
@@ -238,4 +238,33 @@
   
 					
+VssRay *RayCaster::RequestRay(const Vector3 &origin, 
+							  const Vector3 &termination, 
+							  Intersectable *originObject, 
+							  Intersectable *terminationObject, 
+							  const int pass, 
+							  const float pdf)
+{
+ #if DEBUG_RAYCAST
+	Debug<<"PR2a"<<flush;
+#endif
+	
+	// old method: always allocate
+	if (1) return new VssRay(origin, termination, originObject, terminationObject, pass, pdf);
+
+	VssRay *vssRay = mVssRayPool.Alloc();
+
+#if DEBUG_RAYCAST
+	Debug<<"PR2b"<<flush;
+#endif
+	
+	*vssRay = VssRay(origin, termination, originObject, terminationObject, pass, pdf);
+
+#if DEBUG_RAYCAST
+	Debug<<"PR2c"<<flush;
+#endif
+
+	return vssRay;
+}
+
 
 int
@@ -306,15 +335,7 @@
 
 	  if (!pruneInvalidRays || hitA.mObject) {
-#if DEBUG_RAYCAST
-		Debug<<"PR2a"<<flush;
-#endif
-		
-		VssRay *vssRay = mVssRayPool.Alloc();
-
-#if DEBUG_RAYCAST
-		Debug<<"PR2b"<<flush;
-#endif
-		*vssRay = VssRay(
-						 !castDoubleRay ? simpleRay.mOrigin : clipB,
+
+		  VssRay *vssRay = 
+			  RequestRay(!castDoubleRay ? simpleRay.mOrigin : clipB,
 						 hitA.mPoint,
 						 hitB.mObject,
@@ -323,8 +344,5 @@
 						 1.0f //simpleRay.mPdf
 						 );
-#if DEBUG_RAYCAST
-		Debug<<"PR2c"<<flush;
-#endif
-		
+
 		if (validA)
 		  vssRay->mFlags |= VssRay::Valid;
@@ -344,14 +362,12 @@
 	if (castDoubleRay && (!pruneInvalidRays || hitB.mObject))
 	{
-		VssRay *vssRay = mVssRayPool.Alloc();
-
-		*vssRay = VssRay(
-			clipA,
-			hitB.mPoint,
-			hitA.mObject,
-			hitB.mObject,
-			mPreprocessor.mPass,
-			1.0f //simpleRay.mPdf
-			);
+		VssRay *vssRay = RequestRay(
+									clipA,
+									hitB.mPoint,
+									hitA.mObject,
+									hitB.mObject,
+									mPreprocessor.mPass,
+									1.0f //simpleRay.mPdf
+									);
 
 		if (validB)
@@ -381,8 +397,8 @@
 					const bool pruneInvalidRays )
 {
-  SimpleRayContainer::const_iterator rit, rit_end = rays.end();
-  
-  for (rit = rays.begin(); rit != rit_end; ++ rit) {
-	CastRay(
+	SimpleRayContainer::const_iterator rit, rit_end = rays.end();
+
+	for (rit = rays.begin(); rit != rit_end; ++ rit) {
+		CastRay(
 			*rit,				
 			vssRays,
@@ -390,7 +406,7 @@
 			castDoubleRay,
 			pruneInvalidRays);
-  }
-  
-}
-
-}
+	}
+}
+
+
+}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp	(revision 2176)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/common.cpp	(revision 2187)
@@ -158,7 +158,7 @@
 TimeDiff(long time1, long time2) // in ms
 {
-  const Real clk=1.0e-3f; // ticks per second
+  //const Real clk=1.0e-3f; // ticks per second
   // $$ tmp store time in ms
-  //const Real clk=1.0f; // ticks per second
+  const Real clk=1.0f; // ticks per second
   long t=time2-time1;
   
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2161)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2187)
@@ -1163,4 +1163,5 @@
 void GvsPreprocessor::DeterminePvsObjects(VssRayContainer &rays)
 {
+	// store triangle directly
 	mViewCellsManager->DeterminePvsObjects(rays, true);
 }
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2170)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2187)
@@ -409,4 +409,52 @@
 
 
+void HierarchyManager::PrintTimings(const bool lastSplitWasOsp)
+{
+	double sortTime, evalTime, nodeTime, splitTime, subdTime;
+
+	sortTime = mBvHierarchy->mSortTimer.TotalTime();
+	evalTime = mBvHierarchy->mEvalTimer.TotalTime();
+	nodeTime = mBvHierarchy->mNodeTimer.TotalTime();
+	splitTime = mBvHierarchy->mSplitTimer.TotalTime();
+	subdTime = mBvHierarchy->mSubdivTimer.TotalTime();
+
+	cout << "bvh times"
+		 << " sort : " << sortTime
+		 << " eval : " << evalTime
+		 << " node : " << nodeTime
+		 << " split: " << splitTime
+		 << " subd : " << subdTime << endl;
+
+	Debug << "bvh times"
+		<< " sort : " << sortTime
+		 << " eval : " << evalTime
+		 << " node : " << nodeTime
+		 << " split: " << splitTime
+		 << " subd : " << subdTime << endl;
+
+	sortTime = mVspTree->mSortTimer.TotalTime();
+	evalTime = mVspTree->mEvalTimer.TotalTime();
+	nodeTime = mVspTree->mNodeTimer.TotalTime();
+	splitTime = mVspTree->mSplitTimer.TotalTime();
+	subdTime = mVspTree->mSubdivTimer.TotalTime();
+
+	cout << "vsp times"
+		 << " sort : " << sortTime
+		 << " eval : " << evalTime
+		 << " node : " << nodeTime
+		 << " split: " << splitTime
+		 << " subd : " << subdTime << endl;
+
+	Debug << "vsp times"
+		<< " sort : " << sortTime
+		 << " eval : " << evalTime
+		 << " node : " << nodeTime
+		 << " split: " << splitTime
+		 << " subd : " << subdTime << endl;
+	cout << endl;
+	Debug << endl;
+}
+
+
 void HierarchyManager::ConstructInterleavedWithGradient(const VssRayContainer &sampleRays,
 														const ObjectContainer &objects,
@@ -518,4 +566,7 @@
 		//if (!lastSplitWasOsp)
 		{
+			/////////////////
+			// subdivide object space with respect to the objects
+
 			lastSplitWasOsp = true;
 			cout << "osp" << endl;
@@ -545,9 +596,9 @@
 		else
 		{
+			/////////////////
+			// subdivide view space with respect to the objects
+
 			lastSplitWasOsp = false;
 			cout << "vsp" << endl;
-			
-			/////////////////
-			// subdivide view space with respect to the objects
 
 			// dirtied object space candidates
@@ -574,4 +625,6 @@
 				 << (int)dirtyOspList.size() << " dirtied candidates" << endl;
 		}
+
+		PrintTimings(lastSplitWasOsp);
 	}
 
@@ -1845,5 +1898,5 @@
 		//cout << "priority: " << nodeWrapper->GetMergeCost() << endl;
 		// save the view cells if it is a leaf or if enough view cells have already been traversed
-		// because of the priority queue, this will be the optimal set of v
+		// because of the priority queue, this will be the optimal set of view cells
 		if (nodeWrapper->IsLeaf() || 
 			((viewCells.size() + bvhNodes.size() + tqueue.size() + 1) >= maxSplits) ||
@@ -1887,5 +1940,8 @@
 
 		if (obj->Type() != Intersectable::BVH_INTERSECTABLE)
-			cout << "error " << obj->Type() << endl;
+		{
+			cout << "error: wrong object type detected: " << obj->Type() << endl;
+			exit(0);
+		}
 
 		BvhNode *intersect = static_cast<BvhNode *>(obj);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2116)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/SamplingStrategy.cpp	(revision 2187)
@@ -52,22 +52,19 @@
 	// terminate the whole method?
 	for (; i < number; i++) 
-	  {
+	{
 		int j = 0;
 		bool sampleGenerated = false;
-		
+
 		for (j = 0; !sampleGenerated && (j < maxTries); ++ j)
-		  {
+		{
 			sampleGenerated = GenerateSample(ray);
-			
+
 			if (sampleGenerated)
-			  {		
+			{		
 				++ samples;
 				rays.push_back(ray);
-			  }
-		  }
-	  }
-
-
-	
+			}
+		}
+	}
 
 	return samples;
@@ -313,37 +310,4 @@
 	return true;
 }
-
-
-#if 0
-bool ObjectsInteriorDistribution::GenerateSample(SimpleRay &ray)
-{
-	Vector3 origin, direction; 
-
-	// get random object
-	const int i = RandomValue(0, mPreprocessor.mObjects.size() - 1);
-
-	const Intersectable *obj = mPreprocessor.mObjects[i];
-
-	// note: if we load the polygons as meshes, 
-	// asymtotically every second sample is lost!
-	origin = obj->GetBox().GetRandomPoint();
-
-	// uniformly distributed direction
-	direction = UniformRandomVector();
-
-	const float c = Magnitude(direction);
-
-	if (c <= Limits::Small) 
-		return false;
-
-	const float pdf = 1.0f;
-
-	direction *= 1.0f / c;
-	ray = SimpleRay(origin, direction, pdf);
-
-	return true;
-}
-
-#endif
 
 
