将自定义函数放在类外,报多次定义
const bool sortHeight(pcl::PointXYZI& x, pcl::PointXYZI& y) { return (x.z < y.z); };
void GetMinAndMaxHeight(pcl::PointCloud<pcl::PointXYZI>::Ptr input, double &minZ, double &maxZ)
{
std::sort(input->points.begin(), input->points.end(), sortHeight);
minZ = (input->points.begin())->z;
maxZ = (input->points.end())->z;
std::cout << "get min and max height: minZ" << minZ << ", maxZ " << maxZ << std::endl;
}
放在class内编译不过
最后使用lamba表达式搞定
void MapYaml::GetMinAndMaxHeight(pcl::PointCloud<pcl::PointXYZI>::Ptr input, double &minZ, double &maxZ)
{
std::sort(input->points.begin(), input->points.end(), [](pcl::PointXYZI& a, pcl::PointXYZI& b){
return (a.z < b.z);
});
minZ = (input->points.begin())->z;
maxZ = (input->points.end())->z;
std::cout << "get min and max height: minZ" << minZ << ", maxZ " << maxZ << std::endl;
}