1 #ifndef SOPUHS_TESTS_HPP
2 #define SOPUHS_TESTS_HPP
6 #include <Eigen/StdVector>
7 #include <unsupported/Eigen/MatrixFunctions>
15 #include <ceres/jet.h>
20 template <
class LieGroup_>
24 using Scalar =
typename LieGroup::Scalar;
26 using Tangent =
typename LieGroup::Tangent;
27 using Point =
typename LieGroup::Point;
30 using Line =
typename LieGroup::Line;
31 using Adjoint =
typename LieGroup::Adjoint;
32 static int constexpr
N = LieGroup::N;
33 static int constexpr
DoF = LieGroup::DoF;
37 std::vector<
LieGroup, Eigen::aligned_allocator<LieGroup>>
const&
39 std::vector<
Tangent, Eigen::aligned_allocator<Tangent>>
const&
41 std::vector<
Point, Eigen::aligned_allocator<Point>>
const& point_vec)
48 for (
size_t i = 0; i <
group_vec_.size(); ++i) {
57 Tangent ad2 = LieGroup::vee(T * LieGroup::hat(x) *
60 "Adjoint case %, %", i, j);
75 foo_T3_bar = foo_T_bar;
81 LieGroup foo_T4_bar(foo_T_bar.matrix());
83 passed, foo_T_bar.matrix(), foo_T4_bar.matrix(),
kSmallEps,
84 "Constructor from homogeneous matrix: %\nvs\n %",
87 Eigen::Map<LieGroup> foo_Tmap_bar(foo_T_bar.data());
90 passed, foo_T_bar.matrix(), foo_T5_bar.matrix(),
kSmallEps,
91 "Assignment from Eigen::Map type: %\nvs\n %",
94 Eigen::Map<LieGroup const> foo_Tcmap_bar(foo_T_bar.data());
96 foo_T6_bar = foo_Tcmap_bar;
98 passed, foo_T_bar.matrix(), foo_T5_bar.matrix(),
kSmallEps,
99 "Assignment from Eigen::Map type: %\nvs\n %",
103 Eigen::Map<LieGroup> foo_Tmap2_bar(I.data());
104 foo_Tmap2_bar = foo_T_bar;
106 kSmallEps,
"Assignment to Eigen::Map type: %\nvs\n %",
117 for (
int i = 0; i <
DoF; ++i) {
124 return LieGroup::exp(x).matrix();
128 "Dxi_exp_x_matrix_at_ case %", i);
134 template <
class G = LieGroup>
136 std::is_same<G, Sophus::SO3<Scalar>>::value ||
137 std::is_same<G, Sophus::SE2<Scalar>>::value ||
138 std::is_same<G, Sophus::SE3<Scalar>>::value,
144 Eigen::Matrix<Scalar, num_parameters, DoF> J = LieGroup::Dx_exp_x(a);
145 Eigen::Matrix<Scalar, num_parameters, DoF> J_num =
146 vectorFieldNumDiff<Scalar, num_parameters, DoF>(
148 return LieGroup::exp(x).params();
153 "Dx_exp_x case: %", j);
158 Eigen::Matrix<Scalar, num_parameters, DoF> J = LieGroup::Dx_exp_x_at_0();
159 Eigen::Matrix<Scalar, num_parameters, DoF> J_num =
160 vectorFieldNumDiff<Scalar, num_parameters, DoF>(
162 return LieGroup::exp(x).params();
167 for (
size_t i = 0; i <
group_vec_.size(); ++i) {
170 Eigen::Matrix<Scalar, num_parameters, DoF> J = T.Dx_this_mul_exp_x_at_0();
171 Eigen::Matrix<Scalar, num_parameters, DoF> J_num =
172 vectorFieldNumDiff<Scalar, num_parameters, DoF>(
174 return (T * LieGroup::exp(x)).params();
179 "Dx_this_mul_exp_x_at_0 case: %", i);
185 template <
class G = LieGroup>
187 !std::is_same<G, Sophus::SO3<Scalar>>::value &&
188 !std::is_same<G, Sophus::SE2<Scalar>>::value &&
189 !std::is_same<G, Sophus::SE3<Scalar>>::value,
198 for (
size_t i = 0; i <
group_vec_.size() - 1; ++i) {
204 "Product case: %", i);
212 for (
size_t i = 0; i <
group_vec_.size(); ++i) {
228 "expmap(hat(x)) - exp(x) case: %", i);
236 for (
size_t i = 0; i <
group_vec_.size(); ++i) {
237 for (
size_t j = 0; j <
point_vec_.size(); ++j) {
251 "Transform point case: %", i);
253 kSmallEps,
"Transform homogeneous point case: %", i);
255 "Transform map point case: %", i);
264 for (
size_t i = 0; i <
group_vec_.size(); ++i) {
265 for (
size_t j = 0; j + 1 <
point_vec_.size(); ++j) {
268 Line l = Line::Through(p1, p2);
275 "Transform line case (1st point) : %", i);
278 "Transform line case (2nd point) : %", i);
281 "Transform line case (direction) : %", i);
296 Tangent tangent2 = LieGroup::vee(hati * hatj - hatj * hati);
298 "Lie Bracket case: %", i);
327 Scalar const sqrt_eps = sqrt(eps);
354 foo_T_bar.inverse() * foo_T_baz)) {
360 dash_T_foo * foo_T_baz, alpha);
362 (dash_T_foo * foo_T_quiz).matrix(), sqrt_eps);
369 interpolate(foo_T_bar.inverse(), foo_T_baz.inverse(), alpha);
371 foo_T_quiz.matrix(), sqrt_eps);
384 bar_T_foo * baz_T_foo.inverse())) {
390 baz_T_foo * foo_T_dash, alpha);
392 (quiz_T_foo * foo_T_dash).matrix(), sqrt_eps);
401 foo_T_bar.inverse() * foo_T_baz)) {
409 std::array<LieGroup, 2>({{foo_T_bar, foo_T_baz}}), 20);
411 average(std::array<LieGroup, 2>({{foo_T_bar, foo_T_baz}}));
413 "log(foo_T_bar): %\nlog(foo_T_baz): %",
417 passed, foo_T_quiz.matrix(), foo_T_average->matrix(), sqrt_eps,
418 "log(foo_T_bar): %\nlog(foo_T_baz): %\n"
419 "log(interp): %\nlog(average): %",
424 "log(foo_T_bar): %\nlog(foo_T_baz): %\n"
425 "log(interp): %\nlog(iaverage): %",
429 if (foo_T_iaverage) {
431 passed, foo_T_quiz.matrix(), foo_T_iaverage->matrix(), sqrt_eps,
432 "log(foo_T_bar): %\nlog(foo_T_baz): %",
443 std::default_random_engine engine;
444 for (
int i = 0; i < 100; ++i) {
445 LieGroup g = LieGroup::sampleUniform(engine);
451 template <
class S = Scalar>
456 template <
class S = Scalar>
491 Eigen::Matrix<Scalar, N, N>
const& T,
492 Eigen::Matrix<Scalar, N - 1, 1>
const& p) {
493 return T.template topLeftCorner<
N - 1,
N - 1>() * p +
494 T.template topRightCorner<N - 1, 1>();
497 Eigen::Matrix<Scalar, N, 1>
map(Eigen::Matrix<Scalar, N, N>
const& T,
498 Eigen::Matrix<Scalar, N, 1>
const& p) {
502 std::vector<LieGroup, Eigen::aligned_allocator<LieGroup>>
group_vec_;
504 std::vector<Point, Eigen::aligned_allocator<Point>>
point_vec_;
507 template <
class Scalar>
508 std::vector<SE3<Scalar>, Eigen::aligned_allocator<SE3<Scalar>>>
getTestSE3s() {
510 std::vector<SE3<Scalar>, Eigen::aligned_allocator<SE3<Scalar>>> se3_vec;
547 std::vector<SE2<T>, Eigen::aligned_allocator<SE2<T>>>
getTestSE2s() {
549 std::vector<SE2<T>, Eigen::aligned_allocator<SE2<T>>> se2_vec;
550 se2_vec.push_back(
SE2<T>());