Pregunta

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.

¿Fue útil?

Solución

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

:)

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top