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-2021 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["allowMatchAlreadyMatchedPoints"] = true;
137  mPt2Pt->initialize(p2);
138 
140  {m, mPt2Pt}, pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0},
141  {});
142 
143  // std::cout << pairs.contents_summary() << std::endl;
144  ASSERT_EQUAL_(pairs.size(), 2U);
145  ASSERT_EQUAL_(pairs.paired_pt2pt.size(), 1U);
146  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
147  }
148 
149  {
150  // For pose #2 tris, DO avoid duplicated matches with another
151  // pt-to-pt matcher:
152  auto mPt2Pt =
153  mp2p_icp::Matcher_Points_DistanceThreshold::Create();
154  mrpt::containers::yaml p2;
155  p2["threshold"] = 0.1;
156  p2["allowMatchAlreadyMatchedPoints"] = false;
157  mPt2Pt->initialize(p2);
158 
160  {m, mPt2Pt}, pcGlobal, pcLocal, {8.04, 0, 0.0, 0, 0, 0},
161  {});
162 
163  // std::cout << pairs.contents_summary() << std::endl;
164  ASSERT_EQUAL_(pairs.size(), 1U);
165  ASSERT_EQUAL_(pairs.paired_pt2pl.size(), 1U);
166  }
167  }
168  }
169  catch (std::exception& e)
170  {
171  std::cerr << mrpt::exception_to_str(e) << "\n";
172  return 1;
173  }
174 }
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:74
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:47
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Generic representation of pointcloud(s) and/or extracted features.
static mrpt::maps::CSimplePointsMap::Ptr generateGlobalPoints()
virtual bool empty() const
Definition: Pairings.h:118
static constexpr const char * PT_LAYER_RAW
Definition: metricmap.h:56
virtual size_t size() const
Definition: Pairings.cpp:135
static mrpt::maps::CSimplePointsMap::Ptr generateLocalPoints()
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)
Pointcloud matcher: fixed distance thresholds.
Pointcloud matcher: point to plane-fit of nearby points.
mrpt::tfest::TMatchingPairList paired_pt2pt
Definition: Pairings.h:101
MatchedPointPlaneList paired_pt2pl
Definition: Pairings.h:103


mrpt_local_obstacles
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Thu Jun 1 2023 03:06:43