Skip to content

Commit 83454bd

Browse files
authored
se3 expmap (#139)
Co-authored-by: k.koide <[email protected]>
1 parent af0a772 commit 83454bd

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

include/fast_gicp/gicp/impl/lsq_registration_impl.hpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ bool LsqRegistration<PointTarget, PointSource>::step_gn(Eigen::Isometry3d& x0, E
111111
Eigen::LDLT<Eigen::Matrix<double, 6, 6>> solver(H);
112112
Eigen::Matrix<double, 6, 1> d = solver.solve(-b);
113113

114-
delta.setIdentity();
115-
delta.linear() = so3_exp(d.head<3>()).toRotationMatrix();
116-
delta.translation() = d.tail<3>();
114+
delta = se3_exp(d);
117115

118116
x0 = delta * x0;
119117
final_hessian_ = H;
@@ -136,9 +134,7 @@ bool LsqRegistration<PointTarget, PointSource>::step_lm(Eigen::Isometry3d& x0, E
136134
Eigen::LDLT<Eigen::Matrix<double, 6, 6>> solver(H + lm_lambda_ * Eigen::Matrix<double, 6, 6>::Identity());
137135
Eigen::Matrix<double, 6, 1> d = solver.solve(-b);
138136

139-
delta.setIdentity();
140-
delta.linear() = so3_exp(d.head<3>()).toRotationMatrix();
141-
delta.translation() = d.tail<3>();
137+
delta = se3_exp(d);
142138

143139
Eigen::Isometry3d xi = delta * x0;
144140
double yi = compute_error(xi);

include/fast_gicp/so3/so3.hpp

+28-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ inline Eigen::Quaterniond so3_exp(const Eigen::Vector3d& omega) {
6161
double theta;
6262
double imag_factor;
6363
double real_factor;
64-
if(theta_sq < 1e-10) {
64+
if (theta_sq < 1e-10) {
6565
theta = 0;
6666
double theta_quad = theta_sq * theta_sq;
6767
imag_factor = 0.5 - 1.0 / 48.0 * theta_sq + 1.0 / 3840.0 * theta_quad;
@@ -76,6 +76,33 @@ inline Eigen::Quaterniond so3_exp(const Eigen::Vector3d& omega) {
7676
return Eigen::Quaterniond(real_factor, imag_factor * omega.x(), imag_factor * omega.y(), imag_factor * omega.z());
7777
}
7878

79+
// Rotation-first
80+
inline Eigen::Isometry3d se3_exp(const Eigen::Matrix<double, 6, 1>& a) {
81+
using std::cos;
82+
using std::sin;
83+
const Eigen::Vector3d omega = a.head<3>();
84+
85+
double theta = std::sqrt(omega.dot(omega));
86+
const Eigen::Quaterniond so3 = so3_exp(omega);
87+
const Eigen::Matrix3d Omega = skewd(omega);
88+
const Eigen::Matrix3d Omega_sq = Omega * Omega;
89+
Eigen::Matrix3d V;
90+
91+
if (theta < 1e-10) {
92+
V = so3.matrix();
93+
/// Note: That is an accurate expansion!
94+
} else {
95+
const double theta_sq = theta * theta;
96+
V = (Eigen::Matrix3d::Identity() + (1.0 - cos(theta)) / (theta_sq)*Omega + (theta - sin(theta)) / (theta_sq * theta) * Omega_sq);
97+
}
98+
99+
Eigen::Isometry3d se3 = Eigen::Isometry3d::Identity();
100+
se3.linear() = so3.toRotationMatrix();
101+
se3.translation() = V * a.tail<3>();
102+
103+
return se3;
104+
}
105+
79106
} // namespace fast_gicp
80107

81108
#endif

0 commit comments

Comments
 (0)