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/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 
37 #include <boost/assign.hpp>
39 
40 namespace jsk_perception
41 {
43  {
44  DiagnosticNodelet::onInit();
45  pub_ = advertise<geometry_msgs::PolygonStamped>(
46  *pnh_, "output", 1);
48  }
49 
51  {
52  sub_ = pnh_->subscribe("input", 1, &ROIToRect::convert, this);
53  ros::V_string names = boost::assign::list_of("~input");
55  }
56 
58  {
59  sub_.shutdown();
60  }
61 
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(jsk_perception::ROIToRect, nodelet::Nodelet)
virtual void convert(const sensor_msgs::CameraInfo::ConstPtr &roi_msg)
Definition: roi_to_rect.cpp:62
void publish(const boost::shared_ptr< M > &message) const
std::vector< std::string > V_string
ros::Subscriber sub_
Definition: roi_to_rect.h:58
boost::shared_ptr< ros::NodeHandle > pnh_
bool warnNoRemap(const std::vector< std::string > names)
virtual void subscribe()
Definition: roi_to_rect.cpp:50
jsk_topic_tools::VitalChecker::Ptr vital_checker_
virtual void unsubscribe()
Definition: roi_to_rect.cpp:57


jsk_perception
Author(s): Manabu Saito, Ryohei Ueda
autogenerated on Mon May 3 2021 03:03:27