Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2695)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h	(revision 2705)
@@ -227,5 +227,5 @@
 	bool HasContribution(VssRay &ray);
 
-	void IntersectWithViewCell();
+	void ComputeViewCellGeometryIntersection();
 
 	void DeterminePvsObjects(VssRayContainer &rays);
@@ -239,7 +239,7 @@
 	*/
 	void UpdateStatsForVisualization(KdIntersectable *kdInt);
-	/** Keep count of new objects for stats.
-	*/
-	void CountObject(Intersectable *triObj);
+	/** Keep count of new objects for stats. Returns number of new pvs entries.
+	*/
+	int CountObject(Intersectable *triObj);
 
 	void CompileViewCellsFromPointList();
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2696)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2705)
@@ -461,20 +461,20 @@
 	/** Evaluautes histogram for a given number of view cells.
 	*/
-	void EvalViewCellHistogram(const string filename, const int nViewCells);
+	void EvalViewCellHistogram(const string filename, int nViewCells);
 	/** Evaluautes histogram for a given number of view cells.
 	*/
 	void EvalViewCellHistogramForPvsSize(const string filename, 
-										 const int nViewCells);
+										 int nViewCells);
 	/** Evaluautes histogram for a given vector of view cells.
 	*/
 	void EvalViewCellHistogramForPvsSize(const string filename, 
 										 ViewCellContainer &viewCells);
-	float ComputeRenderCost(const int tri, const int obj); //const
+	float ComputeRenderCost(int tri, int obj); //const
 	/** Sets pvs size of a view cell as a scalar. Used when storing pvs only in the leaves
 		of the hierarchy.
 	*/
 	void UpdateScalarPvsSize(ViewCell *vc, 
-							 const float pvsCost, 
-							 const int entriesInPvs) const;
+							 float pvsCost, 
+							 int entriesInPvs) const;
 	/** Sets render cost of a view cell as a scalar.
 	*/
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2704)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2705)
@@ -333,5 +333,5 @@
 			char filename[256];
 			//sprintf(filename, "error-frame-%04d-%0.5f.png", mFrame, pErrorPixels);
-			sprintf(filename, "error-frame-%04d-%04d-%08d.png", mFrame, viewcell->GetId(), pixelCount);
+			sprintf_s(filename, "error-frame-%04d-%04d-%08d.png", mFrame, viewcell->GetId(), pixelCount);
 			QImage im = toImage();
 			string str = mSnapPrefix + filename;
@@ -367,5 +367,5 @@
 
 				im = toImage();
-				sprintf(filename, "error-frame-%04d-%04d-%08d-pvs.png", mFrame, viewcell->GetId(), pixelCount);
+				sprintf_s(filename, "error-frame-%04d-%04d-%08d-pvs.png", mFrame, viewcell->GetId(), pixelCount);
 				str = mSnapPrefix + filename;
 				qstr = str.c_str();
@@ -1004,44 +1004,33 @@
 	switch (e->key()) 
 	{
-case Qt::Key_E:
-	mRenderErrors = !mRenderErrors;
-	updateGL();
-	break;
-case Qt::Key_R:
-	mUseRandomColorPerPvsObject = !mUseRandomColorPerPvsObject;;
-	updateGL();
-	break;
-case Qt::Key_T:
-	mTopView = !mTopView;
-	SetupCameraProjection(width(), height());
-	updateGL();
-	break;
-case Qt::Key_V:
-	mRenderViewCells = !mRenderViewCells;
-	updateGL();
-	break;
-case Qt::Key_P:
-	// set random viewpoint
-	mViewCellsManager->GetViewPoint(mViewPoint);
-	updateGL();
-	break;
-case Qt::Key_S: {
-	// set view poitn and direction
-	QString text;
-	bool ok;
-	text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
-	text = QInputDialog::getText(this,
-		"Enter a view point",
-		"",
-		QLineEdit::Normal,
-		text,
-		&ok);
-	if (!ok)
+	case Qt::Key_E:
+		mRenderErrors = !mRenderErrors;
+		updateGL();
 		break;
-
-	if (sscanf(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
-		text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
+	case Qt::Key_R:
+		mUseRandomColorPerPvsObject = !mUseRandomColorPerPvsObject;;
+		updateGL();
+		break;
+	case Qt::Key_T:
+		mTopView = !mTopView;
+		SetupCameraProjection(width(), height());
+		updateGL();
+		break;
+	case Qt::Key_V:
+		mRenderViewCells = !mRenderViewCells;
+		updateGL();
+		break;
+	case Qt::Key_P:
+		// set random viewpoint
+		mViewCellsManager->GetViewPoint(mViewPoint);
+		updateGL();
+		break;
+	case Qt::Key_S: {
+		// set view poitn and direction
+		QString text;
+		bool ok;
+		text.sprintf("%f %f %f", mViewPoint.x, mViewPoint.y, mViewPoint.z);
 		text = QInputDialog::getText(this,
-			"Enter a direction",
+			"Enter a view point",
 			"",
 			QLineEdit::Normal,
@@ -1050,15 +1039,26 @@
 		if (!ok)
 			break;
-		if (sscanf(text.toAscii(), "%f %f %f", &mViewDirection.x,
-			&mViewDirection.y, &mViewDirection.z) == 3) {
-				updateGL();
+
+		if (sscanf_s(text.toAscii(), "%f %f %f", &mViewPoint.x, &mViewPoint.y, &mViewPoint.z) == 3) {
+			text.sprintf("%f %f %f", mViewDirection.x, mViewDirection.y, mViewDirection.z);
+			text = QInputDialog::getText(this,
+				"Enter a direction",
+				"",
+				QLineEdit::Normal,
+				text,
+				&ok);
+			if (!ok)
+				break;
+			if (sscanf_s(text.toAscii(), "%f %f %f", &mViewDirection.x,
+				&mViewDirection.y, &mViewDirection.z) == 3) {
+					updateGL();
 			}
 			break;
-	}
-				}
-default:
-	cerr << "unknown key" << endl;
-	e->ignore();
-	break;
+		}
+					}
+	default:
+		cerr << "unknown key" << endl;
+		e->ignore();
+		break;
 	}
 }
@@ -2700,5 +2700,5 @@
 	SetupCamera();
 
-	for (size_t i = 0; i < GetPreprocessor()->mDynamicObjects.size(); ++ i)
+	for (GLuint i = 0; i < GetPreprocessor()->mDynamicObjects.size(); ++ i)
 	{
 		glLoadName(i);
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2686)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlViewer.cpp	(revision 2705)
@@ -60,14 +60,14 @@
 void QtGlViewer::RenderScene()
 {
-	GLfloat mat_ambient[]   = {  0.5, 0.5, 0.5, 1.0  };
+	GLfloat mat_ambient[]   = {0.5f, 0.5f, 0.5f, 1.0f};
 	
 	// mat_specular and mat_shininess are NOT default values
-	GLfloat mat_diffuse[]   = {  1.0, 1.0, 1.0, 1.0  };
-	GLfloat mat_specular[]  = {  0.3, 0.3, 0.3, 1.0  };
-	GLfloat mat_shininess[] = {  1.0  };
-
-	GLfloat light_ambient[]  = {  0.2f, 0.2f, 0.2f, 1.0f  };
-	GLfloat light_diffuse[]  = {  0.4f, 0.4f, 0.4f, 1.0f  };
-	GLfloat light_specular[] = {  0.3f, 0.3f, 0.3f, 1.0f };
+	GLfloat mat_diffuse[]   = {1.0f, 1.0f, 1.0f, 1.0f};
+	GLfloat mat_specular[]  = {0.3f, 0.3f, 0.3f, 1.0f};
+	GLfloat mat_shininess[] = {1.0f  };
+
+	GLfloat light_ambient[]  = {0.2f, 0.2f, 0.2f, 1.0f};
+	GLfloat light_diffuse[]  = {0.4f, 0.4f, 0.4f, 1.0f};
+	GLfloat light_specular[] = {0.3f, 0.3f, 0.3f, 1.0f};
 
 	GLfloat lmodel_ambient[] = {0.3f, 0.3f, 0.3f, 1.0f};
@@ -75,9 +75,9 @@
 
 	// set position of the light
-	GLfloat infinite_light[] = {1.0, 0.8, 1.0, 0.0};
+	GLfloat infinite_light[] = {1.0f, 0.8f, 1.0f, 0.0f};
 	glLightfv (GL_LIGHT0, GL_POSITION, infinite_light);
 
 	// set position of the light2
-	GLfloat infinite_light2[] = {-0.3, 1.5, 1.0, 0.0};
+	GLfloat infinite_light2[] = {-0.3f, 1.5f, 1.0f, 0.0f};
 	glLightfv (GL_LIGHT1, GL_POSITION, infinite_light2);
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2702)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2705)
@@ -1445,5 +1445,5 @@
 
 
-float ViewCellsManager::ComputeRenderCost(const int tri, const int obj) //const
+float ViewCellsManager::ComputeRenderCost(int tri, int obj) //const
 {
 	return max((float)tri * mTriangleWeight, (float)obj * mObjectWeight);
@@ -2374,7 +2374,5 @@
 {
 #ifdef USE_VERBOSE_PVS
-	KdIntersectable *kdObj = static_cast<KdIntersectable *>(obj);
-
-	const AxisAlignedBox3 box = kdObj->GetBox();
+	const AxisAlignedBox3 box = obj->GetBox();
 	const float dist = Distance(vc->GetBox().Center(), box.Center());
 
@@ -2431,6 +2429,22 @@
 		//hasAbsContribution = viewCell->GetPvs().AddSample(obj,ray.mPdf);
 		
-		//if (hasAbsContribution) 	UpdateStatsForViewCell(viewCell, obj);
-		
+		if (hasAbsContribution)
+		{
+			if (QT_VISUALIZATION_SHOWN)
+			{
+				int numTriangles;
+
+				if (obj->Type() == Intersectable::KD_INTERSECTABLE)
+				{
+					numTriangles = GetPreprocessor()->mKdTree->GetNumObjects(static_cast<KdIntersectable *>(obj)->GetItem());
+				}
+				else if (obj->Type() == Intersectable::SCENEGRAPHLEAF_INTERSECTABLE)
+				{
+					numTriangles = static_cast<SceneGraphLeafIntersectable *>(obj)->GetItem()->mGeometry.size();
+				}
+
+				UpdateStatsForViewCell(viewCell, obj, numTriangles);
+			}
+		}
 	}
 	else 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj	(revision 2695)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GtpVisibility05.vcproj	(revision 2705)
@@ -202,382 +202,4 @@
 	<Files>
 		<Filter
-			Name="Header Files"
-			Filter="h;hpp;hxx;hm;inl;inc;xsd"
-			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
-			>
-			<File
-				RelativePath=".\AxisAlignedBox3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Beam.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timer\BenchTimer.h"
-				>
-			</File>
-			<File
-				RelativePath=".\BitVectorPvs.h"
-				>
-			</File>
-			<File
-				RelativePath=".\BoostPreprocessorThread.h"
-				>
-			</File>
-			<File
-				RelativePath=".\BoundingBoxConverter.h"
-				>
-			</File>
-			<File
-				RelativePath=".\BvHierarchy.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Camera.h"
-				>
-			</File>
-			<File
-				RelativePath=".\common.h"
-				>
-			</File>
-			<File
-				RelativePath=".\havran\configh.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Containers.h"
-				>
-			</File>
-			<File
-				RelativePath=".\DifferenceSampling.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Environment.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ExactPreprocessor.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Exporter.h"
-				>
-			</File>
-			<File
-				RelativePath=".\FilterBasedDistribution.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\FilterBasedDistribution.h"
-				>
-			</File>
-			<File
-				RelativePath=".\FlexibleHeap.h"
-				>
-			</File>
-			<File
-				RelativePath=".\GzBinFileInputStream.h"
-				>
-			</File>
-			<File
-				RelativePath=".\GzFileInputSource.h"
-				>
-			</File>
-			<File
-				RelativePath=".\gzstream.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Halton.h"
-				>
-			</File>
-			<File
-				RelativePath=".\HashPvs.h"
-				>
-			</File>
-			<File
-				RelativePath=".\HavranRayCaster.h"
-				>
-			</File>
-			<File
-				RelativePath=".\HierarchyManager.h"
-				>
-			</File>
-			<File
-				RelativePath=".\IntelRayCaster.h"
-				>
-			</File>
-			<File
-				RelativePath=".\InternalRayCaster.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Intersectable.h"
-				>
-			</File>
-			<File
-				RelativePath=".\IntersectableWrapper.h"
-				>
-			</File>
-			<File
-				RelativePath=".\IntersectionBoundingBoxConverter.h"
-				>
-			</File>
-			<File
-				RelativePath=".\KdTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\LogManager.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Mailable.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Material.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Matrix4x4.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timer\merror.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Mesh.h"
-				>
-			</File>
-			<File
-				RelativePath=".\MeshKdTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timer\mstring.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Mutation.h"
-				>
-			</File>
-			<File
-				RelativePath=".\MutualVisibility.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ObjectPvs.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ObjExporter.h"
-				>
-			</File>
-			<File
-				RelativePath=".\OcclusionQuery.h"
-				>
-			</File>
-			<File
-				RelativePath=".\OspTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Parser.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timer\PerfTimer.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timer\PerfTimerSkeleton.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Plane3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ply.h"
-				>
-			</File>
-			<File
-				RelativePath=".\PlyParser.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Polygon3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Polytope.h"
-				>
-			</File>
-			<File
-				RelativePath=".\PreprocessorThread.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Pvs.h"
-				>
-			</File>
-			<File
-				RelativePath=".\PvsBase.h"
-				>
-			</File>
-			<File
-				RelativePath=".\PvsDefinitions.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RandomViewCellsHandler.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Ray.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RayCaster.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RayInfo.h"
-				>
-			</File>
-			<File
-				RelativePath=".\havran\raypack.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Timer\RDTSCTimer.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Rectangle3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Renderer.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RenderSimulator.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RenderTexture.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ResourceManager.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ReverseGvs.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RndGauss.h"
-				>
-			</File>
-			<File
-				RelativePath=".\RssTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\SamplingStrategy.h"
-				>
-			</File>
-			<File
-				RelativePath=".\SceneGraph.h"
-				>
-			</File>
-			<File
-				RelativePath=".\SimpleRay.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Statistics.h"
-				>
-			</File>
-			<File
-				RelativePath=".\SubdivisionCandidate.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Tetrahedron3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\havran\timer.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Trackball.h"
-				>
-			</File>
-			<File
-				RelativePath=".\TraversalTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Triangle3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\UnigraphicsParser.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Vector2.h"
-				>
-			</File>
-			<File
-				RelativePath=".\Vector3.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ViewCell.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ViewCellBsp.h"
-				>
-			</File>
-			<File
-				RelativePath=".\ViewCellsManager.h"
-				>
-			</File>
-			<File
-				RelativePath=".\VrmlExporter.h"
-				>
-			</File>
-			<File
-				RelativePath=".\VspBspTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\VspTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\VssRay.h"
-				>
-			</File>
-			<File
-				RelativePath=".\VssTree.h"
-				>
-			</File>
-			<File
-				RelativePath=".\X3dParserXerces.h"
-				>
-			</File>
-		</Filter>
-		<Filter
 			Name="havran"
 			>
@@ -591,4 +213,8 @@
 			</File>
 			<File
+				RelativePath=".\havran\configh.h"
+				>
+			</File>
+			<File
 				RelativePath=".\HavranDynRayCaster.cpp"
 				>
@@ -656,4 +282,8 @@
 			<File
 				RelativePath=".\havran\ktbtrav.h"
+				>
+			</File>
+			<File
+				RelativePath=".\havran\raypack.h"
 				>
 			</File>
@@ -707,4 +337,20 @@
 			>
 			<File
+				RelativePath=".\GzBinFileInputStream.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\GzBinFileInputStream.h"
+				>
+			</File>
+			<File
+				RelativePath=".\GzFileInputSource.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\GzFileInputSource.h"
+				>
+			</File>
+			<File
 				RelativePath=".\ObjectsParser.cpp"
 				>
@@ -727,4 +373,12 @@
 			</File>
 			<File
+				RelativePath=".\Parser.h"
+				>
+			</File>
+			<File
+				RelativePath=".\ply.h"
+				>
+			</File>
+			<File
 				RelativePath=".\plyfile.c"
 				>
@@ -735,4 +389,8 @@
 			</File>
 			<File
+				RelativePath=".\PlyParser.h"
+				>
+			</File>
+			<File
 				RelativePath=".\PreprocessorFactory.h"
 				>
@@ -743,4 +401,12 @@
 			</File>
 			<File
+				RelativePath=".\UnigraphicsParser.h"
+				>
+			</File>
+			<File
+				RelativePath=".\ViewCellsParser.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\ViewCellsParser.h"
 				>
@@ -751,8 +417,4 @@
 			</File>
 			<File
-				RelativePath=".\VrmlExporter.cpp"
-				>
-			</File>
-			<File
 				RelativePath=".\X3dParser.cpp"
 				>
@@ -760,4 +422,8 @@
 			<File
 				RelativePath=".\X3dParser.h"
+				>
+			</File>
+			<File
+				RelativePath=".\X3dParserXerces.h"
 				>
 			</File>
@@ -828,14 +494,40 @@
 		</Filter>
 		<Filter
-			Name="Source Files"
-			Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
-			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+			Name="Exporters"
 			>
 			<File
-				RelativePath=".\AxisAlignedBox3.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Beam.cpp"
+				RelativePath=".\Exporter.h"
+				>
+			</File>
+			<File
+				RelativePath=".\ObjExporter.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\ObjExporter.h"
+				>
+			</File>
+			<File
+				RelativePath=".\VrmlExporter.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\VrmlExporter.h"
+				>
+			</File>
+			<File
+				RelativePath=".\X3dExporter.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\X3dExporter.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="utils"
+			>
+			<File
+				RelativePath=".\AxisAlignedBox3.h"
 				>
 			</File>
@@ -845,13 +537,9 @@
 			</File>
 			<File
-				RelativePath=".\BitVectorPvs.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\BvHierarchy.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Camera.cpp"
+				RelativePath=".\Timer\BenchTimer.h"
+				>
+			</File>
+			<File
+				RelativePath=".\BoostPreprocessorThread.h"
 				>
 			</File>
@@ -861,5 +549,9 @@
 			</File>
 			<File
-				RelativePath=".\DifferenceSampling.cpp"
+				RelativePath=".\common.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Containers.h"
 				>
 			</File>
@@ -869,17 +561,9 @@
 			</File>
 			<File
-				RelativePath=".\ExactPreprocessor.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Exporter.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\GzBinFileInputStream.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\GzFileInputSource.cpp"
+				RelativePath=".\Environment.h"
+				>
+			</File>
+			<File
+				RelativePath=".\FlexibleHeap.h"
 				>
 			</File>
@@ -889,33 +573,17 @@
 			</File>
 			<File
+				RelativePath=".\gzstream.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Halton.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\HierarchyManager.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\IntelRayCaster.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\InternalRayCaster.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Intersectable.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\IntersectableWrapper.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\IntersectionBoundingBoxConverter.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\KdTree.cpp"
+				RelativePath=".\Halton.h"
+				>
+			</File>
+			<File
+				RelativePath=".\HashPvs.h"
 				>
 			</File>
@@ -925,5 +593,5 @@
 			</File>
 			<File
-				RelativePath=".\Mailable.cpp"
+				RelativePath=".\LogManager.h"
 				>
 			</File>
@@ -933,41 +601,25 @@
 			</File>
 			<File
+				RelativePath=".\Material.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Matrix4x4.cpp"
 				>
 			</File>
 			<File
+				RelativePath=".\Matrix4x4.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Timer\merror.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\Mesh.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\MeshKdTree.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Mutation.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\MutualVisibility.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\ObjectPvs.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\ObjExporter.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\OcclusionQuery.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\OspTree.cpp"
+				RelativePath=".\Timer\merror.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Timer\mstring.h"
 				>
 			</File>
@@ -977,73 +629,45 @@
 			</File>
 			<File
+				RelativePath=".\Plane3.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Polygon3.cpp"
 				>
 			</File>
 			<File
+				RelativePath=".\Polygon3.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Polytope.cpp"
 				>
 			</File>
 			<File
+				RelativePath=".\Polytope.h"
+				>
+			</File>
+			<File
 				RelativePath=".\PreprocessorThread.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\RandomViewCellsHandler.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Ray.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\RayCaster.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\RayInfo.cpp"
-				>
-			</File>
-			<File
 				RelativePath=".\Timer\RDTSCTimer.cpp"
 				>
 			</File>
 			<File
+				RelativePath=".\Timer\RDTSCTimer.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Rectangle3.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\Renderer.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\RenderSimulator.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\RenderTexture.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\ReverseGvs.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\RssTree.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\SamplingStrategy.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\SceneGraph.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\SubdivisionCandidate.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\Tetrahedron3.cpp"
+				RelativePath=".\Rectangle3.h"
+				>
+			</File>
+			<File
+				RelativePath=".\Tetrahedron3.h"
 				>
 			</File>
@@ -1053,9 +677,13 @@
 			</File>
 			<File
+				RelativePath=".\havran\timer.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Trackball.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\TraversalTree.cpp"
+				RelativePath=".\Trackball.h"
 				>
 			</File>
@@ -1065,51 +693,435 @@
 			</File>
 			<File
+				RelativePath=".\Triangle3.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Vector2.cpp"
 				>
 			</File>
 			<File
+				RelativePath=".\Vector2.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Vector3.cpp"
 				>
 			</File>
 			<File
-				RelativePath=".\ViewCell.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\ViewCellBsp.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\ViewCellsManager.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\ViewCellsParser.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\VspBspTree.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\VspTree.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\VssRay.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\VssTree.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\X3dExporter.cpp"
-				>
-			</File>
-			<File
-				RelativePath=".\X3dExporter.h"
-				>
-			</File>
+				RelativePath=".\Vector3.h"
+				>
+			</File>
+		</Filter>
+		<Filter
+			Name="main"
+			>
+			<Filter
+				Name="Header Files"
+				Filter="h;hpp;hxx;hm;inl;inc;xsd"
+				UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+				>
+				<File
+					RelativePath=".\Beam.h"
+					>
+				</File>
+				<File
+					RelativePath=".\BitVectorPvs.h"
+					>
+				</File>
+				<File
+					RelativePath=".\BoundingBoxConverter.h"
+					>
+				</File>
+				<File
+					RelativePath=".\BvHierarchy.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Camera.h"
+					>
+				</File>
+				<File
+					RelativePath=".\DifferenceSampling.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ExactPreprocessor.h"
+					>
+				</File>
+				<File
+					RelativePath=".\FilterBasedDistribution.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\FilterBasedDistribution.h"
+					>
+				</File>
+				<File
+					RelativePath=".\HavranRayCaster.h"
+					>
+				</File>
+				<File
+					RelativePath=".\HierarchyManager.h"
+					>
+				</File>
+				<File
+					RelativePath=".\IntelRayCaster.h"
+					>
+				</File>
+				<File
+					RelativePath=".\InternalRayCaster.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Intersectable.h"
+					>
+				</File>
+				<File
+					RelativePath=".\IntersectableWrapper.h"
+					>
+				</File>
+				<File
+					RelativePath=".\IntersectionBoundingBoxConverter.h"
+					>
+				</File>
+				<File
+					RelativePath=".\KdTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Mailable.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Mesh.h"
+					>
+				</File>
+				<File
+					RelativePath=".\MeshKdTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Mutation.h"
+					>
+				</File>
+				<File
+					RelativePath=".\MutualVisibility.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ObjectPvs.h"
+					>
+				</File>
+				<File
+					RelativePath=".\OcclusionQuery.h"
+					>
+				</File>
+				<File
+					RelativePath=".\OspTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Timer\PerfTimer.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Timer\PerfTimerSkeleton.h"
+					>
+				</File>
+				<File
+					RelativePath=".\PreprocessorThread.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Pvs.h"
+					>
+				</File>
+				<File
+					RelativePath=".\PvsBase.h"
+					>
+				</File>
+				<File
+					RelativePath=".\PvsDefinitions.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RandomViewCellsHandler.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Ray.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RayCaster.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RayInfo.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Renderer.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RenderSimulator.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RenderTexture.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ResourceManager.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ReverseGvs.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RndGauss.h"
+					>
+				</File>
+				<File
+					RelativePath=".\RssTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\SamplingStrategy.h"
+					>
+				</File>
+				<File
+					RelativePath=".\SceneGraph.h"
+					>
+				</File>
+				<File
+					RelativePath=".\SimpleRay.h"
+					>
+				</File>
+				<File
+					RelativePath=".\Statistics.h"
+					>
+				</File>
+				<File
+					RelativePath=".\SubdivisionCandidate.h"
+					>
+				</File>
+				<File
+					RelativePath=".\TraversalTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ViewCell.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ViewCellBsp.h"
+					>
+				</File>
+				<File
+					RelativePath=".\ViewCellsManager.h"
+					>
+				</File>
+				<File
+					RelativePath=".\VspBspTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\VspTree.h"
+					>
+				</File>
+				<File
+					RelativePath=".\VssRay.h"
+					>
+				</File>
+				<File
+					RelativePath=".\VssTree.h"
+					>
+				</File>
+			</Filter>
+			<Filter
+				Name="Source Files"
+				Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+				UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+				>
+				<File
+					RelativePath=".\AxisAlignedBox3.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Beam.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\BitVectorPvs.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\BvHierarchy.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Camera.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\DifferenceSampling.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\ExactPreprocessor.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Exporter.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\HierarchyManager.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\IntelRayCaster.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\InternalRayCaster.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Intersectable.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\IntersectableWrapper.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\IntersectionBoundingBoxConverter.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\KdTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Mailable.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Mesh.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\MeshKdTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Mutation.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\MutualVisibility.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\ObjectPvs.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\OcclusionQuery.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\OspTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\RandomViewCellsHandler.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Ray.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\RayCaster.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\RayInfo.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Renderer.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\RenderSimulator.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\RenderTexture.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\ReverseGvs.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\RssTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\SamplingStrategy.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\SceneGraph.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\SubdivisionCandidate.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\Tetrahedron3.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\TraversalTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\ViewCell.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\ViewCellBsp.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\ViewCellsManager.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\VspBspTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\VspTree.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\VssRay.cpp"
+					>
+				</File>
+				<File
+					RelativePath=".\VssTree.cpp"
+					>
+				</File>
+			</Filter>
 		</Filter>
 	</Files>
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/common.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2702)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/common.h	(revision 2705)
@@ -537,11 +537,15 @@
 #define OUT_OF_BOUNDS_ID -1
 
-#endif
-
-
-
-
-
-
-
-
+
+#define QT_VISUALIZATION_SHOWN 1
+
+
+#endif
+
+
+
+
+
+
+
+
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2699)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2705)
@@ -399,5 +399,5 @@
   Vector3 max = sbox.Max();
   
-  int packets = rays.size() / 16;
+  int packets = (int)rays.size() / 16;
   
   int i, k = 0;
@@ -431,5 +431,5 @@
 			       const bool pruneInvalidRays )
 {
-  int buckets = rays.size()/16;
+  int buckets = (int)rays.size()/16;
   int offset = 0;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 2606)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/IntelRayCaster.cpp	(revision 2705)
@@ -429,5 +429,5 @@
   Vector3 max = sbox.Max();
   
-  int packets = rays.size() / 16;
+  int packets = (int)rays.size() / 16;
   
   int i, j, k = 0;
@@ -460,13 +460,12 @@
 
 void
-IntelRayCaster::CastRays(
-			 SimpleRayContainer &rays,
-			 VssRayContainer &vssRays,
-			 const AxisAlignedBox3 &sbox,
-			 const bool castDoubleRay,
-			 const bool pruneInvalidRays )
-{
-
-  int buckets = rays.size()/16;
+IntelRayCaster::CastRays(SimpleRayContainer &rays,
+						 VssRayContainer &vssRays,
+						 const AxisAlignedBox3 &sbox,
+						 bool castDoubleRay,
+						 bool pruneInvalidRays)
+{
+
+  int buckets = (int)rays.size() / 16;
   int offset = 0;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2705)
@@ -34,5 +34,9 @@
 
 KdNode::KdNode(KdInterior *parent):
-mParent(parent), mMailbox(0), mIntersectable(NULL), mMailbox2(0)
+mParent(parent), 
+mMailbox(0), 
+mIntersectable(NULL), 
+mMailbox2(0),
+mNumObjects(0)
 {
   if (parent)
@@ -136,4 +140,8 @@
   SetPvsTerminationNodes(area);
   
+  // sets the number of objects in the subtree
+  KdNode::NewMail();
+  SetNumObjects(mRoot);
+
   return true;
 }
@@ -1057,6 +1065,6 @@
 void
 KdTree::CollectKdObjects(const AxisAlignedBox3 &box,
-			 ObjectContainer &objects
-			)
+						 ObjectContainer &objects
+						 )
 {
   stack<KdNode *> nodeStack;
@@ -1124,5 +1132,5 @@
 void
 KdTree::CollectObjects(const AxisAlignedBox3 &box,
-		       ObjectContainer &objects)
+					   ObjectContainer &objects)
 {
   stack<KdNode *> nodeStack;
@@ -1152,4 +1160,42 @@
     }
   }
+}
+
+
+int KdTree::GetNumObjects(KdNode *node) const
+{
+	return node->mNumObjects;
+}
+
+
+void KdTree::SetNumObjects(KdNode *node)
+{
+	node->mNumObjects = 0;
+
+	if (node->IsLeaf()) 
+	{
+		KdLeaf *leaf = (KdLeaf *)node;
+
+		for (int j=0; j < leaf->mObjects.size(); ++ j) 
+		{
+			Intersectable *object = leaf->mObjects[j];
+
+			if (!object->Mailed()) 
+			{
+				object->Mail();
+				++ node->mNumObjects;
+			}
+		}
+	}
+	else 
+	{
+		KdInterior *interior = (KdInterior *)node;
+
+		SetNumObjects(interior->mFront);
+		SetNumObjects(interior->mBack);
+
+		node->mNumObjects += interior->mFront->mNumObjects;
+		node->mNumObjects += interior->mBack->mNumObjects;
+	}
 }
 
@@ -1670,4 +1716,8 @@
 	SetPvsTerminationNodes(area);
 
+	// sets the number of objects in the subtree
+	KdNode::NewMail();
+	SetNumObjects(mRoot);
+
 	Debug << mStat << endl;
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 2691)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.h	(revision 2705)
@@ -164,4 +164,5 @@
   short mDepth;
   short mPvsTermination;
+  int mNumObjects;
 };
 
@@ -344,14 +345,8 @@
   AxisAlignedBox3 GetBox() const { return mBox; }
 
-  int
-  CastRay(
-		  Ray &ray
-		  );
-  
-
-  int
-  CastBeam(
-		   Beam &beam
-		   );
+  int CastRay(Ray &ray);
+  
+
+  int CastBeam(Beam &beam);
   
   
@@ -368,7 +363,5 @@
 					   vector<ViewCell *> &viewcells);
 
-  const KdTreeStatistics &GetStatistics() const {
-    return mStat;
-  }
+  const KdTreeStatistics &GetStatistics() const { return mStat;  }
 
   /** Returns or creates a new intersectable for use in a kd based pvs.
@@ -394,7 +387,8 @@
 		   );
 
-  // colect objects which are in the bounding box by explictly specifying the
-  // allowed size of the boxes. If this size is smaller than size used for pvs entries
-  // filtering will be more precise
+  /** colect objects which are in the bounding box by explictly specifying the
+      allowed size of the boxes. If this size is smaller than size used for pvs entries
+	  filtering will be more precise.
+  */
   void
   CollectSmallKdObjects(const AxisAlignedBox3 &box,
@@ -403,7 +397,14 @@
 						);
 
-  void
-  CollectObjects(KdNode *n, ObjectContainer &objects);
-  
+  /** warning - uses mailing.
+  */
+  void CollectObjects(KdNode *n, ObjectContainer &objects);
+  /** Sets the number of objects under the current subtree for each node.
+	  warning - uses mailing.
+  */
+  void SetNumObjects(KdNode *root);
+  /** Returns the number of objects under the curretn subtree.
+  */
+  int GetNumObjects(KdNode *node) const;
   /** Collects objects with dublicates (no mailing going on)
   */
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2696)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp	(revision 2705)
@@ -22,5 +22,5 @@
 #define NOT_ACCOUNTED_OBJECT 0
 #define ACCOUNTED_OBJECT 2
-#define SHOW_QT_VISUALIZATION 0
+
 
 static const float MIN_DIST = 0.001f;
@@ -174,12 +174,18 @@
 
 
-void GvsPreprocessor::CountObject(Intersectable *triObj)
-{
+int GvsPreprocessor::CountObject(Intersectable *triObj)
+{
+	int numObjects = 0;
+
 	if ((triObj->mCounter != (NOT_ACCOUNTED_OBJECT + 1)) && 
 		(triObj->mCounter != (ACCOUNTED_OBJECT + 1)))
 	{
 		++ triObj->mCounter;
-		++ mGenericStats[1];
-	}
+		++ numObjects;
+	}
+
+	mGenericStats[1] += numObjects;
+
+	return numObjects;
 }
 
@@ -187,14 +193,17 @@
 void GvsPreprocessor::UpdateStatsForVisualization(KdIntersectable *kdInt)
 {
-	//mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt);
-
 	// count new objects in pvs due to kd node conversion	
 	myobjects.clear();
-	mKdTree->CollectObjects(kdInt->GetItem(), myobjects);
+	// also gather duplicates to avoid mailing
+	mKdTree->CollectObjectsWithDublicates(kdInt->GetItem(), myobjects);
+
+	int numObj;
 
 	ObjectContainer::const_iterator oit, oit_end = myobjects.end();
 
 	for (oit = myobjects.begin(); oit != oit_end; ++ oit)
-		CountObject(*oit);
+		numObj = CountObject(*oit);
+
+	mViewCellsManager->UpdateStatsForViewCell(mCurrentViewCell, kdInt, numObj);
 }	
 
@@ -240,5 +249,5 @@
 				mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
 
-				if (SHOW_QT_VISUALIZATION) UpdateStatsForVisualization(kdInt);	
+				if (QT_VISUALIZATION_SHOWN) UpdateStatsForVisualization(kdInt);	
 			}
 		}
@@ -871,5 +880,5 @@
 
 
-void GvsPreprocessor::IntersectWithViewCell()
+void GvsPreprocessor::ComputeViewCellGeometryIntersection()
 {
 	AxisAlignedBox3 box = mCurrentViewCell->GetBox();
@@ -915,5 +924,5 @@
 			mCurrentViewCell->GetPvs().AddSampleDirty(kdInt, 1.0f);
 			//mCurrentViewCell->GetPvs().AddSampleDirtyCheck(kdInt, 1.0f);
-			if (SHOW_QT_VISUALIZATION) UpdateStatsForVisualization(kdInt);
+			if (QT_VISUALIZATION_SHOWN) UpdateStatsForVisualization(kdInt);
 		}
 	}
@@ -1296,5 +1305,5 @@
 	
 	// at last compute objects that directly intersect view cell
-	IntersectWithViewCell();
+	ComputeViewCellGeometryIntersection();
 
 		
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2588)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp	(revision 2705)
@@ -488,5 +488,6 @@
 
 	// hack: assume that object space can be seen from view space
-	mHierarchyStats.mTotalCost = mInitialRenderCost = GetViewCellsManager()->ComputeRenderCost(objects.size(), 1);
+	mHierarchyStats.mTotalCost = mInitialRenderCost = 
+		GetViewCellsManager()->ComputeRenderCost(objects.size(), 1);
 
 	// only one entry for start
