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 
37 
38 #include <OgreVector3.h>
39 #include <OgreQuaternion.h>
40 #include <OgreSceneNode.h>
41 
42 namespace rviz
43 {
44 
45 LineStripMarker::LineStripMarker(MarkerDisplay* owner, DisplayContext* context, Ogre::SceneNode* parent_node)
46 : MarkerBase(owner, context, parent_node)
47 , lines_(0)
48 {
49 }
50 
52 {
53  delete lines_;
54 }
55 
56 void LineStripMarker::onNewMessage(const MarkerConstPtr& old_message, const MarkerConstPtr& new_message)
57 {
58  ROS_ASSERT(new_message->type == visualization_msgs::Marker::LINE_STRIP);
59 
60  if (!lines_)
61  {
63  }
64 
65  Ogre::Vector3 pos, scale;
66  Ogre::Quaternion orient;
67  transform(new_message, pos, orient, scale);
68 
69  setPosition(pos);
70  setOrientation(orient);
71  lines_->setScale(scale);
72  lines_->setColor(new_message->color.r, new_message->color.g, new_message->color.b, new_message->color.a);
73 
74  lines_->clear();
75  if (new_message->points.empty())
76  {
77  return;
78  }
79 
80  lines_->setLineWidth(new_message->scale.x);
81  lines_->setMaxPointsPerLine(new_message->points.size());
82 
83  bool has_per_point_color = new_message->colors.size() == new_message->points.size();
84 
85  size_t i = 0;
86  std::vector<geometry_msgs::Point>::const_iterator it = new_message->points.begin();
87  std::vector<geometry_msgs::Point>::const_iterator end = new_message->points.end();
88  for ( ; it != end; ++it, ++i )
89  {
90  const geometry_msgs::Point& p = *it;
91 
92  Ogre::Vector3 v( p.x, p.y, p.z );
93 
94  Ogre::ColourValue c;
95  if (has_per_point_color)
96  {
97  const std_msgs::ColorRGBA& color = new_message->colors[i];
98  c.r = color.r;
99  c.g = color.g;
100  c.b = color.b;
101  c.a = color.a;
102  }
103  else
104  {
105  c.r = new_message->color.r;
106  c.g = new_message->color.g;
107  c.b = new_message->color.b;
108  c.a = new_message->color.a;
109  }
110 
111  lines_->addPoint( v, c );
112  }
113 
114  handler_.reset( new MarkerSelectionHandler( this, MarkerID( new_message->ns, new_message->id ), context_ ));
115  handler_->addTrackedObjects( lines_->getSceneNode() );
116 }
117 
119 {
120  S_MaterialPtr materials;
121  materials.insert( lines_->getMaterial() );
122  return materials;
123 }
124 
125 }
Ogre::SceneNode * scene_node_
Definition: marker_base.h:104
bool transform(const MarkerConstPtr &message, Ogre::Vector3 &pos, Ogre::Quaternion &orient, Ogre::Vector3 &scale)
Definition: marker_base.cpp:88
void addPoint(const Ogre::Vector3 &point)
virtual S_MaterialPtr getMaterials()
An object that displays a multi-segment line strip rendered as billboards.
BillboardLine * lines_
virtual void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message)
Ogre::MaterialPtr getMaterial()
virtual void setPosition(const Ogre::Vector3 &position)
Ogre::SceneNode * getSceneNode()
Get the scene node associated with this object.
virtual void setColor(float r, float g, float b, float a)
Set the color of the object. Values are in the range [0, 1].
std::pair< std::string, int32_t > MarkerID
Pure-virtual base class for objects which give Display subclasses context in which to work...
boost::shared_ptr< MarkerSelectionHandler > handler_
Definition: marker_base.h:110
DisplayContext * context_
Definition: marker_base.h:102
void setMaxPointsPerLine(uint32_t max)
LineStripMarker(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:63
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
virtual void setScale(const Ogre::Vector3 &scale)
Set the scale of the object. Always relative to the identity orientation of the object.
std::set< Ogre::MaterialPtr > S_MaterialPtr
Definition: marker_base.h:57
virtual void setOrientation(const Ogre::Quaternion &orientation)
#define ROS_ASSERT(cond)
Displays "markers" sent in by other ROS nodes on the "visualization_marker" topic.
void setLineWidth(float width)


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51