Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2592)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Mutation.cpp	(revision 2599)
@@ -18,4 +18,6 @@
 
 namespace GtpVisibilityPreprocessor {
+
+
 
 #define MUTATION_USE_CDF 0
@@ -92,5 +94,5 @@
 		
 		Intersectable *newObject = vssRays[i]->mTerminationObject;
-
+		
 		Intersectable *oldObject = mRays[vssRays[i]->mGeneratorId].mRay->mTerminationObject;
 		// the ray generated a contribution although it hits the same object
@@ -130,4 +132,5 @@
 		Intersectable *oldObject = oldRay->mTerminationObject;
 
+		  
 		// only allow one reverse mutation per generator ray
 		if (!mRays[newRay->mGeneratorId].HasReverseMutation()) {
@@ -333,4 +336,5 @@
   // in search for unocclude reverse ray
   box.Scale(2.0f);
+  //box.Scale(200.0f);
   
   const int packetSize = 4;
@@ -369,5 +373,5 @@
 		// break on first passing ray
 	    break;
-	  }
+	  } 
 	}
 	float rr = left + (i+1)*(right-left)/(packetSize+1);
@@ -377,8 +381,10 @@
   }
 
+
   float t = right;
   if (right==1.0f)
 	return false;
-  
+
+
   if (i == packetSize)
 	origin = newPivot + right*line;
@@ -464,4 +470,7 @@
   float left = 0.0f;
   float right = radius;
+  
+  AxisAlignedBox3 _box = box;
+  _box.Scale(1.1f);
   // cast rays to find silhouette ray
   for (int j=0; j < mSilhouetteSearchSteps; j++) {
@@ -476,6 +485,10 @@
 	// mlrtaTraverseGroupASEye4(&box.Min().x, &box.Max().x, hit_triangles, dist);
 	assert(preprocessor->mRayCaster);
-	preprocessor->mRayCaster->CastRaysPacket4(box.Min(), box.Max(),
-						  origs, dirs, hit_triangles, dist);       
+	preprocessor->mRayCaster->CastRaysPacket4(_box.Min(),
+											  _box.Max(),
+											  origs,
+											  dirs,
+											  hit_triangles,
+											  dist);       
 	
 	for (i=0; i < packetSize; i++) {
@@ -491,4 +504,6 @@
 	right = rr;
   }
+
+  Vector3 shift;
   
   if (i == packetSize) {
@@ -497,10 +512,66 @@
 	//cout<<"W"<<i<<endl;
 	//	return (RandomValue(1.0f, 1.5f)*radius)*line;
-	return right*line;
-  }
-  
-  //  cout<<i<<endl;
-  return shifts[i];
-
+	shift = right*line;
+  } else {
+	//  cout<<i<<endl;
+	shift = shifts[i];
+  }
+  
+
+  if (0) {
+	
+	static VssRayContainer rRays;
+	static int counter = 0;
+	char filename[256];
+
+	if (counter < 50) {
+	  sprintf(filename, "sil_rays_%03d.x3d", counter++);
+	  
+	  VssRay tRays[10];
+	  rRays.push_back((VssRay *)&ray);
+	  for (int k=0; k < packetSize; k++)
+		if (k!=i) {
+		  tRays[k] = VssRay(origin, ray.mTermination + shifts[k], NULL, NULL);
+		  rRays.push_back(&tRays[k]);
+		}
+	  
+	  Exporter *exporter = NULL;
+	  exporter = Exporter::GetExporter(filename);
+	  
+	  exporter->SetFilled();
+	  
+	  Intersectable *occluder = 
+		ray.mTerminationObject;
+
+	  // cout<<occluder->Type()<<endl;
+	  
+	  exporter->SetForcedMaterial(RgbColor(0,0,1));
+	  exporter->ExportIntersectable(occluder);
+
+	  exporter->SetWireframe();
+	  
+	  exporter->SetForcedMaterial(RgbColor(0,1,0));
+	  exporter->ExportBox(occluder->GetBox());
+
+	  exporter->SetForcedMaterial(RgbColor(0,1,1));
+	  exporter->ExportBox(_box);
+
+	  exporter->ResetForcedMaterial();
+
+	  exporter->ExportRays(rRays, RgbColor(1, 0, 0));
+
+	  rRays.clear();
+	  tRays[0] = VssRay(origin, ray.mTermination+shift, NULL, NULL);
+	  rRays.push_back((VssRay *)&tRays[0]);
+	  exporter->ExportRays(rRays, RgbColor(1, 1, 0));
+
+	  delete exporter;
+	  rRays.clear();
+	}
+  }
+
+  return shift;
+
+  
 #else
   //cerr << "warning: shiluette mutation not supported" << endl;
@@ -540,4 +611,5 @@
 #if !MUTATION_USE_CDF
 #if SORT_RAY_ENTRIES
+  // RAYS are sorted -> find mitation candidate from the tail of the buffer
   index = mLastIndex - 1;
   if (index < 0 || index >= mRays.size()-1) {
@@ -574,4 +646,5 @@
 #endif
 #else
+
   static HaltonSequence iHalton;
   iHalton.GetNext(1, rr);
@@ -596,4 +669,6 @@
   //  cout<<index<<" "<<rr[0]<<" "<<mRays[index].mCdf<<" "<<mRays[(index+1)%mRays.size()].mCdf<<endl;
 
+  // WE HAVE THE INDEX HERE
+
   mLastIndex = index;
   //  Debug<<index<<" "<<mRays[index].GetSamplingFactor()<<endl;
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/run_test2
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 2590)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/run_test2	(revision 2599)
@@ -3,5 +3,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-"
+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"
 
 #SCENE="../data/vienna/vienna-buildings.x3d;../data/vienna/vienna-roofs.x3d;../data/vienna/vienna-roads.x3d"
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2598)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp	(revision 2599)
@@ -1267,10 +1267,9 @@
 
 	}
-
+	
 	//	cerr<<"Determining PVS objects"<<endl;
 	DeterminePvsObjects(vssRays);
 	//	cerr<<"done."<<endl;
-
-
+	
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/default.env
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 2592)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/default.env	(revision 2599)
@@ -53,5 +53,5 @@
 	useGlDebugger false
 # 0 = INTERNAL 	1 = MLRT 2 = HAVRAN
-	rayCastMethod 2
+	rayCastMethod 1
 	
 #	type sampling
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2598)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp	(revision 2599)
@@ -2483,15 +2483,15 @@
 									  const bool useHitObjects)
 {
-	if (!useHitObjects) 
-	{
-		// store higher order object (e.g., bvh node) instead of object itself
-		VssRayContainer::const_iterator it, it_end = rays.end();
-        
-		for (it = rays.begin(); it != it_end; ++ it) 
-		{
-			VssRay *vssRay = *it;
-
-			// set only the termination object
-			vssRay->mTerminationObject = GetIntersectable(*vssRay, true);
+  if (!useHitObjects) 
+	{
+	  // store higher order object (e.g., bvh node) instead of object itself
+	  VssRayContainer::const_iterator it, it_end = rays.end();
+	  
+	  for (it = rays.begin(); it != it_end; ++ it) 
+		{
+		  VssRay *vssRay = *it;
+		  
+		  // set only the termination object
+		  vssRay->mTerminationObject = GetIntersectable(*vssRay, true);
 		}
 	}
@@ -5723,7 +5723,7 @@
 {
 	if (mUseKdPvs)
-		return ViewCellsManager::GetIntersectable(ray, isTermination);
+	  return ViewCellsManager::GetIntersectable(ray, isTermination);
 	else
-		return mHierarchyManager->GetIntersectable(ray, isTermination);
+	  return mHierarchyManager->GetIntersectable(ray, isTermination);
 }
 
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2592)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.cpp	(revision 2599)
@@ -92,15 +92,16 @@
 // We give a box to which each ray is clipped to before the
 // ray shooting is computed !
-void HavranRayCaster::CastRaysPacket4(Vector3 &boxmax,
-				      Vector3 &boxmin,
-				      Vector3 origin4[],
-				      Vector3 direction4[],
-				      int     result4[],
-				      float   dist4[])
-{
-#ifdef _USE_HAVRAN_SSE  
+void HavranRayCaster::CastRaysPacket4(const Vector3 &boxmax,
+									  const Vector3 &boxmin,
+									  const Vector3 origin4[],
+									  const Vector3 direction4[],
+									  int     result4[],
+									  float   dist4[])
+{
+#if defined(_USE_HAVRAN_SSE)
 #ifdef USE_HAVRAN_RAYCASTER 
   for (int i = 0; i < 4; i++) {
     result4[i] = -1;
+	//	raypack.SetObject(i, NULL);
     raypack.SetLoc(i, origin4[i]);
     raypack.SetDir(i, direction4[i]);
@@ -110,5 +111,6 @@
   // a particular ASDS, otherwise it is emulated by decomposition
   // of a packet to individual rays and traced individually.
-  mKtbtree->FindNearestI(raypack, boxmin, boxmax);
+  mKtbtree->FindNearestI(raypack, (Vector3&)boxmin, (Vector3&)boxmax);
+  //  mKtbtree->FindNearestI(raypack, bmin, bmax);
 
   for (int i = 0; i < 4; i++) {
@@ -131,5 +133,5 @@
     sray.mOrigin = origin4[i];
     sray.mDirection = direction4[i];
-    mKtbtree->FindNearestI(sray, boxmin, boxmax);
+    mKtbtree->FindNearestI(sray, (Vector3&)boxmin, (Vector3&)boxmax);
     if (SimpleRay::IntersectionRes[0].intersectable) {
       // This is object ID - is this the triangle index ???
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 2575)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Exporter.cpp	(revision 2599)
@@ -83,25 +83,39 @@
 void Exporter::ExportKdIntersectable(const KdIntersectable &kdObj)
 {
-	KdNode *node = kdObj.GetItem();
+	KdNode *root = kdObj.GetItem();
 	Intersectable::NewMail();
 
-	// todo: traverse to leaves
-	if (node->IsLeaf())
-	{
-		// eyport leaf pvs
-		KdLeaf *leaf = static_cast<KdLeaf *>(node);
-
-		ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
-
-		for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
-		{	
-			Intersectable *obj = *oit;
-        
-			if (!obj->Mailed())
-			{
-				ExportIntersectable(obj);
-				obj->Mail();					
-			}				
-		}
+	stack<KdNode *> tStack;
+
+	tStack.push(root);
+
+	while (!tStack.empty()) {
+	  KdNode *node = tStack.top();
+	  tStack.pop();
+	  // todo: traverse to leaves
+	  if (node->IsLeaf())
+		{
+		  // eyport leaf pvs
+		  KdLeaf *leaf = static_cast<KdLeaf *>(node);
+		  
+		  ObjectContainer::const_iterator oit, oit_end = leaf->mObjects.end();
+		  
+		  for (oit = leaf->mObjects.begin(); oit != oit_end; ++ oit)
+			{	
+			  Intersectable *obj = *oit;
+			  
+			  if (1 || !obj->Mailed())
+				{
+				  ExportIntersectable(obj);
+				  obj->Mail();					
+				}			
+			}
+		} else {
+		  KdInterior *interior = (KdInterior *)node;
+		  tStack.push(interior->mBack);
+		  tStack.push(interior->mFront);
+		  
+		}
+	  
 	}
 }
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2592)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/Makefile	(revision 2599)
@@ -1,5 +1,5 @@
 #############################################################################
 # Makefile for building: preprocessor
-# Generated by qmake (2.00a) (Qt 4.1.2) on: po 14. I 15:10:11 2008
+# Generated by qmake (2.00a) (Qt 4.1.2) on: út 15. I 21:38:15 2008
 # Project:  preprocessor.pro
 # Template: app
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h	(revision 2592)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/HavranRayCaster.h	(revision 2599)
@@ -75,10 +75,10 @@
   // We give a box to which each ray is clipped to before the
   // ray shooting is computed !
-  virtual void CastRaysPacket4(Vector3 &minBox,
-			       Vector3 &maxBox,
-			       Vector3 origin4[],
-			       Vector3 direction4[],
-			       int     result4[],
-			       float   dist4[]);
+  virtual void CastRaysPacket4(const Vector3 &minBox,
+							   const Vector3 &maxBox,
+							   const Vector3 origin4[],
+							   const Vector3 direction4[],
+							   int     result4[],
+							   float   dist4[]);
 
 #ifdef _USE_HAVRAN_SSE  
Index: /GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h
===================================================================
--- /GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h	(revision 2575)
+++ /GTP/trunk/Lib/Vis/Preprocessing/src/IntersectableWrapper.h	(revision 2599)
@@ -152,10 +152,12 @@
 }
   
+
+
 template<typename T>
 std::ostream &IntersectableWrapper<T>::Describe(std::ostream &s)
 {
-	s << mItem;
-	return s;
-}
+ s << mItem;
+   return s;
+	 }
 
 
