Point Cloud Library (PCL) 1.12.0
Loading...
Searching...
No Matches
model_outlier_removal.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 * Copyright (c) 2012-, Open Perception, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * * Neither the name of the copyright holder(s) nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#pragma once
39
40#include <pcl/filters/filter_indices.h>
41#include <pcl/ModelCoefficients.h>
42
43// Sample Consensus models
44#include <pcl/sample_consensus/model_types.h>
45#include <pcl/sample_consensus/sac_model.h>
46
47namespace pcl
48{
49 /** \brief @b ModelOutlierRemoval filters points in a cloud based on the distance between model and point.
50 * \details Iterates through the entire input once, automatically filtering non-finite points and the points outside
51 * the model specified by setSampleConsensusModelPointer() and the threshold specified by setThreholdFunctionPointer().
52 * <br><br>
53 * Usage example:
54 * \code
55 * pcl::ModelCoefficients model_coeff;
56 * model_coeff.values.resize(4);
57 * model_coeff.values[0] = 0; model_coeff.values[1] = 0; model_coeff.values[2] = 1.5; model_coeff.values[3] = 0.5;
58 * pcl::ModelOutlierRemoval<pcl::PointXYZ> filter;
59 * filter.setModelCoefficients (model_coeff);
60 * filter.setThreshold (0.1);
61 * filter.setModelType (pcl::SACMODEL_PLANE);
62 * filter.setInputCloud (*cloud_in);
63 * filter.setFilterLimitsNegative (false);
64 * filter.filter (*cloud_out);
65 * \endcode
66 */
67 template <typename PointT>
68 class ModelOutlierRemoval : public FilterIndices<PointT>
69 {
70 protected:
75
76 public:
79
80 /** \brief Constructor.
81 * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
82 */
83 inline
84 ModelOutlierRemoval (bool extract_removed_indices = false) :
85 FilterIndices<PointT> (extract_removed_indices)
86 {
87 thresh_ = 0;
89 filter_name_ = "ModelOutlierRemoval";
91 }
92
93 /** \brief sets the models coefficients */
94 inline void
96 {
97 model_coefficients_.resize (model_coefficients.values.size ());
98 for (std::size_t i = 0; i < model_coefficients.values.size (); i++)
99 {
100 model_coefficients_[i] = model_coefficients.values[i];
101 }
102 }
103
104 /** \brief returns the models coefficients
105 */
108 {
110 mc.values.resize (model_coefficients_.size ());
111 for (std::size_t i = 0; i < mc.values.size (); i++)
112 mc.values[i] = model_coefficients_[i];
113 return (mc);
114 }
115
116 /** \brief Set the type of SAC model used. */
117 inline void
119 {
120 model_type_ = model;
121 }
122
123 /** \brief Get the type of SAC model used. */
124 inline pcl::SacModel
126 {
127 return (model_type_);
128 }
129
130 /** \brief Set the thresholdfunction*/
131 inline void
132 setThreshold (float thresh)
133 {
134 thresh_ = thresh;
135 }
136
137 /** \brief Get the thresholdfunction*/
138 inline float
140 {
141 return (thresh_);
142 }
143
144 /** \brief Set the normals cloud*/
145 inline void
147 {
148 cloud_normals_ = normals_ptr;
149 }
150
151 /** \brief Get the normals cloud*/
154 {
155 return (cloud_normals_);
156 }
157
158 /** \brief Set the normals distance weight*/
159 inline void
160 setNormalDistanceWeight (const double weight)
161 {
163 }
164
165 /** \brief get the normal distance weight*/
166 inline double
168 {
170 }
171
172 /** \brief Register a different threshold function
173 * \param[in] thresh pointer to a threshold function
174 */
175 void
176 setThresholdFunction (std::function<bool (double)> thresh)
177 {
178 threshold_function_ = thresh;
179 }
180
181 /** \brief Register a different threshold function
182 * \param[in] thresh_function pointer to a threshold function
183 * \param[in] instance
184 */
185 template <typename T> void
186 setThresholdFunction (bool (T::*thresh_function) (double), T& instance)
187 {
188 setThresholdFunction ([=, &instance] (double threshold) { return (instance.*thresh_function) (threshold); });
189 }
190
191 protected:
192 using PCLBase<PointT>::input_;
201
202 /** \brief Filtered results are indexed by an indices array.
203 * \param[out] indices The resultant indices.
204 */
205 void
206 applyFilter (Indices &indices) override
207 {
208 applyFilterIndices (indices);
209 }
210
211 /** \brief Filtered results are indexed by an indices array.
212 * \param[out] indices The resultant indices.
213 */
214 void
215 applyFilterIndices (Indices &indices);
216
217 protected:
220
221 /** \brief The model used to calculate distances */
223
224 /** \brief The threshold used to separate outliers (removed_indices) from inliers (indices) */
225 float thresh_;
226
227 /** \brief The model coefficients */
228 Eigen::VectorXf model_coefficients_;
229
230 /** \brief The type of model to use (user given parameter). */
232 std::function<bool (double)> threshold_function_;
233
234 inline bool
235 checkSingleThreshold (double value)
236 {
237 return (value < thresh_);
238 }
239
240 private:
241 virtual bool
242 initSACModel (pcl::SacModel model_type);
243 };
244}
245
246#ifdef PCL_NO_PRECOMPILE
247#include <pcl/filters/impl/model_outlier_removal.hpp>
248#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.
ModelOutlierRemoval filters points in a cloud based on the distance between model and point.
typename SampleConsensusModel< PointT >::Ptr SampleConsensusModelPtr
Eigen::VectorXf model_coefficients_
The model coefficients.
void setInputNormals(const PointCloudNConstPtr normals_ptr)
Set the normals cloud.
std::function< bool(double)> threshold_function_
void applyFilterIndices(Indices &indices)
Filtered results are indexed by an indices array.
void setModelType(pcl::SacModel model)
Set the type of SAC model used.
typename PointCloud::Ptr PointCloudPtr
float thresh_
The threshold used to separate outliers (removed_indices) from inliers (indices)
float getThreshold() const
Get the thresholdfunction.
pcl::SacModel model_type_
The type of model to use (user given parameter).
typename PointCloud::ConstPtr PointCloudConstPtr
pcl::PointCloud< pcl::Normal >::Ptr PointCloudNPtr
double getNormalDistanceWeight() const
get the normal distance weight
pcl::PointCloud< pcl::Normal >::ConstPtr PointCloudNConstPtr
ModelOutlierRemoval(bool extract_removed_indices=false)
Constructor.
void applyFilter(Indices &indices) override
Filtered results are indexed by an indices array.
void setThresholdFunction(bool(T::*thresh_function)(double), T &instance)
Register a different threshold function.
pcl::ModelCoefficients getModelCoefficients() const
returns the models coefficients
PointCloudNConstPtr getInputNormals() const
Get the normals cloud.
void setNormalDistanceWeight(const double weight)
Set the normals distance weight.
SampleConsensusModelPtr model_
The model used to calculate distances.
typename FilterIndices< PointT >::PointCloud PointCloud
void setThresholdFunction(std::function< bool(double)> thresh)
Register a different threshold function.
pcl::SacModel getModelType() const
Get the type of SAC model used.
PointCloudNConstPtr cloud_normals_
bool checkSingleThreshold(double value)
void setModelCoefficients(const pcl::ModelCoefficients model_coefficients)
sets the models coefficients
void setThreshold(float thresh)
Set the thresholdfunction.
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
shared_ptr< const PointCloud< PointT > > ConstPtr
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition sac_model.h:77
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
std::vector< float > values
A point structure representing Euclidean xyz coordinates, and the RGB color.