|
| 1 | +/* |
| 2 | + * Software License Agreement (BSD License) |
| 3 | + * |
| 4 | + * Copyright (c) 2016, Fraunhofer IPA. |
| 5 | + * All rights reserved. |
| 6 | + * |
| 7 | + * Redistribution and use in source and binary forms, with or without |
| 8 | + * modification, are permitted provided that the following conditions |
| 9 | + * are met: |
| 10 | + * |
| 11 | + * * Redistributions of source code must retain the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer. |
| 13 | + * * Redistributions in binary form must reproduce the above |
| 14 | + * copyright notice, this list of conditions and the following |
| 15 | + * disclaimer in the documentation and/or other materials provided |
| 16 | + * with the distribution. |
| 17 | + * * Neither the name of the copyright holder nor the names of its |
| 18 | + * contributors may be used to endorse or promote products derived |
| 19 | + * from this software without specific prior written permission. |
| 20 | + * |
| 21 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 22 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 23 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 24 | + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 25 | + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 | + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 27 | + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 28 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 29 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 30 | + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 31 | + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 32 | + * POSSIBILITY OF SUCH DAMAGE. |
| 33 | + * |
| 34 | + * |
| 35 | + */ |
| 36 | + |
| 37 | +/* |
| 38 | + * Author: Sofie Nilsson |
| 39 | + */ |
| 40 | + |
| 41 | +#ifndef ROI_OUTLIER_REMOVAL_NODELET |
| 42 | +#define ROI_OUTLIER_REMOVAL_NODELET |
| 43 | + |
| 44 | +#include "ros/ros.h" |
| 45 | +#include "boost/thread/mutex.hpp" |
| 46 | + |
| 47 | +#include "nodelet/nodelet.h" |
| 48 | +#include "tf2_ros/buffer.h" |
| 49 | +#include "tf2_ros/transform_listener.h" |
| 50 | +#include "tf2_ros/message_filter.h" |
| 51 | +#include <tf2_sensor_msgs/tf2_sensor_msgs.h> |
| 52 | +#include <tf2_geometry_msgs/tf2_geometry_msgs.h> |
| 53 | +#include "sensor_msgs/PointCloud2.h" |
| 54 | + |
| 55 | +// includes for pcl filtering |
| 56 | +#include <pcl_ros/point_cloud.h> |
| 57 | + |
| 58 | +namespace pointcloud_to_laserscan |
| 59 | +{ |
| 60 | + typedef tf2_ros::MessageFilter<sensor_msgs::PointCloud2> MessageFilter; |
| 61 | +/** |
| 62 | +* The ROI outlier removal removes all points outside the specified region of interest (ROI) and publishes the remaining points into a new pointcloud. |
| 63 | +* The roi is defined as a z value range, angle range in the xy plane, and a max and min range in the xyy plane, for a chosen frame. |
| 64 | +* The filter converts the roi borders to to the original pointcloud frame in order to not have to waist time on transforming points |
| 65 | +* that are not to be used later on. |
| 66 | +* The points within the roi are transformed to and published in the same frame as the borders were given. |
| 67 | +* The filter is relevant to the pointcloud to laserscan transformation since it creates a possibility to apply additional statistical filtering |
| 68 | +* to a reduced pointcloud before creating the scan. The loclation of this filter within the pointcloud to laserscan package is however questionable. |
| 69 | +*/ |
| 70 | + class RoiOutlierRemovalNodelet : public nodelet::Nodelet |
| 71 | + { |
| 72 | + |
| 73 | + public: |
| 74 | + RoiOutlierRemovalNodelet(); |
| 75 | + void configure_roi_settings(); |
| 76 | + |
| 77 | + private: |
| 78 | + virtual void onInit(); |
| 79 | + |
| 80 | + void cloudCb(const sensor_msgs::PointCloud2ConstPtr &cloud_msg); |
| 81 | + |
| 82 | + void reduce_point_cloud_to_roi(const pcl::PointCloud<pcl::PointXYZ>::Ptr pcl_cloud, |
| 83 | + pcl::PointCloud<pcl::PointXYZ>::Ptr reduced_pcl_cloud, |
| 84 | + const tf2::Transform &T); |
| 85 | + |
| 86 | + ros::NodeHandle nh_, private_nh_; |
| 87 | + ros::Publisher pub_; |
| 88 | + |
| 89 | + boost::shared_ptr<tf2_ros::Buffer> tf2_; |
| 90 | + boost::shared_ptr<tf2_ros::TransformListener> tf2_listener_; |
| 91 | + |
| 92 | + ros::Subscriber sub_; |
| 93 | + |
| 94 | + // ROS Parameters |
| 95 | + unsigned int input_queue_size_; |
| 96 | + std::string roi_def_frame_; |
| 97 | + double tolerance_; |
| 98 | + double min_height_, max_height_, angle_min_, angle_max_, angle_increment_, range_min_, range_max_; |
| 99 | + }; |
| 100 | + |
| 101 | +} // roi_outlier_removal |
| 102 | + |
| 103 | +#endif // ROI_OUTLIER_REMOVAL_NODELET |
0 commit comments