ROS-UVS  1.0.0
A Minimalistic ROS Library for Visual Constraint Minimization through Uncalibrated Visual Servoing
 All Classes Files Functions Variables
util.h
Go to the documentation of this file.
1 #ifndef UTIL_H
2 #define UTIL_H
3 #include <Eigen/Core>
4 #include <Eigen/SVD>
5 
7 
9 template<typename _Matrix_Type_>
10 bool pseudoInverse(const _Matrix_Type_ &a, _Matrix_Type_ &result, double epsilon = std::numeric_limits<typename _Matrix_Type_::Scalar>::epsilon())
11 {
12  Eigen::JacobiSVD< _Matrix_Type_ > svd = a.jacobiSvd(Eigen::ComputeThinU | Eigen::ComputeThinV);
13 
14  typename _Matrix_Type_::Scalar tolerance = epsilon * std::max(a.cols(), a.rows()) *
15  svd.singularValues().array().abs().maxCoeff();
16 
17  result = svd.matrixV() * _Matrix_Type_( (svd.singularValues().array().abs() >
18  tolerance).select(svd.singularValues().array().inverse(), 0) ).asDiagonal() *
19  svd.matrixU().adjoint();
20 }
21 
22 #endif // UTIL_H
bool pseudoInverse(const _Matrix_Type_ &a, _Matrix_Type_ &result, double epsilon=std::numeric_limits< typename _Matrix_Type_::Scalar >::epsilon())
Moore-Penrose pseudoinverse.
Definition: util.h:10