40 #include <pcl/filters/model_outlier_removal.h>
41 #include <pcl/common/point_tests.h>
42 #include <pcl/sample_consensus/sac_model_circle.h>
43 #include <pcl/sample_consensus/sac_model_cylinder.h>
44 #include <pcl/sample_consensus/sac_model_cone.h>
45 #include <pcl/sample_consensus/sac_model_line.h>
46 #include <pcl/sample_consensus/sac_model_normal_plane.h>
47 #include <pcl/sample_consensus/sac_model_normal_sphere.h>
48 #include <pcl/sample_consensus/sac_model_parallel_plane.h>
49 #include <pcl/sample_consensus/sac_model_normal_parallel_plane.h>
50 #include <pcl/sample_consensus/sac_model_parallel_line.h>
51 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
52 #include <pcl/sample_consensus/sac_model_plane.h>
53 #include <pcl/sample_consensus/sac_model_sphere.h>
56 template <
typename Po
intT>
bool
64 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelPLANE\n", getClassName ().c_str ());
65 model_.reset (
new SampleConsensusModelPlane<PointT> (input_));
70 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelLINE\n", getClassName ().c_str ());
71 model_.reset (
new SampleConsensusModelLine<PointT> (input_));
76 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelCIRCLE2D\n", getClassName ().c_str ());
77 model_.reset (
new SampleConsensusModelCircle2D<PointT> (input_));
82 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelSPHERE\n", getClassName ().c_str ());
83 model_.reset (
new SampleConsensusModelSphere<PointT> (input_));
88 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelPARALLEL_LINE\n", getClassName ().c_str ());
89 model_.reset (
new SampleConsensusModelParallelLine<PointT> (input_));
94 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelPERPENDICULAR_PLANE\n", getClassName ().c_str ());
95 model_.reset (
new SampleConsensusModelPerpendicularPlane<PointT> (input_));
100 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelCYLINDER\n", getClassName ().c_str ());
101 model_.reset (
new SampleConsensusModelCylinder<PointT, pcl::Normal> (input_));
106 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelNORMAL_PLANE\n", getClassName ().c_str ());
107 model_.reset (
new SampleConsensusModelNormalPlane<PointT, pcl::Normal> (input_));
112 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelCONE\n", getClassName ().c_str ());
113 model_.reset (
new SampleConsensusModelCone<PointT, pcl::Normal> (input_));
118 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelNORMAL_SPHERE\n", getClassName ().c_str ());
119 model_.reset (
new SampleConsensusModelNormalSphere<PointT, pcl::Normal> (input_));
124 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelNORMAL_PARALLEL_PLANE\n", getClassName ().c_str ());
125 model_.reset (
new SampleConsensusModelNormalParallelPlane<PointT, pcl::Normal> (input_));
130 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelPARALLEL_PLANE\n", getClassName ().c_str ());
131 model_.reset (
new SampleConsensusModelParallelPlane<PointT> (input_));
136 PCL_ERROR (
"[pcl::%s::initSACModel] No valid model given!\n", getClassName ().c_str ());
144 template <
typename Po
intT>
void
148 indices.resize (indices_->size ());
149 removed_indices_->resize (indices_->size ());
150 int oii = 0, rii = 0;
152 bool valid_setup =
true;
154 valid_setup &= initSACModel (model_type_);
158 auto *model_from_normals =
dynamic_cast<SACModelFromNormals *
> (& (*model_));
160 if (model_from_normals)
165 PCL_ERROR (
"[pcl::ModelOutlierRemoval::applyFilterIndices]: no normals cloud set.\n");
169 model_from_normals->setNormalDistanceWeight (normals_distance_weight_);
170 model_from_normals->setInputNormals (cloud_normals_);
177 for (
const auto& iii : (*indices_))
182 if (extract_removed_indices_)
183 (*removed_indices_)[rii++] = iii;
186 indices[oii++] = iii;
191 std::vector<double> distances;
193 model_->setIndices(indices_);
194 model_->getDistancesToModel (model_coefficients_, distances);
199 for (
int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)
202 if (!
isFinite ((*input_)[ (*indices_)[iii]]))
204 if (extract_removed_indices_)
205 (*removed_indices_)[rii++] = (*indices_)[iii];
210 thresh_result = threshold_function_ (distances[iii]);
213 if (!negative_ && !thresh_result)
215 if (extract_removed_indices_)
216 (*removed_indices_)[rii++] = (*indices_)[iii];
221 if (negative_ && thresh_result)
223 if (extract_removed_indices_)
224 (*removed_indices_)[rii++] = (*indices_)[iii];
229 indices[oii++] = (*indices_)[iii];
234 indices.resize (oii);
235 removed_indices_->resize (rii);
239 #define PCL_INSTANTIATE_ModelOutlierRemoval(T) template class PCL_EXPORTS pcl::ModelOutlierRemoval<T>;
ModelOutlierRemoval filters points in a cloud based on the distance between model and point.
void applyFilterIndices(Indices &indices)
Filtered results are indexed by an indices array.
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
@ SACMODEL_PARALLEL_PLANE
@ SACMODEL_NORMAL_PARALLEL_PLANE
@ SACMODEL_PERPENDICULAR_PLANE
IndicesAllocator<> Indices
Type used for indices in PCL.