在 QT 对象类中声明 PCL 点云

Declare a PCL point cloud in QT object class

本文关键字:声明 PCL 点云 QT 对象      更新时间:2023-10-16

我是使用PCL(点云库)的新手。我尝试私下在QT对象类中声明一个点云,如下所示:

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;
};

然后我在打开程序时新建了点云:

pcl_sys::pcl_sys()
{
     cloud_test=0;
     cloud_test= new pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
}      

但是当我尝试在尝试加载文件时清除点时,QT 给我一个错误,显示点不属于模板cloud_test。

bool pcl_sys::load_pcd_file(int choice)
{
     cloud_test->points.clear();
}

如何解决此问题?谢谢。

他cloud_test是一个指向PointCloud::P tr类型的指针。因此,您必须使用函数 get() 访问其主体,然后通过它访问点。

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::P tr 类型(不是引用指针):

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::P tr 类型的指针,如下所示:

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();

:)

只需执行cloud_test = new pcl::PointCloud<pcl::PointXYZ>,而不是创建指向PointCloud的新指针。