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-2024 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 }
mp2p_icp::OptimalTF_Result::optimalPose
mrpt::poses::CPose3D optimalPose
Definition: OptimalTF_Result.h:26
mp2p_icp::Solver::optimal_pose
virtual bool optimal_pose(const Pairings &pairings, OptimalTF_Result &out, const SolverContext &sc) const
Definition: Solver.cpp:28
mp2p_icp::Solver_GaussNewton
Definition: Solver_GaussNewton.h:25
mp2p_icp::Pairings
Definition: Pairings.h:78
mp2p_icp::SolverContext
Definition: Solver.h:36
mrpt
Definition: LogRecord.h:100
mp2p_icp::OptimalTF_Result
Definition: OptimalTF_Result.h:24
mp2p_icp::SolverContext::guessRelativePose
std::optional< mrpt::poses::CPose3D > guessRelativePose
Definition: Solver.h:40
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_optimize_pt2ln.cpp:75
Solver_GaussNewton.h
ICP registration for points and planes.
mp2p_icp::Pairings::paired_pt2ln
MatchedPointLineList paired_pt2ln
Definition: Pairings.h:89
test_opt_pt2ln
static void test_opt_pt2ln(const mrpt::poses::CPose3D &groundTruth)
Definition: test-mp2p_optimize_pt2ln.cpp:17
mp2p_icp::Solver_GaussNewton::initialize
void initialize(const mrpt::containers::yaml &params) override
Definition: Solver_GaussNewton.cpp:21


mp2p_icp
Author(s):
autogenerated on Thu Dec 26 2024 03:48:12