Point Cloud Library (PCL) 1.14.0
Loading...
Searching...
No Matches
filter_indices.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: filter_indices.h 4707 2012-02-23 10:34:17Z florentinus $
37 *
38 */
39
40#pragma once
41
42#include <pcl/filters/filter.h>
43
44namespace pcl
45{
46 /** \brief Removes points with x, y, or z equal to NaN (dry run).
47 *
48 * This function only computes the mapping between the points in the input
49 * cloud and the cloud that would result from filtering. It does not
50 * actually construct and output the filtered cloud.
51 *
52 * \note This function does not modify the input point cloud!
53 *
54 * \param cloud_in the input point cloud
55 * \param index the mapping (ordered): filtered_cloud[i] = cloud_in[index[i]]
56 *
57 * \see removeNaNFromPointCloud
58 * \ingroup filters
59 */
60 template<typename PointT> void
62
63 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
64 /** \brief @b FilterIndices represents the base class for filters that are about binary point removal.
65 * <br>
66 * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (Indices &indices) methods.
67 * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems.
68 * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically
69 * filters non-finite entries in the filtering methods (recommended).
70 * \author Justin Rosen
71 * \ingroup filters
72 */
73 template<typename PointT>
74 class FilterIndices : public Filter<PointT>
75 {
76 public:
79
80 using Ptr = shared_ptr<FilterIndices<PointT> >;
81 using ConstPtr = shared_ptr<const FilterIndices<PointT> >;
82
83
84 /** \brief Constructor.
85 * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
86 */
87 FilterIndices (bool extract_removed_indices = false) :
88 Filter<PointT> (extract_removed_indices),
89
90 user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
91 {
92 }
93
95
96 /** \brief Calls the filtering method and returns the filtered point cloud indices.
97 * \param[out] indices the resultant filtered point cloud indices
98 */
99 void
100 filter (Indices &indices)
101 {
102 if (!initCompute ())
103 return;
104
105 // Apply the actual filter
106 applyFilter (indices);
107
108 deinitCompute ();
109 }
110
111 /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
112 * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
113 */
114 inline void
115 setNegative (bool negative)
116 {
117 negative_ = negative;
118 }
119
120 /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
121 * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
122 */
123 inline bool
124 getNegative () const
125 {
126 return (negative_);
127 }
128
129 /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
130 * or removed from the PointCloud, thus potentially breaking its organized structure.
131 * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
132 */
133 inline void
134 setKeepOrganized (bool keep_organized)
135 {
136 keep_organized_ = keep_organized;
137 }
138
139 /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN),
140 * or removed from the PointCloud, thus potentially breaking its organized structure.
141 * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
142 */
143 inline bool
145 {
146 return (keep_organized_);
147 }
148
149 /** \brief Provide a value that the filtered points should be set to instead of removing them.
150 * Used in conjunction with \a setKeepOrganized ().
151 * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
152 */
153 inline void
154 setUserFilterValue (float value)
155 {
156 user_filter_value_ = value;
157 }
158
159 protected:
160
163 using Filter<PointT>::input_;
165
166 /** \brief False = normal filter behavior (default), true = inverted behavior. */
167 bool negative_{false};
168
169 /** \brief False = remove points (default), true = redefine points, keep structure. */
170 bool keep_organized_{false};
171
172 /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
174
175 /** \brief Abstract filter method for point cloud indices. */
176 virtual void
177 applyFilter (Indices &indices) = 0;
178
179 /** \brief Abstract filter method for point cloud. */
180 void
181 applyFilter (PointCloud &output) override;
182 };
183
184 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
185 /** \brief @b FilterIndices represents the base class for filters that are about binary point removal.
186 * <br>
187 * All derived classes have to implement the \a filter (PointCloud &output) and the \a filter (Indices &indices) methods.
188 * Ideally they also make use of the \a negative_, \a keep_organized_ and \a extract_removed_indices_ systems.
189 * The distinguishment between the \a negative_ and \a extract_removed_indices_ systems only makes sense if the class automatically
190 * filters non-finite entries in the filtering methods (recommended).
191 * \author Justin Rosen
192 * \ingroup filters
193 */
194 template<>
195 class PCL_EXPORTS FilterIndices<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
196 {
197 public:
199
200 /** \brief Constructor.
201 * \param[in] extract_removed_indices Set to true if you want to extract the indices of points being removed (default = false).
202 */
203 FilterIndices (bool extract_removed_indices = false) :
204 Filter<PCLPointCloud2> (extract_removed_indices),
205
206 user_filter_value_ (std::numeric_limits<float>::quiet_NaN ())
207 {
208 }
209
210 using Filter<PCLPointCloud2>::filter;
211
212 /** \brief Calls the filtering method and returns the filtered point cloud indices.
213 * \param[out] indices the resultant filtered point cloud indices
214 */
215 void
216 filter (Indices &indices);
217
218 /** \brief Set whether the regular conditions for points filtering should apply, or the inverted conditions.
219 * \param[in] negative false = normal filter behavior (default), true = inverted behavior.
220 */
221 inline void
222 setNegative (bool negative)
223 {
224 negative_ = negative;
225 }
226
227 /** \brief Get whether the regular conditions for points filtering should apply, or the inverted conditions.
228 * \return The value of the internal \a negative_ parameter; false = normal filter behavior (default), true = inverted behavior.
229 */
230 inline bool
231 getNegative () const
232 {
233 return (negative_);
234 }
235
236 /** \brief Set whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default: NaN),
237 * or removed from the PointCloud, thus potentially breaking its organized structure.
238 * \param[in] keep_organized false = remove points (default), true = redefine points, keep structure.
239 */
240 inline void
241 setKeepOrganized (bool keep_organized)
242 {
243 keep_organized_ = keep_organized;
244 }
245
246 /** \brief Get whether the filtered points should be kept and set to the value given through \a setUserFilterValue (default = NaN),
247 * or removed from the PointCloud, thus potentially breaking its organized structure.
248 * \return The value of the internal \a keep_organized_ parameter; false = remove points (default), true = redefine points, keep structure.
249 */
250 inline bool
252 {
253 return (keep_organized_);
254 }
255
256 /** \brief Provide a value that the filtered points should be set to instead of removing them.
257 * Used in conjunction with \a setKeepOrganized ().
258 * \param[in] value the user given value that the filtered point dimensions should be set to (default = NaN).
259 */
260 inline void
261 setUserFilterValue (float value)
262 {
263 user_filter_value_ = value;
264 }
265
266 protected:
267
268 /** \brief False = normal filter behavior (default), true = inverted behavior. */
269 bool negative_{false};
270
271 /** \brief False = remove points (default), true = redefine points, keep structure. */
272 bool keep_organized_{false};
273
274 /** \brief The user given value that the filtered point dimensions should be set to (default = NaN). */
276
277 /** \brief Abstract filter method for point cloud indices. */
278 virtual void
279 applyFilter (Indices &indices) = 0;
280
281 /** \brief Abstract filter method for point cloud. */
282 void
283 applyFilter (PCLPointCloud2 &output) override = 0;
284 };
285}
286
287#ifdef PCL_NO_PRECOMPILE
288#include <pcl/filters/impl/filter_indices.hpp>
289#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
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition filter.h:155
float user_filter_value_
The user given value that the filtered point dimensions should be set to (default = NaN).
void applyFilter(PCLPointCloud2 &output) override=0
Abstract filter method for point cloud.
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions.
void setUserFilterValue(float value)
Provide a value that the filtered points should be set to instead of removing them.
virtual void applyFilter(Indices &indices)=0
Abstract filter method for point cloud indices.
bool getNegative() const
Get whether the regular conditions for points filtering should apply, or the inverted conditions.
FilterIndices(bool extract_removed_indices=false)
Constructor.
void filter(Indices &indices)
Calls the filtering method and returns the filtered point cloud indices.
bool getKeepOrganized() const
Get whether the filtered points should be kept and set to the value given through setUserFilterValue ...
void setKeepOrganized(bool keep_organized)
Set whether the filtered points should be kept and set to the value given through setUserFilterValue ...
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).
void setKeepOrganized(bool keep_organized)
Set whether the filtered points should be kept and set to the value given through setUserFilterValue ...
bool keep_organized_
False = remove points (default), true = redefine points, keep structure.
FilterIndices(bool extract_removed_indices=false)
Constructor.
virtual void applyFilter(Indices &indices)=0
Abstract filter method for point cloud indices.
void filter(Indices &indices)
Calls the filtering method and returns the filtered point cloud indices.
bool getNegative() const
Get whether the regular conditions for points filtering should apply, or the inverted conditions.
void setNegative(bool negative)
Set whether the regular conditions for points filtering should apply, or the inverted conditions.
shared_ptr< const FilterIndices< PointT > > ConstPtr
void setUserFilterValue(float value)
Provide a value that the filtered points should be set to instead of removing them.
bool negative_
False = normal filter behavior (default), true = inverted behavior.
bool getKeepOrganized() const
Get whether the filtered points should be kept and set to the value given through setUserFilterValue ...
shared_ptr< FilterIndices< PointT > > Ptr
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
bool initCompute()
This method should get called before starting the actual computation.
Definition pcl_base.hpp:138
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition pcl_base.hpp:175
PointCloud represents the base class in PCL for storing collections of 3D points.
void removeNaNFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, Indices &index)
Removes points with x, y, or z equal to NaN.
Definition filter.hpp:46
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.