MOLA keyframe metadata¶
Overview¶
Each keyframe of a simple-map may hold one mrpt::obs::CObservationComment with sensorLabel metadata whose text is a YAML map: per-keyframe facts written by the tools that build or process the map (odometry, partitions…). Each top-level key belongs to the tool that writes it; every tool that rewrites a keyframe keeps the keys it does not know. A version key gives the format version; a missing one means 1. See the “MOLA keyframe metadata” page of the MOLA documentation.
// global variables constexpr const char* mp2p_icp::KEYFRAME_METADATA_LABEL = "metadata"; constexpr int mp2p_icp::KEYFRAME_METADATA_VERSION = 1; // global functions mrpt::obs::CObservationComment::ConstPtr mp2p_icp::find_keyframe_metadata_obs(const mrpt::obs::CSensoryFrame& sf); std::optional<mrpt::containers::yaml> mp2p_icp::parse_keyframe_metadata(const mrpt::obs::CObservation& obs); std::optional<mrpt::containers::yaml> mp2p_icp::get_keyframe_metadata(const mrpt::obs::CSensoryFrame& sf); int mp2p_icp::keyframe_metadata_version(const mrpt::containers::yaml& metadata); void mp2p_icp::set_keyframe_metadata( mrpt::obs::CSensoryFrame& sf, const std::string& key, const mrpt::containers::yaml& value, const std::optional<mrpt::Clock::time_point>& stamp = std::nullopt ); void mp2p_icp::set_keyframe_metadata( mrpt::obs::CSensoryFrame& sf, const mrpt::containers::yaml& entries, const std::optional<mrpt::Clock::time_point>& stamp = std::nullopt ); std::string mp2p_icp::keyframe_metadata_text_with( const std::string& text, const std::string& key, const mrpt::containers::yaml& value );
Global Variables¶
constexpr const char* mp2p_icp::KEYFRAME_METADATA_LABEL = "metadata"
sensorLabel of the keyframe metadata comment
constexpr int mp2p_icp::KEYFRAME_METADATA_VERSION = 1
The current format version (the value of the optional version key)
Global Functions¶
mrpt::obs::CObservationComment::ConstPtr mp2p_icp::find_keyframe_metadata_obs(const mrpt::obs::CSensoryFrame& sf)
The keyframe metadata comment of sf (the first CObservationComment with sensorLabel KEYFRAME_METADATA_LABEL), or nullptr.
std::optional<mrpt::containers::yaml> mp2p_icp::parse_keyframe_metadata(const mrpt::obs::CObservation& obs)
The YAML map in obs if it is a keyframe metadata comment, std::nullopt otherwise: another kind of observation or label, or a text that is not a YAML map (an empty text gives an empty map).
std::optional<mrpt::containers::yaml> mp2p_icp::get_keyframe_metadata(const mrpt::obs::CSensoryFrame& sf)
The keyframe metadata of sf as a YAML map, std::nullopt if it has none (see parse_keyframe_metadata()).
int mp2p_icp::keyframe_metadata_version(const mrpt::containers::yaml& metadata)
The format version of some keyframe metadata: its version key, or 1 if it has none (legacy files).
void mp2p_icp::set_keyframe_metadata( mrpt::obs::CSensoryFrame& sf, const std::string& key, const mrpt::containers::yaml& value, const std::optional<mrpt::Clock::time_point>& stamp = std::nullopt )
Sets the top-level key of the keyframe metadata of sf to value, or removes it if value is a null node. Without a metadata comment, one is appended, stamped with stamp or, if not given, with the first valid timestamp of the observations in sf.
Other entries: if the text is a block-style YAML map whose top-level keys are plain or simply quoted (what every producer writes), their text is kept as it is, with the blank and comment lines around them. Anything else (flow maps, keys with escapes or starting with ‘-’, several documents) is parsed and written again whole: the entries read back the same, but their text may change.
Strings: a string that is already a quoted YAML scalar (e.g. “’[1 2 3]’”, as the odometry writes its bounding boxes) stands for its contents. MRPT’s YAML printer writes strings as they are before MRPT 3.7: such strings are then written as is, and any other string is quoted unless it reads back as the same string. From MRPT 3.7 on, the printer quotes strings itself (except those that read as numbers, booleans or null), and pre-quoted strings are given to it unquoted. The new text is parsed once and must read back with key equal to value (and, when written again whole, the other entries unchanged), or nothing is changed and an exception is thrown: a string that reads as a number, boolean or null may be refused, depending on the MRPT version.
sf itself is modified: its metadata comment is replaced by a modified copy (the comment object is never changed in place), or a new one is added. Copies of a CSimpleMap share their sensory frames, so to leave other maps unchanged, copy the CSensoryFrame first and change the copy.
Parameters:
std::exception |
If the existing comment is not a YAML map or is of a newer format version (a |
void mp2p_icp::set_keyframe_metadata( mrpt::obs::CSensoryFrame& sf, const mrpt::containers::yaml& entries, const std::optional<mrpt::Clock::time_point>& stamp = std::nullopt )
Sets several top-level keys at once: each entry of the YAML map entries, in order, as set_keyframe_metadata() with one key does.
std::string mp2p_icp::keyframe_metadata_text_with( const std::string& text, const std::string& key, const mrpt::containers::yaml& value )
The text set_keyframe_metadata() leaves in a comment whose text is text (empty for a new one): key set to value, or removed if it is a null node, and every other entry unchanged.
Parameters:
std::exception |