Matcher_Point2Plane.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  * ------------------------------------------------------------------------- */
15 #include <mrpt/core/exceptions.h>
16 #include <mrpt/core/round.h>
17 #include <mrpt/version.h>
18 
20 
21 using namespace mp2p_icp;
22 
24 {
25  mrpt::system::COutputLogger::setLoggerName("Matcher_Point2Plane");
26 }
27 
28 void Matcher_Point2Plane::initialize(const mrpt::containers::yaml& params)
29 {
32 }
33 
35  const mrpt::maps::CMetricMap& pcGlobalMap, const mrpt::maps::CPointsMap& pcLocal,
36  const mrpt::poses::CPose3D& localPose, MatchState& ms,
37  [[maybe_unused]] const layer_name_t& globalName, const layer_name_t& localName,
38  Pairings& out) const
39 {
40  MRPT_START
41 
43 
44  const mp2p_icp::NearestPlaneCapable& nnGlobal =
45  *mp2p_icp::MapToNP(pcGlobalMap, true /*throw if cannot convert*/);
46 
47  out.potential_pairings += pcLocal.size();
48 
49  // Empty maps? Nothing to do
50  if (pcGlobalMap.isEmpty() || pcLocal.empty()) return;
51 
53  pcLocal, localPose, maxLocalPointsPerLayer_, localPointsSampleSeed_);
54 
55  // Try to do matching only if the bounding boxes have some overlap:
56  if (!pcGlobalMap.boundingBox().intersection(
57  {tl.localMin, tl.localMax},
59  return;
60 
61  // Prepare output: no correspondences initially:
62  out.paired_pt2pl.reserve(out.paired_pt2pl.size() + pcLocal.size() / 10);
63 
64  // Loop for each point in local map:
65  // --------------------------------------------------
66  // searchRadius
67 
68  const auto& lxs = pcLocal.getPointsBufferRef_x();
69  const auto& lys = pcLocal.getPointsBufferRef_y();
70  const auto& lzs = pcLocal.getPointsBufferRef_z();
71 
72  for (size_t i = 0; i < tl.x_locals.size(); i++)
73  {
74  const size_t localIdx = tl.idxs.has_value() ? (*tl.idxs)[i] : i;
75 
77  ms.localPairedBitField.point_layers.at(localName)[localIdx])
78  continue; // skip, already paired.
79 
80  // Don't discard **global** map points if already used by another
81  // matcher, since the assumption of "plane" features implies that
82  // many local points may match the *same* "global plane", so it's ok
83  // to have multiple-local-to-one-global pairings.
84 
85  // For speed-up:
86  const float lx = tl.x_locals[i], ly = tl.y_locals[i], lz = tl.z_locals[i];
87 
88  // Use a KD-tree to look for the nearnest neighbor(s) of
89  // (x_local, y_local, z_local) in the global map.
91  nnGlobal.nn_search_pt2pl({lx, ly, lz}, distanceThreshold);
92 
93  if (!np.pairing) continue;
94  if (np.distance > distanceThreshold) continue; // plane is too distant
95 
96  // OK, all conditions pass: add the new pairing:
97  auto& p = out.paired_pt2pl.emplace_back();
98  p.pt_local = {lxs[localIdx], lys[localIdx], lzs[localIdx]};
99  p.pl_global = np.pairing->pl_global;
100 
101  // Mark local point as already paired:
102  ms.localPairedBitField.point_layers[localName].mark_as_set(localIdx);
103 
104  } // For each local point
105 
106  MRPT_END
107 }
mp2p_icp::Matcher_Point2Plane::initialize
void initialize(const mrpt::containers::yaml &params) override
Definition: Matcher_Point2Plane.cpp:28
mp2p_icp::Parameterizable::checkAllParametersAreRealized
void checkAllParametersAreRealized() const
Definition: Parameterizable.cpp:135
mp2p_icp
Definition: covariance.h:17
mp2p_icp::Matcher_Point2Plane
Definition: Matcher_Point2Plane.h:30
mp2p_icp::Matcher_Points_Base::bounding_box_intersection_check_epsilon_
double bounding_box_intersection_check_epsilon_
Definition: Matcher_Points_Base.h:63
mp2p_icp::Matcher_Points_Base::TransformedLocalPointCloud
Definition: Matcher_Points_Base.h:90
mp2p_icp::Matcher
Definition: Matcher.h:73
mp2p_icp::NearestPlaneCapable::NearestPlaneResult
Definition: NearestPlaneCapable.h:31
mp2p_icp::Matcher_Points_Base::TransformedLocalPointCloud::y_locals
mrpt::aligned_std_vector< float > y_locals
Definition: Matcher_Points_Base.h:100
mp2p_icp::Pairings
Definition: Pairings.h:76
mp2p_icp::layer_name_t
std::string layer_name_t
Definition: layer_name_t.h:22
mp2p_icp::Matcher_Points_Base::allowMatchAlreadyMatchedPoints_
bool allowMatchAlreadyMatchedPoints_
Definition: Matcher_Points_Base.h:52
mp2p_icp::NearestPlaneCapable::NearestPlaneResult::distance
float distance
Absolute value of plane-point distance, if a pairing is found:
Definition: NearestPlaneCapable.h:39
DECLARE_PARAMETER_REQ
#define DECLARE_PARAMETER_REQ(__yaml, __variable)
Definition: Parameterizable.h:162
mp2p_icp::Matcher_Points_Base::TransformedLocalPointCloud::idxs
std::optional< std::vector< std::size_t > > idxs
Definition: Matcher_Points_Base.h:97
IMPLEMENTS_MRPT_OBJECT
IMPLEMENTS_MRPT_OBJECT(FilterDecimateVoxelsQuadratic, mp2p_icp_filters::FilterBase, mp2p_icp_filters) using namespace mp2p_icp_filters
mp2p_icp::Matcher_Points_Base::initialize
void initialize(const mrpt::containers::yaml &params) override
Definition: Matcher_Points_Base.cpp:114
mp2p_icp::Matcher_Points_Base::TransformedLocalPointCloud::z_locals
mrpt::aligned_std_vector< float > z_locals
Definition: Matcher_Points_Base.h:100
mp2p_icp::MatchState
Definition: Matcher.h:37
kitti-batch-convert.out
string out
Definition: kitti-batch-convert.py:7
mp2p_icp::Matcher_Points_Base::localPointsSampleSeed_
uint64_t localPointsSampleSeed_
Definition: Matcher_Points_Base.h:48
mp2p_icp::NearestPlaneCapable
Definition: NearestPlaneCapable.h:25
mp2p_icp::Matcher_Point2Plane::implMatchOneLayer
void implMatchOneLayer(const mrpt::maps::CMetricMap &pcGlobal, const mrpt::maps::CPointsMap &pcLocal, const mrpt::poses::CPose3D &localPose, MatchState &ms, const layer_name_t &globalName, const layer_name_t &localName, Pairings &out) const override
Definition: Matcher_Point2Plane.cpp:34
mp2p_icp::Matcher_Point2Plane::Matcher_Point2Plane
Matcher_Point2Plane()
Definition: Matcher_Point2Plane.cpp:23
mp2p_icp::pointcloud_bitfield_t::point_layers
std::map< layer_name_t, DenseOrSparseBitField > point_layers
Definition: pointcloud_bitfield.h:82
mp2p_icp::NearestPlaneCapable::NearestPlaneResult::pairing
std::optional< point_plane_pair_t > pairing
Found pairing:
Definition: NearestPlaneCapable.h:36
mp2p_icp::Matcher_Points_Base::maxLocalPointsPerLayer_
uint64_t maxLocalPointsPerLayer_
Definition: Matcher_Points_Base.h:47
mp2p_icp::MatchState::localPairedBitField
pointcloud_bitfield_t localPairedBitField
Definition: Matcher.h:47
mp2p_icp::NearestPlaneCapable::nn_search_pt2pl
virtual NearestPlaneResult nn_search_pt2pl(const mrpt::math::TPoint3Df &point, const float max_search_distance) const =0
mp2p_icp::Matcher_Points_Base::TransformedLocalPointCloud::x_locals
mrpt::aligned_std_vector< float > x_locals
Definition: Matcher_Points_Base.h:100
estimate_points_eigen.h
Calculate eigenvectors and eigenvalues from a set of points.
mp2p_icp::Matcher_Points_Base::transform_local_to_global
static TransformedLocalPointCloud transform_local_to_global(const mrpt::maps::CPointsMap &pcLocal, const mrpt::poses::CPose3D &localPose, const std::size_t maxLocalPoints=0, const uint64_t localPointsSampleSeed=0)
Definition: Matcher_Points_Base.cpp:163
Matcher_Point2Plane.h
Pointcloud matcher: point to plane-fit of nearby points.
mp2p_icp::MapToNP
const mp2p_icp::NearestPlaneCapable * MapToNP(const mrpt::maps::CMetricMap &map, bool throwIfNotImplemented)
Definition: metricmap.cpp:672
mp2p_icp::Matcher_Point2Plane::distanceThreshold
double distanceThreshold
Definition: Matcher_Point2Plane.h:45


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