Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

c++ - Declare a PCL point cloud in QT object class

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...