0
$\begingroup$

Rosanswers logo

Dear all, I am using Indigo, coming from Groovy and Hydro, I found it difficult to understand the internals of pcl_ros and pcl_conversions packages.

My problem is the following: I have a subscription callback like this: void RosHandler::xtionCloudCallback(const sensor_msgs::PointCloud2::ConstPtr& msg); or, for me it's the same, like this: void RosHandler::xtionCloudCallback(const pcl::PointCloudpcl::PointXYZRGB::ConstPtr& msg);

the first question is: is this pcl::PointCloudpcl::PointXYZRGB the same as in pcl? if it is the same, how can I clone the data, in such a way that I can use them without bothering of what ROS is doing meanwhile (i.e., in another thread)?

What I did in Groovy (and it worked) was to manually copy the message field by field (and cloning "data"), but it does not work anymore (and, indeed, I was not sure it was safe to do that in that way).

EDIT: when I say "it does not work" I mean that it segfault when I delete the new (cloned) cloud, so this means the ownership of the cloud was not (entirely?) mine EDIT2: the problem is not only I cannot delete the cloud, of course, but also that I cannot read it (it has been deleted by someone else)


Originally posted by madmage on ROS Answers with karma: 293 on 2014-09-18

Post score: 1

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

just to expand on @Paulbovbel 's answer

If you want to continue with processing shared_ptrs maybe the makeShared() method helps you. Creates a deep copy of the cloud and returns you a shared_ptr to the copied cloud, see:

http://docs.pointclouds.org/trunk/classpcl_1_1_point_cloud.html#a7b01fdbe1dba1e640bbabc0295021e75


Originally posted by Wolf with karma: 7555 on 2014-09-19

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

Yes it is the same object as in PCL, so the same APIs will work. pcl::Poincloud has a copy constructor that you can use to make the copy (pcl::Poincloud copy = pcl::PointCloud(*cloud_msg_const_ptr))

Addendum, the message you receive is const, so you can feel safe using the received cloud directly without copying, as long as you don't need/try to modify it.


Originally posted by paulbovbel with karma: 4518 on 2014-09-18

This answer was NOT ACCEPTED on the original site

Post score: 1


Original comments

Comment by madmage on 2014-09-19:
Actually, I temporary solved the problem,by cloning the vector (that I know how to deep-clone), and it works without segfaults. It means that during the copy (I tested with the copy constructor and with the copy field by field) there's something in the header that is not copied properly

Comment by paulbovbel on 2014-09-19:
Either copy constructor or @Wolf's answer (makeShared()) should work to make a deep copy the original object.

Comment by paulbovbel on 2014-09-19:
I'm not really sure what you mean by cloning, but for modern C++ with std and boost libraries and RAII, there's not many occasions when you should be calling delete on anything, ever. If you want to post a gist of your code, I could tell you more.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.