00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00035 #include <pcl/point_types.h> 00036 #include <pcl/io/pcd_io.h> 00037 #include <pcl/kdtree/kdtree_flann.h> 00038 #include <pcl/features/normal_3d.h> 00039 #include <pcl/surface/gp3.h> 00040 00041 int 00042 main (int argc, char** argv) 00043 { 00044 // Load input file into a PointCloud<T> with an appropriate type 00045 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); 00046 sensor_msgs::PointCloud2 cloud_blob; 00047 pcl::io::loadPCDFile ("bun0.pcd", cloud_blob); 00048 pcl::fromROSMsg (cloud_blob, *cloud); 00049 //* the data should be available in cloud 00050 00051 // Normal estimation* 00052 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n; 00053 pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>); 00054 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>); 00055 tree->setInputCloud (cloud); 00056 n.setInputCloud (cloud); 00057 n.setSearchMethod (tree); 00058 n.setKSearch (20); 00059 n.compute (*normals); 00060 //* normals should not contain the point normals + surface curvatures 00061 00062 // Concatenate the XYZ and normal fields* 00063 pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>); 00064 pcl::concatenateFields (*cloud, *normals, *cloud_with_normals); 00065 //* cloud_with_normals = cloud + normals 00066 00067 // Create search tree* 00068 pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>); 00069 tree2->setInputCloud (cloud_with_normals); 00070 00071 // Initialize objects 00072 pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3; 00073 pcl::PolygonMesh triangles; 00074 00075 // Set the maximum distance between connected points (maximum edge length) 00076 gp3.setSearchRadius (0.025); 00077 00078 // Set typical values for the parameters 00079 gp3.setMu (2.5); 00080 gp3.setMaximumNearestNeighbors (100); 00081 gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees 00082 gp3.setMinimumAngle(M_PI/18); // 10 degrees 00083 gp3.setMaximumAngle(2*M_PI/3); // 120 degrees 00084 gp3.setNormalConsistency(false); 00085 00086 // Get result 00087 gp3.setInputCloud (cloud_with_normals); 00088 gp3.setSearchMethod (tree2); 00089 gp3.reconstruct (triangles); 00090 00091 // Additional vertex information 00092 std::vector<int> parts = gp3.getPartIDs(); 00093 std::vector<int> states = gp3.getPointStates(); 00094 00095 // Finish 00096 return (0); 00097 }