greedy_triangulation.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
35 #include <pcl/point_types.h>
36 #include <pcl/io/pcd_io.h>
37 #include <pcl/kdtree/kdtree_flann.h>
38 #include <pcl/features/normal_3d.h>
39 #include <pcl/surface/gp3.h>
40 
41 int
42 main (int argc, char** argv)
43 {
44  // Load input file into a PointCloud<T> with an appropriate type
45  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
46  sensor_msgs::PointCloud2 cloud_blob;
47  pcl::io::loadPCDFile ("bun0.pcd", cloud_blob);
48  pcl::fromROSMsg (cloud_blob, *cloud);
49  //* the data should be available in cloud
50 
51  // Normal estimation*
52  pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
53  pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
54  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
55  tree->setInputCloud (cloud);
56  n.setInputCloud (cloud);
57  n.setSearchMethod (tree);
58  n.setKSearch (20);
59  n.compute (*normals);
60  //* normals should not contain the point normals + surface curvatures
61 
62  // Concatenate the XYZ and normal fields*
63  pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
64  pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
65  //* cloud_with_normals = cloud + normals
66 
67  // Create search tree*
68  pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
69  tree2->setInputCloud (cloud_with_normals);
70 
71  // Initialize objects
72  pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
73  pcl::PolygonMesh triangles;
74 
75  // Set the maximum distance between connected points (maximum edge length)
76  gp3.setSearchRadius (0.025);
77 
78  // Set typical values for the parameters
79  gp3.setMu (2.5);
80  gp3.setMaximumNearestNeighbors (100);
81  gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
82  gp3.setMinimumAngle(M_PI/18); // 10 degrees
83  gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
84  gp3.setNormalConsistency(false);
85 
86  // Get result
87  gp3.setInputCloud (cloud_with_normals);
88  gp3.setSearchMethod (tree2);
89  gp3.reconstruct (triangles);
90 
91  // Additional vertex information
92  std::vector<int> parts = gp3.getPartIDs();
93  std::vector<int> states = gp3.getPointStates();
94 
95  // Finish
96  return (0);
97 }
int main(int argc, char **argv)
_EXTERN_ pcl::PointCloud< pcl::PointXYZ > cloud


polygon_primitives_extraction
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:42