Create a pcl::PointCloud::Ptr from a pcl::PointCloud

前端 未结 2 1579
有刺的猬
有刺的猬 2021-02-13 23:57

I would like to know if this is possible. I have a function:

 pcl::PointCloud createPointCloud(std::Vector input)

相关标签:
2条回答
  • 2021-02-14 00:42

    Yes, use the makeShared() method.

    0 讨论(0)
  • 2021-02-14 00:51

    I know this is old and probably of no more use to OP, but other users might stumble upon it. I would suggest doing it as follows:

    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudPTR(new pcl::PointCloud<pcl::PointXYZRGB>);
    *cloudPTR = createPointCloud(nodeList);
    

    The reason Jonathon's answer is dangerous is that Pointcloud::Ptr is a typedef for a boost::shared_ptr which implies ownership of the object pointed to. In his answer, however, the object is actually a local variable meaning that it might go out of scope while there are still references to it and that shared_ptr will eventually call delete on it, which is undefined behavior.

    Using make_shared() on the other hand deep copies the cloud. The program will work correctly, but if you didn't need the extra copy, it is far from optimal.

    0 讨论(0)
提交回复
热议问题