Index: trunk/VUT/GtpVisibilityPreprocessor/src/UnigraphicsParser.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/UnigraphicsParser.cpp	(revision 312)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/UnigraphicsParser.cpp	(revision 340)
@@ -143,10 +143,10 @@
       currentMesh->AddFace(face);
       if (meshGrouping != 0 &&
-	  currentMesh->mFaces.size() >=  meshGrouping) {
-	currentMesh->Preprocess();
-	// make an instance of this mesh
-	MeshInstance *mi = new MeshInstance(currentMesh);
-	root->mGeometry.push_back(mi);	
-	currentMesh = new Mesh;
+					currentMesh->mFaces.size() >=  meshGrouping) {
+				currentMesh->Preprocess();
+				// make an instance of this mesh
+				MeshInstance *mi = new MeshInstance(currentMesh);
+				root->mGeometry.push_back(mi);	
+				currentMesh = new Mesh;
       }
     }
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 339)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 340)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Oct 18 11:00:55 2005
+# Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Oct 18 16:48:33 2005
 # Project:  preprocessor.pro
 # Template: app
@@ -13,11 +13,11 @@
 LEX		= flex
 YACC		= byacc
-CFLAGS	=	-nologo -Zm200 -W0 -MDd -Zi -Gm -GX  -DUNICODE -DWIN32 -DQT_DLL -DQT_THREAD_SUPPORT
-CXXFLAGS	=	-nologo -Zm200 -W0 -MDd -Zi -Gm -GX  -DUNICODE -DWIN32 -DQT_DLL -DQT_THREAD_SUPPORT
+CFLAGS	=	-nologo -Zm200 -W0 -MD -O2 -G7 -GX  -DUNICODE -DWIN32 -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG
+CXXFLAGS	=	-nologo -Zm200 -W0 -MD -O2 -G7 -GX  -DUNICODE -DWIN32 -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG
 LEXFLAGS	=
 YACCFLAGS	=-d
 INCPATH	=	 -I"..\src" -I"..\support\xerces\include" -I"..\support\zlib\include" -I"..\support\boost" -I"..\support\devil\include" -I"$(QTDIR)\include" -I"d:\gametools\svn\trunk\VUT\GtpVisibilityPreprocessor\src" -I"C:\Qt\3.3.2\mkspecs\win32-msvc.net"
 LINK	=	"c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe"
-LFLAGS	=	/NOLOGO /DEBUG /SUBSYSTEM:CONSOLE /LIBPATH:"../support/xerces/lib" /LIBPATH:"../support/devil/lib" /LIBPATH:"$(QTDIR)\lib"
+LFLAGS	=	/NOLOGO /DELAYLOAD:comdlg32.dll /DELAYLOAD:oleaut32.dll /DELAYLOAD:winmm.dll /DELAYLOAD:wsock32.dll /DELAYLOAD:winspool.dll /SUBSYSTEM:CONSOLE /LIBPATH:"../support/xerces/lib" /LIBPATH:"../support/devil/lib" /LIBPATH:"$(QTDIR)\lib"
 LIBS	=	 "qt-mt332.lib" "qtmain.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "imm32.lib" "winmm.lib" "wsock32.lib" "winspool.lib" "delayimp.lib" "xerces-c_2.lib" "devil.lib" "ilu.lib" "ilut.lib" "opengl32.lib" "glu32.lib"
 MOC		=	$(QTDIR)\bin\moc.exe
@@ -188,9 +188,4 @@
 	-$(DEL_FILE) ViewCell.obj
 	-$(DEL_FILE) ViewCellBsp.obj
-	-$(DEL_FILE) preprocessor.pdb
-	-$(DEL_FILE) preprocessor.ilk
-	-$(DEL_FILE) vc*.pdb
-	-$(DEL_FILE) vc*.idb
-
 
 
@@ -349,13 +344,15 @@
 		SceneGraph.h \
 		X3dExporter.h \
-		Containers.h \
-		AxisAlignedBox3.h \
-		Rectangle3.h \
-		Matrix4x4.h \
-		Vector3.h \
-		Plane3.h \
-		common.h \
-		Exporter.h \
-		Material.h \
+		Intersectable.h \
+		Containers.h \
+		AxisAlignedBox3.h \
+		Rectangle3.h \
+		Matrix4x4.h \
+		Vector3.h \
+		Plane3.h \
+		common.h \
+		Exporter.h \
+		Material.h \
+		Pvs.h \
 		
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 328)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h	(revision 340)
@@ -233,4 +233,8 @@
   friend float DistanceToZPlane(const Vector3 &vec, const Ray &ray);
   friend int MakeIntersectLine(const Plane3 &p, const Plane3 &q, Ray &ray);
+
+	friend ostream &operator<<(ostream &s, const Ray &r) {
+		return s<<"Ray:loc="<<r.loc<<" dir="<<r.dir;
+	}
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h	(revision 333)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h	(revision 340)
@@ -77,5 +77,9 @@
   void AddTriangle(const Triangle3 &triangle);
   void AddRectangle(const Rectangle3 &triangle);
-  
+
+	void Cleanup();
+	bool
+	ValidateFace(const int face);
+
   void AddFace(Face *face) 
   {
@@ -141,4 +145,8 @@
   void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal);
 
+	virtual ostream &Describe(ostream &s) {
+		return s<<"Mesh #vertices="<<mVertices.size()<<" #faces="<<mFaces.size();
+	}
+
 };
 
@@ -179,4 +187,9 @@
 
 
+	virtual ostream &Describe(ostream &s) {
+		s<<"MeshInstance Id="<<GetId();
+		return mMesh->Describe(s);
+	}
+	
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp	(revision 176)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Vector3.cpp	(revision 340)
@@ -200,26 +200,26 @@
   
   Vector3 dir(sinTheta*sin(fi),
-	      cosTheta,
-	      sinTheta*cos(fi));
-
+							cosTheta,
+							sinTheta*cos(fi));
+	
   
   //  return Normalize(dir);
-
+	
   Matrix4x4 m = RotationVectorsMatrix(
-				      normal,
-				      Vector3(0,1,0));
+																			normal,
+																			Vector3(0,1,0));
   Matrix4x4 mi = Invert(m);
   m = m*RotationVectorsMatrix(
-			      Vector3(0,1,0),
-			      Normalize(dir))*mi;
+															Vector3(0,1,0),
+															Normalize(dir))*mi;
   
   return TransformNormal(m, normal);
   
-//    return TransformNormal(
-//  			 RotationVectorsMatrix(
-//  					       Vector3(0,1,0),
-//  					       Normalize(dir)
-//  					       ),
-//  			 normal
-//  			 );
-}
+	//    return TransformNormal(
+	//  			 RotationVectorsMatrix(
+	//  					       Vector3(0,1,0),
+	//  					       Normalize(dir)
+	//  					       ),
+	//  			 normal
+	//  			 );
+}
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h	(revision 339)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h	(revision 340)
@@ -43,4 +43,6 @@
   virtual void GetRandomSurfacePoint(Vector3 &point, Vector3 &normal) = 0;
 
+	virtual ostream &Describe(ostream &s) = 0;
+	
 };
 
Index: trunk/VUT/GtpVisibilityPreprocessor/src/default.env
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 335)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/default.env	(revision 340)
@@ -9,7 +9,7 @@
 #	filename vienna.x3d
 #	filename ../data/vienna/vienna-simple.x3d
-	filename ../data/vienna/vienna-buildings.x3d
+#	filename ../data/vienna/vienna-buildings.x3d
 #	filename ../data/vienna/viewcells-25-sel.x3d
-#	filename ../data/atlanta/atlanta2.x3d
+	filename ../data/atlanta/atlanta2.x3d
 #	filename ../data/soda/soda.dat
 #	filename ../data/soda/soda5.dat
@@ -61,6 +61,6 @@
 
 ViewCells {
-	#hierarchy kdTree
-	hierarchy bspTree
+	hierarchy kdTree
+	#hierarchy bspTree
 	# hierarchy sceneDependent
 	
Index: trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 339)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 340)
@@ -13,5 +13,5 @@
 
 # debuc config
-CONFIG		+= console warn_off thread debug
+CONFIG		+= console warn_off thread release
 
 # RELEASE CONFIG
Index: trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 339)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 340)
@@ -153,10 +153,15 @@
 	int sampleContributions = 0;
 
-	long t1 = GetTime();
+	long t1 = GetRealTime();
 	// cast ray to KD tree to find intersection with other objects
 	mKdTree->CastRay(ray);
-	long t2 = GetTime();
-
-	cout<<object->GetId()<<" "<<TimeDiff(t1, t2);
+	long t2 = GetRealTime();
+
+	if (0 && object->GetId() > 2197) {
+		object->Describe(cout)<<endl;
+		cout<<ray<<endl;
+	}
+
+	//	cout<<object->GetId()<<" "<<TimeDiff(t1, t2)<<endl;
 
 	if (mViewCellsType == BSP_VIEW_CELLS)
@@ -380,5 +385,5 @@
 			bool viewcellSample = true;
 			int sampleContributions;
-
+			bool debug = false; //(object->GetId() >= 2199);
 			if (viewcellSample) {
 				nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point));
@@ -394,7 +399,14 @@
 								break;							
 						}
-						
 						if (tries == maxTries)
 							direction = UniformRandomVector(normal);
+						
+						if (debug) {
+							cout<<
+								"normal "<<normal<<endl<<
+								"tries "<<tries<<endl<<
+								"dir="<<direction<<endl;
+						}
+
 					}
 					else {
Index: trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
===================================================================
--- trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp	(revision 339)
+++ trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp	(revision 340)
@@ -9,6 +9,7 @@
 Mesh::Preprocess()
 {
-  mBox.Initialize();
-
+	Cleanup();
+	
+	mBox.Initialize();
   VertexContainer::const_iterator vi = mVertices.begin();
   for (; vi != mVertices.end(); vi++) {
@@ -282,5 +283,6 @@
   }
   point *= 1.0f/sum;
-  normal = GetFacePlane(faceIndex).mNormal;
+	
+	normal = GetFacePlane(faceIndex).mNormal;
 }
 
@@ -324,7 +326,41 @@
 {
   Face *face = mFaces[faceIndex];
-  return Plane3(mVertices[face->mVertexIndices[0]],
+	return Plane3(mVertices[face->mVertexIndices[0]],
 								mVertices[face->mVertexIndices[1]],
 								mVertices[face->mVertexIndices[2]]);
+}
+
+bool
+Mesh::ValidateFace(const int i)
+{
+	Face *face = mFaces[i];
+
+	Plane3 plane = Plane3(mVertices[face->mVertexIndices[0]],
+												mVertices[face->mVertexIndices[1]],
+												mVertices[face->mVertexIndices[2]]);
+	
+	if (!eq(Magnitude(plane.mNormal), 1.0f))
+		return false;
+}
+
+void
+Mesh::Cleanup()
+{
+	int toRemove = 0;
+	FaceContainer newFaces;
+	for (int i=0; i < mFaces.size(); i++)
+		if (ValidateFace(i)) {
+			newFaces.push_back(mFaces[i]);
+		} else {
+			cout<<"d";
+			delete mFaces[i];
+			toRemove++;
+		}
+	
+	if (toRemove) {
+		mFaces = newFaces;
+	}
+	
+	// cleanup vertices??
 }
 
