pcl_filter.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <algorithm>
25#include <functional>
26#include <vector>
27
28#include <pcl/point_cloud.h>
29
30// To my future me: use std::erase_if (header: <vector>) @ c++20
31// https://en.cppreference.com/w/cpp/container/vector/erase2
32template <typename Predicate>
33void
34erase_if(auto& c, Predicate pred)
35{
36 const auto it = std::remove_if(c.begin(), c.end(), pred);
37 c.erase(it, c.end());
38}
39
40namespace armarx
41{
42
43 template <typename PointT>
44 class Filter
45 {
46 public:
47 virtual ~Filter() = default;
48 virtual void applyFilter(pcl::PointCloud<PointT>& cloud) const = 0;
49 };
50
51 namespace detail
52 {
53
54 template <typename PointT, typename OperatorT>
55 class RangeFilter : virtual public armarx::Filter<PointT>
56 {
57 public:
58 explicit RangeFilter(const float rangeThreshold) : rangeThreshold(rangeThreshold)
59 {
60 }
61
62 void
63 applyFilter(pcl::PointCloud<PointT>& cloud) const override
64 {
65 constexpr auto comp = OperatorT();
66
67 const auto pred = [&](const PointT& point)
68 { return comp(rangeThreshold, Eigen::Vector2f(point.x, point.y).norm()); };
69
70 erase_if(cloud.points, pred);
71 }
72
73 private:
74 const float rangeThreshold;
75 };
76 } // namespace detail
77
78 template <typename PointT>
80 template <typename PointT>
82
83 namespace detail
84 {
85
86 template <typename PointT, typename OperatorT>
87 class PointRangeFilter : virtual public armarx::Filter<PointT>
88 {
89 public:
90 explicit PointRangeFilter(const float rangeThreshold, const Eigen::Vector3f& point) :
91 rangeThreshold(rangeThreshold), point(point)
92 {
93 }
94
95 void
96 applyFilter(pcl::PointCloud<PointT>& cloud) const override
97 {
98 constexpr auto comp = OperatorT();
99
100 const auto pred = [&](const PointT& pclPoint) -> bool
101 {
102 const Eigen::Vector3f pt(pclPoint.x, pclPoint.y, pclPoint.z);
103 return comp(rangeThreshold, (pt - point).norm());
104 };
105
106 erase_if(cloud.points, pred);
107 }
108
109 private:
110 const float rangeThreshold;
111 const Eigen::Vector3f point;
112 };
113 } // namespace detail
114
115 template <typename PointT>
117 template <typename PointT>
119
120} // namespace armarx
constexpr T c
virtual void applyFilter(pcl::PointCloud< PointT > &cloud) const =0
virtual ~Filter()=default
PointRangeFilter(const float rangeThreshold, const Eigen::Vector3f &point)
Definition pcl_filter.h:90
void applyFilter(pcl::PointCloud< PointT > &cloud) const override
Definition pcl_filter.h:96
RangeFilter(const float rangeThreshold)
Definition pcl_filter.h:58
void applyFilter(pcl::PointCloud< PointT > &cloud) const override
Definition pcl_filter.h:63
This file offers overloads of toIce() and fromIce() functions for STL container types.
detail::PointRangeFilter< PointT, std::less< float > > PointMaxRangeFilter
Definition pcl_filter.h:118
detail::RangeFilter< PointT, std::greater< float > > MinRangeFilter
Definition pcl_filter.h:79
detail::PointRangeFilter< PointT, std::greater< float > > PointMinRangeFilter
Definition pcl_filter.h:116
pcl::PointXYZRGBL PointT
Definition Common.h:30
detail::RangeFilter< PointT, std::less< float > > MaxRangeFilter
Definition pcl_filter.h:81
void erase_if(auto &c, Predicate pred)
Definition pcl_filter.h:34
double norm(const Point &a)
Definition point.hpp:102