PointCloudMsgAssembler.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2014, PAL Robotics, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of PAL Robotics, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  */
00035 
00036  /* Author: Bence Magyar
00037   * Email:  bence.magyar@pal-robotics.com
00038   */
00039 
00040 #include <vector>
00041 #include <boost/foreach.hpp>
00042 
00043 #include <ecto/ecto.hpp>
00044 #include <opencv2/core/core.hpp>
00045 
00046 // ROS includes
00047 #include <sensor_msgs/Image.h>
00048 #include <object_recognition_msgs/RecognizedObjectArray.h>
00049 #include <pcl_conversions/pcl_conversions.h>
00050 
00051 namespace object_recognition_clusters
00052 {
00055   struct PointCloudMsgAssembler {
00056     static void
00057     declare_params(ecto::tendrils& params) {}
00058 
00059     static void
00060     declare_io(const ecto::tendrils& params, ecto::tendrils& inputs, ecto::tendrils& outputs) {
00061       inputs.declare(&PointCloudMsgAssembler::clusters3d_,
00062                      "clusters3d", "The 3dpoints as a cv::Mat_<cv::Vec3f>").required(true);
00063       inputs.declare(&PointCloudMsgAssembler::image_message_,
00064                      "image_message", "the image message to get the header").required(true);
00065 
00066       outputs.declare(&PointCloudMsgAssembler::output_msg_, "msg", "Pointcloud ROS message");
00067     }
00068 
00069     void
00070     configure(const ecto::tendrils& params, const ecto::tendrils& inputs, const ecto::tendrils& outputs) {
00071     }
00072 
00073     int
00074     process(const ecto::tendrils& inputs, const ecto::tendrils& outputs) {
00075       // Publish the info
00076       ros::Time time = ros::Time::now();
00077       object_recognition_msgs::RecognizedObjectArrayPtr msg(new object_recognition_msgs::RecognizedObjectArray());
00078 
00079       std::string frame_id;
00080       if (*image_message_) {
00081         frame_id = (*image_message_)->header.frame_id;
00082         time = (*image_message_)->header.stamp;
00083       }
00084       //TODO: figure out what to do if image doesn't give enough info
00085       //      else
00086       //        if (!frame_id_->empty())
00087       //          frame_id = *frame_id_;
00088 
00089       msg->header.stamp = time;
00090 
00091       for (size_t i = 0; i < clusters3d_->size(); ++i){
00092         // for every table
00093         std::vector<std::vector<cv::Vec3f> > &clusters = (*clusters3d_)[i];
00094         for (size_t j = 0; j < clusters.size(); j++){
00095           // for every cluster
00096           object_recognition_msgs::RecognizedObject object;
00097 
00098           // Deal with the header
00099           object.header.stamp = time;
00100 
00101           pcl::PointCloud<pcl::PointXYZ> pcl_cloud;
00102           pcl_cloud.reserve(clusters[j].size());
00103           BOOST_FOREACH(const cv::Vec3f& point, clusters[j])
00104           {
00105             pcl_cloud.push_back(pcl::PointXYZ(point[0], point[1], point[2]));
00106           }
00107 
00108           sensor_msgs::PointCloud2 cloud;
00109           pcl::toROSMsg(pcl_cloud, cloud);
00110           cloud.header.frame_id = frame_id;
00111           cloud.header.stamp = time;
00112 
00113           object.point_clouds.push_back(cloud);
00114           msg->objects.push_back(object);
00115         }
00116       }
00117 
00118       *output_msg_ = msg;
00119       return ecto::OK;
00120     }
00121   private:
00123     ecto::spore<sensor_msgs::ImageConstPtr> image_message_;
00125     ecto::spore<std::vector<std::vector<std::vector<cv::Vec3f> > > > clusters3d_;
00127     ecto::spore<object_recognition_msgs::RecognizedObjectArrayConstPtr> output_msg_;
00128   };
00129 }
00130 
00131 ECTO_CELL(io_clusters, object_recognition_clusters::PointCloudMsgAssembler, "PointCloudMsgAssembler",
00132           "Given object ids and poses, fill the object recognition message.");


object_recognition_clusters
Author(s): Bence Magyar , Kaijen Hsiao
autogenerated on Wed Aug 26 2015 14:58:56