test-mp2p_matcher_pt2pl.cpp
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------
2  * A Modular Optimization framework for Localization and mApping (MOLA)
3  * Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
4  * See LICENSE for license information.
5  * ------------------------------------------------------------------------- */
6 
16 #include <mp2p_icp/metricmap.h>
17 #include <mrpt/maps/CSimplePointsMap.h>
18 
19 namespace
20 {
21 mrpt::maps::CSimplePointsMap::Ptr generateGlobalPoints()
22 {
23  auto pts = mrpt::maps::CSimplePointsMap::Create();
24 
25  // Plane:
26  for (int ix = 0; ix < 10; ix++)
27  for (int iy = 0; iy < 10; iy++) pts->insertPoint(ix * 0.01f, 5.0f + iy * 0.01f, .0f);
28 
29  // Plane:
30  for (int iy = 0; iy < 10; iy++)
31  for (int iz = 0; iz < 10; iz++) pts->insertPoint(10.0f, iy * 0.01f, iz * 0.01f);
32 
33  // Not a plane:
34  for (int ix = 0; ix < 10; ix++)
35  for (int iy = 0; iy < 10; iy++)
36  for (int iz = 0; iz < 10; iz++)
37  pts->insertPoint(20.0f + ix * 0.01f, iy * 0.01f, iz * 0.01f);
38 
39  return pts;
40 }
41 
42 mrpt::maps::CSimplePointsMap::Ptr generateLocalPoints()
43 {
44  auto pts = mrpt::maps::CSimplePointsMap::Create();
45 
46  pts->insertPointFast(0.f, 0.f, 0.f);
47  pts->insertPointFast(2.f, 0.f, 0.f);
48 
49  return pts;
50 }
51 } // namespace
52 
53 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
54 {
55  try
56  {
57  mp2p_icp::metric_map_t pcGlobal;
59 
60  mp2p_icp::metric_map_t pcLocal;
62 
63  {
64  auto m = mp2p_icp::Matcher_Point2Plane::Create();
65 
66  mrpt::containers::yaml p;
67  p["distanceThreshold"] = 0.1;
68  p["searchRadius"] = 0.1;
69  p["minimumPlanePoints"] = 5.0;
70  p["knn"] = 5;
71  p["planeEigenThreshold"] = 0.1;
72 
73  m->initialize(p);
74 
75  {
76  // For pose: identity
77  mp2p_icp::Pairings pairs;
78  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
79  m->match(pcGlobal, pcLocal, {0, 0, 0, 0, 0, 0}, {}, ms, pairs);
80  ASSERT_(pairs.empty());
81  }
82 
83  {
84  // For pose #1
85  mp2p_icp::Pairings pairs;
86  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
87  m->match(pcGlobal, pcLocal, {0, 5, 0, 0, 0, 0}, {}, ms, pairs);
88  ASSERT_EQUAL_(pairs.size(), 1U);
89  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
90  }
91 
92  {
93  // For pose #2
94  mp2p_icp::Pairings pairs;
95  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
96  m->match(pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0}, {}, ms, pairs);
97  ASSERT_EQUAL_(pairs.size(), 1U);
98  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
99 
100  const auto& p0 = pairs.paired_pt2pl.at(0);
101 
102  ASSERT_NEAR_(p0.pt_local.x, 2.0, 1e-3);
103  ASSERT_NEAR_(p0.pt_local.y, 0.0, 1e-3);
104  ASSERT_NEAR_(p0.pt_local.z, 0.0, 1e-3);
105 
106  ASSERT_NEAR_(p0.pl_global.centroid.x, 10.0, 0.01);
107  ASSERT_NEAR_(p0.pl_global.centroid.y, 0.0, 0.01);
108  ASSERT_NEAR_(p0.pl_global.centroid.z, 0.0, 0.01);
109 
110  // Plane equation: "x=10" (Ax+By+Cz+D=0)
111  ASSERT_NEAR_(p0.pl_global.plane.coefs[0], 1.0, 1e-3);
112  ASSERT_NEAR_(p0.pl_global.plane.coefs[1], 0.0, 1e-3);
113  ASSERT_NEAR_(p0.pl_global.plane.coefs[2], 0.0, 1e-3);
114  ASSERT_NEAR_(p0.pl_global.plane.coefs[3], -10.0, 1e-3);
115  }
116 
117  {
118  // For pose #3
119  mp2p_icp::Pairings pairs;
120  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
121  m->match(pcGlobal, pcLocal, {18.053, 0.05, 0.03, 0, 0, 0}, {}, ms, pairs);
122  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 0U);
123  }
124 
125  {
126  // For pose #2 bis, NOT avoiding duplicated matches with another
127  // pt-to-pt matcher:
128  auto mPt2Pt = mp2p_icp::Matcher_Points_DistanceThreshold::Create();
129  mrpt::containers::yaml p2;
130  p2["threshold"] = 0.1;
131  p2["thresholdAngularDeg"] = .0;
132  p2["allowMatchAlreadyMatchedPoints"] = true;
133  mPt2Pt->initialize(p2);
134 
136  {m, mPt2Pt}, pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0}, {});
137 
138  // std::cout << pairs.contents_summary() << std::endl;
139  ASSERT_EQUAL_(pairs.size(), 2U);
140  ASSERT_EQUAL_(pairs.paired_pt2pt.size(), 1U);
141  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
142  }
143 
144  {
145  // For pose #2 tris, DO avoid duplicated matches with another
146  // pt-to-pt matcher:
147  auto mPt2Pt = mp2p_icp::Matcher_Points_DistanceThreshold::Create();
148  mrpt::containers::yaml p2;
149  p2["threshold"] = 0.1;
150  p2["thresholdAngularDeg"] = .0;
151  p2["allowMatchAlreadyMatchedPoints"] = false;
152  mPt2Pt->initialize(p2);
153 
155  {m, mPt2Pt}, pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0}, {});
156 
157  // std::cout << pairs.contents_summary() << std::endl;
158  ASSERT_EQUAL_(pairs.size(), 1U);
159  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
160  }
161  }
162  }
163  catch (std::exception& e)
164  {
165  std::cerr << mrpt::exception_to_str(e) << "\n";
166  return 1;
167  }
168 }
kitti-run-seq.f
string f
Definition: kitti-run-seq.py:12
mp2p_icp::Pairings
Definition: Pairings.h:76
mp2p_icp::Pairings::empty
virtual bool empty() const
Definition: Pairings.h:109
generateLocalPoints
static mrpt::maps::CSimplePointsMap::Ptr generateLocalPoints()
Definition: test-mp2p_matcher_pt2pt.cpp:28
mp2p_icp::metric_map_t::PT_LAYER_RAW
constexpr static const char * PT_LAYER_RAW
Definition: metricmap.h:64
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_matcher_pt2pl.cpp:53
mp2p_icp::MatchState
Definition: Matcher.h:37
Matcher_Points_DistanceThreshold.h
Pointcloud matcher: fixed distance thresholds.
mp2p_icp::Pairings::size
virtual size_t size() const
Definition: Pairings.cpp:135
generateGlobalPoints
static mrpt::maps::CSimplePointsMap::Ptr generateGlobalPoints()
Definition: test-mp2p_matcher_pt2pt.cpp:18
mp2p_icp::run_matchers
Pairings run_matchers(const matcher_list_t &matchers, const metric_map_t &pcGlobal, const metric_map_t &pcLocal, const mrpt::poses::CPose3D &local_wrt_global, const MatchContext &mc, const mrpt::optional_ref< MatchState > &userProvidedMS=std::nullopt)
Definition: mp2p_icp/src/Matcher.cpp:38
metricmap.h
Generic representation of pointcloud(s) and/or extracted features.
mp2p_icp::metric_map_t
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:55
mp2p_icp::Pairings::paired_pt2pt
mrpt::tfest::TMatchingPairList paired_pt2pt
Definition: Pairings.h:86
mp2p_icp::metric_map_t::layers
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:82
Matcher_Point2Plane.h
Pointcloud matcher: point to plane-fit of nearby points.
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