segment_array_display.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Ryohei Ueda and 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 
35 #include "segment_array_display.h"
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", 0.8,
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 
69  QColor SegmentArrayDisplay::getColor(size_t index)
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  return QColor(255, 255, 255, 255);
82  }
83 
85  {
87  scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
88 
89  updateColor();
90  updateAlpha();
93  }
94 
96  {
98  if (latest_msg_) {
100  }
101  }
102 
104  {
106  if (latest_msg_) {
108  }
109  }
110 
112  {
114  if (latest_msg_) {
116  }
117  }
118 
120  {
121  if (coloring_property_->getOptionInt() == 0) {
122  coloring_method_ = "auto";
124  }
125  else if (coloring_property_->getOptionInt() == 1) {
126  coloring_method_ = "flat";
128  }
129 
130  if (latest_msg_) {
132  }
133  }
134 
136  {
137  MFDClass::reset();
138  edges_.clear();
139  latest_msg_.reset();
140  }
141 
143  {
144  if (num > edges_.size()) {
145  for (size_t i = edges_.size(); i < num; i++) {
147  this->context_->getSceneManager(), this->scene_node_));
148  edges_.push_back(line);
149  }
150  }
151  else if (num < edges_.size())
152  {
153  edges_.resize(num); // ok??
154  }
155  }
156 
158  const jsk_recognition_msgs::SegmentArray::ConstPtr& msg)
159  {
160  allocateBillboardLines(msg->segments.size());
161  for (size_t i = 0; i < msg->segments.size(); i++) {
162  jsk_recognition_msgs::Segment edge_msg = msg->segments[i];
163 
164  BillboardLinePtr edge = edges_[i];
165  edge->clear();
166 
167  geometry_msgs::Pose start_pose_local;
168  geometry_msgs::Pose end_pose_local;
169  start_pose_local.position = edge_msg.start_point;
170  start_pose_local.orientation.w = 1.0;
171  end_pose_local.position = edge_msg.end_point;
172  end_pose_local.orientation.w = 1.0;
173 
174  Ogre::Vector3 start_point;
175  Ogre::Vector3 end_point;
176  Ogre::Quaternion quaternion; // not used to visualize
177  bool transform_ret;
178  transform_ret =
179  context_->getFrameManager()->transform(msg->header, start_pose_local, start_point, quaternion)
180  && context_->getFrameManager()->transform(msg->header, end_pose_local, end_point, quaternion);
181  if(!transform_ret) {
182  ROS_ERROR( "Error transforming pose"
183  "'%s' from frame '%s' to frame '%s'",
184  qPrintable( getName() ), msg->header.frame_id.c_str(),
185  qPrintable( fixed_frame_ ));
186  return; // return?
187  }
188  edge->addPoint(start_point);
189  edge->addPoint(end_point);
190  edge->setLineWidth(line_width_);
191  QColor color = getColor(i);
192  edge->setColor(color.red() / 255.0,
193  color.green() / 255.0,
194  color.blue() / 255.0,
195  alpha_);
196  }
197  }
198 
200  const jsk_recognition_msgs::SegmentArray::ConstPtr& msg)
201  {
202  // Store latest message
203  latest_msg_ = msg;
204 
205  showEdges(msg);
206  }
207 }
208 
virtual QColor getColor() const
void processMessage(const jsk_recognition_msgs::SegmentArray::ConstPtr &msg)
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
DisplayContext * context_
std::vector< BillboardLinePtr > edges_
virtual float getFloat() const
Ogre::SceneNode * scene_node_
QString fixed_frame_
virtual void addOption(const QString &option, int value=0)
jsk_recognition_msgs::SegmentArray::ConstPtr latest_msg_
virtual void showEdges(const jsk_recognition_msgs::SegmentArray::ConstPtr &msg)
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