11 Eigen::JacobiSVD<Eigen::Matrix3d> svd(rmtx, Eigen::ComputeFullU | Eigen::ComputeFullV);
12 const Eigen::Matrix3d& umtx = svd.matrixU();
13 Eigen::Matrix3d vmtx = svd.matrixV();
14 Eigen::Matrix3d sigma = Eigen::Matrix3d::Identity();
15 if ((umtx * vmtx.transpose()).determinant() < 0.0) {
18 return umtx * sigma * vmtx.transpose();
21inline Eigen::Matrix3d
skew(
const Eigen::Vector3d& vec) {
22 Eigen::Matrix3d skew_mtx;
23 skew_mtx << 0, -vec.z(), vec.y(), vec.z(), 0, -vec.x(), -vec.y(), vec.x(), 0;
27inline Eigen::Vector3d
log_so3(
const Eigen::Matrix3d& rot_in) {
29 double cos_theta = (rotation.trace() - 1.0) * 0.5;
30 cos_theta = std::min(1.0, std::max(-1.0, cos_theta));
31 double theta = std::acos(cos_theta);
33 return Eigen::Vector3d::Zero();
36 wvec << rotation(2, 1) - rotation(1, 2), rotation(0, 2) - rotation(2, 0),
37 rotation(1, 0) - rotation(0, 1);
38 wvec *= 0.5 / std::sin(theta);
65inline std::array<double, 6>
pose_to_array(
const Eigen::Isometry3d& pose) {
66 Eigen::AngleAxisd axisangle(pose.linear());
67 return {axisangle.axis().x() * axisangle.angle(),
68 axisangle.axis().y() * axisangle.angle(),
69 axisangle.axis().z() * axisangle.angle(),
70 pose.translation().x(),
71 pose.translation().y(),
72 pose.translation().z()};
77 return Eigen::Isometry3d::Identity();
79 Eigen::Vector3d translation = Eigen::Vector3d::Zero();
80 Eigen::Quaterniond q_sum(0, 0, 0, 0);
81 for (
const auto& p : poses) {
82 translation += p.translation();
83 Eigen::Quaterniond q(p.linear());
84 if (q_sum.coeffs().dot(q.coeffs()) < 0.0) {
87 q_sum.coeffs() += q.coeffs();
89 translation /=
static_cast<double>(poses.size());
91 Eigen::Isometry3d avg = Eigen::Isometry3d::Identity();
92 avg.linear() = q_sum.toRotationMatrix();
93 avg.translation() = translation;