Point Cloud Library (PCL) 1.14.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 * <br><br>
52 * Usage example:
53 * \code
54 *
55 * pcl::ModelCoefficients model_coeff;
56 * model_coeff.values.resize(4);
57 * model_coeff.values[0] = 0;
58 * model_coeff.values[1] = 0;
59 * model_coeff.values[2] = 1;
60 * model_coeff.values[3] = 0.5;
61 * pcl::ModelOutlierRemoval<pcl::PointXYZ> filter;
62 * filter.setModelCoefficients (model_coeff);
63 * filter.setThreshold (0.1);
64 * filter.setModelType (pcl::SACMODEL_PLANE);
65 * filter.setInputCloud (*cloud_in);
66 * filter.setNegative (false);
67 * filter.filter (*cloud_out);
68
69 * \endcode
70 */
71 template <typename PointT>
72 class ModelOutlierRemoval : public FilterIndices<PointT>
73 {
74 protected:
79
80 public:
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 inline
88 ModelOutlierRemoval (bool extract_removed_indices = false) :
89 FilterIndices<PointT> (extract_removed_indices)
90 {
91 thresh_ = 0;
93 filter_name_ = "ModelOutlierRemoval";
95 }
96
97 /** \brief sets the models coefficients */
98 inline void
99 setModelCoefficients (const pcl::ModelCoefficients& model_coefficients)
100 {
101 model_coefficients_.resize (model_coefficients.values.size ());
102 for (std::size_t i = 0; i < model_coefficients.values.size (); i++)
103 {
104 model_coefficients_[i] = model_coefficients.values[i];
105 }
106 }
107
108 /** \brief returns the models coefficients
109 */
112 {
114 mc.values.resize (model_coefficients_.size ());
115 for (std::size_t i = 0; i < mc.values.size (); i++)
116 mc.values[i] = model_coefficients_[i];
117 return (mc);
118 }
119
120 /** \brief Set the type of SAC model used. */
121 inline void
123 {
124 model_type_ = model;
125 }
126
127 /** \brief Get the type of SAC model used. */
128 inline pcl::SacModel
130 {
131 return (model_type_);
132 }
133
134 /** \brief Set the thresholdfunction*/
135 inline void
136 setThreshold (float thresh)
137 {
138 thresh_ = thresh;
139 }
140
141 /** \brief Get the thresholdfunction*/
142 inline float
144 {
145 return (thresh_);
146 }
147
148 /** \brief Set the normals cloud*/
149 inline void
151 {
152 cloud_normals_ = normals_ptr;
153 }
154
155 /** \brief Get the normals cloud*/
158 {
159 return (cloud_normals_);
160 }
161
162 /** \brief Set the normals distance weight*/
163 inline void
164 setNormalDistanceWeight (const double weight)
165 {
167 }
168
169 /** \brief get the normal distance weight*/
170 inline double
172 {
174 }
175
176 /** \brief Register a different threshold function
177 * \param[in] thresh pointer to a threshold function
178 */
179 void
180 setThresholdFunction (std::function<bool (double)> thresh)
181 {
182 threshold_function_ = thresh;
183 }
184
185 /** \brief Register a different threshold function
186 * \param[in] thresh_function pointer to a threshold function
187 * \param[in] instance
188 */
189 template <typename T> void
190 setThresholdFunction (bool (T::*thresh_function) (double), T& instance)
191 {
192 setThresholdFunction ([=, &instance] (double threshold) { return (instance.*thresh_function) (threshold); });
193 }
194
195 protected:
196 using PCLBase<PointT>::input_;
205
206 /** \brief Filtered results are indexed by an indices array.
207 * \param[out] indices The resultant indices.
208 */
209 void
210 applyFilter (Indices &indices) override
211 {
212 applyFilterIndices (indices);
213 }
214
215 /** \brief Filtered results are indexed by an indices array.
216 * \param[out] indices The resultant indices.
217 */
218 void
219 applyFilterIndices (Indices &indices);
220
221 protected:
224
225 /** \brief The model used to calculate distances */
227
228 /** \brief The threshold used to separate outliers (removed_indices) from inliers (indices) */
229 float thresh_;
230
231 /** \brief The model coefficients */
232 Eigen::VectorXf model_coefficients_;
233
234 /** \brief The type of model to use (user given parameter). */
236 std::function<bool (double)> threshold_function_;
237
238 inline bool
239 checkSingleThreshold (double value)
240 {
241 return (value < thresh_);
242 }
243
244 private:
245 virtual bool
246 initSACModel (pcl::SacModel model_type);
247 };
248}
249
250#ifdef PCL_NO_PRECOMPILE
251#include <pcl/filters/impl/model_outlier_removal.hpp>
252#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.
void setModelCoefficients(const pcl::ModelCoefficients &model_coefficients)
sets the models coefficients
PointCloudNConstPtr cloud_normals_
bool checkSingleThreshold(double value)
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
PointCloud represents the base class in PCL for storing collections of 3D points.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition sac_model.h:78
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.