human_skeleton_array_display.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019, JSK Lab
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/o2r other materials provided
16  * with the distribution.
17  * * Neither the name of the JSK Lab nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
37 namespace jsk_rviz_plugins
38 {
40  {
42  "coloring", "Auto",
43  "coloring method",
44  this, SLOT(updateColoring()));
45  coloring_property_->addOption("Auto", 0);
46  coloring_property_->addOption("Flat color", 1);
47 
49  "color", QColor(25, 255, 0),
50  "color to draw the edges",
51  this, SLOT(updateColor()));
53  "alpha", 1.0,
54  "alpha value to draw the edges",
55  this, SLOT(updateAlpha()));
57  "line width", 0.005,
58  "line width of the edges",
59  this, SLOT(updateLineWidth()));
60  }
61 
63  {
64  delete color_property_;
65  delete alpha_property_;
66  delete coloring_property_;
67  }
68 
70  {
71  if (coloring_method_ == "auto") {
72  std_msgs::ColorRGBA ros_color = jsk_topic_tools::colorCategory20(index);
73  return QColor(ros_color.r * 255.0,
74  ros_color.g * 255.0,
75  ros_color.b * 255.0,
76  ros_color.a * 255.0);
77  }
78  else if (coloring_method_ == "flat") {
79  return color_;
80  }
81  }
82 
84  {
86  scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
87 
88  updateColor();
89  updateAlpha();
92  }
93 
95  {
97  if (latest_msg_) {
99  }
100  }
101 
103  {
105  if (latest_msg_) {
107  }
108  }
109 
111  {
113  if (latest_msg_) {
115  }
116  }
117 
119  {
120  if (coloring_property_->getOptionInt() == 0) {
121  coloring_method_ = "auto";
123  }
124  else if (coloring_property_->getOptionInt() == 1) {
125  coloring_method_ = "flat";
127  }
128 
129  if (latest_msg_) {
131  }
132  }
133 
135  {
136  MFDClass::reset();
137  edges_.clear();
138  latest_msg_.reset();
139  }
140 
142  if (num > shapes_.size()) {
143  for (size_t i = shapes_.size(); i < num; i++) {
144  ShapePtr shape;
146  scene_node_));
147  shapes_.push_back(shape);
148  }
149  }
150  else if (num < shapes_.size()) {
151  shapes_.resize(num);
152  }
153  }
154 
156  {
157  if (num > edges_.size()) {
158  for (size_t i = edges_.size(); i < num; i++) {
160  this->context_->getSceneManager(), this->scene_node_));
161  edges_.push_back(line);
162  }
163  }
164  else if (num < edges_.size())
165  {
166  edges_.resize(num); // ok??
167  }
168  }
169 
171  const jsk_recognition_msgs::HumanSkeletonArray::ConstPtr& msg)
172  {
173  int line_num = 0;
174  for (size_t i = 0; i < msg->skeletons.size(); i++) {
175  line_num = line_num + msg->skeletons[i].bones.size();
176  }
177  allocateBillboardLines(line_num);
178  allocateSpheres(2 * line_num);
179  int line_i = 0;
180  for (size_t i = 0; i < msg->skeletons.size(); i++) {
181  for (size_t j = 0; j < msg->skeletons[i].bones.size(); j++) {
182  jsk_recognition_msgs::Segment edge_msg = msg->skeletons[i].bones[j];
183  BillboardLinePtr edge = edges_[line_i];
184  ShapePtr start_shape = shapes_[2 * line_i];
185  ShapePtr end_shape = shapes_[2 * line_i + 1];
186  edge->clear();
187 
188  geometry_msgs::Pose start_pose_local;
189  geometry_msgs::Pose end_pose_local;
190  start_pose_local.position = edge_msg.start_point;
191  start_pose_local.orientation.w = 1.0;
192  end_pose_local.position = edge_msg.end_point;
193  end_pose_local.orientation.w = 1.0;
194 
195  Ogre::Vector3 start_point;
196  Ogre::Vector3 end_point;
197  Ogre::Quaternion quaternion; // not used to visualize
198  bool transform_ret;
199  transform_ret =
200  context_->getFrameManager()->transform(msg->header, start_pose_local, start_point, quaternion)
201  && context_->getFrameManager()->transform(msg->header, end_pose_local, end_point, quaternion);
202  if(!transform_ret) {
203  ROS_ERROR( "Error transforming pose"
204  "'%s' from frame '%s' to frame '%s'",
205  qPrintable( getName() ), msg->header.frame_id.c_str(),
206  qPrintable( fixed_frame_ ));
207  return; // return?
208  }
209  edge->addPoint(start_point);
210  edge->addPoint(end_point);
211  edge->setLineWidth(line_width_);
212  QColor color = getColor(i);
213  edge->setColor(color.red() / 255.0,
214  color.green() / 255.0,
215  color.blue() / 255.0,
216  alpha_);
217 
218  Ogre::Vector3 scale;
219  scale[0] = 2.0 * line_width_;
220  scale[1] = 2.0 * line_width_;
221  scale[2] = 2.0 * line_width_;
222  start_shape->setPosition(start_point);
223  start_shape->setScale(scale);
224  start_shape->setOrientation(quaternion);
225  start_shape->setColor(color.red() / 255.0,
226  color.green() / 255.0,
227  color.blue() / 255.0,
228  alpha_);
229  end_shape->setPosition(end_point);
230  end_shape->setScale(scale);
231  end_shape->setOrientation(quaternion);
232  end_shape->setColor(color.red() / 255.0,
233  color.green() / 255.0,
234  color.blue() / 255.0,
235  alpha_);
236  line_i++;
237  }
238  }
239  }
240 
242  const jsk_recognition_msgs::HumanSkeletonArray::ConstPtr& msg)
243  {
244  // Store latest message
245  latest_msg_ = msg;
246 
247  showEdges(msg);
248  }
249 }
250 
virtual QColor getColor() const
jsk_recognition_msgs::HumanSkeletonArray::ConstPtr latest_msg_
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
DisplayContext * context_
virtual void showEdges(const jsk_recognition_msgs::HumanSkeletonArray::ConstPtr &msg)
virtual float getFloat() const
void processMessage(const jsk_recognition_msgs::HumanSkeletonArray::ConstPtr &msg)
Ogre::SceneNode * scene_node_
QString fixed_frame_
virtual void addOption(const QString &option, int value=0)
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
virtual FrameManager * getFrameManager() const =0
Ogre::SceneManager * scene_manager_
virtual Ogre::SceneManager * getSceneManager() const =0
std_msgs::ColorRGBA colorCategory20(int i)
virtual int getOptionInt()
#define ROS_ERROR(...)
virtual QString getName() const


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Sat Mar 20 2021 03:03:18