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, Pairings& out,
19  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 {
41  Pairings out;
42 
43  ASSERT_(sc.guessRelativePose.has_value());
44  const auto& relPose = *sc.guessRelativePose;
45 
46  const double ratio = 0.25;
47  std::multimap<double, mrpt::tfest::TMatchingPair> sortedOut;
48 
49  // ===========================================================
50  // point-to-plane => point to closest point on plane
51  // ===========================================================
52  for (const auto& p : in.paired_pt2pl)
53  {
54  const auto pt_g = relPose.composePoint(p.pt_local);
55  const auto& pl = p.pl_global.plane;
56 
57  const auto plNormal = pl.getNormalVector();
58 
59  ASSERT_NEAR_(plNormal.norm(), 1.0, 1e-4);
60 
61  // project
62  const double d = pl.evaluatePoint(pt_g);
63 
64  const mrpt::math::TPoint3D c = pt_g - (plNormal * d);
65 
66  mrpt::tfest::TMatchingPair new_p;
67 
68  new_p.globalIdx = 0; // dummy
69  new_p.localIdx = 0;
70 
71  new_p.global = c;
72  new_p.local = p.pt_local;
73 
74  sortedOut.insert({std::abs(d), new_p});
75  }
76  out.paired_pt2pl.clear();
77  append_from_sorted(sortedOut, out, ratio);
78  sortedOut.clear();
79 
80  // ===========================================================
81  // point-to-plane => point to closest point on line
82  // ===========================================================
83  for (const auto& p : in.paired_pt2ln)
84  {
85  const auto pt_g = relPose.composePoint(p.pt_local);
86  const auto& ln = p.ln_global;
87 
88  const mrpt::math::TPoint3D c = ln.closestPointTo(pt_g);
89  const double d = (c - pt_g).norm();
90 
91  mrpt::tfest::TMatchingPair new_p;
92 
93  new_p.globalIdx = 0; // dummy
94  new_p.localIdx = 0;
95 
96  new_p.global = c;
97  new_p.local = p.pt_local;
98 
99  sortedOut.insert({std::abs(d), new_p});
100  }
101  out.paired_pt2ln.clear();
102  append_from_sorted(sortedOut, out, ratio);
103 
104  return out;
105 }
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:76
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:87
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:88


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