1. OMPL
  2. OMPL
  3. ompl

Commits

Ioan Sucan  committed 4c5aa84

allow 0-scaling of projection columns

  • Participants
  • Parent commits 7c45cba
  • Branches default

Comments (0)

Files changed (2)

File src/ompl/base/ProjectionEvaluator.h

View file
                 argument: all elements (rows) in column[i] are divided
                 by scale[i]. This is useful to specify if scaling of
                 the elements of the state is to be applied before
-                projection.
+                projection. If the scale for a column is 0, the column
+                itself is set to 0.
 
                 Each element is sampled with a Gaussian distribution
                 with mean 0 and variance 1 and the matrix rows are
             /** \brief Compute a random projection matrix with \e from
                 columns and \e to rows. A vector with \e from elements
                 can be multiplied by this matrix in order to produce a
-                vector with \e to elements.
+                vector with \e to elements. This uses the function above
+                called with an empty \e scale vector.
 
                 Each element is sampled with a Gaussian distribution
                 with mean 0 and variance 1 and the matrix rows are

File src/ompl/base/src/ProjectionEvaluator.cpp

View file
     RNG rng;
     Matrix projection(to, from);
 
-    for (unsigned int i = 0 ; i < to ; ++i)
-    {
-        for (unsigned int j = 0 ; j < from ; ++j)
-            projection(i, j) = rng.gaussian01();
+    for (unsigned int j = 0 ; j < from ; ++j)
+    {    
+        if (scale.size() == from && fabs(scale[j]) < std::numeric_limits<double>::epsilon())
+            boost::numeric::ublas::column(projection, j) = boost::numeric::ublas::zero_vector<double>(to);
+        else
+            for (unsigned int i = 0 ; i < to ; ++i)
+                projection(i, j) = rng.gaussian01();
     }
 
     for (unsigned int i = 0 ; i < to ; ++i)
 
     assert(scale.size() == from || scale.size() == 0);
     if (scale.size() == from)
+    {
+        unsigned int z = 0;
         for (unsigned int i = 0 ; i < from ; ++i)
         {
             if (fabs(scale[i]) < std::numeric_limits<double>::epsilon())
-                throw Exception("Scaling factor must be non-zero");
-            boost::numeric::ublas::column(projection, i) /= scale[i];
+                boost::numeric::ublas::column(projection, i) /= scale[i];
+            else
+                z++;
         }
+        if (z == from)
+            OMPL_WARN("Computed projection matrix is all 0s");
+    }
     return projection;
 }