Point Cloud Library (PCL)  1.11.1-dev
surface.h
1 #pragma once
2 
3 #include <pcl/kdtree/kdtree_flann.h>
4 #include <pcl/surface/mls.h>
5 #include <pcl/surface/convex_hull.h>
6 #include <pcl/surface/concave_hull.h>
7 #include <pcl/surface/gp3.h>
8 #include <pcl/surface/marching_cubes_greedy.h>
9 
10 #include "typedefs.h"
11 
12 
13 class Mesh
14 {
15  public:
16  Mesh () : points (new PointCloud) {}
17  PointCloudPtr points;
18  std::vector<pcl::Vertices> faces;
19 };
20 
21 using MeshPtr = std::shared_ptr<Mesh>;
22 
23 PointCloudPtr
24 smoothPointCloud (const PointCloudPtr & input, float radius, int polynomial_order)
25 {
28  mls.setSearchRadius (radius);
29  mls.setSqrGaussParam (radius*radius);
30  mls.setPolynomialFit (polynomial_order > 1);
31  mls.setPolynomialOrder (polynomial_order);
32 
33  mls.setInputCloud (input);
34 
35  PointCloudPtr output (new PointCloud);
36  mls.reconstruct (*output);
37 
38  return (output);
39 }
40 
41 SurfaceElementsPtr
42 computeSurfaceElements (const PointCloudPtr & input, float radius, int polynomial_order)
43 {
46  mls.setSearchRadius (radius);
47  mls.setSqrGaussParam (radius*radius);
48  mls.setPolynomialFit (polynomial_order > 1);
49  mls.setPolynomialOrder (polynomial_order);
50 
51  mls.setInputCloud (input);
52 
53  PointCloudPtr points (new PointCloud);
54  SurfaceNormalsPtr normals (new SurfaceNormals);
55  mls.setOutputNormals (normals);
56  mls.reconstruct (*points);
57 
58  SurfaceElementsPtr surfels (new SurfaceElements);
59  pcl::copyPointCloud (*points, *surfels);
60  pcl::copyPointCloud (*normals, *surfels);
61  return (surfels);
62 }
63 
64 MeshPtr
65 computeConvexHull (const PointCloudPtr & input)
66 {
67  pcl::ConvexHull<PointT> convex_hull;
68  convex_hull.setInputCloud (input);
69 
70  MeshPtr output (new Mesh);
71  convex_hull.reconstruct (*(output->points), output->faces);
72 
73  return (output);
74 }
75 
76 
77 MeshPtr
78 computeConcaveHull (const PointCloudPtr & input, float alpha)
79 {
80  pcl::ConcaveHull<PointT> concave_hull;
81  concave_hull.setInputCloud (input);
82  concave_hull.setAlpha (alpha);
83 
84  MeshPtr output (new Mesh);
85  concave_hull.reconstruct (*(output->points), output->faces);
86 
87  return (output);
88 }
89 
91 greedyTriangulation (const SurfaceElementsPtr & surfels, float radius, float mu, int max_nearest_neighbors,
92  float max_surface_angle, float min_angle, float max_angle)
93 
94 {
97 
98  gpt.setSearchRadius (radius);
99  gpt.setMaximumNearestNeighbors (max_nearest_neighbors);
100  gpt.setMu (mu);
101  gpt.setMaximumSurfaceAgle (max_surface_angle);
102  gpt.setMinimumAngle (min_angle);
103  gpt.setMaximumAngle (max_angle);
104  gpt.setNormalConsistency (true);
105 
106  gpt.setInputCloud (surfels);
108  gpt.reconstruct (*output);
109 
110  return (output);
111 }
112 
113 
115 marchingCubesTriangulation (const SurfaceElementsPtr & surfels, float leaf_size, float iso_level)
116 {
117  pcl::MarchingCubesGreedy<SurfelT> marching_cubes;
118  marching_cubes.setSearchMethod (pcl::KdTree<SurfelT>::Ptr (new pcl::KdTreeFLANN<SurfelT> ()));
119  marching_cubes.setLeafSize (leaf_size);
120  marching_cubes.setIsoLevel (iso_level);
121 
122  marching_cubes.setInputCloud (surfels);
124  marching_cubes.reconstruct (*output);
125 
126  return (output);
127 }
pcl::GreedyProjectionTriangulation::setNormalConsistency
void setNormalConsistency(bool consistent)
Set the flag if the input normals are oriented consistently.
Definition: gp3.h:250
pcl::GreedyProjectionTriangulation::setMinimumAngle
void setMinimumAngle(double minimum_angle)
Set the minimum angle each triangle should have.
Definition: gp3.h:217
Mesh::points
PointCloudPtr points
Definition: surface.h:17
pcl::MovingLeastSquares::setPolynomialOrder
void setPolynomialOrder(int order)
Set the order of the polynomial to be fit.
Definition: mls.h:349
pcl::MovingLeastSquares
MovingLeastSquares represent an implementation of the MLS (Moving Least Squares) algorithm for data s...
Definition: mls.h:251
pcl::ConcaveHull::reconstruct
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a concave hull for all points given.
Definition: concave_hull.hpp:88
pcl::GreedyProjectionTriangulation::setMu
void setMu(double mu)
Set the multiplier of the nearest neighbor distance to obtain the final search radius for each point ...
Definition: gp3.h:185
pcl::ConcaveHull::setAlpha
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:104
pcl::MeshConstruction::reconstruct
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
Definition: reconstruction.hpp:132
pcl::MovingLeastSquares::setSearchRadius
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:360
pcl::ConvexHull::reconstruct
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a convex hull for all points given.
Definition: convex_hull.hpp:482
pcl::GreedyProjectionTriangulation::setMaximumAngle
void setMaximumAngle(double maximum_angle)
Set the maximum angle each triangle can have.
Definition: gp3.h:228
pcl::PolygonMesh::Ptr
shared_ptr< ::pcl::PolygonMesh > Ptr
Definition: PolygonMesh.h:96
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
Mesh::Mesh
Mesh()
Definition: surface.h:16
pcl::PCLBase< PointInT >::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: pcl_base.hpp:65
pcl::copyPointCloud
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
Definition: io.hpp:122
Mesh
Definition: surface.h:13
pcl::GreedyProjectionTriangulation::setSearchRadius
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:206
pcl::KdTreeFLANN< PointT >
pcl::GreedyProjectionTriangulation
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points ...
Definition: gp3.h:130
pcl::PolygonMesh
Definition: PolygonMesh.h:14
Mesh::faces
std::vector< pcl::Vertices > faces
Definition: surface.h:18
pcl::KdTree::Ptr
shared_ptr< KdTree< PointT > > Ptr
Definition: kdtree.h:68
pcl::MovingLeastSquares::setSqrGaussParam
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:371
pcl::ConvexHull
ConvexHull using libqhull library.
Definition: convex_hull.h:72
pcl::PCLSurfaceBase::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide an optional pointer to a search object.
Definition: reconstruction.h:77
pcl::MovingLeastSquares::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: mls.h:330
pcl::ConcaveHull
ConcaveHull (alpha shapes) using libqhull library.
Definition: concave_hull.h:55
pcl::KdTreeFLANN::Ptr
shared_ptr< KdTreeFLANN< PointT, Dist > > Ptr
Definition: kdtree_flann.h:84
pcl::GreedyProjectionTriangulation::setMaximumNearestNeighbors
void setMaximumNearestNeighbors(int nnn)
Set the maximum number of nearest neighbors to be searched for.
Definition: gp3.h:195