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 = mrpt::poses::CPose3D::FromXYZYawPitchRoll(
65  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(
79  result.optimalPose - expected)
80  .norm(),
81  0.0, 1e-3);
82  };
83  break;
84  case 1:
85  expected = prior.mean;
86  for (int i = 0; i < 3; i++) prior.cov_inv(i, i) = 100.0;
87  checkFn = [&]() {
88  for (int i = 0; i < 3; i++)
89  ASSERT_NEAR_(
90  result.optimalPose[i], prior.mean[i], 0.05);
91  };
92  break;
93  case 2:
94  expected = prior.mean;
95  for (int i = 3; i < 6; i++) prior.cov_inv(i, i) = 100.0;
96  checkFn = [&]() {
97  for (int i = 3; i < 6; i++)
98  ASSERT_NEAR_(
99  result.optimalPose[i], prior.mean[i], 0.05);
100  };
101  break;
102  };
103 
104  bool solvedOk = solver.optimal_pose(p, result, sc);
105 
106  std::cout << "Case:" << Case << "\n"
107  << "Found optimalPose: " << result.optimalPose
108  << std::endl;
109  std::cout << "Expected optimalPose: " << expected << std::endl;
110 
111  checkFn();
112 
113  // check results:
114  ASSERT_(solvedOk);
115  }
116 
117  MRPT_END
118 }
119 
120 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
121 {
122  using mrpt::poses::CPose3D;
123  using namespace mrpt; // _deg
124 
125  try
126  {
127  test_opt_prior(CPose3D::FromXYZYawPitchRoll(
128  1.0, 2.0, 3.0, 5.0_deg, 15.0_deg, 20.0_deg));
129  }
130  catch (std::exception& e)
131  {
132  std::cerr << mrpt::exception_to_str(e) << "\n";
133  return 1;
134  }
135 }
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
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:120
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:88
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:13