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