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,
36  const mrpt::maps::CPointsMap& pcLocal,
37  const mrpt::poses::CPose3D& localPose, MatchState& ms,
38  [[maybe_unused]] const layer_name_t& globalName,
39  const layer_name_t& localName, Pairings& out) const
40 {
41  MRPT_START
42 
44 
45  const mp2p_icp::NearestPlaneCapable& nnGlobal =
46  *mp2p_icp::MapToNP(pcGlobalMap, true /*throw if cannot convert*/);
47 
48  out.potential_pairings += pcLocal.size();
49 
50  // Empty maps? Nothing to do
51  if (pcGlobalMap.isEmpty() || pcLocal.empty()) return;
52 
54  pcLocal, localPose, maxLocalPointsPerLayer_, localPointsSampleSeed_);
55 
56  // Try to do matching only if the bounding boxes have some overlap:
57  if (!pcGlobalMap.boundingBox().intersection(
58  {tl.localMin, tl.localMax},
60  return;
61 
62  // Prepare output: no correspondences initially:
63  out.paired_pt2pl.reserve(out.paired_pt2pl.size() + pcLocal.size() / 10);
64 
65  // Loop for each point in local map:
66  // --------------------------------------------------
67  // searchRadius
68 
69  const auto& lxs = pcLocal.getPointsBufferRef_x();
70  const auto& lys = pcLocal.getPointsBufferRef_y();
71  const auto& lzs = pcLocal.getPointsBufferRef_z();
72 
73  for (size_t i = 0; i < tl.x_locals.size(); i++)
74  {
75  const size_t localIdx = tl.idxs.has_value() ? (*tl.idxs)[i] : i;
76 
78  ms.localPairedBitField.point_layers.at(localName)[localIdx])
79  continue; // skip, already paired.
80 
81  // Don't discard **global** map points if already used by another
82  // matcher, since the assumption of "plane" features implies that
83  // many local points may match the *same* "global plane", so it's ok
84  // to have multiple-local-to-one-global pairings.
85 
86  // For speed-up:
87  const float lx = tl.x_locals[i], ly = tl.y_locals[i],
88  lz = tl.z_locals[i];
89 
90  // Use a KD-tree to look for the nearnest neighbor(s) of
91  // (x_local, y_local, z_local) in the global map.
93  nnGlobal.nn_search_pt2pl({lx, ly, lz}, distanceThreshold);
94 
95  if (!np.pairing) continue;
96  if (np.distance > distanceThreshold) continue; // plane is too distant
97 
98  // OK, all conditions pass: add the new pairing:
99  auto& p = out.paired_pt2pl.emplace_back();
100  p.pt_local = {lxs[localIdx], lys[localIdx], lzs[localIdx]};
101  p.pl_global = np.pairing->pl_global;
102 
103  // Mark local point as already paired:
104  ms.localPairedBitField.point_layers[localName].mark_as_set(localIdx);
105 
106  } // For each local point
107 
108  MRPT_END
109 }
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:138
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:78
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:175
mp2p_icp::Matcher_Points_Base::TransformedLocalPointCloud::idxs
std::optional< std::vector< std::size_t > > idxs
Definition: Matcher_Points_Base.h:97
mp2p_icp::Matcher_Points_Base::initialize
void initialize(const mrpt::containers::yaml &params) override
Definition: Matcher_Points_Base.cpp:120
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
IMPLEMENTS_MRPT_OBJECT
IMPLEMENTS_MRPT_OBJECT(QualityEvaluator_RangeImageSimilarity, QualityEvaluator, mp2p_icp) using namespace mp2p_icp
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:174
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:701
mp2p_icp::Matcher_Point2Plane::distanceThreshold
double distanceThreshold
Definition: Matcher_Point2Plane.h:45


mp2p_icp
Author(s):
autogenerated on Thu Dec 26 2024 03:48:12