Index: GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
===================================================================
--- GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1874)
+++ GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp	(revision 1876)
@@ -1795,5 +1795,4 @@
 {
   stack<RssTreeNode *> tstack;
-  PushRoots(tstack);
 	
   float sumPvsSize = 0.0f;
@@ -1809,5 +1808,7 @@
   for (int i=0; i < mRoots.size(); i++)
 	UpdateImportance(mRoots[i]);
-  
+
+  PushRoots(tstack);
+
   while (!tstack.empty()) {
     RssTreeNode *node = tstack.top();
@@ -1882,5 +1883,4 @@
   // works only with single root now!
   node = mRoots[0];
-  
   while (!node->IsLeaf()) {
 	RssTreeInterior *in = (RssTreeInterior *)node;
@@ -1889,5 +1889,6 @@
 	//	float p = in->GetRelativePosition(); 
 	float p = in->back->GetImportance()/(in->back->GetImportance() + in->front->GetImportance());
-	
+
+	//	cout<<"p = "<<p<<endl;
 	//	cout<<"axis="<<axis<<" pos="<<pos<<endl;
 	//	cout<<GetBBox(in)<<endl;
@@ -1897,8 +1898,10 @@
 	if (params[axis] < p) {
 	  node = in->back;
-	  params[axis] = params[axis] / p;
+	  if (p > Limits::Small)
+		params[axis] = params[axis] / p;
 	} else {
 	  node = in->front;
-	  params[axis] = (params[axis] - p) / ( 1.0f - p);
+	  if (p < 1.0f - Limits::Small)
+		params[axis] = (params[axis] - p) / (1.0f - p);
 	}
   }
@@ -1907,4 +1910,6 @@
   
   GenerateLeafRay(params, rays, node->bbox, node->dirBBox);
+
+
 }
 
@@ -1914,7 +1919,4 @@
 					  SimpleRayContainer &rays)
 {
-
-  
-
 
   stack<RssTreeNode *> tstack;
@@ -2228,7 +2230,6 @@
   
   int startIndex = (int)rays.size();
-
   //  Debug<<"B"<<flush;
-
+  
   AxisAlignedBox3 box = GetBBox(leaf);
   AxisAlignedBox3 dirBox = GetDirBBox(leaf);
@@ -2270,10 +2271,12 @@
 						 float *params,
 						 SimpleRayContainer &rays,
-						 const AxisAlignedBox3 &box,
-						 const AxisAlignedBox3 &dirBBox
+						 const AxisAlignedBox3 &sbox,
+						 const AxisAlignedBox3 &sDirBBox
 						 )
 {
-  Vector3 origin = bbox.GetPoint(Vector3(params[0], params[1], params[2]));
-  Vector3 dirVector = dirBBox.GetPoint(Vector3(params[3], params[4], 0.0f));
+  Vector3 origin = sbox.GetPoint(Vector3(params[0], params[1], params[2]));
+
+  Vector3 dirVector = sDirBBox.GetPoint(Vector3(params[3], params[4], 0.0f));
+
   Vector3 direction = VssRay::GetInvDirParam(dirVector.x, dirVector.y);
   
@@ -2282,9 +2285,9 @@
   float minT, maxT;
   
-  float boxSize = Magnitude(bbox.Size());
+  float boxSize = Magnitude(sbox.Size());
   // compute interection of the ray with the box
 #if 1
-  if (bbox.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT)
-	dist = (maxT + 1e-2*boxSize);
+  if (sbox.ComputeMinMaxT(origin, direction, &minT, &maxT) && minT < maxT)
+	dist = (maxT + 0.0f*boxSize);
 #else
   dist = 0.5f*boxSize;
@@ -2292,6 +2295,5 @@
   
   origin += direction*dist;
-  
-  
+
   //Debug<<"dir vector.x="<<dirVector.x<<"direction'.x="<<atan2(direction.x, direction.y)<<endl;
   rays.push_back(SimpleRay(origin, direction));
@@ -2666,12 +2668,14 @@
 {
 
-  float param[5];
-
-  for (int i=0; i < numberOfRays; i++) {
-	halton.GetNext(param);
-	GenerateRay(param, rays);
-  }
-
-  return rays.size();
+  if (1) {
+	float param[5];
+	
+	for (int i=0; i < numberOfRays; i++) {
+	  mHalton.GetNext(5, param);
+	  GenerateRay(param, rays);
+	}
+
+	return rays.size();
+  }
   
   vector<RssTreeLeaf *> leaves;
@@ -2778,5 +2782,5 @@
 // if 1.0f then weighs = 1 1/2 1/3 1/4
 //float passSampleWeightDecay = 1.0f;
-float passSampleWeightDecay = 1.0f;
+float passSampleWeightDecay = 1000.0f;
 
 float
@@ -2786,28 +2790,28 @@
   float weight;
   if (1) 
-		weight = 1.0f/(passDiff + passSampleWeightDecay);
+	weight = 1.0f/(passDiff + passSampleWeightDecay);
   else 
-		switch (passDiff) {
-	  case 0:
-			//	  weight = 1.0f;
-			//	  break;
-		default:
-			weight = 1.0f;
-			break;
+	switch (passDiff) {
+	case 0:
+	  //	  weight = 1.0f;
+	  //	  break;
+	default:
+	  weight = 1.0f;
+	  break;
 	  // 	case 1:
-// 	  weight = 0.5f;
-// 	  break;
-// 	case 2:
-// 	  weight = 0.25f;
-// 	  break;
-// 	case 3:
-// 	  weight = 0.12f;
-// 	  break;
-// 	case 4:
-// 	  weight = 0.06f;
-// 	  break;
-// 	default:
-// 	  weight = 0.03f;
-// 	  break;
+	  // 	  weight = 0.5f;
+	  // 	  break;
+	  // 	case 2:
+	  // 	  weight = 0.25f;
+	  // 	  break;
+	  // 	case 3:
+	  // 	  weight = 0.12f;
+	  // 	  break;
+	  // 	case 4:
+	  // 	  weight = 0.06f;
+	  // 	  break;
+	  // 	default:
+	  // 	  weight = 0.03f;
+	  // 	  break;
 	}
   return weight;
