Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only pass one regular expression to filter topics #1053

Merged
merged 1 commit into from
Aug 3, 2022
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
4 changes: 2 additions & 2 deletions ros2bag/ros2bag/verb/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def add_arguments(self, parser, cli_name): # noqa: D102
help='topics to replay, separated by space. If none specified, all topics will be '
'replayed.')
parser.add_argument(
'-e', '--regex', type=str, default=[], nargs='+',
'-e', '--regex', default='',
help='filter topics by regular expression to replay, separated by space. If none '
'specified, all topics will be replayed.')
parser.add_argument(
Expand Down Expand Up @@ -190,7 +190,7 @@ def main(self, *, args): # noqa: D102
play_options.node_prefix = NODE_NAME_PREFIX
play_options.rate = args.rate
play_options.topics_to_filter = args.topics
play_options.regex_to_filter = args.regex
play_options.topics_regex_to_filter = args.regex
play_options.topic_qos_profile_overrides = qos_profile_overrides
play_options.loop = args.loop
play_options.topic_remapping_options = topic_remapping
Expand Down
2 changes: 1 addition & 1 deletion rosbag2_py/src/rosbag2_py/_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ PYBIND11_MODULE(_transport, m) {
.def_readwrite("node_prefix", &PlayOptions::node_prefix)
.def_readwrite("rate", &PlayOptions::rate)
.def_readwrite("topics_to_filter", &PlayOptions::topics_to_filter)
.def_readwrite("regex_to_filter", &PlayOptions::regex_to_filter)
.def_readwrite("topics_regex_to_filter", &PlayOptions::topics_regex_to_filter)
.def_property(
"topic_qos_profile_overrides",
&PlayOptions::getTopicQoSProfileOverrides,
Expand Down
4 changes: 2 additions & 2 deletions rosbag2_storage/include/rosbag2_storage/storage_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ struct StorageFilter
// and all messages are returned.
std::vector<std::string> topics;

// Regular expressions of topic names to whitelist when playing a bag.
// Regular expression of topic names to whitelist when playing a bag.
// Only messages matching these specified topics will be played.
// If list is empty, the filter is ignored and all messages are played.
std::vector<std::string> regex = {};
std::string topics_regex = "";
};

} // namespace rosbag2_storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,10 @@ void SqliteStorage::prepare_for_reading()
statement_str += "(topics.name IN (" + topic_list + ")) AND ";
}
// add topic filter based on regular expression
if (!storage_filter_.regex.empty()) {
if (!storage_filter_.topics_regex.empty()) {
// Construct string for selected topics
statement_str += "(";
for (auto & topic_regex : storage_filter_.regex) {
statement_str += "(topics.name REGEXP '" + topic_regex + "')";
if (&topic_regex != &storage_filter_.regex.back()) {
statement_str += " OR ";
}
}
statement_str += ") AND ";
statement_str += "(topics.name REGEXP '" + storage_filter_.topics_regex + "')";
statement_str += " AND ";
}
// add start time filter
statement_str += "(((timestamp = " + std::to_string(seek_time_) + ") "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ TEST_F(StorageTestFixture, read_next_returns_filtered_messages_regex) {
readable_storage->open({db_filename, kPluginID});

rosbag2_storage::StorageFilter storage_filter;
storage_filter.regex.push_back("topic.*");
storage_filter.topics_regex = "topic.*";
readable_storage->set_filter(storage_filter);

EXPECT_TRUE(readable_storage->has_next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ struct PlayOptions
// If list is empty, the filter is ignored and all messages are played.
std::vector<std::string> topics_to_filter = {};

// Regular expressions of topic names to whitelist when playing a bag.
// Regular expression of topic names to whitelist when playing a bag.
// Only messages matching these specified topics will be played.
// If list is empty, the filter is ignored and all messages are played.
std::vector<std::string> regex_to_filter = {};
std::string topics_regex_to_filter = "";

std::unordered_map<std::string, rclcpp::QoS> topic_qos_profile_overrides = {};
bool loop = false;
Expand Down
2 changes: 1 addition & 1 deletion rosbag2_transport/src/rosbag2_transport/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ void Player::prepare_publishers()
{
rosbag2_storage::StorageFilter storage_filter;
storage_filter.topics = play_options_.topics_to_filter;
storage_filter.regex = play_options_.regex_to_filter;
storage_filter.topics_regex = play_options_.topics_regex_to_filter;
reader_->set_filter(storage_filter);

// Create /clock publisher
Expand Down