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 static mrpt::maps::CSimplePointsMap::Ptr generateGlobalPoints()
20 {
21  auto pts = mrpt::maps::CSimplePointsMap::Create();
22 
23  // Plane:
24  for (int ix = 0; ix < 10; ix++)
25  for (int iy = 0; iy < 10; iy++)
26  pts->insertPoint(ix * 0.01f, 5.0f + iy * 0.01f, .0f);
27 
28  // Plane:
29  for (int iy = 0; iy < 10; iy++)
30  for (int iz = 0; iz < 10; iz++)
31  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 static 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 
52 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
53 {
54  try
55  {
56  mp2p_icp::metric_map_t pcGlobal;
59 
60  mp2p_icp::metric_map_t pcLocal;
63 
64  {
65  auto m = mp2p_icp::Matcher_Point2Plane::Create();
66 
67  mrpt::containers::yaml p;
68  p["distanceThreshold"] = 0.1;
69  p["searchRadius"] = 0.1;
70  p["minimumPlanePoints"] = 5.0;
71  p["knn"] = 5;
72  p["planeEigenThreshold"] = 0.1;
73 
74  m->initialize(p);
75 
76  {
77  // For pose: identity
78  mp2p_icp::Pairings pairs;
79  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
80  m->match(pcGlobal, pcLocal, {0, 0, 0, 0, 0, 0}, {}, ms, pairs);
81  ASSERT_(pairs.empty());
82  }
83 
84  {
85  // For pose #1
86  mp2p_icp::Pairings pairs;
87  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
88  m->match(pcGlobal, pcLocal, {0, 5, 0, 0, 0, 0}, {}, ms, pairs);
89  ASSERT_EQUAL_(pairs.size(), 1U);
90  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
91  }
92 
93  {
94  // For pose #2
95  mp2p_icp::Pairings pairs;
96  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
97  m->match(
98  pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0}, {}, ms, pairs);
99  ASSERT_EQUAL_(pairs.size(), 1U);
100  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
101 
102  const auto& p0 = pairs.paired_pt2pl.at(0);
103 
104  ASSERT_NEAR_(p0.pt_local.x, 2.0, 1e-3);
105  ASSERT_NEAR_(p0.pt_local.y, 0.0, 1e-3);
106  ASSERT_NEAR_(p0.pt_local.z, 0.0, 1e-3);
107 
108  ASSERT_NEAR_(p0.pl_global.centroid.x, 10.0, 0.01);
109  ASSERT_NEAR_(p0.pl_global.centroid.y, 0.0, 0.01);
110  ASSERT_NEAR_(p0.pl_global.centroid.z, 0.0, 0.01);
111 
112  // Plane equation: "x=10" (Ax+By+Cz+D=0)
113  ASSERT_NEAR_(p0.pl_global.plane.coefs[0], 1.0, 1e-3);
114  ASSERT_NEAR_(p0.pl_global.plane.coefs[1], 0.0, 1e-3);
115  ASSERT_NEAR_(p0.pl_global.plane.coefs[2], 0.0, 1e-3);
116  ASSERT_NEAR_(p0.pl_global.plane.coefs[3], -10.0, 1e-3);
117  }
118 
119  {
120  // For pose #3
121  mp2p_icp::Pairings pairs;
122  mp2p_icp::MatchState ms(pcGlobal, pcLocal);
123  m->match(
124  pcGlobal, pcLocal, {18.053, 0.05, 0.03, 0, 0, 0}, {}, ms,
125  pairs);
126  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 0U);
127  }
128 
129  {
130  // For pose #2 bis, NOT avoiding duplicated matches with another
131  // pt-to-pt matcher:
132  auto mPt2Pt =
133  mp2p_icp::Matcher_Points_DistanceThreshold::Create();
134  mrpt::containers::yaml p2;
135  p2["threshold"] = 0.1;
136  p2["thresholdAngularDeg"] = .0;
137  p2["allowMatchAlreadyMatchedPoints"] = true;
138  mPt2Pt->initialize(p2);
139 
141  {m, mPt2Pt}, pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0},
142  {});
143 
144  // std::cout << pairs.contents_summary() << std::endl;
145  ASSERT_EQUAL_(pairs.size(), 2U);
146  ASSERT_EQUAL_(pairs.paired_pt2pt.size(), 1U);
147  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
148  }
149 
150  {
151  // For pose #2 tris, DO avoid duplicated matches with another
152  // pt-to-pt matcher:
153  auto mPt2Pt =
154  mp2p_icp::Matcher_Points_DistanceThreshold::Create();
155  mrpt::containers::yaml p2;
156  p2["threshold"] = 0.1;
157  p2["thresholdAngularDeg"] = .0;
158  p2["allowMatchAlreadyMatchedPoints"] = false;
159  mPt2Pt->initialize(p2);
160 
162  {m, mPt2Pt}, pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0},
163  {});
164 
165  // std::cout << pairs.contents_summary() << std::endl;
166  ASSERT_EQUAL_(pairs.size(), 1U);
167  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
168  }
169  }
170  }
171  catch (std::exception& e)
172  {
173  std::cerr << mrpt::exception_to_str(e) << "\n";
174  return 1;
175  }
176 }
kitti-run-seq.f
string f
Definition: kitti-run-seq.py:12
mp2p_icp::Pairings
Definition: Pairings.h:78
mp2p_icp::Pairings::empty
virtual bool empty() const
Definition: Pairings.h:111
generateLocalPoints
static mrpt::maps::CSimplePointsMap::Ptr generateLocalPoints()
Definition: test-mp2p_matcher_pt2pl.cpp:42
mp2p_icp::metric_map_t::PT_LAYER_RAW
constexpr static const char * PT_LAYER_RAW
Definition: metricmap.h:58
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_matcher_pt2pl.cpp:52
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:141
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:39
generateGlobalPoints
static mrpt::maps::CSimplePointsMap::Ptr generateGlobalPoints()
Definition: test-mp2p_matcher_pt2pl.cpp:19
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:49
mp2p_icp::Pairings::paired_pt2pt
mrpt::tfest::TMatchingPairList paired_pt2pt
Definition: Pairings.h:88
mp2p_icp::metric_map_t::layers
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:76
Matcher_Point2Plane.h
Pointcloud matcher: point to plane-fit of nearby points.
mp2p_icp::Pairings::paired_pt2pl
MatchedPointPlaneList paired_pt2pl
Definition: Pairings.h:90


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