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 <pcl/io/pcd_io.h>
00041 #include <pcl/io/vtk_io.h>
00042 #include <pcl/surface/concave_hull.h>
00043 #include <pcl/surface/convex_hull.h>
00044
00045 #include <pcl/console/print.h>
00046 #include <pcl/console/parse.h>
00047 #include <pcl/console/time.h>
00048
00049 using namespace std;
00050 using namespace pcl;
00051 using namespace pcl::io;
00052 using namespace pcl::console;
00053
00054 float default_alpha = 0.15f;
00055
00056 void
00057 printHelp (int, char **argv)
00058 {
00059 print_error ("Syntax is: %s input.pcd output.vtk [optional_arguments]\n", argv[0]);
00060 print_info (" where the optional arguments are:\n");
00061 print_info (" -alpha X = the alpha value for the ConcaveHull (Alpha Shapes) algorithm. If alpha is not specified, the tool will run the ConvexHull method (default: ");
00062 print_value ("%f", default_alpha); print_info (")\n");
00063 }
00064
00065
00066 void
00067 compute (PointCloud<PointXYZ>::ConstPtr cloud_in,
00068 bool convex_concave_hull,
00069 float alpha,
00070 PolygonMesh &mesh_out)
00071 {
00072 if (!convex_concave_hull)
00073 {
00074 print_info ("Computing the convex hull of a cloud with %zu points.\n", cloud_in->size ());
00075 ConvexHull<PointXYZ> convex_hull;
00076 convex_hull.setInputCloud (cloud_in);
00077 convex_hull.reconstruct (mesh_out);
00078 }
00079 else
00080 {
00081 print_info ("Computing the concave hull (alpha shapes) with alpha %f of a cloud with %zu points.\n", alpha, cloud_in->size ());
00082 ConcaveHull<PointXYZ> concave_hull;
00083 concave_hull.setInputCloud (cloud_in);
00084 concave_hull.setAlpha (alpha);
00085 concave_hull.reconstruct (mesh_out);
00086 }
00087 }
00088
00089
00090
00091 int
00092 main (int argc, char** argv)
00093 {
00094 print_info ("Compute the convex or concave hull of a point cloud. For more information, use: %s -h\n", argv[0]);
00095
00096 if (argc < 3)
00097 {
00098 printHelp (argc, argv);
00099 return (-1);
00100 }
00101
00102
00103 bool convex_concave_hull = false;
00104 float alpha = default_alpha;
00105
00106 if (parse_argument (argc, argv, "-alpha", alpha) != -1)
00107 convex_concave_hull = true;
00108
00109 vector<int> pcd_file_indices;
00110 pcd_file_indices = parse_file_extension_argument (argc, argv, ".pcd");
00111 if (pcd_file_indices.size () != 1)
00112 {
00113 print_error ("Need one input PCD file to continue.\n");
00114 return (-1);
00115 }
00116
00117 vector<int> vtk_file_indices;
00118 vtk_file_indices = parse_file_extension_argument (argc, argv, ".vtk");
00119 if (vtk_file_indices.size () != 1)
00120 {
00121 print_error ("Need one ouput VTK file to continue.\n");
00122 return (-1);
00123 }
00124
00125
00126
00127 PointCloud<PointXYZ>::Ptr cloud_in (new PointCloud<PointXYZ> ());
00128 if (loadPCDFile (argv[pcd_file_indices[0]], *cloud_in) != 0)
00129 {
00130 print_error ("Could not load input file %s\n", argv[pcd_file_indices[0]]);
00131 return (-1);
00132 }
00133
00134
00135 PolygonMesh mesh_out;
00136 compute (cloud_in, convex_concave_hull, alpha, mesh_out);
00137
00138
00139 io::saveVTKFile (argv[vtk_file_indices[0]], mesh_out);
00140
00141 return (0);
00142 }
00143