Created
September 11, 2015 13:45
-
-
Save pranny/38e23fb68bd352505f06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool findConcaveHull(pcl::PointCloud <pcl::PointXYZRGB>::Ptr cloud, pcl::PointCloud <pcl::PointXYZRGB>::Ptr &hull) | |
{ | |
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_projected (new pcl::PointCloud<pcl::PointXYZRGB>); | |
pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients); | |
pcl::PointIndices::Ptr inliers (new pcl::PointIndices); | |
// Create the segmentation object | |
pcl::SACSegmentation<pcl::PointXYZRGB> seg; | |
// Optional | |
seg.setOptimizeCoefficients (true); | |
// Mandatory | |
seg.setModelType (pcl::SACMODEL_PLANE); | |
seg.setMethodType (pcl::SAC_RANSAC); | |
seg.setDistanceThreshold (0.01); | |
seg.setInputCloud (cloud); | |
seg.segment (*inliers, *coefficients); | |
std::cerr << "PointCloud after segmentation has: " | |
<< inliers->indices.size () << " inliers." << std::endl; | |
pcl::ProjectInliers<pcl::PointXYZRGB> proj; | |
proj.setModelType (pcl::SACMODEL_PLANE); | |
proj.setIndices (inliers); | |
proj.setInputCloud (cloud); | |
proj.setModelCoefficients (coefficients); | |
proj.filter (*cloud_projected); | |
pcl::ConcaveHull<pcl::PointXYZRGB> chull; | |
chull.setInputCloud (cloud_projected); | |
chull.setAlpha (0.1); | |
chull.reconstruct (*hull); | |
std::cerr << "Concave hull has: " << hull->points.size () | |
<< " data points." << std::endl; | |
std::cout<< "Dimensionality: "<< chull.getDimension () << std::endl; | |
for (size_t i =0; i < hull->points.size() ; ++i) | |
{ | |
std::cout << "Point " << i << " : [" << hull->points[i].x << ", " << hull->points[i].y << ", " << hull->points[i].z << std::endl; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment