27 const std::vector<Eigen::Matrix<double, 7, 1>> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t,
28 double &s, std::string method,
int n_aligned) {
31 if (method ==
"posyaw") {
34 }
else if (method ==
"posyawsingle") {
37 }
else if (method ==
"se3") {
39 align_se3(traj_es, traj_gt, R, t, n_aligned);
40 }
else if (method ==
"se3single") {
43 }
else if (method ==
"sim3") {
44 assert(n_aligned >= 2 || n_aligned == -1);
45 align_sim3(traj_es, traj_gt, R, t, s, n_aligned);
46 }
else if (method ==
"none") {
52 PRINT_ERROR(
RED "[ALIGN]: Possible options: posyaw, posyawsingle, se3, se3single, sim3, none\n" RESET);
53 std::exit(EXIT_FAILURE);
58 const std::vector<Eigen::Matrix<double, 7, 1>> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t) {
61 Eigen::Vector4d q_es_0 = traj_es.at(0).block(3, 0, 4, 1);
62 Eigen::Vector3d p_es_0 = traj_es.at(0).block(0, 0, 3, 1);
64 Eigen::Vector4d q_gt_0 = traj_gt.at(0).block(3, 0, 4, 1);
65 Eigen::Vector3d p_gt_0 = traj_gt.at(0).block(0, 0, 3, 1);
72 Eigen::Matrix3d C_R = est_rot * g_rot.transpose();
81 t.noalias() = p_gt_0 - R * p_es_0;
85 const std::vector<Eigen::Matrix<double, 7, 1>> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t,
94 assert(!traj_es.empty());
95 std::vector<Eigen::Vector3d> pos_est, pos_gt;
96 for (
size_t i = 0; i < traj_es.size() && i < traj_gt.size(); i++) {
97 pos_est.push_back(traj_es.at(i).block(0, 0, 3, 1));
98 pos_gt.push_back(traj_gt.at(i).block(0, 0, 3, 1));
109 const std::vector<Eigen::Matrix<double, 7, 1>> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t) {
112 Eigen::Vector4d q_es_0 = traj_es.at(0).block(3, 0, 4, 1);
113 Eigen::Vector3d p_es_0 = traj_es.at(0).block(0, 0, 3, 1);
115 Eigen::Vector4d q_gt_0 = traj_gt.at(0).block(3, 0, 4, 1);
116 Eigen::Vector3d p_gt_0 = traj_gt.at(0).block(0, 0, 3, 1);
122 R.noalias() = g_rot * est_rot.transpose();
123 t.noalias() = p_gt_0 - R * p_es_0;
127 const std::vector<Eigen::Matrix<double, 7, 1>> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t,
131 if (n_aligned == 1) {
136 assert(!traj_es.empty());
137 std::vector<Eigen::Vector3d> pos_est, pos_gt;
138 for (
size_t i = 0; i < traj_es.size() && i < traj_gt.size(); i++) {
139 pos_est.push_back(traj_es.at(i).block(0, 0, 3, 1));
140 pos_gt.push_back(traj_gt.at(i).block(0, 0, 3, 1));
150 const std::vector<Eigen::Matrix<double, 7, 1>> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t,
double &s,
154 assert(n_aligned >= 2 || n_aligned == -1);
157 assert(!traj_es.empty());
158 std::vector<Eigen::Vector3d> pos_est, pos_gt;
159 for (
size_t i = 0; i < traj_es.size() && i < traj_gt.size(); i++) {
160 pos_est.push_back(traj_es.at(i).block(0, 0, 3, 1));
161 pos_gt.push_back(traj_gt.at(i).block(0, 0, 3, 1));
static void align_posyaw(const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_es, const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t, int n_aligned=-1)
Align estimate to GT using only position and yaw (for gravity aligned trajectories) using a set of in...
static void align_se3_single(const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_es, const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t)
Align estimate to GT using a full SE(3) transform using only the first poses.
Evaluation and recording utilities.
static void align_trajectory(const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_es, const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t, double &s, std::string method, int n_aligned=-1)
Align estimate to GT using a desired method using a set of initial poses.
static void align_se3(const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_es, const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t, int n_aligned=-1)
Align estimate to GT using a full SE(3) transform using a set of initial poses.
static void align_sim3(const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_es, const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t, double &s, int n_aligned=-1)
Align estimate to GT using a full SIM(3) transform using a set of initial poses.
static void align_umeyama(const std::vector< Eigen::Matrix< double, 3, 1 >> &data, const std::vector< Eigen::Matrix< double, 3, 1 >> &model, Eigen::Matrix< double, 3, 3 > &R, Eigen::Matrix< double, 3, 1 > &t, double &s, bool known_scale, bool yaw_only)
Given a set of points in a model frame and a set of points in a data frame, finds best transform betw...
#define PRINT_ERROR(x...)
static void align_posyaw_single(const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_es, const std::vector< Eigen::Matrix< double, 7, 1 >> &traj_gt, Eigen::Matrix3d &R, Eigen::Vector3d &t)
Align estimate to GT using only position and yaw (for gravity aligned trajectories) using only the fi...
static double get_best_yaw(const Eigen::Matrix< double, 3, 3 > &C)
Gets best yaw from Frobenius problem. Equation (17)-(18) in Zhang et al. 2018 IROS paper...
Eigen::Matrix< double, 3, 3 > rot_z(double t)
Eigen::Matrix< double, 3, 3 > quat_2_Rot(const Eigen::Matrix< double, 4, 1 > &q)