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/or 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);
51  onInitPostProcess();
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++) {
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 
jsk_pcl_ros_utils
Definition: add_point_indices.h:51
jsk_pcl_ros_utils::PolygonMagnifier::Config
PolygonMagnifierConfig Config
Definition: polygon_magnifier.h:117
msg
msg
_2
boost::arg< 2 > _2
jsk_recognition_utils::ConvexPolygon
jsk_pcl_ros_utils::PolygonMagnifier::unsubscribe
virtual void unsubscribe()
Definition: polygon_magnifier_nodelet.cpp:59
boost::shared_ptr< ConvexPolygon >
i
int i
jsk_pcl_ros_utils::PolygonMagnifier::use_scale_factor_
bool use_scale_factor_
Definition: polygon_magnifier.h:131
jsk_recognition_utils::ConvexPolygon::fromROSMsg
static ConvexPolygon fromROSMsg(const geometry_msgs::Polygon &polygon)
lock
lock
jsk_pcl_ros_utils::PolygonMagnifier::magnify_distance_
double magnify_distance_
Definition: polygon_magnifier.h:132
geo_util.h
jsk_recognition_utils::ConvexPolygon::magnifyByDistance
virtual Ptr magnifyByDistance(const double distance)
ros::Subscriber::shutdown
void shutdown()
jsk_pcl_ros_utils::PolygonMagnifier::sub_
ros::Subscriber sub_
Definition: polygon_magnifier.h:127
jsk_recognition_utils::ConvexPolygon::magnify
virtual Ptr magnify(const double scale_factor)
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
jsk_pcl_ros_utils::PolygonMagnifier
Definition: polygon_magnifier.h:81
class_list_macros.h
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros_utils::PolygonMagnifier, nodelet::Nodelet)
jsk_pcl_ros_utils::PolygonMagnifier::mutex_
boost::mutex mutex_
Definition: polygon_magnifier.h:130
polygon_magnifier.h
_1
boost::arg< 1 > _1
ROS_WARN
#define ROS_WARN(...)
jsk_pcl_ros_utils::PolygonMagnifier::magnify_scale_factor_
double magnify_scale_factor_
Definition: polygon_magnifier.h:133
jsk_pcl_ros_utils::PolygonMagnifier::configCallback
virtual void configCallback(Config &config, uint32_t level)
Definition: polygon_magnifier_nodelet.cpp:64
jsk_pcl_ros_utils::PolygonMagnifier::srv_
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
Definition: polygon_magnifier.h:129
f
f
nodelet::Nodelet
jsk_pcl_ros_utils::PolygonMagnifier::subscribe
virtual void subscribe()
Definition: polygon_magnifier_nodelet.cpp:54
jsk_pcl_ros_utils::PolygonMagnifier::magnify
virtual void magnify(const jsk_recognition_msgs::PolygonArray::ConstPtr &polygon_msg)
Definition: polygon_magnifier_nodelet.cpp:72
jsk_pcl_ros_utils::PolygonMagnifier::onInit
virtual void onInit()
Definition: polygon_magnifier_nodelet.cpp:42
config
config
jsk_pcl_ros_utils::PolygonMagnifier::pub_
ros::Publisher pub_
Definition: polygon_magnifier.h:128


jsk_pcl_ros_utils
Author(s): Yohei Kakiuchi
autogenerated on Fri May 16 2025 03:11:43