test-mp2p_quality_reproject_ranges.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 <mp2p_icp/load_xyz_file.h>
16 #include <mrpt/containers/yaml.h>
17 #include <mrpt/core/exceptions.h>
18 #include <mrpt/maps/CSimplePointsMap.h>
19 
20 #include <cstdlib>
21 
22 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
23 {
24  const std::string datasetDir = MP2P_DATASET_DIR;
25 
26  try
27  {
28  const auto inFile = std::string("happy_buddha_decim.xyz.gz");
29 
30  const auto fileFullPath = datasetDir + inFile;
31  mrpt::maps::CSimplePointsMap::Ptr pts = mp2p_icp::load_xyz_file(fileFullPath);
32 
33  mrpt::containers::yaml params;
34 
35  params["ncols"] = 100;
36  params["nrows"] = 60;
37 
38  params["fx"] = 20.0;
39  params["fy"] = 20.0;
40  params["cx"] = 50.0;
41  params["cy"] = 30.0;
42 
43  params["sigma"] = 0.1;
44 
45  // params["debug_save_all_matrices"] = true;
46 
48  q.initialize(params);
49 
50  {
51  const auto viewPose = mrpt::poses::CPose3D(-0.2, 0, 0, 0, 0, 0);
52  pts->changeCoordinatesReference(viewPose);
53  }
54 
55  // Pairs: ground-truth transformation (xyz yaw pitch roll) + test pose:
56  std::vector<std::tuple<mrpt::poses::CPose3D, mrpt::poses::CPose3D, double>> testPairs = {
57  // #1:
58  {{.0, .0, .0, .0, .0, .0}, {.0, .0, .0, .0, .0, .0}, 1.0},
59  // #1:
60  {{1.0, 1.0, .0, .0, .0, .0}, {1.0, 1.0, .0, .0, .0, .0}, 1.0},
61  // #2:
62  {{.1, .1, .2, .0, .0, .0}, {.101, .1, .2, .0, .0, .0}, 0.93},
63  };
64 
65  // Test 1: quality for identity pose:
66  for (const auto& p : testPairs)
67  {
68  const mrpt::poses::CPose3D& relPoseGT = std::get<0>(p);
69  const mrpt::poses::CPose3D& relPoseTest = std::get<1>(p);
70  const double expectedVal = std::get<2>(p);
71 
72  auto p1 = mrpt::maps::CSimplePointsMap::Create();
73  p1->insertAnotherMap(pts.get(), mrpt::poses::CPose3D::Identity());
74 
75  auto p2 = mrpt::maps::CSimplePointsMap::Create();
76  p2->insertAnotherMap(pts.get(), relPoseGT);
77 
80 
83 
84  const auto res = q.evaluate(pcG, pcL, relPoseTest, {});
85  const double quality = res.quality;
86 
87  if (std::abs(quality - expectedVal) > 0.1)
88  {
89  std::cerr << "Failed for test case:\n"
90  << " relPoseGT : " << relPoseGT << "\n"
91  << " relPoseTest : " << relPoseTest << "\n"
92  << " expectedVal : " << expectedVal << "\n"
93  << " quality : " << quality << "\n";
94 
95  throw std::runtime_error("test failed (see cerr above)");
96  }
97  }
98  }
99  catch (std::exception& e)
100  {
101  std::cerr << mrpt::exception_to_str(e) << "\n";
102  return 1;
103  }
104 }
test.res
res
Definition: test.py:11
mp2p_icp::metric_map_t::PT_LAYER_RAW
constexpr static const char * PT_LAYER_RAW
Definition: metricmap.h:64
testing::internal::string
::std::string string
Definition: gtest.h:1979
mp2p_icp::QualityEvaluator_RangeImageSimilarity
Definition: QualityEvaluator_RangeImageSimilarity.h:35
main
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
Definition: test-mp2p_quality_reproject_ranges.cpp:22
mp2p_icp::load_xyz_file
mrpt::maps::CSimplePointsMap::Ptr load_xyz_file(const std::string &fil)
Definition: load_xyz_file.cpp:21
mp2p_icp::metric_map_t
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:55
test.q
q
Definition: test.py:8
load_xyz_file.h
Unit tests common utilities.
mp2p_icp::metric_map_t::layers
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:82
QualityEvaluator_RangeImageSimilarity.h
Matching quality evaluator from paper [Bogoslavskyi,IROS2017].


mp2p_icp
Author(s):
autogenerated on Mon May 26 2025 02:45:50