Point Cloud Library (PCL) 1.12.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 <cfloat> // for FLT_MIN, FLT_MAX
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 (FLT_MIN, 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 filter_field_name_ (""),
101 filter_limit_min_ (FLT_MIN),
102 filter_limit_max_ (FLT_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 = FLT_MIN).
129 * \param[in] limit_max The maximum allowed field value (default = FLT_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 = FLT_MIN).
140 * \param[out] limit_max The maximum allowed field value (default = FLT_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 Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max)
150 * Default: false.
151 * \warning This method will be removed in the future. Use setNegative() instead.
152 * \param[in] limit_negative return data inside the interval (false) or outside (true)
153 */
154 PCL_DEPRECATED(1, 13, "use inherited FilterIndices::setNegative() instead")
155 inline void
156 setFilterLimitsNegative (const bool limit_negative)
157 {
158 negative_ = limit_negative;
159 }
160
161 /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
162 * \warning This method will be removed in the future. Use getNegative() instead.
163 * \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
164 */
165 PCL_DEPRECATED(1, 13, "use inherited FilterIndices::getNegative() instead")
166 inline void
167 getFilterLimitsNegative (bool &limit_negative) const
168 {
169 limit_negative = negative_;
170 }
171
172 /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
173 * \warning This method will be removed in the future. Use getNegative() instead.
174 * \return true if data \b outside the interval [min; max] is to be returned, false otherwise
175 */
176 inline bool
178 {
179 return (negative_);
180 }
181
182 protected:
183 using PCLBase<PointT>::input_;
192
193 /** \brief Filtered results are indexed by an indices array.
194 * \param[out] indices The resultant indices.
195 */
196 void
197 applyFilter (Indices &indices) override
198 {
199 applyFilterIndices (indices);
200 }
201
202 /** \brief Filtered results are indexed by an indices array.
203 * \param[out] indices The resultant indices.
204 */
205 void
206 applyFilterIndices (Indices &indices);
207
208 private:
209 /** \brief The name of the field that will be used for filtering. */
210 std::string filter_field_name_;
211
212 /** \brief The minimum allowed field value (default = FLT_MIN). */
213 float filter_limit_min_;
214
215 /** \brief The maximum allowed field value (default = FLT_MIN). */
216 float filter_limit_max_;
217 };
218
219 ////////////////////////////////////////////////////////////////////////////////////////////
220 /** \brief PassThrough uses the base Filter class methods to pass through all data that satisfies the user given
221 * constraints.
222 * \author Radu B. Rusu
223 * \ingroup filters
224 */
225 template<>
226 class PCL_EXPORTS PassThrough<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
227 {
229 using PCLPointCloud2Ptr = PCLPointCloud2::Ptr;
230 using PCLPointCloud2ConstPtr = PCLPointCloud2::ConstPtr;
231
232 using Filter<pcl::PCLPointCloud2>::removed_indices_;
233 using Filter<pcl::PCLPointCloud2>::extract_removed_indices_;
234
235 public:
236 /** \brief Constructor. */
237 PassThrough (bool extract_removed_indices = false) :
238 FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
239 filter_field_name_ (""), filter_limit_min_ (-FLT_MAX), filter_limit_max_ (FLT_MAX)
240 {
241 filter_name_ = "PassThrough";
242 }
243
244 /** \brief Provide the name of the field to be used for filtering data. In conjunction with \a setFilterLimits,
245 * points having values outside this interval will be discarded.
246 * \param[in] field_name the name of the field that contains values used for filtering
247 */
248 inline void
249 setFilterFieldName (const std::string &field_name)
250 {
251 filter_field_name_ = field_name;
252 }
253
254 /** \brief Get the name of the field used for filtering. */
255 inline std::string const
257 {
258 return (filter_field_name_);
259 }
260
261 /** \brief Set the field filter limits. All points having field values outside this interval will be discarded.
262 * \param[in] limit_min the minimum allowed field value
263 * \param[in] limit_max the maximum allowed field value
264 */
265 inline void
266 setFilterLimits (const double &limit_min, const double &limit_max)
267 {
268 filter_limit_min_ = limit_min;
269 filter_limit_max_ = limit_max;
270 }
271
272 /** \brief Get the field filter limits (min/max) set by the user. The default values are -FLT_MAX, FLT_MAX.
273 * \param[out] limit_min the minimum allowed field value
274 * \param[out] limit_max the maximum allowed field value
275 */
276 inline void
277 getFilterLimits (double &limit_min, double &limit_max) const
278 {
279 limit_min = filter_limit_min_;
280 limit_max = filter_limit_max_;
281 }
282
283 protected:
284 void
285 applyFilter (PCLPointCloud2 &output) override;
286
287 void
288 applyFilter (Indices &indices) override;
289
290 private:
291 /** \brief The desired user filter field name. */
292 std::string filter_field_name_;
293
294 /** \brief The minimum allowed filter value a point will be considered from. */
295 double filter_limit_min_;
296
297 /** \brief The maximum allowed filter value a point will be considered from. */
298 double filter_limit_max_;
299
300 };
301}
302
303#ifdef PCL_NO_PRECOMPILE
304#include <pcl/filters/impl/passthrough.hpp>
305#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 setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
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.
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major....
Definition pcl_macros.h:156
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.