1、判断点云的点是否是有效的
pcl::PointXYZ p_valid; p_valid.x = 0; p_valid.y = 0; p_valid.z = 0; std::cout << "Is p_valid valid? " << pcl::isFinite(p_valid) << std::endl; // If any component is NaN, the point is not finite. pcl::PointXYZ p_invalid; p_invalid.x = std::numeric_limits<float>::quiet_NaN(); p_invalid.y = 0; p_invalid.z = 0; std::cout << "Is p_invalid valid? " << pcl::isFinite(p_invalid) << std::endl;
打印结果:
2、复制同类的点云
// 拷贝点云 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>()); pcl::PointCloud<pcl::PointXYZ>::PointType p;// 相当于 pcl::PointXYZ p; p.x = 1; p.y = 2; p.z = 3; cloud->push_back(p); std::cout << p.x << " " << p.y << " " << p.z << std::endl; pcl::PointCloud<pcl::PointXYZ>::Ptr cloud2(new pcl::PointCloud<pcl::PointXYZ>()); copyPointCloud(*cloud, *cloud2);// 相同类型复制 pcl::PointCloud<pcl::PointXYZ>::PointType p_retrieved = (*cloud2)[0]; //pcl::PointXYZ p_retrieved = cloud2->points.at(0);// 同上 std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl;
结果:
3、 类型不同的点云复制
// 拷贝点云 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>()); pcl::PointCloud<pcl::PointXYZ>::PointType p;// 相当于 pcl::PointXYZ p; p.x = 1; p.y = 2; p.z = 3; cloud->push_back(p); std::cout << p.x << " " << p.y << " " << p.z << std::endl; pcl::PointCloud<pcl::PointNormal>::Ptr cloud2(new pcl::PointCloud<pcl::PointNormal>()); copyPointCloud(*cloud, *cloud2);// 不同类型复制,注意cloud2是包含点和法线的,若类型是pcl::Normal会报错 //pcl::PointCloud<pcl::PointNormal>::PointType p_retrieved = (*cloud2)[0]; pcl::PointNormal p_retrieved = cloud2->points.at(0);// 同上 std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl; std::cout << cloud2->points.at(0).x << " " << cloud2->points.at(0).y << " " << cloud2->points.at(0).z << std::endl; std::cout << cloud2->points.at(0).normal[0] << std::endl; std::cout << cloud2->points.at(0).normal_y << std::endl; std::cout << cloud2->points.at(0).normal[2] << std::endl;
结果:
4、获取导入点云文件的最大值和最小值点
pcl::PointXYZ minPt, maxPt; pcl::getMinMax3D(*n.cloud, minPt, maxPt); std::cout << "Max x: " << maxPt.x << std::endl; std::cout << "Max y: " << maxPt.y << std::endl; std::cout << "Max z: " << maxPt.z << std::endl; std::cout << "Min x: " << minPt.x << std::endl; std::cout << "Min y: " << minPt.y << std::endl; std::cout << "Min z: " << minPt.z << std::endl;
结果:
另一种写法:
// 遍历点云区间 for (const auto& p : n.cloud->points) { if (minX > p.x) minX = p.x; if (minX > p.y) minY = p.y; if (minX > p.z) minZ = p.z; if (maxX < p.x) maxX = p.x; if (maxY < p.y) maxY = p.y; if (maxZ < p.z) maxZ = p.z; } qDebug() << minX << minY << minZ << maxX << maxY << maxZ;
结果:
导入的是同一个文件,但为什么结果不一样呢,因为这个没有做无效点判断,而上面那个底层是有判断的
5、组织有序的点云
// Setup the cloud using PointType = pcl::PointXYZ; using CloudType = pcl::PointCloud<PointType>; CloudType::Ptr cloud(new CloudType); // Make the cloud a 10x10 grid cloud->height = 10; cloud->width = 10; cloud->is_dense = true; cloud->resize(cloud->height * cloud->width); // Output the (0,0) point std::cout << (*cloud)(0, 0) << std::endl; // Set the (0,0) point PointType p; p.x = 1; p.y = 2; p.z = 3; (*cloud)(0, 0) = p; // Confirm that the point was set std::cout << (*cloud)(0, 0) << std::endl;
结果:
标签:cloud2,例子,文档,pcl,点云,PointCloud,cloud,points From: https://www.cnblogs.com/yaoshunyu/p/18435030