在QT对象类中声明PCL点云 [英] Declare a PCL point cloud in QT object class
问题描述
我是使用PCL(点云库)的新手.我尝试在QT对象类中私下声明一个点云,如下所示:
I'm new from using the PCL (Point Cloud Library). I try to declare a point cloud in QT object class in private, like this:
class pcl_sys : public QThread
{
Q_OBJECT
public:
explicit pcl_sys();
~pcl_sys();
void stop();
bool load_pcd_file(int type);
signals:
public slots:
protected:
void run();
private:
pcl::PointCloud<pcl::PointXYZ>::Ptr *cloud_test;
};
然后我在打开程序时新建了点云:
Then I new the point cloud when I opened up the program:
pcl_sys::pcl_sys()
{
cloud_test=0;
cloud_test= new pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
}
但是当我尝试加载文件时尝试清除这些点时,QT给我一个错误,表明这些点不属于模板cloud_test.
but when i try to clear the points when I try to load a file, QT give me an error shows that points is not belong to template cloud_test.
bool pcl_sys::load_pcd_file(int choice)
{
cloud_test->points.clear();
}
如何解决此问题?非常感谢.
How do I fix this issue? Thank you very much.
推荐答案
cloud_test是指向PointCloud :: Ptr类型的指针.因此,您必须使用函数get()访问其主体,然后通过它访问点.
he cloud_test is a pointer to a PointCloud::Ptr type. So you have to access to its body using function get() and then access the points through it.
pcl::PointCloud<pcl::PointXYZ>::Ptr *cloud_test;
cloud_test= new pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
if (!cloud_test) cloud_test->get()->points.clear();
您可以使用它之一.在下面,cloud_test是PointCloud :: Ptr类型(不是引用指针):
you can use this either. in the below, cloud_test is a PointCloud::Ptr type (not a reference pointer):
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_test ;
cloud_test = pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
cloud_test.get()->points.clear();
或者您可以使用boost :: shared_ptr作为指向PointCloud :: Ptr类型的指针,如下所示:
or you can use boost::shared_ptr as pointer to PointCloud::Ptr type as below:
boost::shared_ptr<pcl::PointCloud<pcl::PointXYZ>::Ptr> cloud_test;
cloud_test = boost::make_shared <pcl::PointCloud<pcl::PointXYZ>::Ptr> (new pcl::PointCloud<pcl::PointXYZ>);
cloud_test->get()->points.clear();
:)
这篇关于在QT对象类中声明PCL点云的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!