我试图使用模板类来使用我的函数而不管点类型。我读了“编写一个新的PCL类”教程,但我没有得到它。我将分享我尝试使用这种技术的最简单的类。它唯一的功能是在执行父进程树的正确点创建一个pointcloud的KDtree。
KdtreeBuilder_Process.h
#ifndef KDTREEBUILDER_PROCESS_H
#define KDTREEBUILDER_PROCESS_H
#include "ProcessManager/ProcessConcurrent.h" //Parent class
#include <pcl/kdtree/kdtree_flann.h>
class KdtreeBuilder_Process:public ProcessConcurrent
{
public:
KdtreeBuilder_Process(pcl::PointCloud<pcl::PointXYZ>::Ptr inputCloud,pcl::KdTree<pcl::PointXYZ>::Ptr cloudKdtree);
virtual void run(); //method that executed when the process starts
private:
pcl::PointCloud<pcl::PointXYZ>::Ptr mInputCloud;
pcl::KdTree<pcl::PointXYZ>::Ptr mCloudKdtree;
};
#endif // KDTREEBUILDER_PROCESS_H
KdtreeBuilder_Process.cpp
#include "KdtreeBuilder_Process.h"
KdtreeBuilder_Process::KdtreeBuilder_Process(pcl::PointCloud<pcl::PointXYZ>::Ptr inputCloud,pcl::KdTree<pcl::PointXYZ>::Ptr cloudKdtree):
mInputCloud(inputCloud),mCloudKdtree(cloudKdtree)
{
}
void KdtreeBuilder_Process::run(){
mCloudKdtree->setInputCloud(mInputCloud);
}
我的目的是能够将此类用于包含XYZ坐标的任何点类型
感谢您的支持。 BR
答案 0 :(得分:0)
首先,在处理模板时,您必须接受所有实现都需要移动到头文件。如果您希望KdtreeBuilder_Process
成为一个在参数中使用point类的模板,您只需要添加适当的模板声明语法:
template<class PointType>
class KdtreeBuilder_Process:public ProcessConcurrent
{
public:
如果PointCloud
类已准备好接受所有具有XYZ坐标的类,则只需相应地更改代码
KdtreeBuilder_Process(pcl::PointCloud<PointType>::Ptr inputCloud,pcl::KdTree<PointType>::Ptr cloudKdtree): mInputCloud(inputCloud), mCloudKdtree(cloudKdtree) { }
virtual void run(){
mCloudKdtree->setInputCloud(mInputCloud);
}
private:
pcl::PointCloud<PointType>::Ptr mInputCloud;
pcl::KdTree<PointType>::Ptr mCloudKdtree;
};
祝你好运!
答案 1 :(得分:0)
我解决了这个问题。以下是仅使用头文件的最终解决方案:
KdtreeBuilder_Process.h
#ifndef KDTREEBUILDER_PROCESS_H
#define KDTREEBUILDER_PROCESS_H
#include "ProcessManager/ProcessConcurrent.h"
#include "PointDefinitions.h"
#include <pcl/kdtree/kdtree_flann.h>
#include <QDebug>
template<class PointType>
class KdtreeBuilder_Process:public ProcessConcurrent
{
typedef typename pcl::PointCloud<PointType>::Ptr PointCloudPtr;
typedef typename pcl::KdTree<PointType>::Ptr KdTreePtr;
public:
KdtreeBuilder_Process(PointCloudPtr inputCloud,KdTreePtr cloudKdtree): mInputCloud(inputCloud), mCloudKdtree(cloudKdtree) { }
virtual void run(){
mCloudKdtree->setInputCloud(mInputCloud);
}
private:
PointCloudPtr mInputCloud;
KdTreePtr mCloudKdtree;
};
#endif // KDTREEBUILDER_PROCESS_H