Declare a PCL point cloud in QT object class

筅森魡賤 提交于 2019-12-12 06:27:14

问题


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

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.


回答1:


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

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

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

:)




回答2:


Just do cloud_test = new pcl::PointCloud<pcl::PointXYZ> instead of creating a new pointer to a PointCloud.



来源:https://stackoverflow.com/questions/21954618/declare-a-pcl-point-cloud-in-qt-object-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!