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

frame axes trail #1677

Merged
merged 3 commits into from
Nov 5, 2021
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
67 changes: 63 additions & 4 deletions src/rviz/default_plugin/axes_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <OGRE/OgreSceneNode.h>
#include <OGRE/OgreSceneManager.h>
#include <OGRE/OgreRibbonTrail.h>

#include <rviz/display_context.h>
#include <rviz/frame_manager.h>
Expand All @@ -42,11 +43,11 @@

namespace rviz
{
AxesDisplay::AxesDisplay() : Display(), axes_(nullptr)
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()));
Expand All @@ -56,6 +57,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);
Expand All @@ -64,6 +69,11 @@ AxesDisplay::AxesDisplay() : Display(), axes_(nullptr)

AxesDisplay::~AxesDisplay()
{
if (trail_)
{
scene_manager_->destroyRibbonTrail(trail_);
}

delete axes_;
}

Expand All @@ -76,14 +86,34 @@ 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);
if (trail_)
trail_->setVisible(true);
}

void AxesDisplay::onDisable()
{
axes_->getSceneNode()->setVisible(false);
if (trail_)
trail_->setVisible(false);
}

void AxesDisplay::updateShape()
Expand All @@ -92,6 +122,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();
Expand Down
11 changes: 11 additions & 0 deletions src/rviz/default_plugin/axes_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@

#include <rviz/display.h>

namespace Ogre
{
class RibbonTrail;
}

namespace rviz
{
class Axes;
Expand Down Expand Up @@ -60,18 +65,24 @@ 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
Ogre::RibbonTrail* trail_;

FloatProperty* length_property_;
FloatProperty* radius_property_;
Property* trail_property_;
FloatProperty* alpha_property_;
TfFrameProperty* frame_property_;
};
Expand Down