point_display.cpp
Go to the documentation of this file.
1 #include <OgreSceneNode.h>
2 #include <OgreSceneManager.h>
3 
8 #include <rviz/frame_manager.h>
9 #include <rviz/validate_floats.h>
10 
11 #include "point_visual.h"
12 
13 #include "point_display.h"
14 
15 namespace rviz
16 {
18 {
19  color_property_ = new rviz::ColorProperty("Color", QColor(204, 41, 204), "Color of a point", this,
20  SLOT(updateColorAndAlpha()));
21 
22  alpha_property_ = new rviz::FloatProperty("Alpha", 1.0, "0 is fully transparent, 1.0 is fully opaque.",
23  this, SLOT(updateColorAndAlpha()));
24 
26  new rviz::FloatProperty("Radius", 0.2, "Radius of a point", this, SLOT(updateColorAndAlpha()));
27 
29  new rviz::IntProperty("History Length", 1, "Number of prior measurements to display.", this,
30  SLOT(updateHistoryLength()));
33 }
34 
36 {
39 }
40 
42 {
43 }
44 
45 // Clear the visuals by deleting their objects.
47 {
49  visuals_.clear();
50 }
51 
52 // Set the current color and alpha values for each visual.
54 {
55  float alpha = alpha_property_->getFloat();
56  float radius = radius_property_->getFloat();
57  Ogre::ColourValue color = color_property_->getOgreColor();
58 
59  for (size_t i = 0; i < visuals_.size(); i++)
60  {
61  visuals_[i]->setColor(color.r, color.g, color.b, alpha);
62  visuals_[i]->setRadius(radius);
63  }
64 }
65 
66 // Set the number of past visuals to show.
68 {
69  visuals_.rset_capacity(history_length_property_->getInt());
70 }
71 
72 // This is our callback to handle an incoming message.
73 void PointStampedDisplay::processMessage(const geometry_msgs::PointStamped::ConstPtr& msg)
74 {
75  if (!rviz::validateFloats(msg->point))
76  {
78  "Message contained invalid floating point values (nans or infs)");
79  return;
80  }
81 
82  // Here we call the rviz::FrameManager to get the transform from the
83  // fixed frame to the frame in the header of this Point message. If
84  // it fails, we can't do anything else so we return.
85  Ogre::Quaternion orientation;
86  Ogre::Vector3 position;
87  if (!context_->getFrameManager()->getTransform(msg->header.frame_id, msg->header.stamp, position,
88  orientation))
89  {
90  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(),
91  qPrintable(fixed_frame_));
92  return;
93  }
94 
95  // We are keeping a circular buffer of visual pointers. This gets
96  // the next one, or creates and stores it if the buffer is not full
98  if (visuals_.full())
99  {
100  visual = visuals_.front();
101  }
102  else
103  {
105  }
106 
107 
108  // Now set or update the contents of the chosen visual.
109  float radius = radius_property_->getFloat();
110  visual->setRadius(radius); // has to be set before setting message
111  visual->setMessage(msg);
112  visual->setFramePosition(position);
113  visual->setFrameOrientation(orientation);
114  float alpha = alpha_property_->getFloat();
115  Ogre::ColourValue color = color_property_->getOgreColor();
116  visual->setColor(color.r, color.g, color.b, alpha);
117 
118 
119  // And send it to the end of the circular buffer
120  visuals_.push_back(visual);
121 }
122 
123 } // end namespace rviz
124 
125 // Tell pluginlib about this class. It is important to do this in
126 // global scope, outside our package's namespace.
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz...
Definition: display.h:287
boost::circular_buffer< boost::shared_ptr< PointStampedVisual > > visuals_
Definition: point_display.h:53
void reset() override
Called to tell the display to clear its state.
Ogre::ColourValue getOgreColor() const
void setMin(int min)
Property specialized to enforce floating point max/min.
Property specialized to provide max/min enforcement for integers.
Definition: int_property.h:37
rviz::FloatProperty * alpha_property_
Definition: point_display.h:57
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
void onInitialize() override
Override this function to do subclass-specific initialization.
void setMax(int max)
void processMessage(const geometry_msgs::PointStamped::ConstPtr &msg) override
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
bool validateFloats(const sensor_msgs::CameraInfo &msg)
rviz::FloatProperty * radius_property_
Definition: point_display.h:57
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
rviz::IntProperty * history_length_property_
Definition: point_display.h:58
virtual int getInt() const
Return the internal property value as an integer.
Definition: int_property.h:74
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
virtual float getFloat() const
bool getTransform(const Header &header, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Return the pose for a header, relative to the fixed frame, in Ogre classes.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:175
rviz::ColorProperty * color_property_
Definition: point_display.h:56
#define ROS_DEBUG(...)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25