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

Added regex filter field for TF display #1032

Merged
merged 6 commits into from
Mar 15, 2024
Merged

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Aug 15, 2023

related with this PR in RViz for ROS 1

When there is a lot of frames on /tf it can be hard to properly visualize them in RViz especially if frames overlap. Usually solution to this is to enable and disable desired frames in Frames field of the TF display. But it quickly become very annoying task if there is a lot of frames (e.g. 100 +) and each one needs to be found in a long list first and then disabled/enabled.
Because of that I suggest adding regex field which filters frames and displays only the ones matching entered expression. For convenience I also suggest adding additional field for blacklist filter.
Benefit of this approach is that user can quickly setup one or more displays, each showing specific group of frames and he can turn each one on/off as needed.
Scene with a lot of frames ...
image
... can be easily filtered so only interesting frames are displayed
image
Example when multiple TF displays are added. Each one has its own settings and frame filter.
image

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde ahcorde self-assigned this Aug 15, 2023
Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
Comment on lines 69 to 73
try {
regex_.assign(value.toLocal8Bit().constData(), std::regex_constants::optimize);
} catch (const std::regex_error & e) {
regex_ = default_;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to this code as-is, but I'm just wondering; can this exception actually happen given the RegexValidator we have installed?

Comment on lines 304 to 326
while (it != end) {
if (it->empty() || !std::regex_search(*it, filter_whitelist_property_->regex()) ||
std::regex_search(*it, filter_blacklist_property_->regex()))
{
std::swap(*it, *--end); // swap current to-be-dropped name with last one
} else {
++it;
}
}

std::sort(frames.begin(), end);

S_FrameInfo current_frames;
for (it = frames.begin(); it != end; ++it) {
FrameInfo * info = getFrameInfo(*it);
if (!info) {
info = createFrame(*it);
} else {
updateFrame(info);
}

current_frames.insert(info);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels to me like these loops are going to be doing an unnecessary amount of work, in both the case where filtering is used and where it is not used. I'm particularly worried about large TF trees.

For the first loop, if someone is not using the filtering, we are still going to be iterating over every single frame to just ignore it. It seems like if both the whitelist and the blacklist are empty, we should skip the loop completely.

If the user is using the filtering, then we are iterating over the list of frames 3 times; once to apply the regex, once to sort, and once to build up the current frames. It seems to me that we should be able to get away with only iterating once. That is, we have a loop, and in the loop body we compare it to the whitelist and blacklist. If it is not to be shown because it is explicitly in the blacklist, or it is not in the whitelist (or it is empty), we do nothing more. If we are going to show it, then we create/update the frame for it, and insert it into current_frames. Since current_frames is a set anyway (which is sorted: https://en.cppreference.com/w/cpp/container/set), there is no need for a separate sort step. We can do a similar thing for the case where the whitelist and blacklist are empty, and skip the additional sort step.

At least, that's how it seems to me. Does that make sense to you? Am I possibly missing something with the separate sort and "insert into sorted set" step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think @clalancette ? 246e0d7

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Oct 6, 2023

friendly ping @clalancette

3 similar comments
@ahcorde
Copy link
Contributor Author

ahcorde commented Oct 30, 2023

friendly ping @clalancette

@ahcorde
Copy link
Contributor Author

ahcorde commented Jan 18, 2024

friendly ping @clalancette

@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 23, 2024

friendly ping @clalancette

@ahcorde
Copy link
Contributor Author

ahcorde commented Mar 14, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Mar 14, 2024

  • Windows Build Status

Signed-off-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@ahcorde
Copy link
Contributor Author

ahcorde commented Mar 14, 2024

  • Windows Build Status

@ahcorde
Copy link
Contributor Author

ahcorde commented Mar 15, 2024

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit cdf1c21 into rolling Mar 15, 2024
1 of 2 checks passed
@delete-merged-branch delete-merged-branch bot deleted the ahcorde/rolling/tf_filter branch March 15, 2024 14:35
@ros-discourse
Copy link

This pull request has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/ros-2-jazzy-jalisco-released/37862/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants