Point Cloud Library (PCL)  1.7.1
surface.h
1 #ifndef SURFACE_H_
2 #define SURFACE_H_
3 
4 #include <pcl/kdtree/kdtree_flann.h>
5 #include <pcl/surface/mls.h>
6 #include <pcl/surface/convex_hull.h>
7 #include <pcl/surface/concave_hull.h>
8 #include <pcl/surface/gp3.h>
9 #include <pcl/surface/marching_cubes_greedy.h>
10 
11 #include "typedefs.h"
12 
13 
14 class Mesh
15 {
16  public:
17  Mesh () : points (new PointCloud) {}
18  PointCloudPtr points;
19  std::vector<pcl::Vertices> faces;
20 };
21 
22 typedef boost::shared_ptr<Mesh> MeshPtr;
23 
24 PointCloudPtr
25 smoothPointCloud (const PointCloudPtr & input, float radius, int polynomial_order)
26 {
29  mls.setSearchRadius (radius);
30  mls.setSqrGaussParam (radius*radius);
31  mls.setPolynomialFit (polynomial_order > 1);
32  mls.setPolynomialOrder (polynomial_order);
33 
34  mls.setInputCloud (input);
35 
36  PointCloudPtr output (new PointCloud);
37  mls.reconstruct (*output);
38 
39  return (output);
40 }
41 
42 SurfaceElementsPtr
43 computeSurfaceElements (const PointCloudPtr & input, float radius, int polynomial_order)
44 {
47  mls.setSearchRadius (radius);
48  mls.setSqrGaussParam (radius*radius);
49  mls.setPolynomialFit (polynomial_order > 1);
50  mls.setPolynomialOrder (polynomial_order);
51 
52  mls.setInputCloud (input);
53 
54  PointCloudPtr points (new PointCloud);
55  SurfaceNormalsPtr normals (new SurfaceNormals);
56  mls.setOutputNormals (normals);
57  mls.reconstruct (*points);
58 
59  SurfaceElementsPtr surfels (new SurfaceElements);
60  pcl::copyPointCloud (*points, *surfels);
61  pcl::copyPointCloud (*normals, *surfels);
62  return (surfels);
63 }
64 
65 MeshPtr
66 computeConvexHull (const PointCloudPtr & input)
67 {
68  pcl::ConvexHull<PointT> convex_hull;
69  convex_hull.setInputCloud (input);
70 
71  MeshPtr output (new Mesh);
72  convex_hull.reconstruct (*(output->points), output->faces);
73 
74  return (output);
75 }
76 
77 
78 MeshPtr
79 computeConcaveHull (const PointCloudPtr & input, float alpha)
80 {
81  pcl::ConcaveHull<PointT> concave_hull;
82  concave_hull.setInputCloud (input);
83  concave_hull.setAlpha (alpha);
84 
85  MeshPtr output (new Mesh);
86  concave_hull.reconstruct (*(output->points), output->faces);
87 
88  return (output);
89 }
90 
92 greedyTriangulation (const SurfaceElementsPtr & surfels, float radius, float mu, int max_nearest_neighbors,
93  float max_surface_angle, float min_angle, float max_angle)
94 
95 {
98 
99  gpt.setSearchRadius (radius);
100  gpt.setMaximumNearestNeighbors (max_nearest_neighbors);
101  gpt.setMu (mu);
102  gpt.setMaximumSurfaceAgle (max_surface_angle);
103  gpt.setMinimumAngle (min_angle);
104  gpt.setMaximumAngle (max_angle);
105  gpt.setNormalConsistency (true);
106 
107  gpt.setInputCloud (surfels);
109  gpt.reconstruct (*output);
110 
111  return (output);
112 }
113 
114 
116 marchingCubesTriangulation (const SurfaceElementsPtr & surfels, float leaf_size, float iso_level)
117 {
118  pcl::MarchingCubesGreedy<SurfelT> marching_cubes;
119  marching_cubes.setSearchMethod (pcl::KdTree<SurfelT>::Ptr (new pcl::KdTreeFLANN<SurfelT> ()));
120  marching_cubes.setLeafSize (leaf_size);
121  marching_cubes.setIsoLevel (iso_level);
122 
123  marching_cubes.setInputCloud (surfels);
125  marching_cubes.reconstruct (*output);
126 
127  return (output);
128 }
129 
130 #endif
PCL_EXPORTS void copyPointCloud(const pcl::PCLPointCloud2 &cloud_in, const std::vector< int > &indices, pcl::PCLPointCloud2 &cloud_out)
Extract the indices of a given point cloud as a new point cloud.
MovingLeastSquares represent an implementation of the MLS (Moving Least Squares) algorithm for data s...
Definition: mls.h:65
void setSearchRadius(double radius)
Set the sphere radius that is to be used for determining the k-nearest neighbors used for triangulati...
Definition: gp3.h:230
void setMaximumNearestNeighbors(int nnn)
Set the maximum number of nearest neighbors to be searched for.
Definition: gp3.h:219
boost::shared_ptr< ::pcl::PolygonMesh > Ptr
Definition: PolygonMesh.h:28
PointCloudPtr points
Definition: surface.h:18
ConvexHull using libqhull library.
Definition: convex_hull.h:72
void setMu(double mu)
Set the multiplier of the nearest neighbor distance to obtain the final search radius for each point ...
Definition: gp3.h:209
void setMaximumAngle(double maximum_angle)
Set the maximum angle each triangle can have.
Definition: gp3.h:252
void setPolynomialFit(bool polynomial_fit)
Sets whether the surface and normal are approximated using a polynomial, or only via tangent estimati...
Definition: mls.h:158
void setPolynomialOrder(int order)
Set the order of the polynomial to be fit.
Definition: mls.h:148
void setMinimumAngle(double minimum_angle)
Set the minimum angle each triangle should have.
Definition: gp3.h:241
Definition: surface.h:14
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
boost::shared_ptr< KdTreeFLANN< PointT > > Ptr
Definition: kdtree_flann.h:87
void setSearchRadius(double radius)
Set the sphere radius that is to be used for determining the k-nearest neighbors used for fitting...
Definition: mls.h:169
void setSearchMethod(const KdTreePtr &tree)
Provide an optional pointer to a search object.
Mesh()
Definition: surface.h:17
void setSqrGaussParam(double sqr_gauss_param)
Set the parameter used for distance based weighting of neighbors (the square of the search radius wor...
Definition: mls.h:180
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a convex hull for all points given.
void setNormalConsistency(bool consistent)
Set the flag if the input normals are oriented consistently.
Definition: gp3.h:274
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: mls.h:132
void setAlpha(double alpha)
Set the alpha value, which limits the size of the resultant hull segments (the smaller the more detai...
Definition: concave_hull.h:105
boost::shared_ptr< KdTree< PointT > > Ptr
Definition: kdtree.h:70
std::vector< pcl::Vertices > faces
Definition: surface.h:19
virtual void reconstruct(pcl::PolygonMesh &output)
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()> ...
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points ...
Definition: gp3.h:138
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a concave hull for all points given.
ConcaveHull (alpha shapes) using libqhull library.
Definition: concave_hull.h:56