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