首先定义自己的消息类型
struct CustomPoint { // 定义点类型结构
PCL_ADD_POINT4D; // 该点类型有4个元素
float intensity = 0.0;
uint32_t zone;
uint32_t ring;
uint32_t sector;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // 确保new操作符对齐操作
} EIGEN_ALIGN16; // 强制SSE对齐
POINT_CLOUD_REGISTER_POINT_STRUCT( // 注册点类型宏
CustomPoint,
(float, x, x)
(float, y, y)
(float, z, z)
(float, intensity, intensity)
(uint32_t, zone, zone)
(uint32_t, ring, ring)
(uint32_t, sector, sector)
)
// typedef pcl::PointXYZI VPoint;
typedef CustomPoint VPoint;
typedef pcl::PointCloud<VPoint> VPointType;
在定义完自己的消息类型之后,调用pcl::removeNaNFromPointCloud等自带的函数时会报错:
(.text+0x14631): undefined reference to `pcl::PCLBase<CustomPoint>::PCLBase(
cl::removeNaNFromPointCloud<CustomPoint>(pcl::PointCloud<CustomPoint> const&, pcl::PointCloud<CustomPoint>&, std::vector<int, std::allocator<int> >&)'
collect2: error: ld returned 1 exit status
代码如下:
void PatchWorkpp::pointcloud_callback(const sensor_msgs::PointCloud2::ConstPtr &input)
{
VPointType::Ptr cloud_in = boost::make_shared<VPointType>();
VPointType::Ptr src_cloud(new VPointType);
pcl::fromROSMsg(*input, *cloud_in);
std::vector<int> mapping;
pcl::removeNaNFromPointCloud(*cloud_in, *cloud_in, mapping); // 必须要移除NAN点}
此时需要添加头文件如下:
#include <pcl/impl/pcl_base.hpp>
#include <pcl/filters/impl/crop_box.hpp>
#include <pcl/filters/impl/filter.hpp>
#include <pcl/kdtree/impl/kdtree_flann.hpp>
#include <pcl/search/impl/organized.hpp>
#include <pcl/surface/impl/convex_hull.hpp>
参考文章:
https://blog.csdn.net/qq_43427457/article/details/125052803