Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1521)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 1522)
@@ -100,6 +100,5 @@
 	void EnqueueRays(VssRayContainer &samples);
 
-	/** 
-		Hepler function for adaptive border sampling. It finds 
+	/** Hepler function for adaptive border sampling. It finds 
 		new sample points around a triangle in a eps environment
 	*/
@@ -116,4 +115,5 @@
 		const VssRay &oldRay);
 
+	void Visualize();
 	//////////////////////
 
@@ -128,4 +128,5 @@
 	float mEps;
 	float mThreshold;
+	VssRayContainer mVssRays;
 };
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1520)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Environment.cpp	(revision 1522)
@@ -1272,10 +1272,10 @@
    RegisterOption("GvsPreprocessor.epsilon",
 		 optFloat,
-		 "gvs_epsilon",
+		 "gvs_epsilon=",
 		 "0.00001");
 
     RegisterOption("GvsPreprocessor.threshold",
 		 optFloat,
-		 "gvs_threshold",
+		 "gvs_threshold=",
 		 "1.5");
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1521)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 1522)
@@ -434,4 +434,6 @@
 		cout << "loading view cells from " << buf << endl;
 		mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true);
+		if (!mViewCellsManager)
+			return false;
 	}
 	else
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1486)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 1522)
@@ -489,9 +489,9 @@
 	const float renderCostDecr = oldRenderCost - newRenderCost;
 
-//#ifdef _DEBUG
+#ifdef _DEBUG
 	Debug << "old render cost: " << oldRenderCost << endl;
 	Debug << "new render cost: " << newRenderCost << endl;
 	Debug << "render cost decrease: " << renderCostDecr << endl;
-//#endif
+#endif
 	splitCandidate.SetRenderCostDecrease(renderCostDecr);
 
@@ -527,5 +527,5 @@
 		(0
 		|| (mBvhStats.Leaves() >= mTermMaxLeaves)
-		|| (mBvhStats.mGlobalCostMisses >= mTermGlobalCostMissTolerance)
+		//|| (mBvhStats.mGlobalCostMisses >= mTermGlobalCostMissTolerance)
 		//|| mOutOfMemory 
 		);
@@ -974,5 +974,5 @@
 
 #ifdef _DEBUG
-	Debug << "\n§§§§ eval local cost §§§§" << endl
+	Debug << "\n§§§§ bvh eval const decrease §§§§" << endl
 		  << "back pvs: " << (int)objectsBack.size() << " front pvs: " << (int)objectsFront.size() << " total pvs: " << nTotalObjects << endl 
 		  << "back p: " << volBack / viewSpaceVol << " front p " << volFront / viewSpaceVol << " p: " << totalVol / viewSpaceVol << endl
@@ -1656,6 +1656,6 @@
 													   const ObjectContainer &objects)
 {
-	///////////////////////////////////////////////////////////////
-	//-- note matt: we assume that we have objects sorted by their id => 
+	///////////////////////////////////////
+	//-- we assume that we have objects sorted by their id => 
 	//-- we don't have to sort them here and an binary search 
 	//-- for identifying if a object is in a leaf.
@@ -1665,6 +1665,5 @@
 
 	mBvhStats.nodes = 1;
-	
-	
+		
 	// store pointer to this tree
 	BvhSubdivisionCandidate::sBvHierarchy = this;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1520)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 1522)
@@ -1830,8 +1830,7 @@
 	{
 		ViewCell *viewcell = *it;
-
-		if (viewcell->GetValid())
-		{
-			// if ray not outside of view space
+		
+		if (viewcell->GetValid()) // tests if view cellis in valid view space
+		{
 			float contribution;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1449)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 1522)
@@ -562,5 +562,5 @@
 		// || mOutOfMemory
 		|| (mVspStats.Leaves() >= mMaxViewCells)
-        || (mVspStats.mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
+      //  || (mVspStats.mGlobalCostMisses >= mTermGlobalCostMissTolerance) 
 		);
 
@@ -571,4 +571,5 @@
 		Debug << "leaves: " << mVspStats.Leaves() << " " <<  mMaxViewCells << endl;
 	}
+
 	return terminationCriteriaMet;
 }
@@ -1482,5 +1483,5 @@
 	const float renderCostDecrease = (oldRenderCost - newRenderCost) / viewSpaceVol;
 
-//#ifdef _DEBUG
+#ifdef _DEBUG
 	Debug << "\nvsp render cost decrease" << endl
 		  << "back pvs: " << pvsBack << " front pvs " << pvsFront << " total pvs: " << totalPvs << endl 
@@ -1488,5 +1489,5 @@
 		  << "old rc: " << normalizedOldRenderCost << " new rc: " << newRenderCost / viewSpaceVol << endl
 		  << "render cost decrease: " << renderCostDecrease << endl;
-//#endif
+#endif
 	return renderCostDecrease;
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 1521)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/RayCaster.cpp	(revision 1522)
@@ -32,4 +32,6 @@
 	if (!rays.empty())
 		return rays.back();
+	else
+		return NULL;
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1501)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/main.cpp	(revision 1522)
@@ -164,5 +164,9 @@
 
 	// parse view cells related options
-	preprocessor->PrepareViewCells();
+	if (!preprocessor->PrepareViewCells())
+	{
+		Cleanup();
+		exit(1);
+	}
 
 	if (0) 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1521)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 1522)
@@ -8,4 +8,5 @@
 #include "Plane3.h"
 #include "RayCaster.h"
+#include "Exporter.h"
 
 
@@ -13,4 +14,12 @@
 {
   
+struct VizStruct
+{
+	Polygon3 *enlargedTriangle;
+	Triangle3 originalTriangle;
+	VssRay *ray;
+};
+
+static vector<VizStruct> vizContainer;
 
 GvsPreprocessor::GvsPreprocessor(): Preprocessor(), mSamplingType(0)
@@ -59,8 +68,12 @@
 bool GvsPreprocessor::HandleRay(VssRay *vssRay)
 {
-	if (mViewCellsManager->ComputeSampleContribution(*vssRay, true, false))
+	const int oldContri = vssRay->mPvsContribution;
+	mViewCellsManager->ComputeSampleContribution(*vssRay, true, false);
+
+	if ((vssRay->mPvsContribution - oldContri) > 0) // new contribution
 	{
 		//cout << "h";
 		mRayQueue.push(vssRay);
+		mVssRays.push_back(new VssRay(*vssRay));
 		return true;
 	}
@@ -159,5 +172,7 @@
 	
 		VssRay *newRay = mRayCaster->CastSingleRay(sray.mOrigin, sray.mDirection, 1, mViewSpaceBox);
-		bool addedToQueue = HandleRay(newRay);
+
+		if (!newRay) return 0;
+		const bool enqueued = HandleRay(newRay);
 		
 		const int s1 = SubdivideEdge(hitTriangle, p1, p, x, *newRay, oldRay);
@@ -165,5 +180,5 @@
 		return s1 + s2;
 		
-		if (!addedToQueue)
+		if (!enqueued)
 			delete newRay;
 	}
@@ -181,4 +196,9 @@
 	{
 		hitTriangle = dynamic_cast<TriangleIntersectable *>(tObj)->GetItem();
+		cout << "t: " << hitTriangle << endl << endl;
+	}
+	else
+	{
+		cout << "not yet implemented" << endl;
 	}
 
@@ -200,10 +220,17 @@
 	}
 
+	VizStruct dummy;
+	dummy.enlargedTriangle = new Polygon3(enlargedTriangle);
+	dummy.originalTriangle = hitTriangle;
+	//dummy.ray = new VssRay(currentRay);
+	vizContainer.push_back(dummy);
+
 	// establish visibility
 	VssRayContainer vssRays;
 	CastRays(simpleRays, vssRays, false);
+
 	// add to ray queue
 	EnqueueRays(vssRays);
-/*
+#if 0
     // recursivly subdivide each edge
 	for (int i = 0; i < 9; ++ i)
@@ -217,5 +244,5 @@
 			currentRay);
 	}
-*/
+#endif
 	return (int)vssRays.size();
 }
@@ -375,6 +402,29 @@
 	}
 
+	Visualize();	
 	return true;
 }
 
-}
+
+void GvsPreprocessor::Visualize()
+{
+	Exporter *exporter = Exporter::GetExporter("gvs.wrl");
+
+	if (!exporter)
+		return;
+	
+	vector<VizStruct>::const_iterator vit, vit_end = vizContainer.end();
+	for (vit = vizContainer.begin(); vit != vit_end; ++ vit)
+	{
+		cout << "v";
+		exporter->ExportPolygon((*vit).enlargedTriangle);
+		//Material m;
+		//Polygon3 poly = Polygon3((*vit).originalTriangle);
+//		exporter->ExportPolygon(&poly);
+	}
+
+	exporter->ExportRays(mVssRays);
+	delete exporter;
+}
+
+}
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1486)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 1522)
@@ -243,5 +243,5 @@
 		);
 
-	if (1 && terminationCriteriaMet)
+	if (0 && terminationCriteriaMet)
 	{
 		Debug << "hierarchy global termination criteria met:" << endl;
@@ -331,4 +331,6 @@
 	cout << "\nstarting view space hierarchy construction ... " << endl;
 
+	mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses
+
 	RayInfoContainer *viewSpaceRays = new RayInfoContainer();
 	SubdivisionCandidate *vsc = 
@@ -345,4 +347,6 @@
 													 const ObjectContainer &objects)
 {
+	mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses
+
 	if (mObjectSpaceSubdivisionType == KD_BASED_OBJ_SUBDIV)
 	{
@@ -407,5 +411,5 @@
 		// cost ratio of cost decrease / totalCost
 		const float costRatio = mCurrentCandidate->GetRenderCostDecrease() / mTotalCost;
-		Debug << "ratio: " << costRatio << " min ratio: " << mTermMinGlobalCostRatio << endl;
+		//Debug << "ratio: " << costRatio << " min ratio: " << mTermMinGlobalCostRatio << endl;
 	
 		if (costRatio < mTermMinGlobalCostRatio)
@@ -606,5 +610,5 @@
 	cout << "\nresetting bv hierarchy" << endl;
 	mHierarchyStats.nodes -= mBvHierarchy->mBvhStats.nodes;
-	mHierarchyStats.mGlobalCostMisses = 0; // hack: reset global cost misses
+	
 	DEL_PTR(mBvHierarchy);
 	mBvHierarchy = new BvHierarchy();
