cluster_point_indices_to_point_indices_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/o2r 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_utils/cluster_point_indices_to_point_indices.h"
00036 #include <jsk_recognition_utils/pcl_conversion_util.h>
00037 #include <jsk_topic_tools/log_utils.h>
00038 #include <jsk_recognition_msgs/ClusterPointIndices.h>
00039 #include <boost/assign.hpp>
00040 
00041 namespace jsk_pcl_ros_utils
00042 {
00043 
00044   void ClusterPointIndicesToPointIndices::onInit()
00045   {
00046     DiagnosticNodelet::onInit();
00047     // dynamic_reconfigure
00048     srv_ = boost::make_shared <dynamic_reconfigure::Server<Config> > (*pnh_);
00049     dynamic_reconfigure::Server<Config>::CallbackType f =
00050       boost::bind(&ClusterPointIndicesToPointIndices::configCallback, this, _1, _2);
00051     srv_->setCallback(f);
00052 
00053     pub_ = advertise<PCLIndicesMsg>(*pnh_, "output", 1);
00054     onInitPostProcess();
00055   }
00056 
00057   void ClusterPointIndicesToPointIndices::configCallback(
00058     Config &config, uint32_t level)
00059   {
00060     boost::mutex::scoped_lock lock(mutex_);
00061     index_ = config.index;
00062   }
00063 
00064   void ClusterPointIndicesToPointIndices::subscribe()
00065   {
00066     sub_ = pnh_->subscribe("input", 1,
00067                            &ClusterPointIndicesToPointIndices::convert,
00068                            this);
00069     ros::V_string names = boost::assign::list_of("~input");
00070     jsk_topic_tools::warnNoRemap(names);
00071   }
00072 
00073   void ClusterPointIndicesToPointIndices::unsubscribe()
00074   {
00075     sub_.shutdown();
00076   }
00077 
00078   void ClusterPointIndicesToPointIndices::convert(
00079     const jsk_recognition_msgs::ClusterPointIndices::ConstPtr& cluster_indices_msg)
00080   {
00081     vital_checker_->poke();
00082     PCLIndicesMsg indices_msg;
00083     indices_msg.header = cluster_indices_msg->header;
00084 
00085     int cluster_size = cluster_indices_msg->cluster_indices.size();
00086     if (index_ < 0) {
00087       for(int i = 0;i < cluster_size; ++i) {
00088         indices_msg.indices.insert(indices_msg.indices.end(),
00089                                    cluster_indices_msg->cluster_indices[i].indices.begin(),
00090                                    cluster_indices_msg->cluster_indices[i].indices.end());
00091       }
00092     } else if (index_ < cluster_size) {
00093       indices_msg.indices = cluster_indices_msg->cluster_indices[index_].indices;
00094     } else {
00095       NODELET_ERROR_THROTTLE(10, "Invalid ~index %d is specified for cluster size %d.", index_, cluster_size);
00096     }
00097     pub_.publish(indices_msg);
00098   }
00099 
00100 }  // namespace jsk_pcl_ros_utils
00101 
00102 #include <pluginlib/class_list_macros.h>
00103 PLUGINLIB_EXPORT_CLASS(jsk_pcl_ros_utils::ClusterPointIndicesToPointIndices, nodelet::Nodelet);


jsk_pcl_ros_utils
Author(s): Yohei Kakiuchi
autogenerated on Tue Jul 2 2019 19:40:52