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_cloud.h>
00042 #include <pcl/features/normal_3d.h>
00043 #include <pcl/features/intensity_gradient.h>
00044
00045 using namespace pcl;
00046 using namespace pcl::io;
00047 using namespace std;
00048
00050 TEST (PCL, IntensityGradientEstimation)
00051 {
00052
00053 PointCloud<PointXYZI> cloud_xyzi;
00054 cloud_xyzi.height = 1;
00055 cloud_xyzi.is_dense = true;
00056 for (float x = -5.0f; x <= 5.0f; x += 0.1f)
00057 {
00058 for (float y = -5.0f; y <= 5.0f; y += 0.1f)
00059 {
00060 PointXYZI p;
00061 p.x = x;
00062 p.y = y;
00063 p.z = 0.1f * powf (x, 2.0f) + 0.5f * y + 1.0f;
00064 p.intensity = 0.1f * powf (x, 3.0f) + 0.2f * powf (y, 2.0f) + 1.0f * p.z + 20000.0f;
00065
00066 cloud_xyzi.points.push_back (p);
00067 }
00068 }
00069 cloud_xyzi.width = static_cast<uint32_t> (cloud_xyzi.points.size ());
00070 PointCloud<PointXYZI>::ConstPtr cloud_ptr = cloud_xyzi.makeShared ();
00071
00072
00073 PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
00074 NormalEstimation<PointXYZI, Normal> norm_est;
00075 norm_est.setInputCloud (cloud_ptr);
00076 search::KdTree<PointXYZI>::Ptr treept1 (new search::KdTree<PointXYZI> (false));
00077 norm_est.setSearchMethod (treept1);
00078 norm_est.setRadiusSearch (0.25);
00079 norm_est.compute (*normals);
00080
00081
00082 PointCloud<IntensityGradient> gradient;
00083 IntensityGradientEstimation<PointXYZI, Normal, IntensityGradient> grad_est;
00084 grad_est.setInputCloud (cloud_ptr);
00085 grad_est.setInputNormals (normals);
00086 search::KdTree<PointXYZI>::Ptr treept2 (new search::KdTree<PointXYZI> (false));
00087 grad_est.setSearchMethod (treept2);
00088 grad_est.setRadiusSearch (0.25);
00089 grad_est.compute (gradient);
00090
00091
00092 for (size_t i = 0; i < cloud_ptr->points.size (); ++i)
00093 {
00094 const PointXYZI &p = cloud_ptr->points[i];
00095
00096
00097 const float * g_est = gradient.points[i].gradient;
00098
00099
00100 float nx = -0.2f * p.x;
00101 float ny = -0.5f;
00102 float nz = 1.0f;
00103 float magnitude = sqrtf (nx * nx + ny * ny + nz * nz);
00104 nx /= magnitude;
00105 ny /= magnitude;
00106 nz /= magnitude;
00107
00108
00109 float tmpx = 0.3f * powf (p.x, 2.0f);
00110 float tmpy = 0.4f * p.y;
00111 float tmpz = 1.0f;
00112
00113 float gx = (1 - nx * nx) * tmpx + (-nx * ny) * tmpy + (-nx * nz) * tmpz;
00114 float gy = (-ny * nx) * tmpx + (1 - ny * ny) * tmpy + (-ny * nz) * tmpz;
00115 float gz = (-nz * nx) * tmpx + (-nz * ny) * tmpy + (1 - nz * nz) * tmpz;
00116
00117
00118 const float tolerance = 0.11f;
00119 EXPECT_NEAR (g_est[0], gx, tolerance);
00120 EXPECT_NEAR (g_est[1], gy, tolerance);
00121 EXPECT_NEAR (g_est[2], gz, tolerance);
00122 }
00123 }
00124
00125
00126 int
00127 main (int argc, char** argv)
00128 {
00129 testing::InitGoogleTest (&argc, argv);
00130 return (RUN_ALL_TESTS ());
00131 }
00132