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_cloud.h>
00042 #include <pcl/features/feature.h>
00043 #include <pcl/io/pcd_io.h>
00044
00045 using namespace pcl;
00046 using namespace pcl::io;
00047 using namespace std;
00048
00049 typedef search::KdTree<PointXYZ>::Ptr KdTreePtr;
00050
00051 PointCloud<PointXYZ> cloud;
00052 vector<int> indices;
00053 KdTreePtr tree;
00054
00056 TEST (PCL, BaseFeature)
00057 {
00058
00059 Eigen::Vector4f centroid3;
00060 compute3DCentroid (cloud, indices, centroid3);
00061 EXPECT_NEAR (centroid3[0], -0.0290809, 1e-4);
00062 EXPECT_NEAR (centroid3[1], 0.102653, 1e-4);
00063 EXPECT_NEAR (centroid3[2], 0.027302, 1e-4);
00064 EXPECT_NEAR (centroid3[3], 0, 1e-4);
00065
00066
00067 compute3DCentroid (cloud, centroid3);
00068 EXPECT_NEAR (centroid3[0], -0.0290809, 1e-4);
00069 EXPECT_NEAR (centroid3[1], 0.102653, 1e-4);
00070 EXPECT_NEAR (centroid3[2], 0.027302, 1e-4);
00071 EXPECT_NEAR (centroid3[3], 0, 1e-4);
00072
00073
00074 Eigen::VectorXf centroidn;
00075 computeNDCentroid (cloud, indices, centroidn);
00076 EXPECT_NEAR (centroidn[0], -0.0290809, 1e-4);
00077 EXPECT_NEAR (centroidn[1], 0.102653, 1e-4);
00078 EXPECT_NEAR (centroidn[2], 0.027302, 1e-4);
00079
00080
00081 computeNDCentroid (cloud, centroidn);
00082 EXPECT_NEAR (centroidn[0], -0.0290809, 1e-4);
00083 EXPECT_NEAR (centroidn[1], 0.102653, 1e-4);
00084 EXPECT_NEAR (centroidn[2], 0.027302, 1e-4);
00085
00086
00087 Eigen::Matrix3f covariance_matrix;
00088 computeCovarianceMatrix (cloud, indices, centroid3, covariance_matrix);
00089 EXPECT_NEAR (covariance_matrix (0, 0), 0.710046, 1e-4);
00090 EXPECT_NEAR (covariance_matrix (0, 1), -0.234843, 1e-4);
00091 EXPECT_NEAR (covariance_matrix (0, 2), 0.0704933, 1e-4);
00092 EXPECT_NEAR (covariance_matrix (1, 0), -0.234843, 1e-4);
00093 EXPECT_NEAR (covariance_matrix (1, 1), 0.68695, 1e-4);
00094 EXPECT_NEAR (covariance_matrix (1, 2), -0.220504, 1e-4);
00095 EXPECT_NEAR (covariance_matrix (2, 0), 0.0704933, 1e-4);
00096 EXPECT_NEAR (covariance_matrix (2, 1), -0.220504, 1e-4);
00097 EXPECT_NEAR (covariance_matrix (2, 2), 0.195448, 1e-4);
00098
00099
00100 computeCovarianceMatrix (cloud, centroid3, covariance_matrix);
00101 EXPECT_NEAR (covariance_matrix (0, 0), 0.710046, 1e-4);
00102 EXPECT_NEAR (covariance_matrix (0, 1), -0.234843, 1e-4);
00103 EXPECT_NEAR (covariance_matrix (0, 2), 0.0704933, 1e-4);
00104 EXPECT_NEAR (covariance_matrix (1, 0), -0.234843, 1e-4);
00105 EXPECT_NEAR (covariance_matrix (1, 1), 0.68695, 1e-4);
00106 EXPECT_NEAR (covariance_matrix (1, 2), -0.220504, 1e-4);
00107 EXPECT_NEAR (covariance_matrix (2, 0), 0.0704933, 1e-4);
00108 EXPECT_NEAR (covariance_matrix (2, 1), -0.220504, 1e-4);
00109 EXPECT_NEAR (covariance_matrix (2, 2), 0.195448, 1e-4);
00110
00111
00112 computeCovarianceMatrixNormalized (cloud, indices, centroid3, covariance_matrix);
00113 EXPECT_NEAR (covariance_matrix (0, 0), 1.7930e-03, 1e-5);
00114 EXPECT_NEAR (covariance_matrix (0, 1), -5.9304e-04, 1e-5);
00115 EXPECT_NEAR (covariance_matrix (0, 2), 1.7801e-04, 1e-5);
00116 EXPECT_NEAR (covariance_matrix (1, 0), -5.9304e-04, 1e-5);
00117 EXPECT_NEAR (covariance_matrix (1, 1), 1.7347e-03, 1e-5);
00118 EXPECT_NEAR (covariance_matrix (1, 2), -5.5683e-04, 1e-5);
00119 EXPECT_NEAR (covariance_matrix (2, 0), 1.7801e-04, 1e-5);
00120 EXPECT_NEAR (covariance_matrix (2, 1), -5.5683e-04, 1e-5);
00121 EXPECT_NEAR (covariance_matrix (2, 2), 4.9356e-04, 1e-5);
00122
00123
00124 computeCovarianceMatrixNormalized (cloud, centroid3, covariance_matrix);
00125 EXPECT_NEAR (covariance_matrix (0, 0), 1.7930e-03, 1e-5);
00126 EXPECT_NEAR (covariance_matrix (0, 1), -5.9304e-04, 1e-5);
00127 EXPECT_NEAR (covariance_matrix (0, 2), 1.7801e-04, 1e-5);
00128 EXPECT_NEAR (covariance_matrix (1, 0), -5.9304e-04, 1e-5);
00129 EXPECT_NEAR (covariance_matrix (1, 1), 1.7347e-03, 1e-5);
00130 EXPECT_NEAR (covariance_matrix (1, 2), -5.5683e-04, 1e-5);
00131 EXPECT_NEAR (covariance_matrix (2, 0), 1.7801e-04, 1e-5);
00132 EXPECT_NEAR (covariance_matrix (2, 1), -5.5683e-04, 1e-5);
00133 EXPECT_NEAR (covariance_matrix (2, 2), 4.9356e-04, 1e-5);
00134
00135
00136 Eigen::Vector4f plane_parameters;
00137 float curvature;
00138 solvePlaneParameters (covariance_matrix, centroid3, plane_parameters, curvature);
00139 EXPECT_NEAR (fabs (plane_parameters[0]), 0.035592, 1e-4);
00140 EXPECT_NEAR (fabs (plane_parameters[1]), 0.369596, 1e-4);
00141 EXPECT_NEAR (fabs (plane_parameters[2]), 0.928511, 1e-4);
00142 EXPECT_NEAR (fabs (plane_parameters[3]), 0.0622552, 1e-4);
00143 EXPECT_NEAR (curvature, 0.0693136, 1e-4);
00144
00145
00146 float nx, ny, nz;
00147 solvePlaneParameters (covariance_matrix, nx, ny, nz, curvature);
00148 EXPECT_NEAR (fabs (nx), 0.035592, 1e-4);
00149 EXPECT_NEAR (fabs (ny), 0.369596, 1e-4);
00150 EXPECT_NEAR (fabs (nz), 0.928511, 1e-4);
00151 EXPECT_NEAR (curvature, 0.0693136, 1e-4);
00152 }
00153
00154
00155 int
00156 main (int argc, char** argv)
00157 {
00158 if (argc < 2)
00159 {
00160 std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00161 return (-1);
00162 }
00163
00164 if (loadPCDFile<PointXYZ> (argv[1], cloud) < 0)
00165 {
00166 std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00167 return (-1);
00168 }
00169
00170 indices.resize (cloud.points.size ());
00171 for (size_t i = 0; i < indices.size (); ++i)
00172 indices[i] = static_cast<int> (i);
00173
00174 tree.reset (new search::KdTree<PointXYZ> (false));
00175 tree->setInputCloud (cloud.makeShared ());
00176
00177 testing::InitGoogleTest (&argc, argv);
00178 return (RUN_ALL_TESTS ());
00179 }
00180