Go to the documentation of this file.00001 #include "pointcloud_to_mesh_alg.h"
00002
00003 PointCloudToMeshAlgorithm::PointCloudToMeshAlgorithm(void):
00004 down_res_(0.01f),radius_(0.025f), mu_(1.5f), num_neigh_(100),
00005 max_surf_angle_(M_PI/4), min_ang_(M_PI/18),
00006 max_ang_(2*M_PI/3), norm_consistency_(false)
00007 {
00008 }
00009
00010 PointCloudToMeshAlgorithm::~PointCloudToMeshAlgorithm(void)
00011 {
00012 }
00013
00014 void PointCloudToMeshAlgorithm::config_update(Config& new_cfg, uint32_t level)
00015 {
00016 this->lock();
00017
00018
00019 this->config_=new_cfg;
00020
00021 this->unlock();
00022 }
00023
00024
00025 bool PointCloudToMeshAlgorithm::compute_mesh(const sensor_msgs::PointCloud2::ConstPtr& msg)
00026 {
00027 pcl::PointCloud<pcl::PointXYZ>::Ptr input_pcl (new pcl::PointCloud<pcl::PointXYZ>);
00028 pcl::fromROSMsg(*msg, *input_pcl);
00029 std::vector<int> index;
00030 pcl::removeNaNFromPointCloud (*input_pcl, *input_pcl, index);
00031 return compute_mesh(input_pcl);
00032 }
00033
00034 bool PointCloudToMeshAlgorithm::compute_mesh(pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud){
00035
00036
00037 pcl::VoxelGrid<pcl::PointXYZ> sor;
00038 sor.setInputCloud(cloud);
00039 sor.setLeafSize(down_res_, down_res_, down_res_);
00040 sor.filter(*cloud);
00041
00042 pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> n;
00043 pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
00044 pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);
00045 tree->setInputCloud (cloud);
00046 n.setInputCloud (cloud);
00047 n.setSearchMethod (tree);
00048 n.setKSearch (20);
00049 n.compute (*normals);
00050
00051
00052
00053 pcl::PointCloud<pcl::PointNormal>::Ptr cloud_with_normals (new pcl::PointCloud<pcl::PointNormal>);
00054 pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
00055
00056
00057
00058 pcl::search::KdTree<pcl::PointNormal>::Ptr tree2 (new pcl::search::KdTree<pcl::PointNormal>);
00059 tree2->setInputCloud (cloud_with_normals);
00060
00061
00062 pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp3;
00063 pcl::PolygonMesh triangles;
00064
00065
00066 gp3.setSearchRadius (radius_);
00067
00068
00069 gp3.setMu (mu_);
00070 gp3.setMaximumNearestNeighbors (num_neigh_);
00071 gp3.setMaximumSurfaceAngle(max_surf_angle_);
00072 gp3.setMinimumAngle(min_ang_);
00073 gp3.setMaximumAngle(max_ang_);
00074 gp3.setNormalConsistency(norm_consistency_);
00075
00076
00077 gp3.setInputCloud (cloud_with_normals);
00078 gp3.setSearchMethod (tree2);
00079 gp3.reconstruct (triangles);
00080
00081
00082 std::vector<int> parts = gp3.getPartIDs();
00083 std::vector<int> states = gp3.getPointStates();
00084
00085 pcl::io::saveVTKFile ("mesh.vtk", triangles);
00086 return true;
00087 }
00088
00089 void PointCloudToMeshAlgorithm::set_down_res(double down_res){
00090 down_res_ = down_res;
00091 }
00092
00093 void PointCloudToMeshAlgorithm::set_radius(double radius){
00094 radius_ = radius;
00095 }
00096
00097 void PointCloudToMeshAlgorithm::set_mu(double mu){
00098 mu_ = mu;
00099 }
00100
00101 void PointCloudToMeshAlgorithm::set_num_of_neigh(unsigned int num_neigh){
00102 num_neigh_ = num_neigh;
00103 }
00104
00105 void PointCloudToMeshAlgorithm::set_max_surface_angle(double max_surf_angle){
00106 max_surf_angle_ = max_surf_angle;
00107 }
00108
00109 void PointCloudToMeshAlgorithm::set_min_angle(double min_ang){
00110 min_ang_ = min_ang;
00111 }
00112
00113 void PointCloudToMeshAlgorithm::set_max_angle(double max_ang){
00114 max_ang_ = max_ang;
00115 }
00116
00117 void PointCloudToMeshAlgorithm::set_normal_consistency(bool norm_consistency){
00118 norm_consistency_ = norm_consistency;
00119 }