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/or 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"
36 #include <jsk_topic_tools/color_utils.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 
rviz::BillboardLine
jsk_rviz_plugins::SegmentArrayDisplay::BillboardLinePtr
boost::shared_ptr< rviz::BillboardLine > BillboardLinePtr
Definition: segment_array_display.h:127
rviz::EnumProperty::getOptionInt
virtual int getOptionInt()
rviz::ColorProperty::getColor
virtual QColor getColor() const
rviz::MessageFilterDisplay< MessageType >::reset
void reset() override
jsk_rviz_plugins::SegmentArrayDisplay::line_width_property_
rviz::FloatProperty * line_width_property_
Definition: segment_array_display.h:142
msg
msg
boost::shared_ptr< rviz::BillboardLine >
jsk_rviz_plugins::SegmentArrayDisplay::processMessage
void processMessage(const jsk_recognition_msgs::SegmentArray::ConstPtr &msg)
Definition: segment_array_display.cpp:231
rviz::Property::show
void show()
jsk_rviz_plugins::SegmentArrayDisplay::alpha_property_
rviz::FloatProperty * alpha_property_
Definition: segment_array_display.h:141
jsk_rviz_plugins::SegmentArrayDisplay::updateAlpha
void updateAlpha()
Definition: segment_array_display.cpp:143
jsk_rviz_plugins::SegmentArrayDisplay::edges_
std::vector< BillboardLinePtr > edges_
Definition: segment_array_display.h:147
jsk_rviz_plugins::SegmentArrayDisplay::coloring_property_
rviz::EnumProperty * coloring_property_
Definition: segment_array_display.h:139
rviz::Display::fixed_frame_
QString fixed_frame_
jsk_rviz_plugins::SegmentArrayDisplay::onInitialize
virtual void onInitialize()
Definition: segment_array_display.cpp:116
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const=0
rviz::ColorProperty
jsk_rviz_plugins::SegmentArrayDisplay::reset
virtual void reset()
Definition: segment_array_display.cpp:167
rviz::Display
rviz::EnumProperty
rviz::FloatProperty
jsk_rviz_plugins::SegmentArrayDisplay::coloring_method_
std::string coloring_method_
Definition: segment_array_display.h:145
class_list_macros.h
rviz::Property::hide
void hide()
jsk_rviz_plugins::SegmentArrayDisplay::showEdges
virtual void showEdges(const jsk_recognition_msgs::SegmentArray::ConstPtr &msg)
Definition: segment_array_display.cpp:189
jsk_rviz_plugins::SegmentArrayDisplay::updateColor
void updateColor()
Definition: segment_array_display.cpp:135
jsk_rviz_plugins::SegmentArrayDisplay::alpha_
double alpha_
Definition: segment_array_display.h:144
rviz::FloatProperty::getFloat
virtual float getFloat() const
rviz::EnumProperty::addOption
virtual void addOption(const QString &option, int value=0)
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
jsk_rviz_plugins::SegmentArrayDisplay::color_
QColor color_
Definition: segment_array_display.h:143
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
jsk_rviz_plugins::SegmentArrayDisplay::latest_msg_
jsk_recognition_msgs::SegmentArray::ConstPtr latest_msg_
Definition: segment_array_display.h:149
rviz::DisplayContext::getFrameManager
virtual FrameManager * getFrameManager() const=0
num
num
rviz::MessageFilterDisplay< MessageType >::onInitialize
void onInitialize() override
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
segment_array_display.h
jsk_rviz_plugins::SegmentArrayDisplay::color_property_
rviz::ColorProperty * color_property_
Definition: segment_array_display.h:140
rviz::Property::getName
virtual QString getName() const
rviz::Display::context_
DisplayContext * context_
jsk_rviz_plugins::SegmentArrayDisplay::allocateBillboardLines
void allocateBillboardLines(int num)
Definition: segment_array_display.cpp:174
ROS_ERROR
#define ROS_ERROR(...)
rviz::FrameManager::transform
bool transform(const Header &header, const geometry_msgs::Pose &pose, Ogre::Vector3 &position, Ogre::Quaternion &orientation)
jsk_rviz_plugins::SegmentArrayDisplay::getColor
QColor getColor(size_t index)
Definition: segment_array_display.cpp:101
jsk_rviz_plugins::SegmentArrayDisplay::SegmentArrayDisplay
SegmentArrayDisplay()
Definition: segment_array_display.cpp:71
jsk_rviz_plugins::SegmentArrayDisplay::~SegmentArrayDisplay
virtual ~SegmentArrayDisplay()
Definition: segment_array_display.cpp:94
jsk_rviz_plugins::SegmentArrayDisplay::updateLineWidth
void updateLineWidth()
Definition: segment_array_display.cpp:127
jsk_rviz_plugins::SegmentArrayDisplay
Definition: segment_array_display.h:87
jsk_rviz_plugins
Definition: __init__.py:1
jsk_rviz_plugins::SegmentArrayDisplay::updateColoring
void updateColoring()
Definition: segment_array_display.cpp:151
jsk_rviz_plugins::SegmentArrayDisplay::line_width_
double line_width_
Definition: segment_array_display.h:146


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Tue Dec 10 2024 03:48:24