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
00042 #include <pcl/point_types.h>
00043 #include <pcl/io/pcd_io.h>
00044 #include <pcl/io/vtk_io.h>
00045 #include <pcl/features/normal_3d.h>
00046 #include <pcl/surface/organized_fast_mesh.h>
00047 #include <pcl/common/common.h>
00048
00049 using namespace pcl;
00050 using namespace pcl::io;
00051 using namespace std;
00052
00053 PointCloud<PointXYZ>::Ptr cloud (new PointCloud<PointXYZ>);
00054 PointCloud<PointNormal>::Ptr cloud_with_normals (new PointCloud<PointNormal>);
00055 search::KdTree<PointXYZ>::Ptr tree;
00056 search::KdTree<PointNormal>::Ptr tree2;
00057
00058
00059 PointCloud<PointXYZ>::Ptr cloud1 (new PointCloud<PointXYZ>);
00060 PointCloud<PointNormal>::Ptr cloud_with_normals1 (new PointCloud<PointNormal>);
00061 search::KdTree<PointXYZ>::Ptr tree3;
00062 search::KdTree<PointNormal>::Ptr tree4;
00063
00065 TEST (PCL, Organized)
00066 {
00067
00068 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_organized (new pcl::PointCloud<pcl::PointXYZ> ());
00069 cloud_organized->width = 5;
00070 cloud_organized->height = 10;
00071 cloud_organized->points.resize (cloud_organized->width * cloud_organized->height);
00072
00073 int npoints = 0;
00074 for (size_t i = 0; i < cloud_organized->height; i++)
00075 {
00076 for (size_t j = 0; j < cloud_organized->width; j++)
00077 {
00078 cloud_organized->points[npoints].x = static_cast<float> (i);
00079 cloud_organized->points[npoints].y = static_cast<float> (j);
00080 cloud_organized->points[npoints].z = static_cast<float> (cloud_organized->points.size ());
00081 npoints++;
00082 }
00083 }
00084 int nan_idx = cloud_organized->width*cloud_organized->height - 2*cloud_organized->width + 1;
00085 cloud_organized->points[nan_idx].x = numeric_limits<float>::quiet_NaN ();
00086 cloud_organized->points[nan_idx].y = numeric_limits<float>::quiet_NaN ();
00087 cloud_organized->points[nan_idx].z = numeric_limits<float>::quiet_NaN ();
00088
00089
00090 PolygonMesh triangles;
00091 OrganizedFastMesh<PointXYZ> ofm;
00092
00093
00094 ofm.setInputCloud (cloud_organized);
00095 ofm.setMaxEdgeLength (1.5);
00096 ofm.setTrianglePixelSize (1);
00097 ofm.setTriangulationType (OrganizedFastMesh<PointXYZ>::TRIANGLE_ADAPTIVE_CUT);
00098
00099
00100 ofm.reconstruct (triangles);
00101
00102
00103
00104 EXPECT_EQ (triangles.cloud.width, cloud_organized->width);
00105 EXPECT_EQ (triangles.cloud.height, cloud_organized->height);
00106 EXPECT_EQ (int (triangles.polygons.size ()), 2*(triangles.cloud.width-1)*(triangles.cloud.height-1) - 4);
00107 EXPECT_EQ (int (triangles.polygons.at (0).vertices.size ()), 3);
00108 EXPECT_EQ (int (triangles.polygons.at (0).vertices.at (0)), 0);
00109 EXPECT_EQ (int (triangles.polygons.at (0).vertices.at (1)), triangles.cloud.width+1);
00110 EXPECT_EQ (int (triangles.polygons.at (0).vertices.at (2)), 1);
00111 }
00112
00113
00114 int
00115 main (int argc, char** argv)
00116 {
00117 if (argc < 2)
00118 {
00119 std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00120 return (-1);
00121 }
00122
00123
00124 pcl::PCLPointCloud2 cloud_blob;
00125 loadPCDFile (argv[1], cloud_blob);
00126 fromPCLPointCloud2 (cloud_blob, *cloud);
00127
00128
00129 tree.reset (new search::KdTree<PointXYZ> (false));
00130 tree->setInputCloud (cloud);
00131
00132
00133 NormalEstimation<PointXYZ, Normal> n;
00134 PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
00135 n.setInputCloud (cloud);
00136
00137 n.setSearchMethod (tree);
00138 n.setKSearch (20);
00139 n.compute (*normals);
00140
00141
00142 pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
00143
00144
00145 tree2.reset (new search::KdTree<PointNormal>);
00146 tree2->setInputCloud (cloud_with_normals);
00147
00148
00149 if(argc == 3){
00150 pcl::PCLPointCloud2 cloud_blob1;
00151 loadPCDFile (argv[2], cloud_blob1);
00152 fromPCLPointCloud2 (cloud_blob1, *cloud1);
00153
00154 tree3.reset (new search::KdTree<PointXYZ> (false));
00155 tree3->setInputCloud (cloud1);
00156
00157
00158 NormalEstimation<PointXYZ, Normal> n1;
00159 PointCloud<Normal>::Ptr normals1 (new PointCloud<Normal> ());
00160 n1.setInputCloud (cloud1);
00161
00162 n1.setSearchMethod (tree3);
00163 n1.setKSearch (20);
00164 n1.compute (*normals1);
00165
00166
00167 pcl::concatenateFields (*cloud1, *normals1, *cloud_with_normals1);
00168
00169 tree4.reset (new search::KdTree<PointNormal>);
00170 tree4->setInputCloud (cloud_with_normals1);
00171 }
00172
00173
00174 testing::InitGoogleTest (&argc, argv);
00175 return (RUN_ALL_TESTS ());
00176 }
00177