Index: GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 2636)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 2638)
@@ -4,5 +4,5 @@
 
 #COMMAND="./release/preprocessor.exe -preprocessor_quit_on_finish+"
-COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=5000000 -samples_per_pass=500000 -total_samples=20000000 -mutation_use_pass_importance- -mutation_silhouette_search_steps=3 -preprocessor_ray_cast_method=3 -preprocessor_detect_empty_viewspace+"
+COMMAND="../scripts/preprocessor.sh -preprocessor_quit_on_finish- -preprocessor_use_gl_renderer+ -preprocessor_evaluate_filter- -samples_per_evaluation=50000000 -samples_per_pass=1000000 -total_samples=20000000 -mutation_use_pass_importance- -mutation_silhouette_search_steps=3 -preprocessor_ray_cast_method=1 -preprocessor_detect_empty_viewspace+ -total_time=140"
 
 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d"
@@ -29,18 +29,19 @@
 #VIEWCELLS=../data/test1/test-viewcells.xml
 
-#SCENE=../data/Arena/arena-high-lods.obj
-#VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz
+SCENE=../data/Arena/arena-high-lods.obj
+VIEWCELLS=../data/Arena/arena-high-lods-5000-viewcells.xml.gz
 #VIEWCELLS=../data/Arena/viewcells-5000.xml.gz
 #VIEWCELLS=../data/Arena/arena-high-lods-57000-viewcells.xml.gz
 
 
-SCENE=../data/vienna/vienna_cropped.obj
-VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz
+# SCENE=../data/vienna/vienna_cropped.obj
+# VIEWCELLS=../data/vienna/vienna_cropped-gradient-viewcells.xml.gz
+#VIEWCELLS=../data/vienna/vienna_cropped-20000-viewcells.xml.gz
 
 #VIEWCELLS=../data/vienna/vienna-sequential-30000-single-viewcell.xml
 
 
-# SCENE=../data/Pompeii/PompeiiTen.obj
-# VIEWCELLS=../data/Pompeii/pompeii_big-seq-viewcells.xml.gz
+#SCENE=../data/Pompeii/PompeiiTen.obj
+#VIEWCELLS=../data/Pompeii/pompeii_big-seq-viewcells.xml.gz
 
 PREFIX=../work/plots/osp-TEST
@@ -58,6 +59,13 @@
 
 
-$COMMAND -preprocessor=combined -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
+$COMMAND -preprocessor=sampling -scene_filename=$SCENE -view_cells_filename=$VIEWCELLS \
 -rss_distributions=mutation+object_direction+spatial \
+-mutation_silhouette_prob=0.5 \
+-mutation_reverse_samples_distance=1.0 \
+-mutation_radius_origin=1.0 \
+-mutation_radius_termination=0.2 \
+-mutation_use_unsucc_count_importance+ \
+-mutation_use_pass_importance- \
+-mutation_buffer_size=2000000 \
 -view_cells_use_kd_pvs+ -af_use_kd_pvs+ -view_cells_filter_width=1.0 \
 -preprocessor_visibility_file=$PREFIX-i-mixed-b1-n4a.xml \
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2625)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.h	(revision 2638)
@@ -635,4 +635,9 @@
 	VizBuffer mVizBuffer;
 
+	/** Intersects box with the tree and returns the number of intersected boxes.
+		@returns number of view cells found
+	*/
+	virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, 
+										ViewCellContainer &viewCells) const;
 
 protected:
@@ -649,9 +654,4 @@
 								  int rightIdx) const;
 
-	/** Intersects box with the tree and returns the number of intersected boxes.
-		@returns number of view cells found
-	*/
-	virtual int ComputeBoxIntersections(const AxisAlignedBox3 &box, 
-										ViewCellContainer &viewCells) const;
 	/** Tests the visibility filter functionality.
 	*/
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2636)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2638)
@@ -1731,17 +1731,45 @@
 
 	SceneGraphLeaf *leaf = new SceneGraphLeaf(dynamic);
-
-	if (LoadBinaryObj(filename, leaf, NULL, 100))
-	{
+	bool parsed = false;
+
+	if (strstr(filename.c_str(), ".obj")) {
+	  cout<<"parsing obj file.."<<endl;
+	  ObjParser *p = new ObjParser;
+	  parsed = p->ParseFile(filename, 
+							leaf,
+							false);
+	  leaf->UpdateBox();
+	  cout<<leaf->GetBox();
+
+	  float s = 10.0f;
+	  leaf->ApplyTransform(ScaleMatrix(s, s, s));
+	  leaf->ApplyTransform(TranslationMatrix(Vector3(0, 10, 0)));
+
+	  
+	} else {
+	  cout<<"parsing binary obj file.."<<endl;
+
+	  parsed = LoadBinaryObj(filename, leaf, NULL, 100);
+	}
+	
+	if (parsed)
+	  {
+		cout<<"success."<<endl;
+		leaf->UpdateBox();
+		cout<<leaf->GetBox();
 		mDynamicObjects.push_back(leaf);
-		leaf->RebuildKtbTree();
+		//	  leaf->RebuildKtbTree();
 		mSceneGraph->GetRoot()->mChildren.push_back(leaf);
-
+		
 		if (mRayCaster)
 		  mRayCaster->AddDynamicObjecs(leaf->mGeometry, leaf->GetTransformation());
-
-
+		
+	  
 		return true;
-	}
+	  } else
+		{
+		  cout<<"failed."<<endl;
+
+		}
 
 #endif
@@ -1759,11 +1787,36 @@
   AxisAlignedBox3 box = object->GetBox();
 
-  KdNode::NewMail();
-
   ObjectContainer objects;
-  // first mail all kDObjects which are intersected by the object
-  preprocessor->mKdTree->CollectKdObjects(box,
-										  objects);
-  
+
+  if (0) {
+	// simplified computation taking only the objects intersecting the box
+	KdNode::NewMail();
+	
+	// first mail all kDObjects which are intersected by the object
+	preprocessor->mKdTree->CollectKdObjects(box,
+											objects);
+	
+  } else {
+	ViewCellContainer viewCells;
+	mViewCellsManager->ComputeBoxIntersections(box, viewCells);
+	
+	ViewCellContainer::const_iterator it = viewCells.begin(), it_end = viewCells.end();
+	
+	ObjectPvs pvs;
+	
+	for (int i=0; it != it_end; ++ it, ++ i) {
+	  //cout<<"v"<<i<<" pvs="<<(*it)->GetPvs().mEntries.size()<<endl;
+	  pvs.MergeInPlace((*it)->GetPvs());
+	}
+
+	ObjectPvsIterator pit = pvs.GetIterator();
+	while (pit.HasMoreEntries())  {		
+	  PvsData pvsData;
+	  Intersectable *object = pit.Next(pvsData);
+	  objects.push_back(object);
+	}
+  }
+  
+  int pvsCounter = 0;
   // now search for pvss which contained any mailed node
   for (vit = mViewCellsManager->GetViewCells().begin(); vit != vit_end; ++ vit) {
@@ -1775,8 +1828,13 @@
 		// clear the pvs
 		pvs.Clear();
+		pvsCounter++;
 		break;
 	  }
 	}
   }
+
+  cout<<"Number of affected objects "<<objects.size()<<endl;
+  cout<<"Cleared "<<pvsCounter<<" PVSs ("<<mViewCellsManager->GetViewCells().size()/
+	(float)pvsCounter*100.0f<<"%) "<<endl;
   
 }
@@ -1786,10 +1844,16 @@
 {
   if (mUpdateDynamicObjects) {
+
 	preprocessor->mRayCaster->DeleteDynamicObjects();
 	
 	for (int i=0; i < mDynamicObjects.size(); i++) {
 	  SceneGraphLeaf *l = mDynamicObjects[i];
+	  cout<<"Updating dynamic objects in ray caster..."<<endl;
 	  mRayCaster->AddDynamicObjecs(l->mGeometry, l->GetTransformation());
+	  cout<<"done."<<endl;
+	  cout<<"Updating affected PVSs..."<<endl;
 	  preprocessor->ObjectMoved(l);
+	  cout<<"done."<<endl;
+	  
 	}
 	mUpdateDynamicObjects = false;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 1004)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RenderSampler.cpp	(revision 2638)
@@ -27,4 +27,15 @@
 	Environment::GetSingleton()->GetBoolValue("RenderSampler.useOcclusionQueries", useOcclusionQueries);
 
+#if SG08_HACK
+	// evaluate histogram of loaded pvs solution
+	
+
+
+
+#endif
+	
+	
+
+	
 	Debug << "************* render sampler ****************" << endl;
 	Debug << "threshold: " << threshold << endl;
Index: GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2636)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/QtInterface/QtGlRenderer.cpp	(revision 2638)
@@ -600,7 +600,10 @@
 	glStencilOp(GL_KEEP, GL_KEEP, GL_INCR); 
 
-	mUseForcedColors = true;
-
-	glColor3f(0.0f, 0.8f, 0.2f);
+	//mUseForcedColors = true;
+
+	//	glColor3f(0.0f, 0.8f, 0.2f);
+	//	glColor3f(0.5f, 0.5f, 0.5f);
+
+	glColor3f(0.6f, 0.6f, 0.6f);
 
 	// Render PVS
@@ -617,4 +620,6 @@
 
 	SetupCamera();
+
+	mUseForcedColors = true;
 
 	glColor3f(1.0f, 0.0f, 0.0f);
@@ -705,7 +710,12 @@
 			case 0:
 				{
+				  if (e->modifiers() & Qt::ShiftModifier) {
+					const Vector3 transl(0, diffy, 0);
+					tm = TranslationMatrix(transl);
+				  
+				  } else {
 					const Vector3 transl(diffx, 0, diffy);
-					
 					tm = TranslationMatrix(transl);
+				  }
 				}
 				break;
@@ -720,5 +730,6 @@
 			case 2:
 				{
-					tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
+				  //					tm = RotationXMatrix(diffx) * RotationYMatrix(diffy);
+				  tm = RotationYMatrix(diffx);
 				}
 				break;
@@ -791,4 +802,5 @@
 	RenderInfo();
 	mFrame ++;
+	//	cout<<"vp="<<mViewPoint<<" vd="<<mViewDirection<<endl;
 }
 
@@ -1094,5 +1106,7 @@
 void QtGlRendererWidget::LoadObject()
 {
-	string filename("../data/teapot.bn");
+  //	string filename("../data/teapot.bn");
+  // string filename("../data/teapot.bn");
+  string filename("../data/cube.obj");
 	
 	cout << "Loading model << " << filename << endl;
@@ -1254,9 +1268,10 @@
 	renderText(20, 40, s);
 #endif
-	
+#if 0
 	QFont font40; font40.setPointSize(30);
 	s.sprintf("PVS: %04d", mPvsSize);
 	renderText(20, 40, s, font40);
-
+#endif
+	
 /*	QFont font40; font40.setPointSize(30);
 	s.sprintf("New triangles: %04d", 100);
Index: GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 2635)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 2638)
@@ -185,5 +185,5 @@
 	splitMethod SAH
 	splitBorder 0.01
-	pvsArea 1e-3
+	pvsArea 1e-4
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2635)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2638)
@@ -3371,6 +3371,6 @@
 			// $$ warning collect objects takes only unmailed ones!
 			if (mUseKdPvs) {
-			  //			  GetPreprocessor()->mKdTree->CollectKdObjects(box, objects);
-			  GetPreprocessor()->mKdTree->CollectSmallKdObjects(box, objects, 0.02f);
+			  GetPreprocessor()->mKdTree->CollectKdObjects(box, objects);
+			  //GetPreprocessor()->mKdTree->CollectSmallKdObjects(box, objects, 0.02f);
 
 			} else
Index: GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2633)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/GlRenderer.cpp	(revision 2638)
@@ -89,11 +89,15 @@
 	mSceneGraph->CollectObjects(mObjects);
 
-#if 1
+#if 0
 	viewCellsManager->GetViewPoint(mViewPoint);
 	mViewDirection = Vector3(0,0,1);
 #else
-	
-	mViewPoint = Vector3(1213.85, 176.988, -437.364);
-	mViewDirection = Vector3(0.433884, 0, -0.900969);
+
+	// for sg snapshot
+	mViewPoint = Vector3(18.5133, 10.9818, -1032.24);
+	mViewDirection = Vector3(-0.5373, 0, 0.843391);
+	  
+	  //	mViewPoint = Vector3(1213.85, 176.988, -437.364);
+	  //	mViewDirection = Vector3(0.433884, 0, -0.900969);
 	
 	//mViewPoint = Vector3(1099.9,183.0,-387);
@@ -505,6 +509,12 @@
 
 	glEnd();
-
+	
 	glPopMatrix();
+
+#if 1
+	// test the box of the object
+	AxisAlignedBox3 box = leaf->GetBox();
+	RenderBox(box);
+#endif
 }
 
Index: GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2635)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2638)
@@ -433,4 +433,5 @@
 	       castDoubleRay, pruneInvalidRays);
 
+	preprocessor->UpdateDynamicObjects();
     if ((int)rays.size() > 100000 && i % (100000/16) == 0)
       cout<<"\r"<<offset<<"/"<<(int)rays.size()<<"\r";
Index: GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2634)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2638)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: st 23. I 01:44:33 2008
+# Generated by qmake (2.00a) (Qt 4.1.2) on: st 23. I 19:46:53 2008
 # Project:  preprocessor.pro
 # Template: app
Index: GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2636)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/KdTree.cpp	(revision 2638)
@@ -9,4 +9,5 @@
 #include "ViewCell.h"
 #include "IntersectableWrapper.h"
+
 
 
@@ -1065,8 +1066,8 @@
     nodeStack.pop();
     if (node->IsLeaf() || node->mPvsTermination == 1)  {
-      Intersectable *object = GetOrCreateKdIntersectable(node);
       if (!node->Mailed()) {
-	node->Mail();
-	objects.push_back(object);
+		Intersectable *object = GetOrCreateKdIntersectable(node);
+		node->Mail();
+		objects.push_back(object);
       }
     }
