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>
20 const bool VERBOSE = mrpt::get_env<bool>(
"VERBOSE",
false);
21 const double SCALE = mrpt::get_env<double>(
"SCALE", 3.0);
26 mrpt::system::pathJoin({MOLA_TEST_DATASET_DIR,
"loop_closures"});
31 mrpt::system::pathJoin({
datasetDir,
"dataset.yaml"});
33 const auto dataset = mrpt::containers::yaml::FromFile(datasetListFile);
35 const auto badOnes = dataset[
"bad"];
36 const auto goodOnes = dataset[
"good"];
38 ASSERT_(badOnes.isSequence());
39 ASSERT_(goodOnes.isSequence());
42 mrpt::containers::yaml params;
43 params[
"voxel_layer_name"] =
"localmap_voxels";
44 params[
"dist2quality_scale"] =
SCALE;
52 mrpt::poses::CPose3D local_pose_wrt_global;
56 std::vector<Entry> LCs;
58 auto lambdaProcessYaml =
59 [&](
const mrpt::containers::yaml::sequence_t& seq,
bool are_good_lcs)
61 for (
const auto& p : seq)
63 auto& lc = LCs.emplace_back();
64 lc.is_good_lc = are_good_lcs;
65 lc.global = p.asMap().at(
"global").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>()));
79 lambdaProcessYaml(goodOnes.asSequenceRange(),
true);
82 lambdaProcessYaml(badOnes.asSequenceRange(),
false);
84 for (
const auto& e : LCs)
92 const auto res =
q.evaluate(pcG, pcL, e.local_pose_wrt_global, {});
93 const double quality =
res.quality;
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";
103 if ((quality < 0.2 && e.is_good_lc) ||
104 (quality >= 0.5 && !e.is_good_lc))
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)");
116 int main([[maybe_unused]]
int argc, [[maybe_unused]]
char** argv)
122 catch (std::exception& e)
124 std::cerr << mrpt::exception_to_str(e) <<
"\n";