test-mp2p_quality_voxels.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 
15 #include <mrpt/containers/yaml.h>
16 #include <mrpt/core/exceptions.h>
17 #include <mrpt/core/get_env.h>
18 #include <mrpt/system/filesystem.h> // pathJoin()
19 
20 const bool VERBOSE = mrpt::get_env<bool>("VERBOSE", false);
21 const double SCALE = mrpt::get_env<double>("SCALE", 3.0);
22 
23 void unit_test()
24 {
25  const std::string datasetDir =
26  mrpt::system::pathJoin({MOLA_TEST_DATASET_DIR, "loop_closures"});
27 
28  ASSERT_DIRECTORY_EXISTS_(datasetDir);
29 
30  const std::string datasetListFile =
31  mrpt::system::pathJoin({datasetDir, "dataset.yaml"});
32 
33  const auto dataset = mrpt::containers::yaml::FromFile(datasetListFile);
34 
35  const auto badOnes = dataset["bad"];
36  const auto goodOnes = dataset["good"];
37 
38  ASSERT_(badOnes.isSequence());
39  ASSERT_(goodOnes.isSequence());
40 
42  mrpt::containers::yaml params;
43  params["voxel_layer_name"] = "localmap_voxels";
44  params["dist2quality_scale"] = SCALE;
45 
47  q.initialize(params);
48 
49  struct Entry
50  {
51  std::string global, local;
52  mrpt::poses::CPose3D local_pose_wrt_global;
53  bool is_good_lc;
54  };
55 
56  std::vector<Entry> LCs;
57 
58  auto lambdaProcessYaml =
59  [&](const mrpt::containers::yaml::sequence_t& seq, bool are_good_lcs)
60  {
61  for (const auto& p : seq)
62  {
63  auto& lc = LCs.emplace_back();
64  lc.is_good_lc = are_good_lcs;
65  lc.global = p.asMap().at("global").as<std::string>();
66  lc.local = p.asMap().at("local").as<std::string>();
67  const auto v = p.asMap().at("final_pose").asSequence();
68  ASSERT_EQUAL_(v.size(), 6UL);
69  lc.local_pose_wrt_global =
70  mrpt::poses::CPose3D::FromXYZYawPitchRoll(
71  v[0].as<double>(), v[1].as<double>(), v[2].as<double>(),
72  mrpt::DEG2RAD(v[3].as<double>()),
73  mrpt::DEG2RAD(v[4].as<double>()),
74  mrpt::DEG2RAD(v[5].as<double>()));
75  }
76  };
77 
78  // Load GOOD loop-closures:
79  lambdaProcessYaml(goodOnes.asSequenceRange(), true);
80 
81  // Load BAD loop-closures:
82  lambdaProcessYaml(badOnes.asSequenceRange(), false);
83 
84  for (const auto& e : LCs)
85  {
87  pcG.load_from_file(mrpt::system::pathJoin({datasetDir, e.global}));
88 
90  pcL.load_from_file(mrpt::system::pathJoin({datasetDir, e.local}));
91 
92  const auto res = q.evaluate(pcG, pcL, e.local_pose_wrt_global, {});
93  const double quality = res.quality;
94 
95  if (VERBOSE)
96  {
97  std::cout << "- global: " << e.global << "\n"
98  << " local: " << e.local << "\n"
99  << " is_good: " << e.is_good_lc << "\n"
100  << " result_quality: " << quality << "\n";
101  }
102 
103  if ((quality < 0.2 && e.is_good_lc) ||
104  (quality >= 0.5 && !e.is_good_lc))
105  {
106  std::cerr << "Failed for test case:\n"
107  << " local : " << e.local << "\n"
108  << " global : " << e.global << "\n"
109  << " is_good : " << e.is_good_lc << "\n"
110  << " quality : " << quality << "\n";
111  throw std::runtime_error("test failed (see cerr above)");
112  }
113  }
114 }
115 
116 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
117 {
118  try
119  {
120  unit_test();
121  }
122  catch (std::exception& e)
123  {
124  std::cerr << mrpt::exception_to_str(e) << "\n";
125  return 1;
126  }
127 }
unit_test
void unit_test()
Definition: test-mp2p_quality_voxels.cpp:23
VERBOSE
const bool VERBOSE
Definition: test-mp2p_quality_voxels.cpp:20
test.res
res
Definition: test.py:11
mp2p_icp::QualityEvaluator_Voxels
Definition: QualityEvaluator_Voxels.h:22
QualityEvaluator_Voxels.h
Matching quality evaluator: comparison via voxel occupancy.
datasetDir
const std::string datasetDir
Definition: test-mp2p_icp_algos.cpp:41
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_quality_voxels.cpp:116
testing::internal::string
::std::string string
Definition: gtest.h:1979
mp2p_icp::metric_map_t::load_from_file
bool load_from_file(const std::string &fileName)
Definition: metricmap.cpp:578
mp2p_icp::metric_map_t
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:49
test.q
q
Definition: test.py:8
SCALE
const double SCALE
Definition: test-mp2p_quality_voxels.cpp:21


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:46:00