-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.cpp
151 lines (121 loc) · 4.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* -------------------------------------------------------------------------
* A repertory of multi primitive-to-primitive (MP2P) ICP algorithms in C++
* Copyright (C) 2018-2024 Jose Luis Blanco, University of Almeria
* See LICENSE for license information.
* ------------------------------------------------------------------------- */
/**
* @file sm2mm/main.cpp
* @brief CLI tool to parse a SimpleMap (from SLAM) to metric maps (mm) via a
* configurable pipeline
* @author Jose Luis Blanco Claraco
* @date Dec 15, 2023
*/
#include <mp2p_icp_filters/sm2mm.h>
#include <mrpt/3rdparty/tclap/CmdLine.h>
#include <mrpt/containers/yaml.h>
#include <mrpt/io/lazy_load_path.h>
#include <mrpt/system/COutputLogger.h>
#include <mrpt/system/filesystem.h>
// CLI flags:
static TCLAP::CmdLine cmd("sm2mm");
static TCLAP::ValueArg<std::string> argInput(
"i", "input", "Input .simplemap file", true, "map.simplemap",
"map.simplemap", cmd);
static TCLAP::ValueArg<std::string> argOutput(
"o", "output", "Output .mm file to write to", true, "out.mm", "out.mm",
cmd);
static TCLAP::ValueArg<std::string> argPlugins(
"l", "load-plugins",
"One or more (comma separated) *.so files to load as plugins, e.g. "
"defining new CMetricMap classes",
false, "foobar.so", "foobar.so", cmd);
static TCLAP::ValueArg<std::string> argPipeline(
"p", "pipeline",
"YAML file with the mp2p_icp_filters pipeline to load. It can optionally "
"contain a `filters:`, a `generators:`, and a `final_filters:` sections. "
"If this argument is not provided, the default generator will be used and "
"no filtering will be applied, which might be ok in some cases. "
"See the app README for examples:\n"
"https://github.com/MOLAorg/mp2p_icp/tree/master/apps/sm2mm",
false, "pipeline.yaml", "pipeline.yaml", cmd);
static TCLAP::ValueArg<std::string> arg_verbosity_level(
"v", "verbosity", "Verbosity level: ERROR|WARN|INFO|DEBUG (Default: INFO)",
false, "", "INFO", cmd);
static TCLAP::ValueArg<std::string> arg_lazy_load_base_dir(
"", "externals-dir",
"Lazy-load base directory for datasets with externally-stored observations",
false, "dataset_Images", "<ExternalsDirectory>", cmd);
static TCLAP::SwitchArg argNoProgressBar(
"", "no-progress-bar",
"Disables the progress bar. Useful for cleaner output when using DEBUG "
"verbosity level.",
cmd);
static TCLAP::ValueArg<size_t> argIndexFrom(
"", "from-index",
"If provided, the simplemap keyframes until this index will be discarded "
"and it will start at this point.",
false, 0, "0", cmd);
static TCLAP::ValueArg<size_t> argIndexTo(
"", "to-index",
"If provided, the simplemap keyframes will be processed up to this index "
"only.",
false, 0, "0", cmd);
void run_sm_to_mm()
{
const auto& filSM = argInput.getValue();
mrpt::maps::CSimpleMap sm;
std::cout << "[sm2mm] Reading simplemap from: '" << filSM << "'..."
<< std::endl;
// TODO: progress bar
sm.loadFromFile(filSM);
std::cout << "[sm2mm] Done read simplemap with " << sm.size()
<< " keyframes." << std::endl;
ASSERT_(!sm.empty());
// Load pipeline from YAML file:
mrpt::containers::yaml yamlData; // default: empty
if (argPipeline.isSet())
{
const auto filYaml = argPipeline.getValue();
ASSERT_FILE_EXISTS_(filYaml);
yamlData = mrpt::containers::yaml::FromFile(filYaml);
}
mp2p_icp::metric_map_t mm;
mrpt::system::VerbosityLevel logLevel = mrpt::system::LVL_INFO;
if (arg_verbosity_level.isSet())
{
using vl = mrpt::typemeta::TEnumType<mrpt::system::VerbosityLevel>;
logLevel = vl::name2value(arg_verbosity_level.getValue());
}
if (arg_lazy_load_base_dir.isSet())
mrpt::io::setLazyLoadPathBase(arg_lazy_load_base_dir.getValue());
mp2p_icp_filters::sm2mm_options_t opts;
opts.showProgressBar = !argNoProgressBar.isSet();
opts.verbosity = logLevel;
if (argIndexFrom.isSet()) opts.start_index = argIndexFrom.getValue();
if (argIndexTo.isSet()) opts.end_index = argIndexTo.getValue();
// Create the map:
mp2p_icp_filters::simplemap_to_metricmap(sm, mm, yamlData, opts);
std::cout << "[sm2mm] Final map: " << mm.contents_summary() << std::endl;
// Save as mm file:
const auto filOut = argOutput.getValue();
std::cout << "[sm2mm] Writing metric map to: '" << filOut << "'..."
<< std::endl;
if (!mm.save_to_file(filOut))
THROW_EXCEPTION_FMT(
"Error writing to target file '%s'", filOut.c_str());
}
int main(int argc, char** argv)
{
try
{
// Parse arguments:
if (!cmd.parse(argc, argv)) return 1; // should exit.
run_sm_to_mm();
}
catch (const std::exception& e)
{
std::cerr << e.what();
return 1;
}
return 0;
}