PerpendicularPlaneFitting.cpp
Go to the documentation of this file.
2
3#include <pcl/segmentation/sac_segmentation.h>
4
5// #include <armar6/skills/components/GuardPoseEstimation/tools.h>
6#include "tools.h"
7
8namespace visionx::tools
9{
10
11 std::optional<PlaneFittingResult>
12 PerpendicularPlaneFitting::fit(pcl::PointCloud<PointT>::ConstPtr input)
13 {
14 pcl::SACSegmentation<PointT> seg;
15 seg.setOptimizeCoefficients(true);
16 seg.setModelType(pcl::SACMODEL_PERPENDICULAR_PLANE);
17 seg.setMethodType(pcl::SAC_RANSAC);
18
19 seg.setDistanceThreshold(distanceThreshold);
20 seg.setAxis(normal);
21 seg.setEpsAngle(epsAngle);
22
23 seg.setMaxIterations(maxIterations);
24 seg.setProbability(probability);
25
26
27 pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
28 pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
29 // Segment the largest planar component from the remaining cloud
30 seg.setInputCloud(input);
31 seg.segment(*inliers, *coefficients);
32
33 if (inliers->indices.empty())
34 {
35 return std::nullopt;
36 }
37
38 /* "The four coefficients of the plane are its Hessian Normal form:
39 * [normal_x normal_y normal_z d]"
40 *
41 * - http://docs.pointclouds.org/trunk/group__sample__consensus.html
42 */
43 Eigen::Vector3f normalEst(
44 coefficients->values[0], coefficients->values[1], coefficients->values[2]);
45 Eigen::Hyperplane3f plane(normalEst, coefficients->values[3]);
46
47 PlaneFittingResult result;
48 result.plane = plane;
49 result.inliers = inliers;
50
51 return result;
52 }
53
54} // namespace visionx::tools
std::optional< PlaneFittingResult > fit(pcl::PointCloud< PointT >::ConstPtr input)
Hyperplane< float, 3 > Hyperplane3f
Definition Elements.h:34