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


mp2p_icp
Author(s):
autogenerated on Wed Oct 23 2024 02:45:40