Skip to content

Commit

Permalink
rawlog-edit: remap timestamps now can filter by label
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Aug 17, 2023
1 parent f8538d4 commit fcaa517
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/nanogui
Submodule nanogui updated 1 files
+6 −1 CMakeLists.txt
2 changes: 2 additions & 0 deletions doc/source/doxygen-docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
\page changelog Change Log

# Version 2.10.2: UNRELEASED
- Changes in apps:
- rawlog-edit: Add `--select-label` optional filter to command `--remap-timestamps`.
- BUG FIXES:
- Fix CSparse "C" linkage build error (OSX Clang). PR [#1280](https://github.com/MRPT/mrpt/pull/1280)
- Fix missing Python wrapping of poses PDF (poses with uncertainty) composition (\oplus and \ominus) operators. (Closes [#1281](https://github.com/MRPT/mrpt/issues/1281)). PR [#1283](https://github.com/MRPT/mrpt/pull/1283)
Expand Down
11 changes: 10 additions & 1 deletion libs/apps/src/RawlogEditApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ TCLAP::SwitchArg arg_overwrite(
"w", "overwrite", "Force overwrite target file without prompting.", cmd,
false);

TCLAP::ValueArg<std::string> arg_select_label(
"", "select-label",
"Select one sensor label on which to apply the operation.\n"
"Several labels can be provided separated by commas.\n"
"Only for those ops that mention --select-label as optional.",
false, "", "label[,label...]", cmd);

TCLAP::SwitchArg arg_quiet("q", "quiet", "Terse output", cmd, false);

void RawlogEditApp::run(int argc, const char** argv)
Expand Down Expand Up @@ -232,8 +239,10 @@ void RawlogEditApp::run(int argc, const char** argv)
"'a*t+b'."
"The parameters 'a' and 'b' must be given separated with a "
"semicolon.\n"
"Optional: --select-label LABEL1[,LABEL2] to limit the operation to "
"those sensors only.\n"
"Requires: -o (or --output)",
false, "", "a;b", cmd));
false, "", "\"a;b\"", cmd));
ops_functors["remap-timestamps"] = &op_remap_timestamps;

arg_ops.push_back(std::make_unique<TCLAP::SwitchArg>(
Expand Down
62 changes: 55 additions & 7 deletions libs/apps/src/rawlog-edit_remap_timestamps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,67 @@ DECLARE_OP_FUNCTION(op_remap_timestamps)
protected:
TOutputRawlogCreator outrawlog;
const double m_a, m_b;
const std::set<std::string> m_labels; //!< empty: all sensors
size_t m_changes = 0;

public:
CRawlogProcessor_RemapTimestamps(
CFileGZInputStream& in_rawlog, TCLAP::CmdLine& cmdline,
bool Verbose, double a, double b)
bool Verbose, double a, double b,
const std::set<std::string>& labels)
: CRawlogProcessorOnEachObservation(in_rawlog, cmdline, Verbose),
m_a(a),
m_b(b)
m_b(b),
m_labels(labels)
{
VERBOSE_COUT << "Applying timestamps remap a*t+b with: a=" << m_a
<< " b=" << m_b << endl;
VERBOSE_COUT
<< mrpt::format(
"Applying timestamps remap a*t+b with: a=%f b=%f", m_a,
m_b)
<< std::endl;

std::string sLog = "Applying to sensor labels: ";
if (m_labels.empty()) { sLog += " (all)\n"; }
else
{
for (const auto& l : m_labels)
{
sLog += "'";
sLog += l;
sLog += "', ";
}
sLog += "\n";
}
VERBOSE_COUT << sLog;
}

~CRawlogProcessor_RemapTimestamps()
{
VERBOSE_COUT << "Changed objects: " << m_changes << "\n";
}

bool checkSensorLabel(const CObservation::Ptr& obs)
{
if (m_labels.empty()) return true;
return m_labels.count(obs->sensorLabel) != 0;
}

bool processOneObservation(CObservation::Ptr& obs) override
{
// does it apply?
if (!checkSensorLabel(obs)) return true;

// T_NEW = a * T_OLD + b
const double t = mrpt::system::timestampToDouble(obs->timestamp);
const double t_new = m_a * t + m_b;
obs->timestamp = mrpt::system::time_tToTimestamp(t_new);

m_changes++;
return true;
}

// This method can be reimplemented to save the modified object to an
// output stream.
// This method can be reimplemented to save the modified object to
// an output stream.
void OnPostProcess(
mrpt::obs::CActionCollection::Ptr& actions,
mrpt::obs::CSensoryFrame::Ptr& SF,
Expand Down Expand Up @@ -85,9 +122,20 @@ DECLARE_OP_FUNCTION(op_remap_timestamps)
const double a = atof(sAB_tokens[0].c_str());
const double b = atof(sAB_tokens[1].c_str());

string filter_labels;
getArgValue<string>(cmdline, "select-label", filter_labels);

std::vector<std::string> lbs;
mrpt::system::tokenize(filter_labels, ";", lbs);

std::set<std::string> applyLabels;
for (const auto& l : lbs)
applyLabels.insert(l);

// Process
// ---------------------------------
CRawlogProcessor_RemapTimestamps proc(in_rawlog, cmdline, verbose, a, b);
CRawlogProcessor_RemapTimestamps proc(
in_rawlog, cmdline, verbose, a, b, applyLabels);
proc.doProcessRawlog();

// Dump statistics:
Expand Down

0 comments on commit fcaa517

Please sign in to comment.