PCL自定义点云类型以及出现无法解析的外部依赖项问题

自定义点云类型并在PCL中进行使用

定义点云类型

  自定义点云类型很简单,也有很多博客介绍了。这里介绍一种自定义的点云类型,每个点附加了一个 时间,存储于double变量中,如下:

//Point Type: x/y/z/GPS time
struct _PointXYZT
{
	PCL_ADD_POINT4D;
	double gps_time;
	EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
}EIGEN_ALIGN16;

struct EIGEN_ALIGN16 PointXYZT: public _PointXYZT
{
	inline PointXYZT(const _PointXYZT &p)
	{
		x = p.x; y = p.y; z = p.z; data[3] = 1.0f;
		gps_time = p.gps_time;
	}

	inline PointXYZT()
	{
		x = y = z = 0.0f;
		data[3] = 1.0f;
		gps_time = 0.0;
	}
	inline PointXYZT(double _time)
	{
		x = y = z = 0.0f;
		data[3] = 1.0f;
		gps_time = _time;
	}

	friend std::ostream& operator << (std::ostream& os, const PointXYZT& p);
	EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};

不要忘了进行注册。

POINT_CLOUD_REGISTER_POINT_STRUCT(_PointXYZT,
(float, x, x)
(float, y, y)
(float, z, z)
(double, gps_time, gps_time)
)

POINT_CLOUD_REGISTER_POINT_WRAPPER(PointXYZT, _PointXYZT)

至于重载的operator函数,按照分文件类外定义的形式写在另外一个cpp文件中即可。

std::ostream& operator << (std::ostream& os, const PointXYZT& p)
{
	os << std::setprecision(3) << "(" << p.x << "," << p.y << "," << p.z << " - "
		<< static_cast<double>(p.gps_time) << ")";
	return (os);
}

使用PCL中的函数

  • 编译时会出现报错,error2001,无法解析的外部符号xxxx这种的。

解决方案: 是在使用函数模板时,添加一个宏定义#define PCL_NO_PRECOMPILE在调用函数模板之前。一般我就用如下的方式:写在hpp,cpp或.h文件最前面。

#ifndef PCL_NO_PRECOMPILE
#define PCL_NO_PRECOMPILE
#endif // PCL_NO_PRECOMPILE
...e.g. kdtree, voxelfilter balabala

Reference

pcl新版说明文档
原话是:
Then, you need to make sure your code includes the template header implementation of the specific class/algorithm in PCL that you want your new point type MyPointType to work with. For example, say you want to use pcl::PassThrough.

  • Starting with PCL-1.7 you need to define PCL_NO_PRECOMPILE before you include any PCL headers to include the templated algorithms as well.
上一篇:8:C++搭配PCL旋转点云和平移点云(自定义旋转矩阵)


下一篇:PCL 常用拟合模型及使用方法