3 #include <pcl/ModelCoefficients.h>
4 #include <pcl/sample_consensus/method_types.h>
5 #include <pcl/sample_consensus/model_types.h>
6 #include <pcl/segmentation/sac_segmentation.h>
16 template <
typename Po
intT,
typename IndicesPtrT = pcl::IndicesPtr>
18 typename pcl::PointCloud<PointT>::Ptr cloud,
19 double distanceThreshold = 1.0,
20 const IndicesPtrT&
indices =
nullptr)
24 pcl::ModelCoefficients::Ptr coefficients(
new pcl::ModelCoefficients);
25 pcl::PointIndices::Ptr inliers(
new pcl::PointIndices);
28 pcl::SACSegmentation<PointT> seg;
31 seg.setOptimizeCoefficients(
true);
34 seg.setModelType(pcl::SACMODEL_PLANE);
35 seg.setMethodType(pcl::SAC_RANSAC);
36 seg.setDistanceThreshold(distanceThreshold);
38 seg.setInputCloud(cloud);
43 seg.segment(*inliers, *coefficients);
45 if (inliers->indices.empty())
50 float a = coefficients->values.at(0);
51 float b = coefficients->values.at(1);
52 float c = coefficients->values.at(2);
53 float d = coefficients->values.at(3);
57 if (plane.normal().dot(Eigen::Vector3f::UnitZ()) < 0)