polygon_magnifier_nodelet.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #define BOOST_PARAMETER_MAX_ARITY 7
39 
40 namespace jsk_pcl_ros_utils
41 {
43  {
44  DiagnosticNodelet::onInit();
45  srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
46  typename dynamic_reconfigure::Server<Config>::CallbackType f =
47  boost::bind (&PolygonMagnifier::configCallback, this, _1, _2);
48  srv_->setCallback (f);
49 
50  pub_ = advertise<jsk_recognition_msgs::PolygonArray>(*pnh_, "output", 1);
52  }
53 
55  {
56  sub_ = pnh_->subscribe("input", 1, &PolygonMagnifier::magnify, this);
57  }
58 
60  {
61  sub_.shutdown();
62  }
63 
64  void PolygonMagnifier::configCallback(Config &config, uint32_t level)
65  {
66  boost::mutex::scoped_lock lock(mutex_);
67  use_scale_factor_ = config.use_scale_factor;
68  magnify_distance_ = config.magnify_distance;
69  magnify_scale_factor_ = config.magnify_scale_factor;
70  }
71 
73  const jsk_recognition_msgs::PolygonArray::ConstPtr& msg)
74  {
75  boost::mutex::scoped_lock lock(mutex_);
76  vital_checker_->poke();
77 
78  jsk_recognition_msgs::PolygonArray ret_polygon_array = *msg;
79 
80  for (size_t i = 0; i < msg->polygons.size(); i++) {
82  jsk_recognition_utils::ConvexPolygon::fromROSMsg(msg->polygons[i].polygon);
83 
85  if (use_scale_factor_) magnified_poly = poly.magnify(magnify_scale_factor_);
86  else magnified_poly = poly.magnifyByDistance(magnify_distance_);
87 
88  if (!magnified_poly->isConvex()) {
89  ROS_WARN("Magnified polygon %ld is not convex.", i);
90  }
91 
92  ret_polygon_array.polygons[i].polygon = magnified_poly->toROSMsg();
93  }
94  pub_.publish(ret_polygon_array);
95  }
96 }
97 
f
lock
static ConvexPolygon fromROSMsg(const geometry_msgs::Polygon &polygon)
void publish(const boost::shared_ptr< M > &message) const
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros_utils::PolygonMagnifier, nodelet::Nodelet)
virtual Ptr magnify(const double scale_factor)
virtual Ptr magnifyByDistance(const double distance)
#define ROS_WARN(...)
virtual void configCallback(Config &config, uint32_t level)
boost::shared_ptr< ros::NodeHandle > pnh_
jsk_topic_tools::VitalChecker::Ptr vital_checker_
virtual void magnify(const jsk_recognition_msgs::PolygonArray::ConstPtr &polygon_msg)
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_


jsk_pcl_ros_utils
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:15