laser_to_pc.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
33 
34 void laser_to_pc::filter (const sensor_msgs::LaserScanPtr& msg)
35 {
36  PointCloud<PointXYZ> laser_cloud;
37  sensor_msgs::PointCloud2 laser; // laser pointcloud out
38  laser.header.frame_id=msg->header.frame_id;
39  tf::TransformListener listener; // not sure why i need this but it is ok :-)
40 
41  tf::StampedTransform transform;
42  try
43  {
44  listener_ptr->lookupTransform(frame_id, msg->header.frame_id, ros::Time(0), transform);
45  }
46  catch (tf::TransformException ex)
47  {
48  ROS_ERROR("%s",ex.what());
49  }
50 
51  laser_geometry::LaserProjection projector_;
52  projector_.transformLaserScanToPointCloud(msg->header.frame_id,*msg,laser,listener);
53 
54  fromROSMsg(laser,laser_cloud);
55  laser_cloud.header.frame_id=msg->header.frame_id;
56 
57  // Transform laser scan
58  PointCloud<PointXYZ> laser_cloud_transformed;
59  pcl_ros::transformPointCloud (laser_cloud,laser_cloud_transformed,transform);
60 
61  // Cut the cloud
62  points_from_volume<PointXYZ> pfv;
63  PointCloud<PointXYZ> cloud_cut;
64  cloud_cut.header.frame_id=frame_id;
65  convex_hull.header.frame_id=frame_id;
66  laser_cloud_transformed.header.frame_id=frame_id;
67  pfv.set_convex_hull(convex_hull);
68  pfv.convexhull_function(laser_cloud_transformed, max_z,min_z, false);
69  cloud_cut=pfv.get_pc_in_volume();
70 
71  sensor_msgs::PointCloud2 msg_laser;
72  toROSMsg(cloud_cut, msg_laser);
73 
74  // Publish the result
75  pub_ptr->publish(msg_laser);
76 
77 };
tf::TransformListener * listener_ptr
transform_listener pointer
Definition: laser_to_pc.h:78
PointCloud< PointXYZ > convex_hull
convex_hull for extraction
Definition: laser_to_pc.h:81
laser_to_pc class declaration
double min_z
z limits for extraction
Definition: laser_to_pc.h:75
ros::Publisher * pub_ptr
publisher pointer
Definition: laser_to_pc.h:64
double max_z
Definition: laser_to_pc.h:75
void filter(const sensor_msgs::LaserScanPtr &msg)
callback function
Definition: laser_to_pc.cpp:34
string frame_id
frame id
Definition: laser_to_pc.h:72


pointcloud_segmentation
Author(s): Tiago Talhada
autogenerated on Mon Mar 2 2015 01:32:39