pt2ln_pl_to_pt2pt.cpp
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A repertory of multi primitive-to-primitive (MP2P) ICP algorithms in C++
3  * Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
14 
15 using namespace mp2p_icp;
16 
17 static void append_from_sorted(
18  const std::multimap<double, mrpt::tfest::TMatchingPair>& sorted,
19  Pairings& out, const double ratio)
20 {
21  // Heuristic: only add those pairings with a given % of the largest error,
22  // since the smallest ones are already satisfied and may constraint the
23  // solution too much:
24  if (sorted.empty()) return;
25 
26  const double largestError = sorted.rbegin()->first;
27  const double threshold = largestError * ratio;
28 
29  for (auto it = sorted.rbegin(); it != sorted.rend(); ++it)
30  {
31  const double err = it->first;
32  // skip the rest... except if we don't have correspondences
33  if (err < threshold && out.paired_pt2pt.size() >= 3) break;
34  out.paired_pt2pt.push_back(it->second);
35  }
36 }
37 
38 // See .h for docs
40  const Pairings& in, const SolverContext& sc)
41 {
42  Pairings out;
43 
44  ASSERT_(sc.guessRelativePose.has_value());
45  const auto& relPose = *sc.guessRelativePose;
46 
47  const double ratio = 0.25;
48  std::multimap<double, mrpt::tfest::TMatchingPair> sortedOut;
49 
50  // ===========================================================
51  // point-to-plane => point to closest point on plane
52  // ===========================================================
53  for (const auto& p : in.paired_pt2pl)
54  {
55  const auto pt_g = relPose.composePoint(p.pt_local);
56  const auto& pl = p.pl_global.plane;
57 
58  const auto plNormal = pl.getNormalVector();
59 
60  ASSERT_NEAR_(plNormal.norm(), 1.0, 1e-4);
61 
62  // project
63  const double d = pl.evaluatePoint(pt_g);
64 
65  const mrpt::math::TPoint3D c = pt_g - (plNormal * d);
66 
67  mrpt::tfest::TMatchingPair new_p;
68 
69  new_p.globalIdx = 0; // dummy
70  new_p.localIdx = 0;
71 
72  new_p.global = c;
73  new_p.local = p.pt_local;
74 
75  sortedOut.insert({std::abs(d), new_p});
76  }
77  out.paired_pt2pl.clear();
78  append_from_sorted(sortedOut, out, ratio);
79  sortedOut.clear();
80 
81  // ===========================================================
82  // point-to-plane => point to closest point on line
83  // ===========================================================
84  for (const auto& p : in.paired_pt2ln)
85  {
86  const auto pt_g = relPose.composePoint(p.pt_local);
87  const auto& ln = p.ln_global;
88 
89  const mrpt::math::TPoint3D c = ln.closestPointTo(pt_g);
90  const double d = (c - pt_g).norm();
91 
92  mrpt::tfest::TMatchingPair new_p;
93 
94  new_p.globalIdx = 0; // dummy
95  new_p.localIdx = 0;
96 
97  new_p.global = c;
98  new_p.local = p.pt_local;
99 
100  sortedOut.insert({std::abs(d), new_p});
101  }
102  out.paired_pt2ln.clear();
103  append_from_sorted(sortedOut, out, ratio);
104 
105  return out;
106 }
mp2p_icp
Definition: covariance.h:17
mp2p_icp::pt2ln_pl_to_pt2pt
Pairings pt2ln_pl_to_pt2pt(const Pairings &in, const SolverContext &sc)
Definition: pt2ln_pl_to_pt2pt.cpp:39
mp2p_icp::Pairings
Definition: Pairings.h:78
mp2p_icp::SolverContext
Definition: Solver.h:36
pt2ln_pl_to_pt2pt.h
Converter of pairings.
mp2p_icp::SolverContext::guessRelativePose
std::optional< mrpt::poses::CPose3D > guessRelativePose
Definition: Solver.h:40
kitti-batch-convert.out
string out
Definition: kitti-batch-convert.py:7
d
d
mp2p_icp::Pairings::paired_pt2ln
MatchedPointLineList paired_pt2ln
Definition: Pairings.h:89
append_from_sorted
static void append_from_sorted(const std::multimap< double, mrpt::tfest::TMatchingPair > &sorted, Pairings &out, const double ratio)
Definition: pt2ln_pl_to_pt2pt.cpp:17
mp2p_icp::Pairings::paired_pt2pl
MatchedPointPlaneList paired_pt2pl
Definition: Pairings.h:90


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:59