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

Gracefully handle loops in TF tree #1820

Merged
merged 1 commit into from
Apr 17, 2024
Merged
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
15 changes: 15 additions & 0 deletions src/rviz/default_plugin/tf_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,17 @@ Ogre::ColourValue lerpColor(const Ogre::ColourValue& start, const Ogre::ColourVa
return start * t + end * (1 - t);
}

bool hasLoop(rviz::Property* child, rviz::Property* parent, rviz::Property* root)
{
while (child != root)
{
if (child == parent)
return true;
child = child->getParent();
}
return false;
}

void TFDisplay::updateFrame(FrameInfo* frame)
{
auto tf = context_->getTF2BufferPtr();
Expand Down Expand Up @@ -736,7 +747,11 @@ void TFDisplay::updateFrame(FrameInfo* frame)
// Retrieve tree property to add the new child at
rviz::Property* parent_tree_property;
if (parent && parent->tree_property_) // parent already created
{
parent_tree_property = parent->tree_property_;
if (hasLoop(parent_tree_property, frame->tree_property_, tree_category_))
parent_tree_property = tree_category_; // insert loops at root node
}
else // create (temporarily) at root
parent_tree_property = tree_category_;

Expand Down
Loading