rearrange_bounding_box_nodelet.cpp
Go to the documentation of this file.
00001 // -*- mode: c++ -*-
00002 /*********************************************************************
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2016, JSK Lab
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of the JSK Lab nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *********************************************************************/
00035 #include "jsk_pcl_ros/rearrange_bounding_box.h"
00036 
00037 namespace jsk_pcl_ros
00038 {
00039   void RearrangeBoundingBox::onInit () {
00040     ConnectionBasedNodelet::onInit();
00041 
00042     pnh_->param("offset_x", offset_x_, 0.0);
00043     pnh_->param("offset_y", offset_y_, 0.0);
00044     pnh_->param("offset_z", offset_z_, 0.0);
00045     pnh_->param("scale_x", scale_x_, 1.0);
00046     pnh_->param("scale_y", scale_y_, 1.0);
00047     pnh_->param("scale_z", scale_z_, 1.0);
00048     pnh_->param("rotate_x", rotate_x_, 0.0);
00049     pnh_->param("rotate_y", rotate_y_, 0.0);
00050     pnh_->param("rotate_z", rotate_z_, 0.0);
00051     q_ = tf2::Quaternion();
00052     q_.setEuler(rotate_y_, rotate_x_, rotate_z_);
00053 
00054     srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
00055     dynamic_reconfigure::Server<Config>::CallbackType f =
00056       boost::bind(&RearrangeBoundingBox::configCallback, this, _1, _2);
00057     srv_->setCallback (f);
00058 
00059     pub_bouding_box_array_ = advertise<jsk_recognition_msgs::BoundingBoxArray>(*pnh_, "output", 1);
00060     onInitPostProcess();
00061   }
00062 
00063   void RearrangeBoundingBox::configCallback(Config &config, uint32_t level) {
00064     boost::mutex::scoped_lock lock(mutex_);
00065     offset_x_ = config.offset_x;
00066     offset_y_ = config.offset_y;
00067     offset_z_ = config.offset_z;
00068     scale_x_ = config.scale_x;
00069     scale_y_ = config.scale_y;
00070     scale_z_ = config.scale_z;
00071     rotate_x_ = config.rotate_x;
00072     rotate_y_ = config.rotate_y;
00073     rotate_z_ = config.rotate_z;
00074     q_ = tf2::Quaternion();
00075     q_.setEuler(rotate_y_, rotate_x_, rotate_z_);
00076   }
00077 
00078   void RearrangeBoundingBox::subscribe() {
00079     sub_bounding_box_array_ = pnh_->subscribe("input", 1,
00080                                               &RearrangeBoundingBox::rearrangeBoundingBoxCallback, this);
00081   }
00082 
00083   void RearrangeBoundingBox::unsubscribe() {
00084     sub_bounding_box_array_.shutdown();
00085   }
00086 
00087   void RearrangeBoundingBox::rearrangeBoundingBoxCallback(const jsk_recognition_msgs::BoundingBoxArray::ConstPtr& box_array) {
00088     boost::mutex::scoped_lock lock(mutex_);
00089     jsk_recognition_msgs::BoundingBoxArray bba;
00090     bba.header = box_array->header;
00091     bba.boxes = box_array->boxes;
00092     for(size_t i = 0; i < box_array->boxes.size(); ++i) {
00093       bba.boxes[i].pose.position.x += offset_x_;
00094       bba.boxes[i].pose.position.y += offset_y_;
00095       bba.boxes[i].pose.position.z += offset_z_;
00096       bba.boxes[i].dimensions.x *= scale_x_;
00097       bba.boxes[i].dimensions.y *= scale_y_;
00098       bba.boxes[i].dimensions.z *= scale_z_;
00099       bba.boxes[i].pose.orientation.x += q_.x();
00100       bba.boxes[i].pose.orientation.y += q_.y();
00101       bba.boxes[i].pose.orientation.z += q_.z();
00102       bba.boxes[i].pose.orientation.w += q_.w();
00103     }
00104     pub_bouding_box_array_.publish(bba);
00105   }
00106 }
00107 
00108 #include <pluginlib/class_list_macros.h>
00109 PLUGINLIB_EXPORT_CLASS (jsk_pcl_ros::RearrangeBoundingBox, nodelet::Nodelet);


jsk_pcl_ros
Author(s): Yohei Kakiuchi
autogenerated on Sun Oct 8 2017 02:43:50