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

Add ability to set alpha channel value of Axes and TF displays #1357

Merged
merged 1 commit into from
Mar 29, 2019
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
10 changes: 8 additions & 2 deletions src/rviz/default_plugin/axes_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ AxesDisplay::AxesDisplay()
"Radius of each axis, in meters.",
this, SLOT( updateShape() ));
radius_property_->setMin( 0.0001 );

alpha_property_ = new FloatProperty( "Alpha", 1.0,
"Alpha channel value of each axis.",
this, SLOT( updateShape() ));
alpha_property_->setMin( 0.0 );
alpha_property_->setMax( 1.0 );
}

AxesDisplay::~AxesDisplay()
Expand All @@ -82,7 +88,7 @@ void AxesDisplay::onInitialize()
{
frame_property_->setFrameManager( context_->getFrameManager() );

axes_ = new Axes( scene_manager_, 0, length_property_->getFloat(), radius_property_->getFloat() );
axes_ = new Axes( scene_manager_, 0, length_property_->getFloat(), radius_property_->getFloat(), alpha_property_->getFloat() );
axes_->getSceneNode()->setVisible( isEnabled() );
}

Expand All @@ -98,7 +104,7 @@ void AxesDisplay::onDisable()

void AxesDisplay::updateShape()
{
axes_->set( length_property_->getFloat(), radius_property_->getFloat() );
axes_->set( length_property_->getFloat(), radius_property_->getFloat(), alpha_property_->getFloat() );
context_->queueRender();
}

Expand Down
1 change: 1 addition & 0 deletions src/rviz/default_plugin/axes_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private Q_SLOTS:

FloatProperty* length_property_;
FloatProperty* radius_property_;
FloatProperty* alpha_property_;
TfFrameProperty* frame_property_;
};

Expand Down
6 changes: 6 additions & 0 deletions src/rviz/default_plugin/tf_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ TFDisplay::TFDisplay()

scale_property_ = new FloatProperty( "Marker Scale", 1, "Scaling factor for all names, axes and arrows.", this );

alpha_property_ = new FloatProperty( "Marker Alpha", 1, "Alpha channel value for all axes.", this );
alpha_property_->setMin( 0 );
alpha_property_->setMax( 1 );

update_rate_property_ = new FloatProperty( "Update Interval", 0,
"The interval, in seconds, at which to update the frame transforms. 0 means to do so every update cycle.",
this );
Expand Down Expand Up @@ -598,6 +602,8 @@ void TFDisplay::updateFrame( FrameInfo* frame )
frame->axes_->getSceneNode()->setVisible( show_axes_property_->getBool() && frame_enabled);
float scale = scale_property_->getFloat();
frame->axes_->setScale( Ogre::Vector3( scale, scale, scale ));
float alpha = alpha_property_->getFloat();
frame->axes_->updateAlpha( alpha );

frame->name_node_->setPosition( position );
frame->name_node_->setVisible( show_names_property_->getBool() && frame_enabled );
Expand Down
1 change: 1 addition & 0 deletions src/rviz/default_plugin/tf_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ private Q_SLOTS:
BoolProperty* all_enabled_property_;

FloatProperty* scale_property_;
FloatProperty* alpha_property_;

Property* frames_category_;
Property* tree_category_;
Expand Down
30 changes: 19 additions & 11 deletions src/rviz/ogre_helpers/axes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
namespace rviz
{

Axes::Axes( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, float length, float radius )
: Object( scene_manager )
Axes::Axes( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, float length, float radius, float alpha )
: Object( scene_manager ),
default_x_color_( 1, 0, 0, alpha ),
default_y_color_( 0, 1, 0, alpha ),
default_z_color_( 0, 0, 1, alpha )

{
if ( !parent_node )
{
Expand All @@ -54,7 +58,7 @@ Axes::Axes( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, flo
y_axis_ = new Shape( Shape::Cylinder, scene_manager_, scene_node_ );
z_axis_ = new Shape( Shape::Cylinder, scene_manager_, scene_node_ );

set( length, radius );
set( length, radius, alpha );
}

Axes::~Axes()
Expand All @@ -66,7 +70,7 @@ Axes::~Axes()
scene_manager_->destroySceneNode( scene_node_->getName() );
}

void Axes::set( float length, float radius )
void Axes::set( float length, float radius, float alpha )
{
x_axis_->setScale(Ogre::Vector3( radius, length, radius ));
y_axis_->setScale(Ogre::Vector3( radius, length, radius ));
Expand All @@ -78,6 +82,7 @@ void Axes::set( float length, float radius )
z_axis_->setPosition( Ogre::Vector3( 0.0, 0.0f, length/2.0f ) );
z_axis_->setOrientation( Ogre::Quaternion( Ogre::Degree( 90 ), Ogre::Vector3::UNIT_X ) );

updateAlpha(alpha);
setToDefaultColors();
}

Expand Down Expand Up @@ -134,16 +139,19 @@ void Axes::setZColor(const Ogre::ColourValue& col)
z_axis_->setColor(col.r, col.g, col.b, col.a);
}

void Axes::setToDefaultColors()
void Axes::updateAlpha(float alpha)
{
x_axis_->setColor( 1.0f, 0.0f, 0.0f, 1.0f );
y_axis_->setColor( 0.0f, 1.0f, 0.0f, 1.0f );
z_axis_->setColor( 0.0f, 0.0f, 1.0f, 1.0f );
default_x_color_.a = alpha;
default_y_color_.a = alpha;
default_z_color_.a = alpha;
}

const Ogre::ColourValue Axes::default_x_color_( 1, 0, 0, 1 );
const Ogre::ColourValue Axes::default_y_color_( 0, 1, 0, 1 );
const Ogre::ColourValue Axes::default_z_color_( 0, 0, 1, 1 );
void Axes::setToDefaultColors()
{
x_axis_->setColor(default_x_color_);
y_axis_->setColor(default_y_color_);
z_axis_->setColor(default_z_color_);
}

const Ogre::ColourValue& Axes::getDefaultXColor()
{
Expand Down
23 changes: 14 additions & 9 deletions src/rviz/ogre_helpers/axes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@

#include <vector>

#include <OgreColourValue.h>

namespace Ogre
{
class SceneManager;
class SceneNode;
class Vector3;
class Quaternion;
class Any;
class ColourValue;
}

namespace rviz
Expand All @@ -65,17 +66,19 @@ class RVIZ_EXPORT Axes : public Object
* @param parent_node A scene node to use as the parent of this object. If NULL, uses the root scene node.
* @param length Length of the axes
* @param radius Radius of the axes
* @param alpha Alpha channel value of the axes
*/
Axes( Ogre::SceneManager* manager, Ogre::SceneNode* parent_node = NULL, float length = 1.0f, float radius = 0.1f );
Axes( Ogre::SceneManager* manager, Ogre::SceneNode* parent_node = NULL, float length = 1.0f, float radius = 0.1f, float alpha = 1.0f );
virtual ~Axes();

/**
* \brief Set the parameters on this object
*
* @param length Length of the axes
* @param radius Radius of the axes
* @param alpha Alpha channel value of the axes
*/
void set( float length, float radius );
void set( float length, float radius , float alpha = 1.0f );

virtual void setOrientation( const Ogre::Quaternion& orientation );
virtual void setPosition( const Ogre::Vector3& position );
Expand All @@ -102,10 +105,12 @@ class RVIZ_EXPORT Axes : public Object
void setXColor(const Ogre::ColourValue& col);
void setYColor(const Ogre::ColourValue& col);
void setZColor(const Ogre::ColourValue& col);
void updateAlpha(float alpha);
void setToDefaultColors();
static const Ogre::ColourValue& getDefaultXColor();
static const Ogre::ColourValue& getDefaultYColor();
static const Ogre::ColourValue& getDefaultZColor();
const Ogre::ColourValue& getDefaultXColor();
const Ogre::ColourValue& getDefaultYColor();
const Ogre::ColourValue& getDefaultZColor();


private:

Expand All @@ -119,9 +124,9 @@ class RVIZ_EXPORT Axes : public Object
Shape* y_axis_; ///< Cylinder for the Y-axis
Shape* z_axis_; ///< Cylinder for the Z-axis

static const Ogre::ColourValue default_x_color_;
static const Ogre::ColourValue default_y_color_;
static const Ogre::ColourValue default_z_color_;
Ogre::ColourValue default_x_color_;
Ogre::ColourValue default_y_color_;
Ogre::ColourValue default_z_color_;
};

} // namespace rviz
Expand Down