【问题标题】:Declare a PCL point cloud in QT object class在 QT 对象类中声明一个 PCL 点云
【发布时间】:2014-03-24 03:49:20
【问题描述】:

我刚开始使用 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();
}

我该如何解决这个问题?非常感谢。

【问题讨论】:

    标签: c++ qt point-cloud-library


    【解决方案1】:

    他的 cloud_test 是一个指向 PointCloud::Ptr 类型的指针。所以你必须使用函数 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::Ptr 类型(不是引用指针):

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

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

    :)

    【讨论】:

    • 还有一个问题,谢谢。它适用于points.clear(); Bit 我有点搞砸了。我现在无法加载文件。 pcl::io::loadPCDFile(fileName.toStdString(), cloud_test-&gt;get()-&gt;Ptr)
    • 注意转换,如果你用过pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr cloud_test;那么你应该使用这样的函数:pcl::io::loadPCDFile("o.pcd", *(cloud_test-&gt;get()));
    • 谢谢。我有点被这些类型搞砸了。
    • 是的,他们把我的脑袋炸飞了! :)
    【解决方案2】:

    只需执行cloud_test = new pcl::PointCloud&lt;pcl::PointXYZ&gt; 而不是创建指向PointCloud 的新指针。

    【讨论】:

    • 如果我将声明和新点云更改为 pcl::PointCloud&lt;pcl::PointXYZ&gt;,我将无法加载任何 PCD 文件,因为 QT 不会接受 cloud_test-&gt;Ptr
    • 你的意思是我把cloud_test= new pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr (new pcl::PointCloud&lt;pcl::PointXYZ&gt;);改成cloud_test = new pcl::PointCloud&lt;pcl::PointXYZ&gt;?它不起作用,我正在使用 QT 5.2.1 和 PCL 1.6.0
    猜你喜欢
    • 2020-01-23
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    相关资源
    最近更新 更多