surface.h
Go to the documentation of this file.
00001 #ifndef SURFACE_H_
00002 #define SURFACE_H_
00003 
00004 #include <pcl/kdtree/kdtree_flann.h>
00005 #include <pcl/surface/mls.h>
00006 #include <pcl/surface/convex_hull.h>
00007 #include <pcl/surface/concave_hull.h>
00008 #include <pcl/surface/gp3.h>
00009 #include <pcl/surface/marching_cubes_greedy.h>
00010 
00011 #include "typedefs.h"
00012 
00013 
00014 class Mesh
00015 {
00016   public:
00017     Mesh () : points (new PointCloud) {}
00018     PointCloudPtr points;
00019     std::vector<pcl::Vertices> faces;
00020 };
00021 
00022 typedef boost::shared_ptr<Mesh> MeshPtr;
00023 
00024 PointCloudPtr
00025 smoothPointCloud (const PointCloudPtr & input, float radius, int polynomial_order)
00026 {
00027   pcl::MovingLeastSquares<PointT, NormalT> mls;
00028   mls.setSearchMethod (pcl::KdTreeFLANN<PointT>::Ptr (new pcl::KdTreeFLANN<PointT>));
00029   mls.setSearchRadius (radius);
00030   mls.setSqrGaussParam (radius*radius);
00031   mls.setPolynomialFit (polynomial_order > 1);
00032   mls.setPolynomialOrder (polynomial_order);
00033   
00034   mls.setInputCloud (input);
00035 
00036   PointCloudPtr output (new PointCloud);
00037   mls.reconstruct (*output);
00038 
00039   return (output);
00040 }
00041 
00042 SurfaceElementsPtr
00043 computeSurfaceElements (const PointCloudPtr & input, float radius, int polynomial_order)
00044 {
00045   pcl::MovingLeastSquares<PointT, NormalT> mls;
00046   mls.setSearchMethod (pcl::KdTreeFLANN<PointT>::Ptr (new pcl::KdTreeFLANN<PointT>));
00047   mls.setSearchRadius (radius);
00048   mls.setSqrGaussParam (radius*radius);
00049   mls.setPolynomialFit (polynomial_order > 1);
00050   mls.setPolynomialOrder (polynomial_order);
00051   
00052   mls.setInputCloud (input);
00053 
00054   PointCloudPtr points (new PointCloud);
00055   SurfaceNormalsPtr normals (new SurfaceNormals);
00056   mls.setOutputNormals (normals);
00057   mls.reconstruct (*points);
00058 
00059   SurfaceElementsPtr surfels (new SurfaceElements);
00060   pcl::copyPointCloud (*points, *surfels);
00061   pcl::copyPointCloud (*normals, *surfels);
00062   return (surfels);
00063 }
00064 
00065 MeshPtr
00066 computeConvexHull (const PointCloudPtr & input)
00067 {
00068   pcl::ConvexHull<PointT> convex_hull;
00069   convex_hull.setInputCloud (input);
00070 
00071   MeshPtr output (new Mesh);
00072   convex_hull.reconstruct (*(output->points), output->faces);
00073 
00074   return (output);
00075 }
00076 
00077 
00078 MeshPtr
00079 computeConcaveHull (const PointCloudPtr & input, float alpha)
00080 {
00081   pcl::ConcaveHull<PointT> concave_hull;
00082   concave_hull.setInputCloud (input);
00083   concave_hull.setAlpha (alpha);
00084 
00085   MeshPtr output (new Mesh);
00086   concave_hull.reconstruct (*(output->points), output->faces);
00087 
00088   return (output);
00089 }
00090 
00091 pcl::PolygonMesh::Ptr
00092 greedyTriangulation (const SurfaceElementsPtr & surfels, float radius, float mu, int max_nearest_neighbors, 
00093                      float max_surface_angle, float min_angle, float max_angle)
00094 
00095 {
00096   pcl::GreedyProjectionTriangulation<pcl::PointNormal> gpt;
00097   gpt.setSearchMethod (pcl::KdTreeFLANN<pcl::PointNormal>::Ptr (new pcl::KdTreeFLANN<pcl::PointNormal>));
00098 
00099   gpt.setSearchRadius (radius);
00100   gpt.setMaximumNearestNeighbors (max_nearest_neighbors);
00101   gpt.setMu (mu);
00102   gpt.setMaximumSurfaceAgle (max_surface_angle);
00103   gpt.setMinimumAngle (min_angle);
00104   gpt.setMaximumAngle (max_angle);
00105   gpt.setNormalConsistency (true);
00106 
00107   gpt.setInputCloud (surfels);
00108   pcl::PolygonMesh::Ptr output (new pcl::PolygonMesh);
00109   gpt.reconstruct (*output);
00110 
00111   return (output);
00112 }
00113 
00114 
00115 pcl::PolygonMesh::Ptr
00116 marchingCubesTriangulation (const SurfaceElementsPtr & surfels, float leaf_size, float iso_level)
00117 {
00118   pcl::MarchingCubesGreedy<SurfelT> marching_cubes;
00119   marching_cubes.setSearchMethod (pcl::KdTree<SurfelT>::Ptr (new pcl::KdTreeFLANN<SurfelT> ()));
00120   marching_cubes.setLeafSize (leaf_size);
00121   marching_cubes.setIsoLevel (iso_level);
00122 
00123   marching_cubes.setInputCloud (surfels);
00124   pcl::PolygonMesh::Ptr output (new pcl::PolygonMesh);
00125   marching_cubes.reconstruct (*output);
00126   
00127   return (output);
00128 }
00129 
00130 #endif


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:18:09