compute_hull.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2012-, Open Perception, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the copyright holder(s) nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
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   // Command line parsing
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   // Load in the point cloud
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   // Compute the hull
00135   PolygonMesh mesh_out;
00136   compute (cloud_in, convex_concave_hull, alpha, mesh_out);
00137 
00138   // Save the mesh
00139   io::saveVTKFile (argv[vtk_file_indices[0]], mesh_out);
00140 
00141   return (0);
00142 }
00143 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:22:51