From 71d3960e93925c29e1a9d4b51bf44524021d73d8 Mon Sep 17 00:00:00 2001 From: Christian Rauch Date: Mon, 1 Nov 2021 20:30:20 +0000 Subject: [PATCH 1/3] frame axes trail --- src/rviz/default_plugin/axes_display.cpp | 44 +++++++++++++++++++++++- src/rviz/default_plugin/axes_display.h | 6 ++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/rviz/default_plugin/axes_display.cpp b/src/rviz/default_plugin/axes_display.cpp index 68d00d1e56..51de30af2d 100644 --- a/src/rviz/default_plugin/axes_display.cpp +++ b/src/rviz/default_plugin/axes_display.cpp @@ -42,7 +42,7 @@ namespace rviz { -AxesDisplay::AxesDisplay() : Display(), axes_(nullptr) +AxesDisplay::AxesDisplay() : Display(), axes_(nullptr), trail_(nullptr) { frame_property_ = new TfFrameProperty("Reference Frame", TfFrameProperty::FIXED_FRAME_STRING, @@ -56,6 +56,10 @@ AxesDisplay::AxesDisplay() : Display(), axes_(nullptr) new FloatProperty("Radius", 0.1, "Radius of each axis, in meters.", this, SLOT(updateShape())); radius_property_->setMin(0.0001); + trail_property_ = + new Property("Show Trail", false, "Enable/disable a 2 meter \"ribbon\" which follows this frame.", + this, SLOT(updateTrail())); + alpha_property_ = new FloatProperty("Alpha", 1.0, "Alpha channel value of each axis.", this, SLOT(updateShape())); alpha_property_->setMin(0.0); @@ -64,6 +68,11 @@ AxesDisplay::AxesDisplay() : Display(), axes_(nullptr) AxesDisplay::~AxesDisplay() { + if (trail_) + { + scene_manager_->destroyRibbonTrail(trail_); + } + delete axes_; } @@ -79,11 +88,15 @@ void AxesDisplay::onInitialize() void AxesDisplay::onEnable() { axes_->getSceneNode()->setVisible(true); + if (trail_) + trail_->setVisible(true); } void AxesDisplay::onDisable() { axes_->getSceneNode()->setVisible(false); + if (trail_) + trail_->setVisible(false); } void AxesDisplay::updateShape() @@ -92,6 +105,35 @@ void AxesDisplay::updateShape() context_->queueRender(); } +void AxesDisplay::updateTrail() +{ + if (trail_property_->getValue().toBool()) + { + if (!trail_) + { + static int count = 0; + std::stringstream ss; + ss << "Trail for frame " << frame_property_->getFrame().toStdString() << count++; + trail_ = scene_manager_->createRibbonTrail(ss.str()); + trail_->setMaxChainElements(100); + trail_->setInitialWidth(0, 0.01f); + trail_->setInitialColour(0, 1, 0, 0); + trail_->addNode(axes_->getSceneNode()); + trail_->setTrailLength(2.0f); + trail_->setVisible(isEnabled()); + axes_->getSceneNode()->getParentSceneNode()->attachObject(trail_); + } + } + else + { + if (trail_) + { + scene_manager_->destroyRibbonTrail(trail_); + trail_ = nullptr; + } + } +} + void AxesDisplay::update(float /*dt*/, float /*ros_dt*/) { QString qframe = frame_property_->getFrame(); diff --git a/src/rviz/default_plugin/axes_display.h b/src/rviz/default_plugin/axes_display.h index bc10cd1915..fa9fa72eb7 100644 --- a/src/rviz/default_plugin/axes_display.h +++ b/src/rviz/default_plugin/axes_display.h @@ -32,6 +32,8 @@ #include +#include + namespace rviz { class Axes; @@ -67,11 +69,15 @@ private Q_SLOTS: /** @brief Update the length and radius of the axes object from property values. */ void updateShape(); + void updateTrail(); + private: Axes* axes_; ///< Handles actually drawing the axes + Ogre::RibbonTrail* trail_; FloatProperty* length_property_; FloatProperty* radius_property_; + Property* trail_property_; FloatProperty* alpha_property_; TfFrameProperty* frame_property_; }; From d57ec806d7d4d72816a1b6ce7071ce3e941a591c Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Wed, 3 Nov 2021 11:18:11 +0100 Subject: [PATCH 2/3] Reduce includes in header --- src/rviz/default_plugin/axes_display.cpp | 1 + src/rviz/default_plugin/axes_display.h | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rviz/default_plugin/axes_display.cpp b/src/rviz/default_plugin/axes_display.cpp index 51de30af2d..b141ede308 100644 --- a/src/rviz/default_plugin/axes_display.cpp +++ b/src/rviz/default_plugin/axes_display.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include diff --git a/src/rviz/default_plugin/axes_display.h b/src/rviz/default_plugin/axes_display.h index fa9fa72eb7..1e3cdadb16 100644 --- a/src/rviz/default_plugin/axes_display.h +++ b/src/rviz/default_plugin/axes_display.h @@ -32,7 +32,10 @@ #include -#include +namespace Ogre +{ +class RibbonTrail; +} namespace rviz { From 371d3bd170e46f365d1398170cf232588213df52 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Wed, 3 Nov 2021 12:20:28 +0100 Subject: [PATCH 3/3] Reset trail on Display::reset and change of reference frame --- src/rviz/default_plugin/axes_display.cpp | 22 +++++++++++++++++++--- src/rviz/default_plugin/axes_display.h | 4 +++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/rviz/default_plugin/axes_display.cpp b/src/rviz/default_plugin/axes_display.cpp index b141ede308..3c321557e0 100644 --- a/src/rviz/default_plugin/axes_display.cpp +++ b/src/rviz/default_plugin/axes_display.cpp @@ -45,9 +45,9 @@ namespace rviz { AxesDisplay::AxesDisplay() : Display(), axes_(nullptr), trail_(nullptr) { - frame_property_ = - new TfFrameProperty("Reference Frame", TfFrameProperty::FIXED_FRAME_STRING, - "The TF frame these axes will use for their origin.", this, nullptr, true); + frame_property_ = new TfFrameProperty("Reference Frame", TfFrameProperty::FIXED_FRAME_STRING, + "The TF frame these axes will use for their origin.", this, + nullptr, true, SLOT(resetTrail())); length_property_ = new FloatProperty("Length", 1.0, "Length of each axis, in meters.", this, SLOT(updateShape())); @@ -86,6 +86,22 @@ void AxesDisplay::onInitialize() axes_->getSceneNode()->setVisible(isEnabled()); } +void AxesDisplay::reset() +{ + Display::reset(); + resetTrail(false); +} + +void AxesDisplay::resetTrail(bool update) +{ + if (!trail_) + return; + if (update) + this->update(0.0, 0.0); + trail_->nodeUpdated(axes_->getSceneNode()); + trail_->clearAllChains(); +} + void AxesDisplay::onEnable() { axes_->getSceneNode()->setVisible(true); diff --git a/src/rviz/default_plugin/axes_display.h b/src/rviz/default_plugin/axes_display.h index 1e3cdadb16..098e425f2d 100644 --- a/src/rviz/default_plugin/axes_display.h +++ b/src/rviz/default_plugin/axes_display.h @@ -65,14 +65,16 @@ class AxesDisplay : public Display protected: // overrides from Display + void reset() override; void onEnable() override; void onDisable() override; private Q_SLOTS: /** @brief Update the length and radius of the axes object from property values. */ void updateShape(); - + /** @brief Create or Destroy trail based on boolean property */ void updateTrail(); + void resetTrail(bool update = true); private: Axes* axes_; ///< Handles actually drawing the axes