00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00046 #include "pcl/ModelCoefficients.h"
00047
00048 #include "pcl/io/pcd_io.h"
00049 #include "pcl/point_types.h"
00050
00051 #include "pcl/sample_consensus/method_types.h"
00052 #include "pcl/sample_consensus/model_types.h"
00053 #include "pcl/segmentation/sac_segmentation.h"
00054
00055
00056 int
00057 main (int argc, char** argv)
00058 {
00059 pcl::PointCloud<pcl::PointXYZ> cloud;
00060
00061
00062 cloud.width = 15;
00063 cloud.height = 1;
00064 cloud.points.resize (cloud.width * cloud.height);
00065
00066
00067 for (size_t i = 0; i < cloud.points.size (); ++i)
00068 {
00069 cloud.points[i].x = 1024 * rand () / (RAND_MAX + 1.0);
00070 cloud.points[i].y = 1024 * rand () / (RAND_MAX + 1.0);
00071 cloud.points[i].z = 1.0;
00072 }
00073
00074
00075 cloud.points[0].z = 2.0;
00076 cloud.points[3].z = -2.0;
00077 cloud.points[6].z = 4.0;
00078
00079 std::cerr << "Point cloud data: " << cloud.points.size () << " points" << std::endl;
00080 for (size_t i = 0; i < cloud.points.size (); ++i)
00081 std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
00082
00083 pcl::ModelCoefficients coefficients;
00084 pcl::PointIndices inliers;
00085
00086 pcl::SACSegmentation<pcl::PointXYZ> seg;
00087
00088 seg.setOptimizeCoefficients (true);
00089
00090 seg.setModelType (pcl::SACMODEL_PLANE);
00091 seg.setMethodType (pcl::SAC_RANSAC);
00092 seg.setDistanceThreshold (0.01);
00093
00094 pcl::PointCloud<pcl::PointXYZ>::Ptr cloudptr (new pcl::PointCloud<pcl::PointXYZ> (cloud));
00095 seg.setInputCloud (cloudptr);
00096 seg.segment (inliers, coefficients);
00097
00098 if (inliers.indices.size () == 0)
00099 {
00100 ROS_ERROR ("Could not estimate a planar model for the given dataset.");
00101 return (-1);
00102 }
00103
00104 std::cerr << "Model coefficients: " << coefficients.values[0] << " " << coefficients.values[1] << " "
00105 << coefficients.values[2] << " " << coefficients.values[3] << std::endl;
00106
00107 std::cerr << "Model inliers: " << inliers.indices.size () << std::endl;
00108 for (size_t i = 0; i < inliers.indices.size (); ++i)
00109 std::cerr << inliers.indices[i] << " " << cloud.points[inliers.indices[i]].x << " "
00110 << cloud.points[inliers.indices[i]].y << " "
00111 << cloud.points[inliers.indices[i]].z << std::endl;
00112
00113 return (0);
00114 }
00115