Point cloud coppy issues

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Point cloud coppy issues

quark90
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Cyril_TheRobotStudio
Hello,

I have to do the same kind of thing in my code, I'm doing it very differently, but I don't know what's the best way though, if other people have any advices.

So i'm doing this :

//Define the previous frame as a pointer, outside the loop
pcl::PointCloud<pcl::PointXYZ>::Ptr prev_cloud(new pcl::PointCloud<pcl::PointXYZ>);

//Define the current frame as a pointer too
pcl::PointCloud<pcl::PointXYZ>::Ptr current_cloud(new pcl::PointCloud<pcl::PointXYZ>);

//in your loop :
//update the current_cloud with a new frame

//just use a passthrough filter to cut area of interest :
pcl::PassThrough<pcl::PointXYZ> pass;
pass.setInputCloud (current_cloud);
pass.setFilterFieldName ("x"); //cut along X axis, or use "z" or "y"
pass.setFilterLimits (X1, X2); //cut cloud outside planes x=X1 and x=X2
pass.filter(*current_cloud); //save the cloud

//do all your process

//at the end of the loop, update the content of the previous cloud with the content of the current one
*prev_cloud = *current_cloud;


I've got a question, is it possible to use PassThrough with something else than planes, but cylinder or sphere instead, or more generally any mathematical surface description ?

Cheers,
Cyril
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Sergey
Administrator
Hi Cyril,

Cyril_TheRobotStudio wrote
//at the end of the loop, update the content of the previous cloud with the content of the current one
*prev_cloud = *current_cloud;
Is there any particular reason to dereference pointers in this assignment? If you just omit both stars, you will get rid of unnecessary memory copying, and the code will be executed faster.

Cyril_TheRobotStudio wrote
I've got a question, is it possible to use PassThrough with something else than planes, but cylinder or sphere instead, or more generally any mathematical surface description ?
What do you mean when you say that PassThrough is used with planes? For example, when you filter along Z axis, you are basically cutting a sphere!

Regards,
Sergey
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Cyril_TheRobotStudio
Hi Sergey,

Thanks for your reply.

taketwo wrote
Is there any particular reason to dereference pointers in this assignment? If you just omit both stars, you will get rid of unnecessary memory copying, and the code will be executed faster.
I'm not sure, if I do :
prev_cloud = current_cloud;
They point to the same address now, so to the same data. So if I update current_cloud, I erase prev_cloud data, or am I missing something ?
But I agree there's a useless memory copy, and I think for this purpose it's even better to use the swap method :
prev_cloud.swap(current_cloud);
What do you think ?

taketwo wrote
What do you mean when you say that PassThrough is used with planes? For example, when you filter along Z axis, you are basically cutting a sphere!
No I don't understand what you mean by "cutting a sphere" when filtering along Z axis. To me, for this filter, you define an axis, say "z", and a min and max values, which creates 2 planes, with equations : z = min and z=max.
So you are basically cutting the 3D space in 3 pieces, and you keep the middle one (unless you swap min and max I guess you keep the 2 outside areas).
But I don't see how you can define a point and a radius to cut a sphere.

Cheers,
Cyril
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Sergey
Administrator
Cyril,

Cyril_TheRobotStudio wrote
So if I update current_cloud, I erase prev_cloud data, or am I missing something ?
Since current_cloud in a (smart) pointer, the outcome depends on the way you are going to "update" it. You could either update the pointer itself, or you can update the data which are referenced by it. For example, if you write

current_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);

Then it will point to another cloud, but nothing will happen to the previous one. If you write

current_cloud->points.clear();

Then you are modifying the actual data to which prev_cloud is pointing.

prev_cloud.swap(current_cloud);

Would also accomplish the task (and change where current_cloud points as a side affect).

Cyril_TheRobotStudio wrote
So you are basically cutting the 3D space in 3 pieces, and you keep the middle one (unless you swap min and max I guess you keep the 2 outside areas).
You are totally right. My fault. Indeed, PassThrough filter only looks into appropriate fields and removes points based on min/max values, so no geometry is involved.

Well, maybe you could create a feature request on dev.pointclouds.org.

Regards,
Sergey
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

quark90
In reply to this post by quark90
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Cyril_TheRobotStudio
In reply to this post by Sergey
Hi,

taketwo wrote
 For example, if you write

current_cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr(new pcl::PointCloud<pcl::PointXYZ>);

Then it will point to another cloud, but nothing will happen to the previous one.
Yes Sergey, your're right about the pointer.

taketwo wrote
Well, maybe you could create a feature request on dev.pointclouds.org.
I think I've found a class that can do this job : pcl::ConditionalRemoval, but you have to built your own conditions.
Maybe this could work for you Ceburakyildirim, to replace your "for loops" and point by point manual filtering ?

Cheers,
Cyril
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

quark90
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Sergey
Administrator
In reply to this post by Cyril_TheRobotStudio
Cyril,

Cyril_TheRobotStudio wrote
I think I've found a class that can do this job : pcl::ConditionalRemoval, but you have to built your own conditions.
There seems to be a post from the author of the original contribution on developers list, that announces the TfQuadraticXYZComparison class. There he explains e.g. how to build a "cylinder" filter. Of course, a tutorial would be better, but at least this :)

Cheers,
Sergey
Reply | Threaded
Open this post in threaded view
|

Re: Point cloud coppy issues

Cyril_TheRobotStudio
Hi Sergey,

Thanks, that was exactly what I was searching for :).

Cheers,
Cyril