14 #include <mrpt/core/exceptions.h>
15 #include <mrpt/core/round.h>
16 #include <mrpt/version.h>
24 mrpt::system::COutputLogger::setLoggerName(
"Matcher_Points_InlierRatio");
28 const mrpt::containers::yaml& params)
36 const mrpt::maps::CMetricMap& pcGlobalMap,
37 const mrpt::maps::CPointsMap& pcLocal,
38 const mrpt::poses::CPose3D& localPose,
MatchState& ms,
47 const mrpt::maps::NearestNeighborsCapable& nnGlobal =
50 out.potential_pairings += pcLocal.size();
53 if (pcGlobalMap.isEmpty() || pcLocal.empty())
return;
59 if (!pcGlobalMap.boundingBox().intersection(
60 {tl.localMin, tl.localMax},
66 const auto& lxs = pcLocal.getPointsBufferRef_x();
67 const auto& lys = pcLocal.getPointsBufferRef_y();
68 const auto& lzs = pcLocal.getPointsBufferRef_z();
70 std::multimap<double, mrpt::tfest::TMatchingPair> sortedPairings;
72 for (
size_t i = 0; i < tl.
x_locals.size(); i++)
74 size_t localIdx = tl.
idxs.has_value() ? (*tl.
idxs)[i] : i;
87 uint64_t tentativeGlobalIdx = 0;
88 float tentativeErrSqr = 0;
89 mrpt::math::TPoint3Df neighborPt;
91 const bool searchOk = nnGlobal.nn_single_search(
93 neighborPt, tentativeErrSqr, tentativeGlobalIdx);
97 mrpt::tfest::TMatchingPair p;
98 p.globalIdx = tentativeGlobalIdx;
99 p.localIdx = localIdx;
100 p.global = neighborPt;
101 p.local = {lxs[localIdx], lys[localIdx], lzs[localIdx]};
103 p.errorSquareAfterTransformation = tentativeErrSqr;
106 sortedPairings.emplace_hint(
107 sortedPairings.begin(), tentativeErrSqr, p);
113 const size_t nTotal = sortedPairings.size();
116 const auto nKeep = mrpt::round(
double(nTotal) *
inliersRatio);
119 auto itEnd = sortedPairings.begin();
120 std::advance(itEnd, nKeep);
122 for (
auto it = sortedPairings.begin(); it != itEnd; ++it)
124 const auto localIdx = it->second.localIdx;
125 const auto globalIdx = it->second.globalIdx;
132 out.paired_pt2pt.push_back(it->second);