00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00032 #ifndef _FILTERING_HPP_ 00033 #define _FILTERING_HPP_ 00034 00035 #include "filtering.h" 00036 00037 template <class T> 00038 void filtering<T>::filter(const sensor_msgs::PointCloud2Ptr& msg) 00039 { 00041 sensor_msgs::PointCloud2 msg_filt; 00042 msg_filt = voxel_filter(msg,voxel_size); 00043 00045 PointCloud<T> cloud_voxelized; 00046 fromROSMsg(msg_filt,cloud_voxelized); 00047 00048 tf::StampedTransform transform; 00049 try 00050 { 00051 transform_listener_ptr->lookupTransform(frame_id, msg->header.frame_id, ros::Time(0), transform); 00052 } 00053 catch (tf::TransformException ex) 00054 { 00055 ROS_ERROR("%s",ex.what()); 00056 } 00057 00058 PointCloud<T> cloud_trans; 00059 pcl_ros::transformPointCloud (cloud_voxelized,cloud_trans,transform); 00060 cloud_trans.header.frame_id=frame_id; 00061 00063 points_from_volume<T> pfv; 00064 PointCloud<T> cloud_cut; 00065 cloud_cut.header.frame_id=frame_id; 00066 pfv.set_convex_hull(convex_hull); 00067 pfv.convexhull_function(cloud_trans, max_z,min_z, false); 00068 cloud_cut=pfv.get_pc_in_volume(); 00069 00070 toROSMsg(cloud_cut,msg_filt); 00071 00073 pub_ptr->publish(msg_filt); 00074 }; 00076 00077 template <class T> 00078 sensor_msgs::PointCloud2 filtering<T>::voxel_filter(const sensor_msgs::PointCloud2Ptr& msg_in, double voxel_size) 00079 { 00080 sensor_msgs::PointCloud2 msg_out; 00081 VoxelGrid<sensor_msgs::PointCloud2> sor; 00082 // sensor_msgs::PointCloud2ConstPtr batatas (new sensor_msgs::PointCloud2 (msg_in)); 00083 sor.setInputCloud(msg_in); 00084 sor.setLeafSize (voxel_size, voxel_size, voxel_size); 00085 sor.filter (msg_out); 00086 return msg_out; 00087 }; 00089 00090 #endif