range_display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <OgreSceneNode.h>
31 #include <OgreSceneManager.h>
32 
33 #include <rviz/display_context.h>
34 #include <rviz/frame_manager.h>
40 
41 #include "range_display.h"
42 #include <limits>
43 
44 namespace rviz
45 {
47 {
48  color_property_ = new ColorProperty("Color", Qt::white, "Color to draw the range.", this,
50 
51  alpha_property_ = new FloatProperty("Alpha", 0.5, "Amount of transparency to apply to the range.",
53 
55  new IntProperty("Buffer Length", 1, "Number of prior measurements to display.", this,
58 }
59 
61 {
65 }
66 
68 {
69  for (size_t i = 0; i < cones_.size(); i++)
70  {
71  delete cones_[i];
72  }
73 }
74 
76 {
79 }
80 
82 {
83  Ogre::ColourValue oc = color_property_->getOgreColor();
84  float alpha = alpha_property_->getFloat();
85  for (size_t i = 0; i < cones_.size(); i++)
86  {
87  cones_[i]->setColor(oc.r, oc.g, oc.b, alpha);
88  }
90 }
91 
93 {
94  int buffer_length = buffer_length_property_->getInt();
95  QColor color = color_property_->getColor();
96 
97  for (size_t i = 0; i < cones_.size(); i++)
98  {
99  delete cones_[i];
100  }
101  cones_.resize(buffer_length);
102  for (size_t i = 0; i < cones_.size(); i++)
103  {
105  cones_[i] = cone;
106 
107  Ogre::Vector3 position;
108  Ogre::Quaternion orientation;
109  geometry_msgs::Pose pose;
110  pose.orientation.w = 1;
111  Ogre::Vector3 scale(0, 0, 0);
112  cone->setScale(scale);
113  cone->setColor(color.redF(), color.greenF(), color.blueF(), 0);
114  }
115 }
116 
117 void RangeDisplay::processMessage(const sensor_msgs::Range::ConstPtr& msg)
118 {
120 
121  Ogre::Vector3 position;
122  Ogre::Quaternion orientation;
123  geometry_msgs::Pose pose;
124  float displayed_range = 0.0;
125  if (msg->min_range <= msg->range && msg->range <= msg->max_range)
126  {
127  displayed_range = msg->range;
128  }
129  else if (msg->min_range == msg->max_range)
130  { // Fixed distance ranger
131  if (msg->range < 0 && !std::isfinite(msg->range))
132  { // NaNs and +Inf return false here: both of those should have 0.0 as the range
133  displayed_range = msg->min_range; // -Inf, display the detectable range
134  }
135  }
136 
137  pose.position.x =
138  displayed_range / 2 -
139  .008824 * displayed_range; // .008824 fudge factor measured, must be inaccuracy of cone model.
140  pose.orientation.z = 0.707;
141  pose.orientation.w = 0.707;
142  if (!context_->getFrameManager()->transform(msg->header.frame_id, msg->header.stamp, pose, position,
143  orientation))
144  {
145  ROS_DEBUG("Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(),
146  qPrintable(fixed_frame_));
147  }
148 
149  cone->setPosition(position);
150  cone->setOrientation(orientation);
151 
152  double cone_width = 2.0 * displayed_range * tan(msg->field_of_view / 2.0);
153  Ogre::Vector3 scale(cone_width, displayed_range, cone_width);
154  cone->setScale(scale);
155 
156  QColor color = color_property_->getColor();
157  cone->setColor(color.redF(), color.greenF(), color.blueF(), alpha_property_->getFloat());
158 }
159 
160 } // namespace rviz
161 
shape.h
rviz::IntProperty::setMin
void setMin(int min)
Definition: int_property.cpp:52
rviz::ColorProperty::getColor
virtual QColor getColor() const
Definition: color_property.h:79
rviz::MessageFilterDisplay< sensor_msgs::Range >::reset
void reset() override
Definition: message_filter_display.h:125
frame_manager.h
rviz::DisplayContext::queueRender
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
rviz::Shape::setColor
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
Definition: shape.cpp:136
int_property.h
rviz::RangeDisplay::processMessage
void processMessage(const sensor_msgs::Range::ConstPtr &msg) override
Overridden from MessageFilterDisplay.
Definition: range_display.cpp:117
range_display.h
rviz::RangeDisplay::RangeDisplay
RangeDisplay()
Definition: range_display.cpp:46
rviz::Shape::Cone
@ Cone
Definition: shape.h:56
float_property.h
rviz::RangeDisplay
Displays a sensor_msgs::Range message as a cone.
Definition: range_display.h:52
rviz::Display::fixed_frame_
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
rviz::RangeDisplay::reset
void reset() override
Overridden from Display.
Definition: range_display.cpp:75
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
rviz::ColorProperty
Definition: color_property.h:40
rviz::Display
Definition: display.h:63
rviz::FloatProperty
Property specialized to enforce floating point max/min.
Definition: float_property.h:37
rviz::RangeDisplay::onInitialize
void onInitialize() override
Overridden from Display.
Definition: range_display.cpp:60
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz::FloatProperty::getFloat
virtual float getFloat() const
Definition: float_property.h:79
ROS_DEBUG
#define ROS_DEBUG(...)
rviz
Definition: add_display_dialog.cpp:54
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
color_property.h
rviz::RangeDisplay::color_property_
ColorProperty * color_property_
Definition: range_display.h:76
rviz::RangeDisplay::updateColorAndAlpha
void updateColorAndAlpha()
Definition: range_display.cpp:81
rviz::RangeDisplay::buffer_length_property_
IntProperty * buffer_length_property_
Definition: range_display.h:78
rviz::RangeDisplay::alpha_property_
FloatProperty * alpha_property_
Definition: range_display.h:77
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const =0
Return the FrameManager instance.
rviz::MessageFilterDisplay< sensor_msgs::Range >::messages_received_
uint32_t messages_received_
Definition: message_filter_display.h:233
rviz::MessageFilterDisplay< sensor_msgs::Range >::onInitialize
void onInitialize() override
Definition: message_filter_display.h:105
rviz::Display::context_
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz....
Definition: display.h:287
rviz::RangeDisplay::updateBufferLength
void updateBufferLength()
Definition: range_display.cpp:92
rviz::Shape
Definition: shape.h:51
class_list_macros.hpp
rviz::FrameManager::transform
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
Transform a pose from a frame into the fixed frame.
Definition: frame_manager.h:148
rviz::RangeDisplay::~RangeDisplay
~RangeDisplay() override
Definition: range_display.cpp:67
rviz::IntProperty::getInt
virtual int getInt() const
Return the internal property value as an integer.
Definition: int_property.h:96
rviz::RangeDisplay::cones_
std::vector< Shape * > cones_
Handles actually drawing the cones.
Definition: range_display.h:74
display_context.h
rviz::Shape::setScale
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: shape.cpp:156
rviz::Shape::setPosition
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: shape.cpp:146
rviz::Shape::setOrientation
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: shape.cpp:151
rviz::ColorProperty::getOgreColor
Ogre::ColourValue getOgreColor() const
Definition: color_property.h:83
rviz::IntProperty
Property specialized to provide max/min enforcement for integers.
Definition: int_property.h:37
parse_color.h


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02