Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apps/sm2mm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ struct CLI

TCLAP::SwitchArg argProfiler{"", "profiler", "Enables profiler.", cmd};

TCLAP::SwitchArg argDontThrowOnMissingExternals{
"", "permit-missing-externals",
"If set, missing external files will generate a warning instead of an exception stopping "
"the processing.",
cmd};

TCLAP::ValueArg<size_t> argIndexFrom{
"",
"from-index",
Expand Down Expand Up @@ -208,6 +214,11 @@ void run_sm_to_mm(CLI& cli)
opts.profiler = *profiler;
}

if (cli.argDontThrowOnMissingExternals.isSet())
{
opts.throw_on_missing_external_files = false;
}

// Create the map:
mp2p_icp_filters::simplemap_to_metricmap(sm, mm, yamlData, opts);

Expand Down
13 changes: 9 additions & 4 deletions docs/source/app_sm2mm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ CLI Reference
USAGE:

sm2mm [--decimate-max <N>] [--decimate-nth <N>] [--to-index <0>]
[--from-index <0>] [--profiler] [--no-progress-bar]
[--externals-dir <<ExternalsDirectory>>] [--compression-method
<METHOD>] [-v <INFO>] [-p <pipeline.yaml>] [-l <foobar.so>] -o
<out.mm> -i <map.simplemap> [--] [--version] [-h]
[--from-index <0>] [--permit-missing-externals] [--profiler]
[--no-progress-bar] [--externals-dir <<ExternalsDirectory>>]
[--compression-method <METHOD>] [-v <INFO>] [-p <pipeline.yaml>]
[-l <foobar.so>] -o <out.mm> -i <map.simplemap> [--] [--version]
[-h]


Where:
Expand All @@ -54,6 +55,10 @@ CLI Reference
If provided, the simplemap keyframes until this index will be
discarded and it will start at this point.

--permit-missing-externals
If set, missing external files will generate a warning instead of an
exception stopping the processing.

--profiler
Enables profiler.

Expand Down
3 changes: 2 additions & 1 deletion mp2p_icp_filters/include/mp2p_icp_filters/sm2mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct sm2mm_options_t

mrpt::system::VerbosityLevel verbosity = mrpt::system::LVL_INFO;
bool showProgressBar = false;
std::vector<std::pair<std::string, double>> customVariables = {};
bool throw_on_missing_external_files = true;
std::vector<std::pair<std::string, double>> customVariables = {};
std::optional<size_t> start_index;
std::optional<size_t> end_index;
mrpt::optional_ref<mrpt::system::CTimeLogger> profiler;
Expand Down
67 changes: 57 additions & 10 deletions mp2p_icp_filters/src/sm2mm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@
#include <cmath>
#include <iostream>

namespace
{
std::string first_n_lines(const std::string& input, std::size_t n)
{
if (n == 0)
{
return {};
}

std::size_t pos = 0;
std::size_t lines = 0;

while (lines < n)
{
pos = input.find('\n', pos);
if (pos == std::string::npos)
{
// Fewer than n lines: return entire string
return input;
}
++pos; // move past '\n'
++lines;
}

return input.substr(0, pos);
}
} // namespace

void mp2p_icp_filters::simplemap_to_metricmap(
const mrpt::maps::CSimpleMap& sm, mp2p_icp::metric_map_t& mm,
const mrpt::containers::yaml& yamlData, const sm2mm_options_t& options)
Expand Down Expand Up @@ -206,22 +234,41 @@ void mp2p_icp_filters::simplemap_to_metricmap(
#endif
}

// Next, do the actual sensor data processing:
for (const auto& obs : *sf)
try
{
ASSERT_(obs);
obs->load();
// Next, do the actual sensor data processing:
for (const auto& obs : *sf)
{
ASSERT_(obs);
obs->load();

bool handled = mp2p_icp_filters::apply_generators(generators, *obs, mm, robotPose);
bool handled = mp2p_icp_filters::apply_generators(generators, *obs, mm, robotPose);

if (!handled)
if (!handled)
{
obs->unload();
continue;
}

// process it:
mp2p_icp_filters::apply_filter_pipeline(filters, mm, options.profiler);
obs->unload();
}
}
catch (const std::exception& e)
{
// If the exception msg contains "Assert file existence failed", it's due to missing
// external files.
const std::string errMsg = e.what();
if (errMsg.find("Assert file existence failed") != std::string::npos &&
!options.throw_on_missing_external_files)
{
std::cerr << "[sm2mm] Keyframe #" << curKF
<< ": skipping observation due to missing external files: "
<< first_n_lines(errMsg, 3) << "\n";
continue;
}

// process it:
mp2p_icp_filters::apply_filter_pipeline(filters, mm, options.profiler);
obs->unload();
throw; // Rethrow other exceptions
}

#if 0
Expand Down