points_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 "points_marker.h"
32 #include "rviz/display_context.h"
35 
37 
38 #include <OgreVector3.h>
39 #include <OgreQuaternion.h>
40 #include <OgreSceneNode.h>
41 #include <OgreSceneManager.h>
42 
43 namespace rviz
44 {
45 PointsMarker::PointsMarker(MarkerDisplay* owner, DisplayContext* context, Ogre::SceneNode* parent_node)
46  : MarkerBase(owner, context, parent_node), points_(nullptr)
47 {
48 }
49 
51 {
52  delete points_;
53 }
54 
55 void PointsMarker::onNewMessage(const MarkerConstPtr& /*old_message*/, const MarkerConstPtr& new_message)
56 {
57  ROS_ASSERT(new_message->type == visualization_msgs::Marker::POINTS ||
58  new_message->type == visualization_msgs::Marker::CUBE_LIST ||
59  new_message->type == visualization_msgs::Marker::SPHERE_LIST);
60 
61  if (!points_)
62  {
63  points_ = new PointCloud();
64  scene_node_->attachObject(points_);
65  }
66 
67  Ogre::Vector3 pos, scale;
68  Ogre::Quaternion orient;
69  transform(new_message, pos, orient, scale);
70 
71  switch (new_message->type)
72  {
73  case visualization_msgs::Marker::POINTS:
75  points_->setDimensions(new_message->scale.x, new_message->scale.y, 0.0f);
76  break;
77  case visualization_msgs::Marker::CUBE_LIST:
79  points_->setDimensions(scale.x, scale.y, scale.z);
80  break;
81  case visualization_msgs::Marker::SPHERE_LIST:
83  points_->setDimensions(scale.x, scale.y, scale.z);
84  break;
85  }
86 
87  setPosition(pos);
88  setOrientation(orient);
89 
90  points_->clear();
91 
92  if (new_message->points.empty())
93  {
94  return;
95  }
96 
97  float r = new_message->color.r;
98  float g = new_message->color.g;
99  float b = new_message->color.b;
100  float a = new_message->color.a;
101 
102  bool has_per_point_color = new_message->colors.size() == new_message->points.size();
103 
104  bool has_nonzero_alpha = false;
105  bool has_per_point_alpha = false;
106 
107  typedef std::vector<PointCloud::Point> V_Point;
108  V_Point points;
109  points.resize(new_message->points.size());
110  std::vector<geometry_msgs::Point>::const_iterator it = new_message->points.begin();
111  std::vector<geometry_msgs::Point>::const_iterator end = new_message->points.end();
112  for (int i = 0; it != end; ++it, ++i)
113  {
114  const geometry_msgs::Point& p = *it;
115  PointCloud::Point& point = points[i];
116 
117  Ogre::Vector3 v(p.x, p.y, p.z);
118 
119  point.position.x = v.x;
120  point.position.y = v.y;
121  point.position.z = v.z;
122 
123  if (has_per_point_color)
124  {
125  const std_msgs::ColorRGBA& color = new_message->colors[i];
126  r = color.r;
127  g = color.g;
128  b = color.b;
129  a = color.a;
130  has_nonzero_alpha = has_nonzero_alpha || a != 0.0;
131  has_per_point_alpha = has_per_point_alpha || a != 1.0;
132  }
133 
134  point.setColor(r, g, b, a);
135  }
136 
137  if (has_per_point_color)
138  {
139  points_->setAlpha(1.0, has_per_point_alpha);
140  }
141  else
142  {
143  points_->setAlpha(a);
144  }
145 
146  points_->addPoints(&points.front(), points.size());
147 
148  handler_.reset(new MarkerSelectionHandler(this, MarkerID(new_message->ns, new_message->id), context_));
150 }
151 
152 void PointsMarker::setHighlightColor(float r, float g, float b)
153 {
154  points_->setHighlightColor(r, g, b);
155 }
156 
157 } // end namespace rviz
void addPoints(Point *points, uint32_t num_points)
Add points to this point cloud.
Ogre::SceneNode * scene_node_
Definition: marker_base.h:116
bool transform(const MarkerConstPtr &message, Ogre::Vector3 &pos, Ogre::Quaternion &orient, Ogre::Vector3 &scale)
Definition: marker_base.cpp:83
void setRenderMode(RenderMode mode)
Set what type of rendering primitives should be used, currently points, billboards and boxes are supp...
void setPickColor(const Ogre::ColourValue &color)
PointsMarker(MarkerDisplay *owner, DisplayContext *context, Ogre::SceneNode *parent_node)
static Ogre::ColourValue handleToColor(CollObjectHandle handle)
virtual void setPosition(const Ogre::Vector3 &position)
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:122
Representation of a point, with x/y/z position and r/g/b color.
Definition: point_cloud.h:132
void setDimensions(float width, float height, float depth)
Set the dimensions of the billboards used to render each point.
Ogre::Vector3 position
Definition: point_cloud.h:139
DisplayContext * context_
Definition: marker_base.h:114
void setAlpha(float alpha, bool per_point_alpha=false)
void clear()
Clear all the points.
PointCloud * points_
Definition: points_marker.h:57
visualization_msgs::Marker::ConstPtr MarkerConstPtr
Definition: marker_base.h:63
void setHighlightColor(float r, float g, float b)
A visual representation of a set of points.
Definition: point_cloud.h:107
virtual void setOrientation(const Ogre::Quaternion &orientation)
#define ROS_ASSERT(cond)
r
Displays "markers" sent in by other ROS nodes on the "visualization_marker" topic.
void setHighlightColor(float r, float g, float b)
void setColor(float r, float g, float b, float a=1.0)
Definition: point_cloud.h:134
~PointsMarker() override
void onNewMessage(const MarkerConstPtr &old_message, const MarkerConstPtr &new_message) override


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