Point Cloud Library (PCL) 1.14.0
Loading...
Searching...
No Matches
passthrough.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2010-2012, Willow Garage, Inc.
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * * Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer in the documentation and/or other materials provided
18 * with the distribution.
19 * * Neither the name of the copyright holder(s) nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 *
36 * $Id$
37 *
38 */
39
40#pragma once
41
42#include <limits>
43#include <pcl/pcl_macros.h>
44#include <pcl/filters/filter_indices.h>
45
46namespace pcl
47{
48 /** \brief @b PassThrough passes points in a cloud based on constraints for one particular field of the point type.
49 * \details Iterates through the entire input once, automatically filtering non-finite points and the points outside
50 * the interval specified by setFilterLimits(), which applies only to the field specified by setFilterFieldName().
51 * <br><br>
52 * Usage example:
53 * \code
54 * pcl::PassThrough<PointType> ptfilter (true); // Initializing with true will allow us to extract the removed indices
55 * ptfilter.setInputCloud (cloud_in);
56 * ptfilter.setFilterFieldName ("x");
57 * ptfilter.setFilterLimits (0.0, 1000.0);
58 * ptfilter.filter (*indices_x);
59 * // The indices_x array indexes all points of cloud_in that have x between 0.0 and 1000.0
60 * indices_rem = ptfilter.getRemovedIndices ();
61 * // The indices_rem array indexes all points of cloud_in that have x smaller than 0.0 or larger than 1000.0
62 * // and also indexes all non-finite points of cloud_in
63 * ptfilter.setIndices (indices_x);
64 * ptfilter.setFilterFieldName ("z");
65 * ptfilter.setFilterLimits (-10.0, 10.0);
66 * ptfilter.setNegative (true);
67 * ptfilter.filter (*indices_xz);
68 * // The indices_xz array indexes all points of cloud_in that have x between 0.0 and 1000.0 and z larger than 10.0 or smaller than -10.0
69 * ptfilter.setIndices (indices_xz);
70 * ptfilter.setFilterFieldName ("intensity");
71 * ptfilter.setFilterLimits (std::numeric_limits<float>::lowest(), 0.5);
72 * ptfilter.setNegative (false);
73 * ptfilter.filter (*cloud_out);
74 * // The resulting cloud_out contains all points of cloud_in that are finite and have:
75 * // x between 0.0 and 1000.0, z larger than 10.0 or smaller than -10.0 and intensity smaller than 0.5.
76 * \endcode
77 * \author Radu Bogdan Rusu
78 * \ingroup filters
79 */
80 template <typename PointT>
81 class PassThrough : public FilterIndices<PointT>
82 {
83 protected:
87 using FieldList = typename pcl::traits::fieldList<PointT>::type;
88
89 public:
90
91 using Ptr = shared_ptr<PassThrough<PointT> >;
92 using ConstPtr = shared_ptr<const PassThrough<PointT> >;
93
94
95 /** \brief Constructor.
96 * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
97 */
98 PassThrough (bool extract_removed_indices = false) :
99 FilterIndices<PointT> (extract_removed_indices),
100
101 filter_limit_min_ (std::numeric_limits<float>::lowest()),
102 filter_limit_max_ (std::numeric_limits<float>::max())
103 {
104 filter_name_ = "PassThrough";
105 }
106
107 /** \brief Provide the name of the field to be used for filtering data.
108 * \details In conjunction with setFilterLimits(), points having values outside this interval for this field will be discarded.
109 * \param[in] field_name The name of the field that will be used for filtering.
110 */
111 inline void
112 setFilterFieldName (const std::string &field_name)
113 {
114 filter_field_name_ = field_name;
115 }
116
117 /** \brief Retrieve the name of the field to be used for filtering data.
118 * \return The name of the field that will be used for filtering.
119 */
120 inline std::string const
122 {
123 return (filter_field_name_);
124 }
125
126 /** \brief Set the numerical limits for the field for filtering data.
127 * \details In conjunction with setFilterFieldName(), points having values outside this interval for this field will be discarded.
128 * \param[in] limit_min The minimum allowed field value (default = std::numeric_limits<float>::lowest()).
129 * \param[in] limit_max The maximum allowed field value (default = std::numeric_limits<float>::max()).
130 */
131 inline void
132 setFilterLimits (const float &limit_min, const float &limit_max)
133 {
134 filter_limit_min_ = limit_min;
135 filter_limit_max_ = limit_max;
136 }
137
138 /** \brief Get the numerical limits for the field for filtering data.
139 * \param[out] limit_min The minimum allowed field value (default = std::numeric_limits<float>::lowest()).
140 * \param[out] limit_max The maximum allowed field value (default = std::numeric_limits<float>::max()).
141 */
142 inline void
143 getFilterLimits (float &limit_min, float &limit_max) const
144 {
145 limit_min = filter_limit_min_;
146 limit_max = filter_limit_max_;
147 }
148
149 /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
150 * \warning This method will be removed in the future. Use getNegative() instead.
151 * \return true if data \b outside the interval [min; max] is to be returned, false otherwise
152 */
153 inline bool
155 {
156 return (negative_);
157 }
158
159 protected:
160 using PCLBase<PointT>::input_;
169
170 /** \brief Filtered results are indexed by an indices array.
171 * \param[out] indices The resultant indices.
172 */
173 void
174 applyFilter (Indices &indices) override
175 {
176 applyFilterIndices (indices);
177 }
178
179 /** \brief Filtered results are indexed by an indices array.
180 * \param[out] indices The resultant indices.
181 */
182 void
183 applyFilterIndices (Indices &indices);
184
185 private:
186 /** \brief The name of the field that will be used for filtering. */
187 std::string filter_field_name_;
188
189 /** \brief The minimum allowed field value (default = std::numeric_limits<float>::lowest()). */
190 float filter_limit_min_;
191
192 /** \brief The maximum allowed field value (default = std::numeric_limits<float>::max()). */
193 float filter_limit_max_;
194 };
195
196 ////////////////////////////////////////////////////////////////////////////////////////////
197 /** \brief PassThrough uses the base Filter class methods to pass through all data that satisfies the user given
198 * constraints.
199 * \author Radu B. Rusu
200 * \ingroup filters
201 */
202 template<>
203 class PCL_EXPORTS PassThrough<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
204 {
206 using PCLPointCloud2Ptr = PCLPointCloud2::Ptr;
207 using PCLPointCloud2ConstPtr = PCLPointCloud2::ConstPtr;
208
209 using Filter<pcl::PCLPointCloud2>::removed_indices_;
210 using Filter<pcl::PCLPointCloud2>::extract_removed_indices_;
211
212 public:
213 /** \brief Constructor. */
214 PassThrough (bool extract_removed_indices = false) :
215 FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
216 filter_limit_min_(std::numeric_limits<float>::lowest())
217 , filter_limit_max_(std::numeric_limits<float>::max())
218 {
219 filter_name_ = "PassThrough";
220 }
221
222 /** \brief Provide the name of the field to be used for filtering data. In conjunction with \a setFilterLimits,
223 * points having values outside this interval will be discarded.
224 * \param[in] field_name the name of the field that contains values used for filtering
225 */
226 inline void
227 setFilterFieldName (const std::string &field_name)
228 {
229 filter_field_name_ = field_name;
230 }
231
232 /** \brief Get the name of the field used for filtering. */
233 inline std::string const
235 {
236 return (filter_field_name_);
237 }
238
239 /** \brief Set the field filter limits. All points having field values outside this interval will be discarded.
240 * \param[in] limit_min the minimum allowed field value
241 * \param[in] limit_max the maximum allowed field value
242 */
243 inline void
244 setFilterLimits (const double &limit_min, const double &limit_max)
245 {
246 filter_limit_min_ = limit_min;
247 filter_limit_max_ = limit_max;
248 }
249
250 /** \brief Get the field filter limits (min/max) set by the user. The default values are
251 * std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max().
252 * \param[out] limit_min the minimum allowed field value
253 * \param[out] limit_max the maximum allowed field value
254 */
255 inline void
256 getFilterLimits (double &limit_min, double &limit_max) const
257 {
258 limit_min = filter_limit_min_;
259 limit_max = filter_limit_max_;
260 }
261
262 protected:
263 void
264 applyFilter (PCLPointCloud2 &output) override;
265
266 void
267 applyFilter (Indices &indices) override;
268
269 private:
270 /** \brief The desired user filter field name. */
271 std::string filter_field_name_;
272
273 /** \brief The minimum allowed filter value a point will be considered from. */
274 double filter_limit_min_;
275
276 /** \brief The maximum allowed filter value a point will be considered from. */
277 double filter_limit_max_;
278
279 };
280}
281
282#ifdef PCL_NO_PRECOMPILE
283#include <pcl/filters/impl/passthrough.hpp>
284#endif
Filter represents the base filter class.
Definition filter.h:81
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition filter.h:161
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition filter.h:174
std::string filter_name_
The filter name.
Definition filter.h:158
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition filter.h:155
FilterIndices represents the base class for filters that are about binary point removal.
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN).
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
bool negative_
False = normal filter behavior (default), true = inverted behavior.
PCL base class.
Definition pcl_base.h:70
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
void applyFilter(Indices &indices) override
Abstract filter method for point cloud indices.
void applyFilter(PCLPointCloud2 &output) override
Abstract filter method for point cloud.
std::string const getFilterFieldName() const
Get the name of the field used for filtering.
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
PassThrough(bool extract_removed_indices=false)
Constructor.
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
PassThrough passes points in a cloud based on constraints for one particular field of the point type.
Definition passthrough.h:82
typename PointCloud::Ptr PointCloudPtr
Definition passthrough.h:85
void applyFilter(Indices &indices) override
Filtered results are indexed by an indices array.
shared_ptr< const PassThrough< PointT > > ConstPtr
Definition passthrough.h:92
PassThrough(bool extract_removed_indices=false)
Constructor.
Definition passthrough.h:98
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
void setFilterLimits(const float &limit_min, const float &limit_max)
Set the numerical limits for the field for filtering data.
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
typename pcl::traits::fieldList< PointT >::type FieldList
Definition passthrough.h:87
void getFilterLimits(float &limit_min, float &limit_max) const
Get the numerical limits for the field for filtering data.
typename PointCloud::ConstPtr PointCloudConstPtr
Definition passthrough.h:86
void applyFilterIndices(Indices &indices)
Filtered results are indexed by an indices array.
typename FilterIndices< PointT >::PointCloud PointCloud
Definition passthrough.h:84
std::string const getFilterFieldName() const
Retrieve the name of the field to be used for filtering data.
shared_ptr< PassThrough< PointT > > Ptr
Definition passthrough.h:91
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
Defines all the PCL and non-PCL macros used.
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.