ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Filtering (more than once) a Pointcloud.

asked 2012-03-12 09:01:17 -0600

JoaquinV gravatar image

updated 2016-10-24 09:02:40 -0600

ngrennan gravatar image

Hello all, I've been trying to use the point cloud generated by a Kinect camera to fill an occupancy grid. To do so, I have used a passthrough filter (following the information provided in this answer), and the filter is working as expected using an adaptation of this code.

The thing is, in that sample of code both the input and the output cloud are of the same data type (pointcloud::ptr), so if I wanted to filter the same cloud more than once (on two different axis, for instance), there shouldn't be a problem. But when I try to do it with the output I'm getting from the camera, the compiler says I need a const pointer for the input, and a pointcloud for the output of the filter.

Things I've tried:

  • Using Pointcloud2Ptr as the data type (instead of just pointcloud2). The code compiles just fine, but the execution fails with an unhelpful error ("Assertion failed"). It appears to be a problem with how I've used the contructor, but since 2 out of 3 links for pointcloud2 404'd when I was looking for information, I'm not entirely sure what is the correct way to initialize the pointcloud pointers.

  • Various combinations of referencing/dereferencing both the pointclouds and the pointers. None of them seemed to be correct.

  • Converting the input cloud from pointcloud2 to pointcloud and using the same code linked above. This does in fact return the same error, assertion failed.

So, my question is: am I facing this problem correctly? Is there a way to use the same pointcloud as both the input and the output cloud of a passthrough filter?

I hope I didn't miss any important information.

Thanks in advance.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2012-03-12 10:11:10 -0600

Mac gravatar image

In general, PCL filters are not meant to be used in-place; if that works, all that's happened is that you've gotten lucky.

And .makeShared() does, in fact, make a copy. In general, the way to use PCL is to do everything as a pointer explicitly; the correct construction is then

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>());

which gets you a smart pointer for passing around (a boost::shared_ptr, behind the scenes).

I strongly recommend a typedef or three to make that less painful to type...

edit flag offensive delete link more
0

answered 2012-03-14 03:26:22 -0600

JoaquinV gravatar image

Thanks a lot. I think I linked the wrong code in the OP, but what I was doing was subscribing to a sensor message, and then designing my combination of filters in a callback function (as suggested in one of the pcl_ros tutorials which I meant to link originally).

As I said, the problem was me misusing the constructor. Once I used it properly, using both the code and the topic provided, everything works perfectly, and I can filter the same pointcloud as many times as I need. Since I ended up working with pointers, I didn't need to use makeShared() to make it work.

edit flag offensive delete link more

Comments

In general, you should update (or comment on) your original post, rather than writing a followup; this isn't exactly a message board. What would be nice, though, would be to accept my answer (the check mark).

Mac gravatar image Mac  ( 2012-03-14 06:55:38 -0600 )edit

Question Tools

Stats

Asked: 2012-03-12 09:01:17 -0600

Seen: 2,779 times

Last updated: Mar 14 '12