test-mp2p_optimize_with_prior.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_prior(const mrpt::poses::CPose3D& groundTruth)
18 {
19  using namespace mrpt::poses::Lie;
20  using namespace mrpt; // _deg
21 
22  MRPT_START
23 
24  // Prepare test case pairings:
25  // 3 point-to-line correspondences, such that the sought optimal
26  // pose is the given one:
27 
29 
30  {
31  auto& pp = p.paired_pt2pt.emplace_back();
32  pp.global = {1, 0, 0};
33  pp.local = groundTruth.inverseComposePoint(pp.global);
34  }
35  {
36  auto& pp = p.paired_pt2pt.emplace_back();
37  pp.global = {0, 1, 0};
38  pp.local = groundTruth.inverseComposePoint(pp.global);
39  }
40  {
41  auto& pp = p.paired_pt2pt.emplace_back();
42  pp.global = {0, 0, 1};
43  pp.local = groundTruth.inverseComposePoint(pp.global);
44  }
45 
46  std::cout << "Input pairings: " << p.contents_summary() << std::endl;
47 
48  // Init solver:
50 
51  mrpt::containers::yaml solverParams;
52  solverParams["maxIterations"] = 25;
53  solverParams["innerLoopVerbose"] = true;
54 
55  solver.initialize(solverParams);
56 
57  for (int Case = 0; Case < 3; Case++)
58  {
61  sc.guessRelativePose = mrpt::poses::CPose3D::Identity();
62 
63  auto& prior = sc.prior.emplace();
64  prior.mean =
65  mrpt::poses::CPose3D::FromXYZYawPitchRoll(2.0, 3.0, 4.0, 10.0_deg, 10.0_deg, 10.0_deg);
66  prior.cov_inv.fill(0);
67 
68  mrpt::poses::CPose3D expected;
69  std::function<void(void)> checkFn;
70 
71  switch (Case)
72  {
73  case 0:
74  sc.prior.reset(); // no prior. Delete it
75  expected = groundTruth;
76  checkFn = [&]() {
77  ASSERT_NEAR_(
78  mrpt::poses::Lie::SE<3>::log(result.optimalPose - expected).norm(), 0.0,
79  1e-3);
80  };
81  break;
82  case 1:
83  expected = prior.mean;
84  for (int i = 0; i < 3; i++) prior.cov_inv(i, i) = 100.0;
85  checkFn = [&]()
86  {
87  for (int i = 0; i < 3; i++)
88  ASSERT_NEAR_(result.optimalPose[i], prior.mean[i], 0.05);
89  };
90  break;
91  case 2:
92  expected = prior.mean;
93  for (int i = 3; i < 6; i++) prior.cov_inv(i, i) = 100.0;
94  checkFn = [&]()
95  {
96  for (int i = 3; i < 6; i++)
97  ASSERT_NEAR_(result.optimalPose[i], prior.mean[i], 0.05);
98  };
99  break;
100  };
101 
102  bool solvedOk = solver.optimal_pose(p, result, sc);
103 
104  std::cout << "Case:" << Case << "\n"
105  << "Found optimalPose: " << result.optimalPose << std::endl;
106  std::cout << "Expected optimalPose: " << expected << std::endl;
107 
108  checkFn();
109 
110  // check results:
111  ASSERT_(solvedOk);
112  }
113 
114  MRPT_END
115 }
116 
117 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
118 {
119  using mrpt::poses::CPose3D;
120  using namespace mrpt; // _deg
121 
122  try
123  {
124  test_opt_prior(CPose3D::FromXYZYawPitchRoll(1.0, 2.0, 3.0, 5.0_deg, 15.0_deg, 20.0_deg));
125  }
126  catch (std::exception& e)
127  {
128  std::cerr << mrpt::exception_to_str(e) << "\n";
129  return 1;
130  }
131 }
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:76
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
mp2p_icp::SolverContext::prior
std::optional< mrpt::poses::CPose3DPDFGaussianInf > prior
Definition: Solver.h:49
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_optimize_with_prior.cpp:117
Solver_GaussNewton.h
ICP registration for points and planes.
test_opt_prior
static void test_opt_prior(const mrpt::poses::CPose3D &groundTruth)
Definition: test-mp2p_optimize_with_prior.cpp:17
mp2p_icp::Pairings::paired_pt2pt
mrpt::tfest::TMatchingPairList paired_pt2pt
Definition: Pairings.h:86
mp2p_icp::Solver_GaussNewton::initialize
void initialize(const mrpt::containers::yaml &params) override
Definition: Solver_GaussNewton.cpp:21


mp2p_icp
Author(s):
autogenerated on Mon May 26 2025 02:45:50