line_strip_marker.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 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 "line_strip_marker.h"
31 
34 #include <rviz/display_context.h>
35 #include <rviz/validate_floats.h>
36 
38 
40 #include <OgreQuaternion.h>
41 #include <OgreSceneNode.h>
42 
43 namespace rviz
44 {
46  DisplayContext* context,
47  Ogre::SceneNode* parent_node)
48  : MarkerBase(owner, context, parent_node), lines_(nullptr)
49 {
50 }
51 
53 {
54  delete lines_;
55 }
56 
57 void LineStripMarker::onNewMessage(const MarkerConstPtr& /*old_message*/,
58  const MarkerConstPtr& new_message)
59 {
60  ROS_ASSERT(new_message->type == visualization_msgs::Marker::LINE_STRIP);
61 
62  if (!lines_)
63  {
65  }
66 
67  Ogre::Vector3 pos, scale;
68  Ogre::Quaternion orient;
69  if (!transform(new_message, pos, orient, scale))
70  {
71  scene_node_->setVisible(false);
72  return;
73  }
74 
75  scene_node_->setVisible(true);
76  setPosition(pos);
77  setOrientation(orient);
78  lines_->setScale(scale);
79  lines_->setColor(new_message->color.r, new_message->color.g, new_message->color.b,
80  new_message->color.a);
81 
82  lines_->clear();
83  if (new_message->points.empty())
84  {
85  return;
86  }
87 
88  lines_->setLineWidth(new_message->scale.x);
89  lines_->setMaxPointsPerLine(new_message->points.size());
90 
91  bool has_per_point_color = new_message->colors.size() == new_message->points.size();
92 
93  size_t i = 0;
94  std::vector<geometry_msgs::Point>::const_iterator it = new_message->points.begin();
95  std::vector<geometry_msgs::Point>::const_iterator end = new_message->points.end();
96  for (; it != end; ++it, ++i)
97  {
98  const geometry_msgs::Point& p = *it;
99 
100  Ogre::Vector3 v(p.x, p.y, p.z);
101  if (!validateFloats(p))
102  {
103  ROS_WARN("Marker '%s/%d': invalid point[%zu] (%.2f, %.2f, %.2f)", new_message->ns.c_str(),
104  new_message->id, i, p.x, p.y, p.z);
105  continue;
106  }
107 
108  Ogre::ColourValue c;
109  if (has_per_point_color)
110  {
111  const std_msgs::ColorRGBA& color = new_message->colors[i];
112  if (!validateFloats(color))
113  {
114  ROS_WARN("Marker '%s/%d': invalid color[%zu] (%.2f, %.2f, %.2f, %.2f)", new_message->ns.c_str(),
115  new_message->id, i, color.r, color.g, color.b, color.a);
116  continue;
117  }
118  c.r = color.r;
119  c.g = color.g;
120  c.b = color.b;
121  c.a = color.a;
122  }
123  else
124  {
125  c.r = new_message->color.r;
126  c.g = new_message->color.g;
127  c.b = new_message->color.b;
128  c.a = new_message->color.a;
129  }
130 
131  lines_->addPoint(v, c);
132  }
133 
134  handler_.reset(new MarkerSelectionHandler(this, MarkerID(new_message->ns, new_message->id), context_));
135  handler_->addTrackedObjects(lines_->getSceneNode());
136 }
137 
139 {
140  S_MaterialPtr materials;
141  materials.insert(lines_->getMaterial());
142  return materials;
143 }
144 
145 } // namespace rviz
rviz::BillboardLine::clear
void clear()
Definition: billboard_line.cpp:105
rviz::LineStripMarker::~LineStripMarker
~LineStripMarker() override
Definition: line_strip_marker.cpp:52
rviz::MarkerBase::context_
DisplayContext * context_
Definition: marker_base.h:108
rviz::BillboardLine::getSceneNode
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
Definition: billboard_line.h:92
rviz::BillboardLine
An object that displays a multi-segment line strip rendered as billboards.
Definition: billboard_line.h:58
rviz::BillboardLine::setScale
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: billboard_line.cpp:266
rviz::S_MaterialPtr
std::set< Ogre::MaterialPtr > S_MaterialPtr
Definition: marker_base.h:51
rviz::BillboardLine::setLineWidth
void setLineWidth(float width)
Definition: billboard_line.cpp:237
validate_floats.h
rviz::MarkerDisplay
Displays "markers" sent in by other ROS nodes on the "visualization_marker" topic.
Definition: marker_display.h:70
marker_selection_handler.h
rviz::MarkerBase::setPosition
virtual void setPosition(const Ogre::Vector3 &position)
Definition: marker_base.cpp:124
rviz::MarkerBase
Definition: marker_base.h:53
rviz::LineStripMarker::lines_
BillboardLine * lines_
Definition: line_strip_marker.h:52
marker_display.h
rviz::validateFloats
bool validateFloats(const sensor_msgs::CameraInfo &msg)
Definition: camera_display.cpp:72
rviz::MarkerBase::scene_node_
Ogre::SceneNode * scene_node_
Definition: marker_base.h:110
rviz::MarkerBase::setOrientation
virtual void setOrientation(const Ogre::Quaternion &orientation)
Definition: marker_base.cpp:129
rviz::MarkerBase::handler_
boost::shared_ptr< MarkerSelectionHandler > handler_
Definition: marker_base.h:116
rviz::BillboardLine::setMaxPointsPerLine
void setMaxPointsPerLine(uint32_t max)
Definition: billboard_line.cpp:169
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
rviz::LineStripMarker::onNewMessage
void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message) override
Definition: line_strip_marker.cpp:57
rviz::BillboardLine::getMaterial
Ogre::MaterialPtr getMaterial()
Definition: billboard_line.h:104
rviz::MarkerBase::transform
bool transform(const MarkerConstPtr &message, Ogre::Vector3 &pos, Ogre::Quaternion &orient, Ogre::Vector3 &scale)
Definition: marker_base.cpp:87
rviz
Definition: add_display_dialog.cpp:54
rviz::MarkerSelectionHandler
Definition: marker_selection_handler.h:45
ogre_vector.h
ROS_WARN
#define ROS_WARN(...)
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
billboard_line.h
rviz::LineStripMarker::LineStripMarker
LineStripMarker(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
Definition: line_strip_marker.cpp:45
rviz::MarkerID
std::pair< std::string, int32_t > MarkerID
Definition: interactive_marker_display.h:58
rviz::LineStripMarker::getMaterials
S_MaterialPtr getMaterials() override
Definition: line_strip_marker.cpp:138
display_context.h
line_strip_marker.h
ROS_ASSERT
#define ROS_ASSERT(cond)
rviz::MarkerBase::MarkerConstPtr
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:57
rviz::BillboardLine::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: billboard_line.cpp:271
rviz::BillboardLine::addPoint
void addPoint(const Ogre::Vector3 &point)
Definition: billboard_line.cpp:208


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Aug 2 2024 08:43:09