test-mp2p_optimize_pt2ln.cpp
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A Modular Optimization framework for Localization and mApping (MOLA)
3  * Copyright (C) 2018-2021 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
6 
15 #include <mrpt/poses/Lie/SE.h>
16 
17 static void test_opt_pt2ln(const mrpt::poses::CPose3D& groundTruth)
18 {
19  using namespace mrpt::poses::Lie;
20 
21  MRPT_START
22 
23  // Prepare test case pairings:
24  // 3 point-to-line correspondences, such that the sought optimal
25  // pose is the given one:
26 
28 
29  {
30  auto& pp = p.paired_pt2ln.emplace_back();
31  pp.ln_global = mrpt::math::TLine3D::FromTwoPoints({0, 0, 0}, {1, 0, 0});
32  pp.pt_local = groundTruth.inverseComposePoint({0.5, 0, 0});
33  }
34  {
35  auto& pp = p.paired_pt2ln.emplace_back();
36  pp.ln_global = mrpt::math::TLine3D::FromTwoPoints({0, 0, 0}, {0, 1, 0});
37  pp.pt_local = groundTruth.inverseComposePoint({0, 0.4, 0});
38  }
39  {
40  auto& pp = p.paired_pt2ln.emplace_back();
41  pp.ln_global = mrpt::math::TLine3D::FromTwoPoints({0, 0, 0}, {0, 0, 1});
42  pp.pt_local = groundTruth.inverseComposePoint({0, 0, 0.2});
43  }
44 
45  std::cout << "Input pairings: " << p.contents_summary() << std::endl;
46 
47  // Init solver:
49 
50  mrpt::containers::yaml solverParams;
51  solverParams["maxIterations"] = 25;
52  solverParams["innerLoopVerbose"] = true;
53 
54  solver.initialize(solverParams);
55 
58  sc.guessRelativePose = mrpt::poses::CPose3D::Identity();
59 
60  bool solvedOk = solver.optimal_pose(p, result, sc);
61 
62  std::cout << "Found optimalPose: " << result.optimalPose << std::endl;
63  std::cout << "Expected optimalPose: " << groundTruth << std::endl;
64 
65  ASSERT_NEAR_(
66  mrpt::poses::Lie::SE<3>::log(result.optimalPose - groundTruth).norm(),
67  0.0, 1e-3);
68 
69  // check results:
70  ASSERT_(solvedOk);
71 
72  MRPT_END
73 }
74 
75 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
76 {
77  using mrpt::poses::CPose3D;
78  using namespace mrpt; // _deg
79 
80  try
81  {
82  test_opt_pt2ln(CPose3D::FromTranslation(0, 0, 0));
83 
84  test_opt_pt2ln(CPose3D::FromTranslation(1.0, 0, 0));
85  test_opt_pt2ln(CPose3D::FromTranslation(0, 1.0, 0));
86  test_opt_pt2ln(CPose3D::FromTranslation(0, 0, 1.0));
87 
88  test_opt_pt2ln(CPose3D::FromTranslation(-2.0, 0, 0));
89  test_opt_pt2ln(CPose3D::FromTranslation(0, -3.0, 0));
90  test_opt_pt2ln(CPose3D::FromTranslation(0, 0, -4.0));
91 
92  test_opt_pt2ln(CPose3D::FromYawPitchRoll(20.0_deg, 0.0_deg, 0.0_deg));
93  test_opt_pt2ln(CPose3D::FromYawPitchRoll(-20.0_deg, 0.0_deg, 0.0_deg));
94 
95  test_opt_pt2ln(CPose3D::FromYawPitchRoll(0.0_deg, 10.0_deg, 0.0_deg));
96  test_opt_pt2ln(CPose3D::FromYawPitchRoll(0.0_deg, -10.0_deg, 0.0_deg));
97 
98  test_opt_pt2ln(CPose3D::FromYawPitchRoll(0.0_deg, 0.0_deg, 15.0_deg));
99  test_opt_pt2ln(CPose3D::FromYawPitchRoll(0.0_deg, 0.0_deg, -15.0_deg));
100 
101  test_opt_pt2ln(CPose3D::FromTranslation(1.0, 2.0, 3.0));
102  test_opt_pt2ln(CPose3D::FromXYZYawPitchRoll(
103  1.0, 2.0, 3.0, -10.0_deg, 5.0_deg, 30.0_deg));
104  }
105  catch (std::exception& e)
106  {
107  std::cerr << mrpt::exception_to_str(e) << "\n";
108  return 1;
109  }
110 }
std::optional< mrpt::poses::CPose3D > guessRelativePose
Definition: Solver.h:35
virtual bool optimal_pose(const Pairings &pairings, OptimalTF_Result &out, const SolverContext &sc) const
Definition: Solver.cpp:26
ICP registration for points and planes.
void initialize(const mrpt::containers::yaml &params) override
MatchedPointLineList paired_pt2ln
Definition: Pairings.h:102
mrpt::poses::CPose3D optimalPose
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
static void test_opt_pt2ln(const mrpt::poses::CPose3D &groundTruth)


mrpt_local_obstacles
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Thu Jun 1 2023 03:06:43