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");
35 const mrpt::maps::CMetricMap& pcGlobalMap,
const mrpt::maps::CPointsMap& pcLocal,
36 const mrpt::poses::CPose3D& localPose,
MatchState& ms,
45 const mrpt::maps::NearestNeighborsCapable& nnGlobal =
48 out.potential_pairings += pcLocal.size();
51 if (pcGlobalMap.isEmpty() || pcLocal.empty())
return;
57 if (!pcGlobalMap.boundingBox().intersection(
58 {tl.localMin, tl.localMax},
64 const auto& lxs = pcLocal.getPointsBufferRef_x();
65 const auto& lys = pcLocal.getPointsBufferRef_y();
66 const auto& lzs = pcLocal.getPointsBufferRef_z();
68 std::multimap<double, mrpt::tfest::TMatchingPair> sortedPairings;
70 for (
size_t i = 0; i < tl.
x_locals.size(); i++)
72 size_t localIdx = tl.
idxs.has_value() ? (*tl.
idxs)[i] : i;
84 uint64_t tentativeGlobalIdx = 0;
85 float tentativeErrSqr = 0;
86 mrpt::math::TPoint3Df neighborPt;
88 const bool searchOk = nnGlobal.nn_single_search(
90 neighborPt, tentativeErrSqr, tentativeGlobalIdx);
94 mrpt::tfest::TMatchingPair p;
95 p.globalIdx = tentativeGlobalIdx;
96 p.localIdx = localIdx;
97 p.global = neighborPt;
98 p.local = {lxs[localIdx], lys[localIdx], lzs[localIdx]};
100 p.errorSquareAfterTransformation = tentativeErrSqr;
103 sortedPairings.emplace_hint(sortedPairings.begin(), tentativeErrSqr, p);
109 const size_t nTotal = sortedPairings.size();
112 const auto nKeep = mrpt::round(
double(nTotal) *
inliersRatio);
115 auto itEnd = sortedPairings.begin();
116 std::advance(itEnd, nKeep);
118 for (
auto it = sortedPairings.begin(); it != itEnd; ++it)
120 const auto localIdx = it->second.localIdx;
121 const auto globalIdx = it->second.globalIdx;
128 out.paired_pt2pt.push_back(it->second);