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 =
32  mp2p_icp::load_xyz_file(fileFullPath);
33 
34  mrpt::containers::yaml params;
35 
36  params["ncols"] = 100;
37  params["nrows"] = 60;
38 
39  params["fx"] = 20.0;
40  params["fy"] = 20.0;
41  params["cx"] = 50.0;
42  params["cy"] = 30.0;
43 
44  params["sigma"] = 0.1;
45 
46  // params["debug_save_all_matrices"] = true;
47 
49  q.initialize(params);
50 
51  {
52  const auto viewPose = mrpt::poses::CPose3D(-0.2, 0, 0, 0, 0, 0);
53  pts->changeCoordinatesReference(viewPose);
54  }
55 
56  // Pairs: ground-truth transformation (xyz yaw pitch roll) + test pose:
57  std::vector<
58  std::tuple<mrpt::poses::CPose3D, mrpt::poses::CPose3D, double>>
59  testPairs = {
60  // #1:
61  {{.0, .0, .0, .0, .0, .0}, {.0, .0, .0, .0, .0, .0}, 1.0},
62  // #1:
63  {{1.0, 1.0, .0, .0, .0, .0}, {1.0, 1.0, .0, .0, .0, .0}, 1.0},
64  // #2:
65  {{.1, .1, .2, .0, .0, .0}, {.101, .1, .2, .0, .0, .0}, 0.93},
66  };
67 
68  // Test 1: quality for identity pose:
69  for (const auto& p : testPairs)
70  {
71  const mrpt::poses::CPose3D& relPoseGT = std::get<0>(p);
72  const mrpt::poses::CPose3D& relPoseTest = std::get<1>(p);
73  const double expectedVal = std::get<2>(p);
74 
75  auto p1 = mrpt::maps::CSimplePointsMap::Create();
76  p1->insertAnotherMap(pts.get(), mrpt::poses::CPose3D::Identity());
77 
78  auto p2 = mrpt::maps::CSimplePointsMap::Create();
79  p2->insertAnotherMap(pts.get(), relPoseGT);
80 
83 
86 
87  const auto res = q.evaluate(pcG, pcL, relPoseTest, {});
88  const double quality = res.quality;
89 
90  if (std::abs(quality - expectedVal) > 0.1)
91  {
92  std::cerr << "Failed for test case:\n"
93  << " relPoseGT : " << relPoseGT << "\n"
94  << " relPoseTest : " << relPoseTest << "\n"
95  << " expectedVal : " << expectedVal << "\n"
96  << " quality : " << quality << "\n";
97 
98  throw std::runtime_error("test failed (see cerr above)");
99  }
100  }
101  }
102  catch (std::exception& e)
103  {
104  std::cerr << mrpt::exception_to_str(e) << "\n";
105  return 1;
106  }
107 }
test.res
res
Definition: test.py:11
datasetDir
const std::string datasetDir
Definition: test-mp2p_icp_algos.cpp:41
mp2p_icp::metric_map_t::PT_LAYER_RAW
constexpr static const char * PT_LAYER_RAW
Definition: metricmap.h:57
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:48
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:75
QualityEvaluator_RangeImageSimilarity.h
Matching quality evaluator from paper [Bogoslavskyi,IROS2017].


mp2p_icp
Author(s): Jose-Luis Blanco-Claraco
autogenerated on Tue Jul 2 2024 02:47:26