Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

 pcl::PointCloud<pcl::PointXYZRGB> createPointCloud(std::Vector<Nodes> input)

which returns a point cloud. I would like to know if it is possible to take this point cloud, and make a pointer to a copy of it. pcl makes pointers to clouds like this:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudPTR(new pcl::PointCloud<pcl::PointXYZRGB>)

I have tried doing this:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudPTR(createPointCloud(nodeList))

This results in a pretty obvious error ie. createPointCloud doesnt return a pointer to a cloud.

I have also tried this:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudPTR = &createPointCloud(nodeList)

and this:

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloudPTR(&createPointCloud(nodeList))

And this results in the compile error: "taking address of temporary"

Is the only option to have the function return a pointer type or is there a way to do what i am asking?

EDIT:

Both of the below answers are correct, I have awarded Jonathon the correct tick as he got in first this time.

like image 739
Fantastic Mr Fox Avatar asked May 17 '12 22:05

Fantastic Mr Fox


Video Answer


1 Answers

Yes, use the makeShared() method.

like image 89
ergosys Avatar answered Sep 27 '22 18:09

ergosys