Newer
Older
#include <OGRE/OgreSceneNode.h>
#include <OGRE/OgreSceneManager.h>
#include <tf/transform_listener.h>
#include <rviz/visualization_manager.h>
#include <rviz/properties/color_property.h>
#include <rviz/properties/float_property.h>
#include <rviz/default_plugin/covariance_property.h>
#include <rviz/properties/int_property.h>
#include <rviz/frame_manager.h>
#include "perceptions_display.h"
namespace rviz_multiception
{
// The constructor must have no arguments, so we can't give the
// constructor the parameters it needs to fully initialize.
PerceptionsDisplay::PerceptionsDisplay()
{
color_property_ = new rviz::ColorProperty( "Color", QColor( 204, 51, 204 ),
"Color to draw the arrows.",
this, SLOT( updateColorAndAlpha() ));
alpha_property_ = new rviz::FloatProperty( "Alpha", 1.0,
"Object transparency, 0 is fully transparent, 1.0 is fully opaque.",
this, SLOT( updateColorAndAlpha() ));
covariance_property_ = new rviz::CovarianceProperty( "Covariance", true, "Whether or not the covariances of the messages should be shown.",
this, SLOT( queueRender() ));
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
}
// After the top-level rviz::Display::initialize() does its own setup,
// it calls the subclass's onInitialize() function. This is where we
// instantiate all the workings of the class. We make sure to also
// call our immediate super-class's onInitialize() function, since it
// does important stuff setting up the message filter.
//
// Note that "MFDClass" is a typedef of
// ``MessageFilterDisplay<message type>``, to save typing that long
// templated class name every time you need to refer to the
// superclass.
void PerceptionsDisplay::onInitialize()
{
MFDClass::onInitialize();
}
PerceptionsDisplay::~PerceptionsDisplay()
{
}
// Clear the visuals by deleting their objects.
void PerceptionsDisplay::reset()
{
MFDClass::reset();
visuals_.clear();
}
// Set the current color and alpha values for each visual.
void PerceptionsDisplay::updateColorAndAlpha()
{
float alpha = alpha_property_->getFloat();
Ogre::ColourValue color = color_property_->getOgreColor();
for(size_t i=0; i<visuals_.size(); i++)
{
visuals_[i]->setColor(color.r, color.g, color.b, alpha);
}
}
// This is our callback to handle an incoming message.
void PerceptionsDisplay::processMessage(const multiception::Perceptions::ConstPtr& msg)
{
// Here we call the rviz::FrameManager to get the transform from the
// fixed frame to the frame in the header of this message. If
// it fails, we can't do anything else so we return.
const size_t N = msg->perceptions.size();
if(N==0)
{
return;
}
// We are keeping a vector of state visual pointers
visuals_.clear();
visuals_.reserve(N);
for(const multiception::Perception& perception : msg->perceptions)
{
Ogre::Quaternion orientation;
Ogre::Vector3 position;
if(!context_->getFrameManager()->getTransform(perception.header.frame_id, perception.header.stamp, position, orientation))
{
ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", perception.header.frame_id.c_str(), qPrintable(fixed_frame_));
return;
}
boost::shared_ptr<StateVisual> state(new StateVisual(context_->getSceneManager(), scene_node_, covariance_property_));
// Now set or update the contents of the chosen visual.
state->setContent(perception.state);
state->setFramePosition(position);
state->setFrameOrientation(orientation);
float alpha = alpha_property_->getFloat();
Ogre::ColourValue color = color_property_->getOgreColor();
state->setColor(color.r, color.g, color.b, alpha);
}
} // end namespace rviz_multiception
// Tell pluginlib about this class. It is important to do this in
// global scope, outside our package's namespace.
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(rviz_multiception::PerceptionsDisplay,rviz::Display)