int main() { long cases, answer; scanf("%ld", &cases); while (cases--) { input(); findConvexHull(); answer = calArea(); if (answer & 1) printf("%ld.5\n", answer / 2); else printf("%ld.0\n", answer / 2); } return 0; }
/** * @brief It computes de boundary of a cloud. The mask must have at least one element. * * @param cloud Cloud in which the boundary are computed. */ void PlaneSegmentation::computeBoundary(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud) { // Compute normals. pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>()); estimateNormals(cloud, normals, 0.015); // Ignore points with a different normal. pcl::PointIndices::Ptr filtIndices(new pcl::PointIndices()); filterByNormal(normals, maskIndices, coefficients, 15.0, filtIndices); // Project point cloud to a plane. pcl::ModelCoefficients::ConstPtr coefPtr = boost::make_shared<pcl::ModelCoefficients>(coefficients); pcl::PointCloud<pcl::PointXYZRGBA>::Ptr projectedCloud = pcl::PointCloud<pcl::PointXYZRGBA>::Ptr(new pcl::PointCloud<pcl::PointXYZRGBA>()); projectToPlane(cloud, coefPtr, projectedCloud); // Clustering. std::vector<pcl::PointIndices> clusterIndices; clustering(projectedCloud, filtIndices, 0.02, 5000, clusterIndices); assert(clusterIndices.size() > 0); // Find the biggest cluster. int max_size = clusterIndices[0].indices.size(); int max_pos = 0; for(int i = 0; i < clusterIndices.size(); i++) { if (clusterIndices[i].indices.size() > max_size) { max_size = clusterIndices[i].indices.size(); max_pos = i; } } pcl::PointIndices::ConstPtr clusterIndicesPtr = boost::make_shared<pcl::PointIndices>(clusterIndices[max_pos]); // Compute the convex hull of the cluster. pcl::PointIndices hullIndices = pcl::PointIndices(); findConvexHull(projectedCloud, clusterIndicesPtr, hullIndices); pcl::PointIndices::ConstPtr hullIndicesPtr = boost::make_shared<pcl::PointIndices>(hullIndices); // Simplify convex polygon. pcl::PointIndices boundaryIndices; polygonSimplification(projectedCloud, hullIndicesPtr, coefficients.values, 4, boundaryIndices); // Copy boundary points. boundary = std::vector<pcl::PointXYZRGBA>(boundaryIndices.indices.size()); for(int j = 0; j < boundary.size(); j++) { boundary[j] = cloud->points[boundaryIndices.indices[j]]; } }