test-mp2p_optimize_pt2pl.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 <mp2p_icp/Solver_Horn.h>
16 #include <mrpt/poses/Lie/SE.h>
17 
18 static void test_opt_pt2pl(
19  const mrpt::poses::CPose3D& groundTruth, const mp2p_icp::Solver& solver)
20 {
21  using namespace mrpt::poses::Lie;
22 
23  MRPT_START
24 
25  // Prepare test case pairings:
26  // 3 point-to-plane correspondences, such that the sought optimal
27  // pose is the given one:
28 
30 
31  {
32  auto& pp = p.paired_pt2pl.emplace_back();
33  pp.pl_global = {
34  mrpt::math::TPlane::FromPointAndNormal({0, 0, 0}, {0, 0, 1}),
35  {0, 0, 0}};
36  pp.pt_local = groundTruth.inverseComposePoint({0.5, 0, 0});
37  }
38  {
39  auto& pp = p.paired_pt2pl.emplace_back();
40  pp.pl_global = {
41  mrpt::math::TPlane::FromPointAndNormal({0, 0, 0}, {1, 0, 0}),
42  {0, 0, 0}};
43  pp.pt_local = groundTruth.inverseComposePoint({0, 0.8, 0});
44  }
45  {
46  auto& pp = p.paired_pt2pl.emplace_back();
47  pp.pl_global = {
48  mrpt::math::TPlane::FromPointAndNormal({0, 0, 0}, {0, 1, 0}),
49  {0, 0, 0}};
50  pp.pt_local = groundTruth.inverseComposePoint({0, 0, 0.3});
51  }
52  {
53  auto& pp = p.paired_pt2pt.emplace_back();
54  pp.global = {0, 0, 0};
55  const auto loc = groundTruth.inverseComposePoint({0, 0, 0});
56  pp.local = loc;
57  }
58 
59  std::cout << "Input pairings: " << p.contents_summary() << std::endl;
60 
61  // Init solver:
62 
65  sc.guessRelativePose = mrpt::poses::CPose3D::Identity();
66 
67  bool solvedOk = solver.optimal_pose(p, result, sc);
68 
69  std::cout << "Found optimalPose: " << result.optimalPose << std::endl;
70  std::cout << "Expected optimalPose: " << groundTruth << std::endl;
71 
72  // check results:
73  ASSERT_(solvedOk);
74  ASSERT_NEAR_(
75  mrpt::poses::Lie::SE<3>::log(result.optimalPose - groundTruth).norm(),
76  0.0, 1e-3);
77 
78  MRPT_END
79 }
80 
82 {
83  using mrpt::poses::CPose3D;
84  using namespace mrpt; // _deg
85 
86  // With different solvers:
88  {
89  mrpt::containers::yaml solverParams;
90  solverParams["maxIterations"] = 25;
91  // solverParams["innerLoopVerbose"] = true;
92  solverGN.initialize(solverParams);
93  }
94  // mp2p_icp::Solver_Horn solverHorn;
95 
96  const std::vector<const mp2p_icp::Solver*> solvers = {
97  &solverGN,
98  //&solverHorn
99  };
100 
101  for (const auto solverPtr : solvers)
102  {
103  const auto& solver = *solverPtr;
104  std::cout
105  << "Using solver: " << solver.GetRuntimeClass()->className
106  << "\n"
107  "=========================================================\n";
108 
109  test_opt_pt2pl(CPose3D::FromTranslation(0, 0, 0), solver);
110 
111  test_opt_pt2pl(CPose3D::FromTranslation(1.0, 0, 0), solver);
112  test_opt_pt2pl(CPose3D::FromTranslation(0, 1.0, 0), solver);
113  test_opt_pt2pl(CPose3D::FromTranslation(0, 0, 1.0), solver);
114 
115  test_opt_pt2pl(CPose3D::FromTranslation(-2.0, 0, 0), solver);
116  test_opt_pt2pl(CPose3D::FromTranslation(0, -3.0, 0), solver);
117  test_opt_pt2pl(CPose3D::FromTranslation(0, 0, -4.0), solver);
118 
120  CPose3D::FromYawPitchRoll(20.0_deg, 0.0_deg, 0.0_deg), solver);
122  CPose3D::FromYawPitchRoll(-20.0_deg, 0.0_deg, 0.0_deg), solver);
123 
125  CPose3D::FromYawPitchRoll(0.0_deg, 10.0_deg, 0.0_deg), solver);
127  CPose3D::FromYawPitchRoll(0.0_deg, -10.0_deg, 0.0_deg), solver);
128 
130  CPose3D::FromYawPitchRoll(0.0_deg, 0.0_deg, 15.0_deg), solver);
132  CPose3D::FromYawPitchRoll(0.0_deg, 0.0_deg, -15.0_deg), solver);
133 
134  test_opt_pt2pl(CPose3D::FromTranslation(1.0, 2.0, 3.0), solver);
136  CPose3D::FromXYZYawPitchRoll(
137  1.0, 2.0, 3.0, -10.0_deg, 5.0_deg, 30.0_deg),
138  solver);
139  }
140 }
141 
142 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
143 {
144  try
145  {
147  }
148  catch (std::exception& e)
149  {
150  std::cerr << mrpt::exception_to_str(e) << "\n";
151  return 1;
152  }
153 }
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
test_mp2p_optimize_pt2pl
static void test_mp2p_optimize_pt2pl()
Definition: test-mp2p_optimize_pt2pl.cpp:81
mp2p_icp::Solver_GaussNewton
Definition: Solver_GaussNewton.h:25
mp2p_icp::Pairings
Definition: Pairings.h:78
mp2p_icp::SolverContext
Definition: Solver.h:36
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_optimize_pt2pl.cpp:142
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
mp2p_icp::Solver
Definition: Solver.h:66
Solver_Horn.h
ICP solver for pointclouds split in different "layers".
test_opt_pt2pl
static void test_opt_pt2pl(const mrpt::poses::CPose3D &groundTruth, const mp2p_icp::Solver &solver)
Definition: test-mp2p_optimize_pt2pl.cpp:18
Solver_GaussNewton.h
ICP registration for points and planes.
mp2p_icp::Pairings::paired_pt2pl
MatchedPointPlaneList paired_pt2pl
Definition: Pairings.h:90
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