30 using namespace gtsam;
31 using namespace std::placeholders;
36 static const Point3 P(0.2,0.7,-2);
37 static const Rot3 R = Rot3::Rodrigues(0.3,0,0);
38 static const Point3 P2(3.5,-8.2,4.2);
40 static const Pose3 T2(Rot3::Rodrigues(0.3,0.2,0.1),
P2);
41 static const Pose3 T3(Rot3::Rodrigues(-90, 0, 0),
Point3(1, 2, 3));
42 static const double tol=1
e-5;
69 #ifndef GTSAM_POSE3_EXPMAP
76 v(3)=0.2;
v(4)=0.7;
v(5)=-2;
96 v(3)=0.2;
v(4)=0.394742;
v(5)=-2.08998;
107 v(3)=0.2;
v(4)=0.394742;
v(5)=-2.08998;
115 Pose3 p2 =
p1.retract((
Vector(6) << 0.0, 0.0, 0.1, 0.0, 0.0, 0.0).finished());
159 Vector6
xi = (Vector6() << 0.1, 1.2, 2.3, 3.1, 1.4, 4.5).finished();
167 Matrix6 actualH1, actualH2, expectedH1, expectedH2;
168 std::function<Vector6(
const Pose3&,
const Vector6&)> Adjoint_proxy =
169 [&](
const Pose3&
T,
const Vector6&
xi) {
return T.Adjoint(
xi); };
171 T.Adjoint(
xi, actualH1, actualH2);
194 Vector6
xi = (Vector6() << 0.1, 1.2, 2.3, 3.1, 1.4, 4.5).finished();
198 T.AdjointTranspose(
xi));
205 Matrix6 actualH1, actualH2, expectedH1, expectedH2;
206 std::function<Vector6(
const Pose3&,
const Vector6&)> AdjointTranspose_proxy =
207 [&](
const Pose3&
T,
const Vector6&
xi) {
208 return T.AdjointTranspose(
xi);
211 T.AdjointTranspose(
xi, actualH1, actualH2);
233 Vector6
v1(1, 2, 3, 4, 5, 6);
234 Vector6
v2(0.1, -0.5, 1.0, -1.0, 0.5, 2.0);
235 Vector6
v3(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
288 xi = (
Vector(6) << 0.1, 0.2, 0.3, 0.4, 0.5, 0.6).finished();
294 xi = (
Vector(6) << 0.1, -0.2, 0.3, -0.4, 0.5, -0.6).finished();
295 for (
double theta=1.0;0.3*theta<=
M_PI;theta*=2) {
306 xi = (
Vector(6) << 0.2, 0.3, -0.8, 100.0, 120.0, -60.0).finished();
320 Matrix numericalH = numericalDerivative11<Point3, Pose3>(
f,
T);
330 std::function<
Rot3(
const Pose3&)>
f = [](
const Pose3&
T) {
return T.rotation(); };
331 Matrix numericalH = numericalDerivative11<Rot3, Pose3>(
f,
T);
341 Vector x = (
Vector(6) << 0.1, 0.1, 0.1, 0.4, 0.2, 0.8).finished();
357 Matrix actualDcompose1, actualDcompose2;
377 Matrix actualDcompose1, actualDcompose2;
392 Matrix actual =
T.inverse(actualDinverse).matrix();
404 Rot3 R = Rot3::Rodrigues(0.3,0.4,-0.5);
410 T.inverse(actualDinverse);
428 Matrix actualDtransform_from1;
429 T.transformFrom(
P, actualDtransform_from1, {});
436 Matrix actualDtransform_from1;
437 origin.transformFrom(
P, actualDtransform_from1, {});
445 Matrix actualDtransform_from1;
455 Matrix actualDtransform_from1;
465 Matrix actualDtransform_from2;
466 T.transformFrom(
P, {}, actualDtransform_from2);
477 T.transformTo(
P, computed, {});
485 T.transformTo(
P, {}, computed);
493 T.transformTo(
P, actH1, actH2);
503 T.transformFrom(
P, actH1, actH2);
609 d << 1,2,3,4,5,6;
d/=10;
610 const Rot3 R = Rot3::Retract(
d.head<3>());
618 d12 << 1,2,3,4,5,6; d12/=10;
625 Vector d12 = Vector6::Constant(0.1);
663 Vector d = (
Vector(6) << 0.1, 0.2, 0.3, 0.4, 0.5, 0.6).finished();
678 Matrix actualDBetween1,actualDBetween2;
691 Point3 l1(1, 0, 0),
l2(1, 1, 0),
l3(2, 2, 0),
l4(1, 4,-4);
694 xl1(Rot3::Ypr(0.0, 0.0, 0.0),
Point3(1, 0, 0)),
695 xl2(Rot3::Ypr(0.0, 1.0, 0.0),
Point3(1, 1, 0)),
696 xl3(Rot3::Ypr(1.0, 0.0, 0.0),
Point3(2, 2, 0)),
697 xl4(Rot3::Ypr(0.0, 0.0, 1.0),
Point3(1, 4,-4));
705 Matrix expectedH1, actualH1, expectedH2, actualH2;
714 double actual23 =
x2.
range(
l3, actualH1, actualH2);
724 double actual34 =
x3.
range(
l4, actualH1, actualH2);
740 Matrix expectedH1, actualH1, expectedH2, actualH2;
749 double actual23 =
x2.
range(
xl3, actualH1, actualH2);
759 double actual34 =
x3.
range(
xl4, actualH1, actualH2);
774 Matrix expectedH1, actualH1, expectedH2, actualH2;
785 Matrix expectedH1, actualH1, expectedH2, actualH2;
796 Matrix expectedH1, actualH1, expectedH2, actualH2, H2block;
811 Vector x_step = Vector::Unit(6,3)*1.0;
834 const vector<Point3Pair> correspondences{ab1, ab2, ab3};
836 std::optional<Pose3> actual =
Pose3::Align(correspondences);
843 Rot3 R = Rot3::RzRyRx(0.3, 0.2, 0.1);
851 const vector<Point3Pair> correspondences{ab1, ab2, ab3};
853 std::optional<Pose3> actual =
Pose3::Align(correspondences);
871 auto xi = [](
double t) {
876 auto xi_dot = [](
double t) {
885 for (
double t = -2.0;
t < 2.0;
t += 0.3) {
887 const Matrix actual = Pose3::ExpmapDerivative(
xi(
t)) * xi_dot(
t);
894 static const std::vector<Vector3>
small{ {0, 0, 0},
895 {1
e-5, 0, 0}, {0, 1
e-5, 0}, {0, 0, 1
e-5},
896 {1
e-4, 0, 0}, {0, 1
e-4, 0}, {0, 0, 1
e-4} };
897 static const std::vector<Vector3>
large{ {0, 0, 0}, {1, 0, 0}, {0, 1, 0},
898 {0, 0, 1}, {.1, .2, .3}, {1, -2, 3} };
899 auto omegas = [](
bool nearZero) ->
const std::vector<Vector3>&{
return nearZero ?
small :
large; };
900 static const std::vector<Vector3>
vs{ {1, 0, 0}, {0, 1, 0}, {0, 0, 1},
901 {.4, .3, .2}, {4, 5, 6}, {-10, -20, 30} };
906 for (
bool nearZero : {
true,
false}) {
909 const Vector6
xi = (Vector6() <<
w,
v).finished();
911 numericalDerivative21<Pose3, Vector6, OptionalJacobian<6, 6> >(
924 static constexpr
bool nearZero =
true;
927 const Vector6
xi = (Vector6() <<
w,
v).finished();
937 for (
bool nearZero : {
true,
false}) {
939 std::cout <<
"w: " <<
w.transpose() << std::endl;
941 std::cout <<
"v: " <<
v.transpose() << std::endl;
942 const Vector6
xi = (Vector6() <<
w,
v).finished();
945 numericalDerivative21<Vector6, Pose3, OptionalJacobian<6, 6> >(
946 &Pose3::Logmap,
pose, {});
948 Pose3::Logmap(
pose, actualH);
949 #ifdef GTSAM_USE_QUATERNIONS
964 const Rot3 R2((Matrix3() <<
965 -0.750767, -0.0285082, -0.659952,
966 -0.0102558, -0.998445, 0.0547974,
967 -0.660487, 0.0479084, 0.749307).finished());
968 const Rot3 R3((Matrix3() <<
969 -0.747473, -0.00190019, -0.664289,
970 -0.0385114, -0.99819, 0.0461892,
971 -0.663175, 0.060108, 0.746047).finished());
972 const Rot3 R4((Matrix3() <<
973 0.324237, 0.902975, 0.281968,
974 -0.674322, 0.429668, -0.600562,
975 -0.663445, 0.00458662, 0.748211).finished());
979 const Vector6
xi(0.1, -0.1, 0.1, 0.1, -0.1, 0.1);
986 const bool nearPi = (
i == 2 ||
i == 3);
989 const Vector6
xi = Pose3::Logmap(
T, actualH);
994 Matrix6 J_r_inv = Pose3::ExpmapDerivative(
xi).inverse();
1002 const Matrix expectedH = numericalDerivative11<Vector6, Pose3>(
1003 std::bind(&Pose3::Logmap, std::placeholders::_1,
nullptr),
T, 1
e-7);
1016 return Pose3::adjointMap(
xi) *
v;
1020 Vector6
v = (Vector6() << 1, 2, 3, 4, 5, 6).finished();
1023 Matrix actualH1, actualH2;
1026 Matrix numericalH1 = numericalDerivative21<Vector6, Vector6, Vector6>(
1028 Matrix numericalH2 = numericalDerivative22<Vector6, Vector6, Vector6>(
1038 return Pose3::adjointMap(
xi).transpose() *
v;
1042 Vector xi = (
Vector(6) << 0.01, 0.02, 0.03, 1.0, 2.0, 3.0).finished();
1043 Vector v = (
Vector(6) << 0.04, 0.05, 0.06, 4.0, 5.0, 6.0).finished();
1046 Matrix actualH1, actualH2;
1047 Vector actual = Pose3::adjointTranspose(
xi,
v, actualH1, actualH2);
1049 Matrix numericalH1 = numericalDerivative21<Vector6, Vector6, Vector6>(
1051 Matrix numericalH2 = numericalDerivative22<Vector6, Vector6, Vector6>(
1061 std::ostringstream
os;
1064 string expected =
"R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\nt: 0 0 0";
1072 EXPECT(check_group_invariants(
id,
id));
1073 EXPECT(check_group_invariants(
id,
T3));
1074 EXPECT(check_group_invariants(
T2,
id));
1077 EXPECT(check_manifold_invariants(
id,
id));
1078 EXPECT(check_manifold_invariants(
id,
T3));
1079 EXPECT(check_manifold_invariants(
T2,
id));
1113 auto cov2 = FullCovarianceFromSigmas<Pose2>(s2);
1116 auto match_cov3_to_cov2 = [&](
int spatial_axis0,
int spatial_axis1,
int r_axis,
1117 const Pose2::Jacobian &cov2,
const Pose3::Jacobian &cov3) ->
void
1121 Vector3{cov3(spatial_axis0, spatial_axis0), cov3(spatial_axis1, spatial_axis1), cov3(r_axis, r_axis)}));
1123 Vector3{cov2(1, 0), cov2(2, 0), cov2(2, 1)},
1124 Vector3{cov3(spatial_axis1, spatial_axis0), cov3(r_axis, spatial_axis0), cov3(r_axis, spatial_axis1)}));
1129 auto cov3 = FullCovarianceFromSigmas<Pose3>((Vector6{} << s2(2), 0., 0., 0., s2(0), s2(1)).finished());
1131 match_cov3_to_cov2(4, 5, 0, transformed2, transformed3);
1136 auto cov3 = FullCovarianceFromSigmas<Pose3>((Vector6{} << 0., s2(2), 0., s2(1), 0., s2(0)).finished());
1138 match_cov3_to_cov2(5, 3, 1, transformed2, transformed3);
1143 auto cov3 = FullCovarianceFromSigmas<Pose3>((Vector6{} << 0., 0., s2(2), s2(0), s2(1), 0.).finished());
1145 match_cov3_to_cov2(3, 4, 2, transformed2, transformed3);
1157 auto cov = FullCovarianceFromSigmas<Pose3>((Vector6{} << 0.1, 0.2, 0.3, 0.5, 0.7, 1.1).finished());
1161 (Vector6{} << cov(1, 1), cov(2, 2), cov(0, 0), cov(4, 4), cov(5, 5), cov(3, 3)).finished(),
1162 Vector6{transformed.diagonal()}));
1165 (Vector5{} << -cov(2, 1), cov(0, 1), cov(4, 1), -cov(5, 1), cov(3, 1)).finished(),
1166 (Vector5{} << transformed(1, 0), transformed(2, 0), transformed(3, 0),
1167 transformed(4, 0), transformed(5, 0)).finished()));
1172 auto cov = TwoVariableCovarianceFromSigmas<Pose3>(1, 2, 0.7, 0.3);
1186 auto cov = SingleVariableCovarianceFromSigma<Pose3>(0, 0.1);
1194 auto cov = SingleVariableCovarianceFromSigma<Pose3>(1, 0.1);
1198 (Vector6{} << 0., 0., 0.1 * 0.1, 0., 0.1 * 0.1 * 20. * 20., 0.).finished(),
1199 Vector6{transformed.diagonal()}));
1241 Pose3 X = Pose3::Identity();
1245 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1258 Pose3 X = Pose3::Identity();
1261 Pose3 expectedPoseInterp(Rot3::Identity(),
Point3(0.3, 0, 0));
1262 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1275 Pose3 X = Pose3::Identity();
1279 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1296 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1297 interpolate(
X,
Y,
t, actualJacobianX, actualJacobianY, actualJacobianT);
1314 Pose3 X = Pose3::Identity();
1317 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1318 X.interpolateRt(
Y,
t, actualJacobianX, actualJacobianY, actualJacobianT);
1330 Pose3 X = Pose3::Identity();
1333 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1334 X.interpolateRt(
Y,
t, actualJacobianX, actualJacobianY, actualJacobianT);
1346 Pose3 X = Pose3::Identity();
1349 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1350 X.interpolateRt(
Y,
t, actualJacobianX, actualJacobianY, actualJacobianT);
1365 Matrix actualJacobianX, actualJacobianY, actualJacobianT;
1366 X.interpolateRt(
Y,
t, actualJacobianX, actualJacobianY, actualJacobianT);
1389 Matrix expectedJacobianX, expectedJacobianY, expectedJacobianT;
1390 std::vector<Matrix> Hlist = {{},{},{}};
1400 Matrix expectedJacobianX, expectedJacobianY, expectedJacobianT;
1401 std::vector<Matrix> Hlist = {{},{},{}};
1402 Pose3 expected =
X.interpolateRt(
Y,
t, expectedJacobianX, expectedJacobianY, expectedJacobianT);
1414 Matrix63 actualH1, actualH2;
1415 Pose3 actual = Pose3::Create(
R,
P2, actualH1, actualH2);
1418 return Pose3::Create(
R,
t);
1429 std::string
expected =
"R: [\n\t1, 0, 0;\n\t0, 1, 0;\n\t0, 0, 1\n]\nt: 1 2 3\n";
1438 M << 1, 2, 3, 4, 5, 6,
1444 auto g = [&](
const Vector6&
omega) {
1453 const Vector6
delta{0.1, 0.2, 0.3, 0.4, 0.5, 0.6};
1454 const Matrix6 expected2 = numericalDerivative11<Pose3, Vector6>(
g,
delta);
1456 EXPECT(assert_equal<Matrix6>(expected2, analytic, 1
e-5));
1470 Matrix numericalH = numericalDerivative11<Vector16, Pose3>(
f,
T);