40 #include <pcl/filters/model_outlier_removal.h>
41 #include <pcl/common/io.h>
42 #include <pcl/common/point_tests.h>
43 #include <pcl/sample_consensus/sac_model_circle.h>
44 #include <pcl/sample_consensus/sac_model_cylinder.h>
45 #include <pcl/sample_consensus/sac_model_cone.h>
46 #include <pcl/sample_consensus/sac_model_line.h>
47 #include <pcl/sample_consensus/sac_model_normal_plane.h>
48 #include <pcl/sample_consensus/sac_model_normal_sphere.h>
49 #include <pcl/sample_consensus/sac_model_parallel_plane.h>
50 #include <pcl/sample_consensus/sac_model_normal_parallel_plane.h>
51 #include <pcl/sample_consensus/sac_model_parallel_line.h>
52 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
53 #include <pcl/sample_consensus/sac_model_plane.h>
54 #include <pcl/sample_consensus/sac_model_sphere.h>
57 template <
typename Po
intT>
bool
65 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelPLANE\n", getClassName ().c_str ());
66 model_.reset (
new SampleConsensusModelPlane<PointT> (input_));
71 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelLINE\n", getClassName ().c_str ());
72 model_.reset (
new SampleConsensusModelLine<PointT> (input_));
77 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelCIRCLE2D\n", getClassName ().c_str ());
78 model_.reset (
new SampleConsensusModelCircle2D<PointT> (input_));
83 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelSPHERE\n", getClassName ().c_str ());
84 model_.reset (
new SampleConsensusModelSphere<PointT> (input_));
89 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelPARALLEL_LINE\n", getClassName ().c_str ());
90 model_.reset (
new SampleConsensusModelParallelLine<PointT> (input_));
95 PCL_DEBUG (
"[pcl::%s::initSACModel] Using a model of type: modelPERPENDICULAR_PLANE\n", getClassName ().c_str ());
96 model_.reset (
new SampleConsensusModelPerpendicularPlane<PointT> (input_));
101 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelCYLINDER\n", getClassName ().c_str ());
102 model_.reset (
new SampleConsensusModelCylinder<PointT, pcl::Normal> (input_));
107 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelNORMAL_PLANE\n", getClassName ().c_str ());
108 model_.reset (
new SampleConsensusModelNormalPlane<PointT, pcl::Normal> (input_));
113 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelCONE\n", getClassName ().c_str ());
114 model_.reset (
new SampleConsensusModelCone<PointT, pcl::Normal> (input_));
119 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelNORMAL_SPHERE\n", getClassName ().c_str ());
120 model_.reset (
new SampleConsensusModelNormalSphere<PointT, pcl::Normal> (input_));
125 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelNORMAL_PARALLEL_PLANE\n", getClassName ().c_str ());
126 model_.reset (
new SampleConsensusModelNormalParallelPlane<PointT, pcl::Normal> (input_));
131 PCL_DEBUG (
"[pcl::%s::segment] Using a model of type: modelPARALLEL_PLANE\n", getClassName ().c_str ());
132 model_.reset (
new SampleConsensusModelParallelPlane<PointT> (input_));
137 PCL_ERROR (
"[pcl::%s::initSACModel] No valid model given!\n", getClassName ().c_str ());
145 template <
typename Po
intT>
void
149 indices.resize (indices_->size ());
150 removed_indices_->resize (indices_->size ());
151 int oii = 0, rii = 0;
153 bool valid_setup =
true;
155 valid_setup &= initSACModel (model_type_);
159 SACModelFromNormals *model_from_normals =
dynamic_cast<SACModelFromNormals *
> (& (*model_));
161 if (model_from_normals)
166 PCL_ERROR (
"[pcl::ModelOutlierRemoval::applyFilterIndices]: no normals cloud set.\n");
170 model_from_normals->setNormalDistanceWeight (normals_distance_weight_);
171 model_from_normals->setInputNormals (cloud_normals_);
178 for (
int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)
181 if (!
isFinite (input_->points[ (*indices_)[iii]]))
183 if (extract_removed_indices_)
184 (*removed_indices_)[rii++] = (*indices_)[iii];
187 indices[oii++] = (*indices_)[iii];
192 std::vector<double> distances;
194 model_->setIndices(indices_);
195 model_->getDistancesToModel (model_coefficients_, distances);
200 for (
int iii = 0; iii < static_cast<int> (indices_->size ()); ++iii)
203 if (!
isFinite (input_->points[ (*indices_)[iii]]))
205 if (extract_removed_indices_)
206 (*removed_indices_)[rii++] = (*indices_)[iii];
211 thresh_result = threshold_function_ (distances[iii]);
214 if (!negative_ && !thresh_result)
216 if (extract_removed_indices_)
217 (*removed_indices_)[rii++] = (*indices_)[iii];
222 if (negative_ && thresh_result)
224 if (extract_removed_indices_)
225 (*removed_indices_)[rii++] = (*indices_)[iii];
230 indices[oii++] = (*indices_)[iii];
235 indices.resize (oii);
236 removed_indices_->resize (rii);
240 #define PCL_INSTANTIATE_ModelOutlierRemoval(T) template class PCL_EXPORTS pcl::ModelOutlierRemoval<T>;