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-2021 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 #include <sstream>
22 
23 const std::string datasetDir = MP2P_DATASET_DIR;
24 
25 int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
26 {
27  try
28  {
29  const auto inFile = std::string("happy_buddha_decim.xyz.gz");
30 
31  const auto fileFullPath = datasetDir + inFile;
32  mrpt::maps::CSimplePointsMap::Ptr pts =
33  mp2p_icp::load_xyz_file(fileFullPath);
34 
35  mrpt::containers::yaml params;
36 
37  params["ncols"] = 100;
38  params["nrows"] = 60;
39 
40  params["fx"] = 20.0;
41  params["fy"] = 20.0;
42  params["cx"] = 50.0;
43  params["cy"] = 30.0;
44 
45  params["sigma"] = 0.1;
46 
47  // params["debug_save_all_matrices"] = true;
48 
50  q.initialize(params);
51 
52  {
53  const auto viewPose = mrpt::poses::CPose3D(-0.2, 0, 0, 0, 0, 0);
54  pts->changeCoordinatesReference(viewPose);
55  }
56 
57  // Pairs: ground-truth transformation (xyz yaw pitch roll) + test pose:
58  std::vector<
59  std::tuple<mrpt::poses::CPose3D, mrpt::poses::CPose3D, double>>
60  testPairs = {
61  // #1:
62  {{.0, .0, .0, .0, .0, .0}, {.0, .0, .0, .0, .0, .0}, 1.0},
63  // #1:
64  {{1.0, 1.0, .0, .0, .0, .0}, {1.0, 1.0, .0, .0, .0, .0}, 1.0},
65  // #2:
66  {{.1, .1, .2, .0, .0, .0}, {.101, .1, .2, .0, .0, .0}, 0.93},
67  };
68 
69  // Test 1: quality for identity pose:
70  for (const auto& p : testPairs)
71  {
72  const mrpt::poses::CPose3D& relPoseGT = std::get<0>(p);
73  const mrpt::poses::CPose3D& relPoseTest = std::get<1>(p);
74  const double expectedVal = std::get<2>(p);
75 
76  auto p1 = mrpt::maps::CSimplePointsMap::Create();
77  p1->insertAnotherMap(pts.get(), mrpt::poses::CPose3D::Identity());
78 
79  auto p2 = mrpt::maps::CSimplePointsMap::Create();
80  p2->insertAnotherMap(pts.get(), relPoseGT);
81 
84 
87 
88  const double quality = q.evaluate(pcG, pcL, relPoseTest, {});
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 }
std::map< layer_name_t, mrpt::maps::CMetricMap::Ptr > layers
Definition: metricmap.h:74
Matching quality evaluator from paper [Bogoslavskyi,IROS2017].
Generic container of pointcloud(s), extracted features and other maps.
Definition: metricmap.h:47
::std::string string
Definition: gtest.h:1979
mrpt::maps::CSimplePointsMap::Ptr load_xyz_file(const std::string &fil)
Unit tests common utilities.
static constexpr const char * PT_LAYER_RAW
Definition: metricmap.h:56
const std::string datasetDir
double evaluate(const metric_map_t &pcGlobal, const metric_map_t &pcLocal, const mrpt::poses::CPose3D &localPose, const Pairings &pairingsFromICP) const override
int main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
void initialize(const mrpt::containers::yaml &params) override
q
Definition: test.py:8


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