polygon_appender_nodelet.cpp
Go to the documentation of this file.
1 // -*- mode: C++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2013, Ryohei Ueda and 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 
38 
39 namespace jsk_pcl_ros_utils
40 {
42  {
43  ConnectionBasedNodelet::onInit();
44  pub_polygon_ = advertise<jsk_recognition_msgs::PolygonArray>(*pnh_, "output", 1);
45  pub_coefficients_ = advertise<jsk_recognition_msgs::ModelCoefficientsArray>(*pnh_,
46  "output_coefficients", 1);
47 
48  sync_ = boost::make_shared<message_filters::Synchronizer<SyncPolicy2> >(100);
49  sync_->connectInput(sub_polygon0_, sub_coefficients0_,
51  sync_->registerCallback(boost::bind(&PolygonAppender::callback2, this, _1, _2, _3, _4));
52  }
53 
55  {
56  sub_polygon0_.subscribe(*pnh_, "input0", 1);
57  sub_polygon1_.subscribe(*pnh_, "input1", 1);
58  sub_coefficients0_.subscribe(*pnh_, "input_coefficients0", 1);
59  sub_coefficients1_.subscribe(*pnh_, "input_coefficients1", 1);
60  }
61 
63  {
68  }
69 
71  const jsk_recognition_msgs::PolygonArray::ConstPtr& msg0,
72  const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coefficients0,
73  const jsk_recognition_msgs::PolygonArray::ConstPtr& msg1,
74  const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr& coefficients1)
75  {
76  std::vector<jsk_recognition_msgs::PolygonArray::ConstPtr> arrays;
77  arrays.push_back(msg0);
78  arrays.push_back(msg1);
79  std::vector<jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr> coefficients_array;
80  coefficients_array.push_back(coefficients0);
81  coefficients_array.push_back(coefficients1);
82  appendAndPublish(arrays, coefficients_array);
83  }
84 
86  const std::vector<jsk_recognition_msgs::PolygonArray::ConstPtr>& arrays,
87  const std::vector<jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr>& coefficients_array)
88  {
89  if (arrays.size() == 0) {
90  NODELET_ERROR("there is not enough polygons");
91  return;
92  }
93  if (coefficients_array.size() == 0) {
94  NODELET_ERROR("there is not enough coefficients");
95  return;
96  }
97  if (arrays.size() != coefficients_array.size()) {
98  NODELET_ERROR("polygons and coefficients are not the same length");
99  return;
100  }
101  jsk_recognition_msgs::PolygonArray new_array;
102  new_array.header = arrays[0]->header;
103  for (size_t i = 0; i < arrays.size(); i++) {
104  jsk_recognition_msgs::PolygonArray::ConstPtr array = arrays[i];
105  for (size_t j = 0; j < array->polygons.size(); j++) {
106  geometry_msgs::PolygonStamped polygon = array->polygons[j];
107  new_array.polygons.push_back(polygon);
108  }
109  }
110  pub_polygon_.publish(new_array);
111 
112  jsk_recognition_msgs::ModelCoefficientsArray coefficients_new_array;
113  coefficients_new_array.header = coefficients_array[0]->header;
114  for (size_t i = 0; i < coefficients_array.size(); i++) {
115  jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr array = coefficients_array[i];
116  for (size_t j = 0; j < array->coefficients.size(); j++) {
117  coefficients_new_array.coefficients.push_back(array->coefficients[j]);
118  }
119  }
120  pub_coefficients_.publish(coefficients_new_array);
121  }
122 }
123 
125 
#define NODELET_ERROR(...)
message_filters::Subscriber< jsk_recognition_msgs::ModelCoefficientsArray > sub_coefficients1_
void publish(const boost::shared_ptr< M > &message) const
virtual void callback2(const jsk_recognition_msgs::PolygonArray::ConstPtr &msg0, const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr &coefficients0, const jsk_recognition_msgs::PolygonArray::ConstPtr &msg1, const jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr &coefficients1)
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros_utils::PolygonAppender, nodelet::Nodelet)
boost::shared_ptr< message_filters::Synchronizer< SyncPolicy2 > > sync_
message_filters::Subscriber< jsk_recognition_msgs::PolygonArray > sub_polygon1_
boost::shared_ptr< ros::NodeHandle > pnh_
message_filters::Subscriber< jsk_recognition_msgs::PolygonArray > sub_polygon0_
virtual void appendAndPublish(const std::vector< jsk_recognition_msgs::PolygonArray::ConstPtr > &arrays, const std::vector< jsk_recognition_msgs::ModelCoefficientsArray::ConstPtr > &coefficients_array)
void subscribe(ros::NodeHandle &nh, const std::string &topic, uint32_t queue_size, const ros::TransportHints &transport_hints=ros::TransportHints(), ros::CallbackQueueInterface *callback_queue=0)
message_filters::Subscriber< jsk_recognition_msgs::ModelCoefficientsArray > sub_coefficients0_


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