Go to the documentation of this file.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
00038
00039
00040 #include <gtest/gtest.h>
00041 #include <pcl/point_types.h>
00042 #include <pcl/point_cloud.h>
00043 #include <pcl/io/pcd_io.h>
00044 #include <pcl/ModelCoefficients.h>
00045 #include <pcl/PointIndices.h>
00046 #include <pcl/sample_consensus/model_types.h>
00047 #include <pcl/sample_consensus/method_types.h>
00048 #include <pcl/segmentation/sac_segmentation.h>
00049
00050 using namespace pcl;
00051 using namespace pcl::io;
00052
00053 PointCloud<PointXYZ>::Ptr cloud_;
00054
00056 TEST (SACSegmentation, Segmentation)
00057 {
00058 ModelCoefficients::Ptr sphere_coefficients (new ModelCoefficients);
00059 PointIndices::Ptr inliers (new PointIndices);
00060
00061 SACSegmentation<PointXYZ> seg;
00062 seg.setOptimizeCoefficients (true);
00063 seg.setModelType (SACMODEL_SPHERE);
00064 seg.setMethodType (SAC_RANSAC);
00065 seg.setMaxIterations (10000);
00066 seg.setDistanceThreshold (0.01);
00067 seg.setRadiusLimits (0.03, 0.07);
00068 seg.setInputCloud (cloud_);
00069 seg.segment (*inliers, *sphere_coefficients);
00070
00071 EXPECT_NEAR (sphere_coefficients->values[0], 0.998776, 1e-2);
00072 EXPECT_NEAR (sphere_coefficients->values[1], 0.752023, 1e-2);
00073 EXPECT_NEAR (sphere_coefficients->values[2], 1.24558, 1e-2);
00074 EXPECT_NEAR (sphere_coefficients->values[3], 0.0536238, 1e-2);
00075
00076 EXPECT_NEAR (static_cast<int> (inliers->indices.size ()), 3516, 10);
00077 }
00078
00079
00080 int
00081 main (int argc, char** argv)
00082 {
00083 if (argc < 2)
00084 {
00085 std::cerr << "No test file given. Please download `noisy_slice_displaced.pcd` and pass its path to the test." << std::endl;
00086 return (-1);
00087 }
00088
00089
00090 PointCloud<PointXYZ> cloud;
00091 if (loadPCDFile (argv[1], cloud) < 0)
00092 {
00093 std::cerr << "Failed to read test file. Please download `noisy_slice_displaced.pcd` and pass its path to the test." << std::endl;
00094 return (-1);
00095 }
00096
00097 cloud_ = cloud.makeShared ();
00098
00099 testing::InitGoogleTest (&argc, argv);
00100 return (RUN_ALL_TESTS ());
00101 }
00102