rearrange_bounding_box_nodelet.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2016, 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  *********************************************************************/
36 
37 namespace jsk_pcl_ros
38 {
40  ConnectionBasedNodelet::onInit();
41 
42  pnh_->param("offset_x", offset_x_, 0.0);
43  pnh_->param("offset_y", offset_y_, 0.0);
44  pnh_->param("offset_z", offset_z_, 0.0);
45  pnh_->param("scale_x", scale_x_, 1.0);
46  pnh_->param("scale_y", scale_y_, 1.0);
47  pnh_->param("scale_z", scale_z_, 1.0);
48  pnh_->param("rotate_x", rotate_x_, 0.0);
49  pnh_->param("rotate_y", rotate_y_, 0.0);
50  pnh_->param("rotate_z", rotate_z_, 0.0);
51  q_ = tf2::Quaternion();
53 
54  srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
55  dynamic_reconfigure::Server<Config>::CallbackType f =
56  boost::bind(&RearrangeBoundingBox::configCallback, this, _1, _2);
57  srv_->setCallback (f);
58 
59  pub_bouding_box_array_ = advertise<jsk_recognition_msgs::BoundingBoxArray>(*pnh_, "output", 1);
61  }
62 
63  void RearrangeBoundingBox::configCallback(Config &config, uint32_t level) {
64  boost::mutex::scoped_lock lock(mutex_);
65  offset_x_ = config.offset_x;
66  offset_y_ = config.offset_y;
67  offset_z_ = config.offset_z;
68  scale_x_ = config.scale_x;
69  scale_y_ = config.scale_y;
70  scale_z_ = config.scale_z;
71  rotate_x_ = config.rotate_x;
72  rotate_y_ = config.rotate_y;
73  rotate_z_ = config.rotate_z;
74  q_ = tf2::Quaternion();
76  }
77 
79  sub_bounding_box_array_ = pnh_->subscribe("input", 1,
81  }
82 
85  }
86 
87  void RearrangeBoundingBox::rearrangeBoundingBoxCallback(const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& box_array) {
88  boost::mutex::scoped_lock lock(mutex_);
89  jsk_recognition_msgs::BoundingBoxArray bba;
90  bba.header = box_array->header;
91  bba.boxes = box_array->boxes;
92  for(size_t i = 0; i < box_array->boxes.size(); ++i) {
93  bba.boxes[i].pose.position.x += offset_x_;
94  bba.boxes[i].pose.position.y += offset_y_;
95  bba.boxes[i].pose.position.z += offset_z_;
96  bba.boxes[i].dimensions.x *= scale_x_;
97  bba.boxes[i].dimensions.y *= scale_y_;
98  bba.boxes[i].dimensions.z *= scale_z_;
99  bba.boxes[i].pose.orientation.x += q_.x();
100  bba.boxes[i].pose.orientation.y += q_.y();
101  bba.boxes[i].pose.orientation.z += q_.z();
102  bba.boxes[i].pose.orientation.w += q_.w();
103  }
105  }
106 }
107 
jsk_pcl_ros::RearrangeBoundingBoxConfig Config
void configCallback(Config &config, uint32_t level)
void publish(const boost::shared_ptr< M > &message) const
PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros::RearrangeBoundingBox, nodelet::Nodelet)
boost::shared_ptr< ros::NodeHandle > pnh_
void setEuler(const tf2Scalar &yaw, const tf2Scalar &pitch, const tf2Scalar &roll)
boost::shared_ptr< dynamic_reconfigure::Server< Config > > srv_
virtual void rearrangeBoundingBoxCallback(const jsk_recognition_msgs::BoundingBoxArray::ConstPtr &box_array)


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Mon May 3 2021 03:03:47