1. 程式人生 > 其它 >PCL自定義點雲型別以及出現無法解析的外部依賴項問題

PCL自定義點雲型別以及出現無法解析的外部依賴項問題

技術標籤:C++編譯點雲處理c++

自定義點雲型別並在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.