Index: /trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.h	(revision 176)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.h	(revision 339)
@@ -27,5 +27,8 @@
   
   int CollectObjects(ObjectContainer *instances);
-  
+
+  int
+	AssignObjectIds();
+
 protected:
 };
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 333)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Makefile	(revision 339)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Sep 06 13:46:00 2005
+# Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Oct 18 11:00:55 2005
 # Project:  preprocessor.pro
 # Template: app
@@ -13,12 +13,12 @@
 LEX		= flex
 YACC		= byacc
-CFLAGS	=	-nologo -Zm200 -W0 -MD -O2 -GX  -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG
-CXXFLAGS	=	-nologo -Zm200 -W0 -MD -O2 -GX  -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG
+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
 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"
-LINK	=	link
-LFLAGS	=	/NOLOGO delayimp.lib /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" "xerces-c_2.lib" "devil.lib" "ilu.lib" "ilut.lib" "opengl32.lib" "glu32.lib" "delayimp.lib"
+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"
+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
 UIC		=	$(QTDIR)\bin\uic.exe
@@ -148,5 +148,5 @@
 uicables: $(UICIMPLS) $(UICDECLS)
 
-Makefile: preprocessor.pro  C:\Qt\3.3.2\mkspecs\win32-msvc\qmake.conf C:\Qt\3.3.2\lib\qtmain.prl
+Makefile: preprocessor.pro  C:\Qt\3.3.2\mkspecs\win32-msvc.net\qmake.conf C:\Qt\3.3.2\lib\qtmain.prl
 	$(QMAKE) -o Makefile preprocessor.pro
 qmake: 
@@ -188,4 +188,9 @@
 	-$(DEL_FILE) ViewCell.obj
 	-$(DEL_FILE) ViewCellBsp.obj
+	-$(DEL_FILE) preprocessor.pdb
+	-$(DEL_FILE) preprocessor.ilk
+	-$(DEL_FILE) vc*.pdb
+	-$(DEL_FILE) vc*.idb
+
 
 
@@ -231,4 +236,5 @@
 		MutualVisibility.h \
 		Polygon3.h \
+		ViewCell.h \
 		Containers.h \
 		AxisAlignedBox3.h \
@@ -255,4 +261,5 @@
 		KdTree.h \
 		ViewCellBsp.h \
+		ViewCell.h \
 		Intersectable.h \
 		Plane3.h \
@@ -373,13 +380,20 @@
 		AxisAlignedBox3.h \
 		Ray.h \
-		Rectangle3.h \
-		Matrix4x4.h \
-		Vector3.h \
-		Plane3.h \
-		common.h \
+		Polygon3.h \
+		Rectangle3.h \
+		Matrix4x4.h \
+		Vector3.h \
+		Plane3.h \
+		common.h \
+		Containers.h \
+		Mesh.h \
+		Intersectable.h \
+		Material.h \
+		Pvs.h \
 		
 
 Ray.obj: Ray.cpp  \
 		Ray.h \
+		Plane3.h \
 		Matrix4x4.h \
 		Vector3.h \
@@ -396,4 +410,8 @@
 		Camera.h \
 		MeshKdTree.h \
+		Exporter.h \
+		X3dExporter.h \
+		ViewCell.h \
+		SceneGraph.h \
 		Preprocessor.h \
 		Containers.h \
@@ -433,4 +451,5 @@
 		X3dExporter.h \
 		Exporter.h \
+		Containers.h \
 		Material.h \
 		
@@ -459,15 +478,18 @@
 		Mesh.h \
 		SceneGraph.h \
+		Triangle3.h \
+		ViewCell.h \
 		Parser.h \
-		Intersectable.h \
-		Plane3.h \
-		Matrix4x4.h \
-		AxisAlignedBox3.h \
-		Material.h \
-		Pvs.h \
-		Rectangle3.h \
-		Vector3.h \
-		common.h \
-		Containers.h \
+		Containers.h \
+		Intersectable.h \
+		Plane3.h \
+		Matrix4x4.h \
+		AxisAlignedBox3.h \
+		Material.h \
+		Pvs.h \
+		Rectangle3.h \
+		Vector3.h \
+		common.h \
+		Ray.h \
 		
 
@@ -535,9 +557,11 @@
 		Polygon3.h \
 		Mesh.h \
-		Containers.h \
-		Intersectable.h \
-		Plane3.h \
-		Matrix4x4.h \
-		AxisAlignedBox3.h \
+		ViewCellBsp.h \
+		AxisAlignedBox3.h \
+		Ray.h \
+		Containers.h \
+		Intersectable.h \
+		Plane3.h \
+		Matrix4x4.h \
 		Material.h \
 		Pvs.h \
@@ -550,17 +574,17 @@
 		ViewCell.h \
 		Mesh.h \
+		Intersectable.h \
 		MeshKdTree.h \
 		Triangle3.h \
-		Intersectable.h \
-		Containers.h \
-		AxisAlignedBox3.h \
-		Pvs.h \
-		Rectangle3.h \
-		Matrix4x4.h \
-		Vector3.h \
-		Plane3.h \
-		common.h \
-		Material.h \
-		Ray.h \
+		Containers.h \
+		Ray.h \
+		Plane3.h \
+		Matrix4x4.h \
+		AxisAlignedBox3.h \
+		Material.h \
+		Pvs.h \
+		Rectangle3.h \
+		Vector3.h \
+		common.h \
 		
 
@@ -575,4 +599,5 @@
 		Ray.h \
 		AxisAlignedBox3.h \
+		Exporter.h \
 		Vector3.h \
 		Containers.h \
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Parser.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Parser.h	(revision 261)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Parser.h	(revision 339)
@@ -13,5 +13,7 @@
 public:
   Parser() {}
-  virtual bool ParseFile(const string filename, SceneGraphNode **root) = 0;
+
+	virtual bool ParseFile(const string filename, SceneGraphNode **root) = 0;
+	
 };
 
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 338)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellBsp.cpp	(revision 339)
@@ -1101,9 +1101,9 @@
 	// needed for balanced view cells criterium
 	ViewCell::NewMail();
-	int backId = ViewCell::mailID;
+	int backId = ViewCell::sMailId;
 	ViewCell::NewMail();
-	int frontId = ViewCell::mailID;
+	int frontId = ViewCell::sMailId;
 	ViewCell::NewMail();
-	int frontAndBackId = ViewCell::mailID;
+	int frontAndBackId = ViewCell::sMailId;
 
 	PolygonContainer::const_iterator it, it_end = polys.end();
@@ -1145,13 +1145,13 @@
 			if (classification == Plane3::FRONT_SIDE)
 			{
-				if ((viewCell->mailbox != frontId) && 
-					(viewCell->mailbox != frontAndBackId))
+				if ((viewCell->mMailbox != frontId) && 
+					(viewCell->mMailbox != frontAndBackId))
 				{
 					sumBalancedViewCells += 1.0;
 
-					if (viewCell->mailbox != backId)
-						viewCell->mailbox = frontId;
+					if (viewCell->mMailbox != backId)
+						viewCell->mMailbox = frontId;
 					else
-						viewCell->mailbox = frontAndBackId;
+						viewCell->mMailbox = frontAndBackId;
 					
 					++ totalViewCells;
@@ -1160,13 +1160,13 @@
 			else if (classification == Plane3::BACK_SIDE)
 			{
-				if ((viewCell->mailbox != backId) &&
-				    (viewCell->mailbox != frontAndBackId))
+				if ((viewCell->mMailbox != backId) &&
+				    (viewCell->mMailbox != frontAndBackId))
 				{
 					sumBalancedViewCells -= 1.0;
 
-					if (viewCell->mailbox != frontId)
-						viewCell->mailbox = backId;
+					if (viewCell->mMailbox != frontId)
+						viewCell->mMailbox = backId;
 					else
-						viewCell->mailbox = frontAndBackId; 
+						viewCell->mMailbox = frontAndBackId; 
 
 					++ totalViewCells;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp	(revision 260)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/SceneGraph.cpp	(revision 339)
@@ -4,4 +4,5 @@
 #include "SceneGraph.h"
 #include "X3dExporter.h"
+#include "Intersectable.h"
 
 
@@ -50,2 +51,28 @@
   return number;
 }
+
+
+int
+SceneGraph::AssignObjectIds()
+{
+  int id = 1;
+  stack<SceneGraphNode *> nodeStack;
+  
+  nodeStack.push(mRoot);
+  
+  while (!nodeStack.empty()) {
+    SceneGraphNode *node = nodeStack.top();
+    nodeStack.pop();
+		
+    ObjectContainer::const_iterator mi = node->mGeometry.begin();
+    for (; mi != node->mGeometry.end(); mi++) 
+      (*mi)->SetId(id++);
+    
+    SceneGraphNodeContainer::iterator ni = node->mChildren.begin();
+    for (; ni != node->mChildren.end(); ni++) {
+      nodeStack.push(*ni);
+    }
+  }
+	// return max id
+  return id;
+}
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 331)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp	(revision 339)
@@ -13,4 +13,5 @@
 {
 }
+
 
 Preprocessor::~Preprocessor()
@@ -44,5 +45,6 @@
 }
 
-bool Preprocessor::ParseViewCellsOptions()
+bool
+Preprocessor::ParseViewCellsOptions()
 {
 	// parse type of view cells
@@ -114,7 +116,12 @@
 
   bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
-  
+
+	
+	
   delete parser;
 
+	if (result)
+		mSceneGraph->AssignObjectIds();
+	
   return result;
 }
@@ -152,11 +159,11 @@
 bool
 Preprocessor::Export( const string filename,
-		      const bool scene,
-		      const bool kdtree,
-			  const bool bsptree
-		      )
+											const bool scene,
+											const bool kdtree,
+											const bool bsptree
+											)
 {
   Exporter *exporter = Exporter::GetExporter(filename);
-
+	
   if (exporter) {
     if (scene)
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h	(revision 308)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Intersectable.h	(revision 339)
@@ -8,17 +8,26 @@
 class Intersectable {
 public:
-  static int mailID;
-  int mailbox;
+	// last mail id -> warning not thread safe!
+	// both mailId and mailbox should be unique for each thread!!!
+	static int sMailId;
+	int mMailbox;
+	
+	// unique object Id
+	int mId;
 
-  KdPvs mKdPvs;
+	// object based pvs
+	KdPvs mKdPvs;
   
   enum { MESH_INSTANCE, TRANSFORMED_MESH_INSTANCE, SPHERE, VIEW_CELL };
   
-  Intersectable():mailbox(0) {}
-  
-  void Mail() { mailbox = mailID; }
-  static void NewMail() { mailID++; }
-  bool Mailed() const { return mailbox == mailID; }
-  int IncMail() { return ++mailbox - mailID; }
+  Intersectable():mMailbox(0) {}
+
+	void SetId(const int id) { mId = id; }
+	int GetId() { return mId; }
+	
+	void Mail() { mMailbox = sMailId; }
+  static void NewMail() { sMailId++; }
+  bool Mailed() const { return mMailbox == sMailId; }
+  int IncMail() { return ++mMailbox - sMailId; }
 
   virtual AxisAlignedBox3 GetBox() = 0;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 333)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro	(revision 339)
@@ -13,5 +13,5 @@
 
 # debuc config
-CONFIG		+= console warn_off thread release
+CONFIG		+= console warn_off thread debug
 
 # RELEASE CONFIG
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 335)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp	(revision 339)
@@ -27,7 +27,7 @@
 void
 SamplingPreprocessor::SetupRay(Ray &ray, 
-							   const Vector3 &point, 
-							   const Vector3 &direction,
-							   const int type)
+															 const Vector3 &point, 
+															 const Vector3 &direction,
+															 const int type)
 {
   ray.intersections.clear();
@@ -148,37 +148,42 @@
 
 int
-SamplingPreprocessor::CastRay(Intersectable *object, Ray &ray)
+SamplingPreprocessor::CastRay(Intersectable *object,
+															Ray &ray)
 {
 	int sampleContributions = 0;
 
+	long t1 = GetTime();
 	// cast ray to KD tree to find intersection with other objects
 	mKdTree->CastRay(ray);
-	
+	long t2 = GetTime();
+
+	cout<<object->GetId()<<" "<<TimeDiff(t1, t2);
+
 	if (mViewCellsType == BSP_VIEW_CELLS)
-	{
-		// cast ray to BSP tree to get intersection with view cells
-		if (mBspTree)
 		{
-			mBspTree->CastRay(ray);
-		
-			sampleContributions += AddObjectSamples(object, ray);
+			// cast ray to BSP tree to get intersection with view cells
+			if (mBspTree)
+				{
+					mBspTree->CastRay(ray);
+					
+					sampleContributions += AddObjectSamples(object, ray);
 				
-			if (!ray.intersections.empty()) // second intersection found
-			{
-				sampleContributions += 
-					AddObjectSamples(ray.intersections[0].mObject, ray);
-			}
+					if (!ray.intersections.empty()) // second intersection found
+						{
+							sampleContributions += 
+								AddObjectSamples(ray.intersections[0].mObject, ray);
+						}
+				}
 		}
-	}
 	else
-	{
-		if (ray.leaves.size()) {
-			sampleContributions += AddNodeSamples(object, ray);
-		
-			if (ray.intersections.size()) {
-				sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray);
-			}
-		} 
-	} 	
+		{
+			if (ray.leaves.size()) {
+				sampleContributions += AddNodeSamples(object, ray);
+				
+				if (ray.intersections.size()) {
+					sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray);
+				}
+			} 
+		} 	
 	
 	return sampleContributions;
Index: /trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
===================================================================
--- /trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp	(revision 333)
+++ /trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp	(revision 339)
@@ -4,5 +4,5 @@
 #include "Triangle3.h"
 
-int MeshInstance::mailID = 21843194198;
+int Intersectable::sMailId = 21843194198;
 
 void
