Loading...
Searching...
No Matches
surface.h
#pragma once
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/mls.h>
#include <pcl/surface/convex_hull.h>
#include <pcl/surface/concave_hull.h>
#include <pcl/surface/gp3.h>
#include <pcl/surface/marching_cubes_greedy.h>
#include "typedefs.h"
class Mesh
{
public:
Mesh () : points (new PointCloud) {}
PointCloudPtr points;
std::vector<pcl::Vertices> faces;
};
using MeshPtr = std::shared_ptr<Mesh>;
PointCloudPtr
smoothPointCloud (const PointCloudPtr & input, float radius, int polynomial_order)
{
pcl::MovingLeastSquares<PointT, NormalT> mls;
mls.setSearchMethod (pcl::KdTreeFLANN<PointT>::Ptr (new pcl::KdTreeFLANN<PointT>));
mls.setSearchRadius (radius);
mls.setSqrGaussParam (radius*radius);
mls.setPolynomialFit (polynomial_order > 1);
mls.setPolynomialOrder (polynomial_order);
mls.setInputCloud (input);
PointCloudPtr output (new PointCloud);
mls.reconstruct (*output);
return (output);
}
SurfaceElementsPtr
computeSurfaceElements (const PointCloudPtr & input, float radius, int polynomial_order)
{
pcl::MovingLeastSquares<PointT, NormalT> mls;
mls.setSearchMethod (pcl::KdTreeFLANN<PointT>::Ptr (new pcl::KdTreeFLANN<PointT>));
mls.setSearchRadius (radius);
mls.setSqrGaussParam (radius*radius);
mls.setPolynomialFit (polynomial_order > 1);
mls.setPolynomialOrder (polynomial_order);
mls.setInputCloud (input);
PointCloudPtr points (new PointCloud);
SurfaceNormalsPtr normals (new SurfaceNormals);
mls.setOutputNormals (normals);
mls.reconstruct (*points);
SurfaceElementsPtr surfels (new SurfaceElements);
pcl::copyPointCloud (*points, *surfels);
pcl::copyPointCloud (*normals, *surfels);
return (surfels);
}
MeshPtr
computeConvexHull (const PointCloudPtr & input)
{
pcl::ConvexHull<PointT> convex_hull;
convex_hull.setInputCloud (input);
MeshPtr output (new Mesh);
convex_hull.reconstruct (*(output->points), output->faces);
return (output);
}
MeshPtr
computeConcaveHull (const PointCloudPtr & input, float alpha)
{
pcl::ConcaveHull<PointT> concave_hull;
concave_hull.setInputCloud (input);
concave_hull.setAlpha (alpha);
MeshPtr output (new Mesh);
concave_hull.reconstruct (*(output->points), output->faces);
return (output);
}
pcl::PolygonMesh::Ptr
greedyTriangulation (const SurfaceElementsPtr & surfels, float radius, float mu, int max_nearest_neighbors,
float max_surface_angle, float min_angle, float max_angle)
{
pcl::GreedyProjectionTriangulation<pcl::PointNormal> gpt;
gpt.setSearchMethod (pcl::KdTreeFLANN<pcl::PointNormal>::Ptr (new pcl::KdTreeFLANN<pcl::PointNormal>));
gpt.setSearchRadius (radius);
gpt.setMaximumNearestNeighbors (max_nearest_neighbors);
gpt.setMu (mu);
gpt.setMaximumSurfaceAgle (max_surface_angle);
gpt.setMinimumAngle (min_angle);
gpt.setMaximumAngle (max_angle);
gpt.setNormalConsistency (true);
gpt.setInputCloud (surfels);
pcl::PolygonMesh::Ptr output (new pcl::PolygonMesh);
gpt.reconstruct (*output);
return (output);
}
pcl::PolygonMesh::Ptr
marchingCubesTriangulation (const SurfaceElementsPtr & surfels, float leaf_size, float iso_level)
{
pcl::MarchingCubesGreedy<SurfelT> marching_cubes;
marching_cubes.setSearchMethod (pcl::KdTree<SurfelT>::Ptr (new pcl::KdTreeFLANN<SurfelT> ()));
marching_cubes.setLeafSize (leaf_size);
marching_cubes.setIsoLevel (iso_level);
marching_cubes.setInputCloud (surfels);
pcl::PolygonMesh::Ptr output (new pcl::PolygonMesh);
marching_cubes.reconstruct (*output);
return (output);
}
Mesh
Definition surface.h:14
Mesh::Mesh
Mesh()
Definition surface.h:16
Mesh::faces
std::vector< pcl::Vertices > faces
Definition surface.h:18
Mesh::points
PointCloudPtr points
Definition surface.h:17
pcl::ConcaveHull
ConcaveHull (alpha shapes) using libqhull library.
Definition concave_hull.h:56
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::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:102
pcl::ConvexHull
ConvexHull using libqhull library.
Definition convex_hull.h:73
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
GreedyProjectionTriangulation is an implementation of a greedy triangulation algorithm for 3D points ...
Definition gp3.h:132
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:186
pcl::GreedyProjectionTriangulation::setNormalConsistency
void setNormalConsistency(bool consistent)
Set the flag if the input normals are oriented consistently.
Definition gp3.h:230
pcl::GreedyProjectionTriangulation::setMaximumNearestNeighbors
void setMaximumNearestNeighbors(int nnn)
Set the maximum number of nearest neighbors to be searched for.
Definition gp3.h:175
pcl::GreedyProjectionTriangulation::setMinimumAngle
void setMinimumAngle(double minimum_angle)
Set the minimum angle each triangle should have.
Definition gp3.h:197
pcl::GreedyProjectionTriangulation::setMaximumAngle
void setMaximumAngle(double maximum_angle)
Set the maximum angle each triangle can have.
Definition gp3.h:208
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:165
pcl::KdTreeFLANN
KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures.
Definition kdtree_flann.h:132
pcl::KdTreeFLANN::Ptr
shared_ptr< KdTreeFLANN< PointT, Dist > > Ptr
Definition kdtree_flann.h:151
pcl::KdTree::Ptr
shared_ptr< KdTree< PointT > > Ptr
Definition kdtree.h:69
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
MovingLeastSquares represent an implementation of the MLS (Moving Least Squares) algorithm for data s...
Definition mls.h:253
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:361
pcl::MovingLeastSquares::setPolynomialOrder
void setPolynomialOrder(int order)
Set the order of the polynomial to be fit.
Definition mls.h:339
pcl::MovingLeastSquares::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition mls.h:320
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:350
pcl::PCLBase::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition pcl_base.hpp:65
pcl::PCLSurfaceBase::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide an optional pointer to a search object.
Definition reconstruction.h:78
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition point_cloud.h:173
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:142
pcl::PolygonMesh
Definition PolygonMesh.h:15
pcl::PolygonMesh::Ptr
shared_ptr< ::pcl::PolygonMesh > Ptr
Definition PolygonMesh.h:96