Index: GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2237)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/TestPreprocessor.vcproj	(revision 2238)
@@ -215,5 +215,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 QtCore4.lib qtmain.lib cg.lib cgGL.lib QtOpenGL4.lib Qt3Support4.lib QtTest4.lib QtGui4.lib QtInterface.lib"
-				OutputFile="../bin/release/Preprocessor.exe"
+				OutputFile="../bin/release/Preprocessor2.exe"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="..\src\GL;..\lib\release;..\..\Preprocessing\lib\release;..\..\..\..\..\..\NonGTP\Boost\lib;..\..\..\..\..\..\NonGTP\Xerces\xercesc\lib;..\..\..\..\..\..\NonGTP\Zlib\lib;..\..\..\..\..\..\NonGTP\Devil\lib;..\MultiLevelRayTracing\RTScene\Release;..\MultiLevelRayTracing\RTWorld\Release;&quot;$(QTDIR)\lib&quot;;.\QtInterface\Release;&quot;$(CG_LIB_PATH)&quot;"
Index: GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2237)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp	(revision 2238)
@@ -1122,11 +1122,11 @@
 		// should use classical approach here ...
 #if BOUND_RENDERCOST
+		const float rcLeft = std::max(objectsLeft, MIN_RENDERCOST);
+		const float rcRight = std::max(objectsRight, MIN_RENDERCOST);
+
 		const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar;
 #else
-		const float rcLeft = std::max(objectsLeft, MIN_RENDERCOST);
-		const float rcRight = std::max(objectsRight, MIN_RENDERCOST);
 
 		const float sum = noValidSplit ? 1e25f : objectsLeft * al + objectsRight * ar;
-
 #endif
 		/*cout << "pos=" << (*cit).mPos << "\t q=(" << objectsLeft << "," << objectsRight <<")\t r=(" 
@@ -1373,13 +1373,7 @@
 	float volRight = totalVol;
 	
-#if 1//USE_BETTER_RENDERCOST_EST
 	const float nTotalObjects = EvalAbsCost(tData.mNode->mObjects);
 	float nObjectsLeft = 0;
 	float nObjectsRight = nTotalObjects;
-#else
-	const int nTotalObjects = (int)EvalAbsCost(tData.mNode->mObjects);
-	int nObjectsLeft = 0;
-	int nObjectsRight = (int)nTotalObjects;
-#endif
 
 	const float viewSpaceVol = 
@@ -1440,15 +1434,16 @@
 
 #if BOUND_RENDERCOST
+
+		const float rcLeft = max(nObjectsLeft, MIN_RENDERCOST);
+		const float rcRight = max(nObjectsRight, MIN_RENDERCOST);
+		
+		// the heuristics
+	    const float sum = noValidSplit ? 
+			1e25f : volLeft * (float)rcLeft + volRight * (float)rcRight;
+#else
+	
 		// the heuristics
 	    const float sum = noValidSplit ? 
 			1e25f : volLeft * (float)nObjectsLeft + volRight * (float)nObjectsRight;
-#else
-		const float rcLeft = max(nObjectsLeft, MIN_RENDERCOST);
-		const float rcRight = max(nObjectsRight, MIN_RENDERCOST);
-
-		// the heuristics
-	    const float sum = noValidSplit ? 
-			1e25f : volLeft * (float)rcLeft + volRight * (float)rcRight;
-
 #endif
 		
@@ -1792,4 +1787,6 @@
 	VssRayContainer::const_iterator rit, rit_end = rays.end();
 
+	VssRay *lastVssRay = NULL;
+
 	VssRay::NewMail();
 
@@ -1798,25 +1795,32 @@
 		VssRay *ray = (*rit);
 
-		if (ray->mTerminationObject)
-		{
-			ray->mTerminationObject->GetOrCreateRays()->push_back(ray);
-			if (!ray->Mailed())
+		// filter out double rays (last ray the same as this ray
+		if (!lastVssRay ||
+			!(ray->mOrigin == lastVssRay->mTermination) ||
+			!(ray->mTermination == lastVssRay->mOrigin)) 
+		{
+			//cout << "j";
+			if (ray->mTerminationObject)
 			{
-				ray->Mail();
-				++ nRays;
+				ray->mTerminationObject->GetOrCreateRays()->push_back(ray);
+				if (!ray->Mailed())
+				{
+					ray->Mail();
+					++ nRays;
+				}
 			}
-		}
 
 #if COUNT_ORIGIN_OBJECTS
 
-		if (ray->mOriginObject)
-		{
-			cout << "o";
-			ray->mOriginObject->GetOrCreateRays()->push_back(ray);
-
-			if (!ray->Mailed())
+			if (ray->mOriginObject)
 			{
-				ray->Mail();
-				++ nRays;
+				//cout << "o";
+				ray->mOriginObject->GetOrCreateRays()->push_back(ray);
+
+				if (!ray->Mailed())
+				{
+					ray->Mail();
+					++ nRays;
+				}
 			}
 		}
Index: GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2237)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/VspTree.cpp	(revision 2238)
@@ -902,7 +902,7 @@
 
 int VspTree::EvalPvsEntriesIncr(VspSubdivisionCandidate &splitCandidate,
-								const float oldPvsSize,
-								const float fPvsSize,
-								const float bPvsSize) const
+								const int oldPvsSize,
+								const int fPvsSize,
+								const int bPvsSize) const
 {
 	
@@ -914,14 +914,14 @@
 
 	splitCandidate.mCorrectedFrontPvs = 
-		mHierarchyManager->EvalCorrectedPvs(fPvsSize, 
-											correctedOldPvs, 
+		mHierarchyManager->EvalCorrectedPvs((float)fPvsSize, 
+											(float)correctedOldPvs, 
 											splitCandidate.GetAvgRaysPerObject());
 	splitCandidate.mCorrectedBackPvs = 
-		mHierarchyManager->EvalCorrectedPvs(bPvsSize, 
-											correctedOldPvs, 
+		mHierarchyManager->EvalCorrectedPvs((float)bPvsSize, 
+											(float)correctedOldPvs, 
 											splitCandidate.GetAvgRaysPerObject());
 	
-	splitCandidate.mFrontPvs = fPvsSize;
-	splitCandidate.mBackPvs = bPvsSize;
+	splitCandidate.mFrontPvs = (float)fPvsSize;
+	splitCandidate.mBackPvs = (float)bPvsSize;
 
 	if (0)
@@ -3059,6 +3059,7 @@
 		else
 		{
+			//cout << "o";
 			// store object only for one ray
-			lastVssRay->mOriginObject = ray->mTerminationObject;
+			//lastVssRay->mOriginObject = ray->mTerminationObject;
 		}
 	}
