roi_to_rect.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 
37 #include <boost/assign.hpp>
38 #include <jsk_topic_tools/log_utils.h>
39 
40 namespace jsk_perception
41 {
42  void ROIToRect::onInit()
43  {
44  DiagnosticNodelet::onInit();
45  pub_ = advertise<geometry_msgs::PolygonStamped>(
46  *pnh_, "output", 1);
47  onInitPostProcess();
48  }
49 
51  {
52  sub_ = pnh_->subscribe("input", 1, &ROIToRect::convert, this);
53  ros::V_string names = boost::assign::list_of("~input");
54  jsk_topic_tools::warnNoRemap(names);
55  }
56 
58  {
59  sub_.shutdown();
60  }
61 
62  void ROIToRect::convert(
63  const sensor_msgs::CameraInfo::ConstPtr& roi_msg)
64  {
65  vital_checker_->poke();
66  geometry_msgs::PolygonStamped rect;
67  rect.header = roi_msg->header;
68  geometry_msgs::Point32 top_left_pt, top_right_pt, bottom_left_pt, bottom_right_pt;
69  top_left_pt.x = roi_msg->roi.x_offset;
70  top_left_pt.y = roi_msg->roi.y_offset;
71  top_right_pt.x = roi_msg->roi.x_offset + roi_msg->roi.width;
72  top_right_pt.y = roi_msg->roi.y_offset;
73  bottom_left_pt.x = roi_msg->roi.x_offset;
74  bottom_left_pt.y = roi_msg->roi.y_offset + roi_msg->roi.height;
75  bottom_right_pt.x = roi_msg->roi.x_offset + roi_msg->roi.width;
76  bottom_right_pt.y = roi_msg->roi.y_offset + roi_msg->roi.height;
77  rect.polygon.points.push_back(top_left_pt);
78  rect.polygon.points.push_back(bottom_left_pt);
79  rect.polygon.points.push_back(bottom_right_pt);
80  rect.polygon.points.push_back(top_right_pt);
81  pub_.publish(rect);
82  }
83 }
84 
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_perception::ROIToRect, nodelet::Nodelet)
jsk_perception::ROIToRect::onInit
virtual void onInit()
Definition: roi_to_rect.cpp:74
ros::Subscriber::shutdown
void shutdown()
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
jsk_perception::ROIToRect::sub_
ros::Subscriber sub_
Definition: roi_to_rect.h:122
class_list_macros.h
jsk_perception
Definition: add_mask_image.h:48
jsk_perception::ROIToRect::subscribe
virtual void subscribe()
Definition: roi_to_rect.cpp:82
jsk_perception::ROIToRect::convert
virtual void convert(const sensor_msgs::CameraInfo::ConstPtr &roi_msg)
Definition: roi_to_rect.cpp:94
jsk_perception::ROIToRect::unsubscribe
virtual void unsubscribe()
Definition: roi_to_rect.cpp:89
nodelet::Nodelet
jsk_perception::ROIToRect
Definition: roi_to_rect.h:78
roi_to_rect.h
ros::V_string
std::vector< std::string > V_string
jsk_perception::ROIToRect::pub_
ros::Publisher pub_
Definition: roi_to_rect.h:121


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Fri May 16 2025 03:11:17