Pointcloud Library

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
topcyde
Posts: 48
Joined: Wed Mar 05, 2014 5:32 am

Pointcloud Library

Post by topcyde »

Was looking at the cmake file came across the pointcloud library. I was wondering where in FreeCAD is it being used? I was thinking I could build the library and test the features that implement it.
jmaustpc
Veteran
Posts: 11207
Joined: Tue Jul 26, 2011 6:28 am
Location: Australia

Re: Pointcloud Library

Post by jmaustpc »

topcyde wrote:came across the pointcloud library. I was wondering where in FreeCAD is it being used?
In the "points" workbench...

You have to compile FreeCAD with support for PCL if you want to use it. There was a problem with it on my Kubuntu 14.04 64bit system, which stopped FreeCAD from compiling. Currently PCL support is added automatically if PCL is found on your system at compile time....which means I had to remove PCL from my system to be able to compile FreeCAD again.

Peter has offered a fix, see his post on the "Pull Request" forum. One of the fixes he has introduced is an option to compile PCL or not, so that you can still compile FreeCAD without PCL even if PCL is on your system.

I would recommend that you wait until this important improvement has been pushed into master.

Jim
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pointcloud Library

Post by wmayer »

PCL is also used in the Reverse Engineering module. There is a Python command to triangulate a mesh from a point cloud.
topcyde
Posts: 48
Joined: Wed Mar 05, 2014 5:32 am

Re: Pointcloud Library

Post by topcyde »

jmaustpc wrote:I would recommend that you wait until this important improvement has been pushed into master.
I will keep an eye out for it.
wmayer wrote:PCL is also used in the Reverse Engineering module. There is a Python command to triangulate a mesh from a point cloud.
Well that seems handy. Can you throw me a bone to what table that command is? I'd like to look at that. I hope there's one that will make a nurb off a point loud too. That, I could really use.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pointcloud Library

Post by wmayer »

What you need is a point cloud, e.g. an .asc file. If you don't have one you can create one from an existing mesh.

Here is a code snippet:

Code: Select all

# the vertices of a given mesh
mp=App.ActiveDocument.ActiveObject.Mesh.Points

# create a point cloud of it and show it
import Points
pp=Points.Points()
pp.addPoints([i.Vector for i in mp])
Points.show(pp)

# triangulate the point cloud to get a mesh and show it
import ReverseEngineering as Reen
m2=Reen.triangulate(pp)
Mesh.show(m2)
You will see that the new mesh may contain many triangles with wrong orientation. Run the "Harmonize normals" command to fix this. But for very complex meshes this still may fail.
topcyde
Posts: 48
Joined: Wed Mar 05, 2014 5:32 am

Re: Pointcloud Library

Post by topcyde »

wmayer wrote:What you need is a point cloud, e.g. an .asc file. If you don't have one you can create one from an existing mesh.
Thanks for the code example that always helps me understand what I'm looking at. I really appreciate it.

Reading from the http://pointclouds.org/documentation/tu ... format.php documentation it talks about pcd file format. Does it make a difference whether it is .asc or .pcd for effeciency? Reading the format descriptions they look pretty identical except I don't see wher the pcd description allows intensity as a field. However, I don't see where asc notes handling moment invariants.
maito78
Posts: 23
Joined: Fri Feb 26, 2016 9:37 am

Re: Pointcloud Library

Post by maito78 »

Hello everyone, this is my first post.
I am an architect and I am working with PCL to do some segmentation on point cloud of buildings. I took various tutorials of the PCL documentation and I modified them to create some script to segmenting, filtering and downsampling clouds. I am wondering how much difficult could be implementing them on FreeCAD considering that I am not very expert with c++. Then I have also a question on the capability of FreeCAD to show point cloud. I did some tests and the visualization of 6 millions of points is quite smooth until you go over the cloud with the pointer.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pointcloud Library

Post by wmayer »

I am wondering how much difficult could be implementing them on FreeCAD considering that I am not very expert with c++.
It is just a matter of integrating the algorithms. The hard part is already done by pcl and for FreeCAD we have to allow to access the pcl algorithms from Python and for the GUI people offer menus and dialogs.
I did some tests and the visualization of 6 millions of points is quite smooth until you go over the cloud with the pointer.
When moving the mouse cursor over the point cloud then for every little movement a raypick action is applied on the scene graph. Internally this uses every single point to check which point is closest to the ray and inside a certain search radius. So, imagine for 6 millions of points and doing this for every little movement will be quite time consuming.

For mass data we can think of adding a SoPickStyle node and setting it to unpickable and only enable picking when it's really needed.
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Pointcloud Library

Post by ickby »

When moving the mouse cursor over the point cloud then for every little movement a raypick action is applied on the scene graph. Internally this uses every single point to check which point is closest to the ray and inside a certain search radius. So, imagine for 6 millions of points and doing this for every little movement will be quite time consuming.
Werner, out of pure interest, is it possible to use a custom picking algorithm for a document object? I could imagine that PCL has some advanced fast picking algorithm included which would be faster than the generic coin one. I thought about this earlyer with the new and fast OCC picking algorithm, but was unsure if this is possible in FreeCAD.
wmayer
Founder
Posts: 20307
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Pointcloud Library

Post by wmayer »

When moving the mouse or pressing a button an SoHandleEventAction traverses the scene graph. Inside SoFCUnifiedSelection::handleEvent we then invoke its getPickedPoint or getPickedPointList. Internally these methods use the SoRayPickAction class which does all the picking stuff. So, there is no chance to implement our own pick action class and use that.

However, all shape nodes inherit from SoNode and this class has the virtual method rayPick which then of course can be re-implemented in sub-classes.

But depending on the shape type you have to be careful which methods else you need to re-implement. In Inventor Mentor or Toolmaker you should find additional information about this.
Post Reply