Performance of part union?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
eudoxos
Posts: 33
Joined: Tue Jul 19, 2016 4:14 pm

Performance of part union?

Post by eudoxos »

I use FreeCAD to compute surface of solid composed of a number of lightly overlapping spheres. The goal is to export triangulated external surface(s) of fused spheres (with the overlapping parts removed).

Image

Spheres are around 1500 in number and I create them using generated script with these lines for each sphere:

Code: Select all

p=doc.addObject("Part::Sphere","par_1234")
p.Radius=0.004
P.Placement=Placement(Vector(0,1,2),Rotation(Vector(.4,.2,.4),56))
The script takes some time to process (around 1 minute). When I select all spheres and hit Part/Boolean/Union, FreeCAD eats 100% CPU but does not seem to produce any result until I kill it 5 minutes later.

Am I (not) doing something which slows the operation down or is this number of solids simply beyond what the OCC kernel can handle in a reasonable time? Is there some other way to get the result?

Thanks!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Performance of part union?

Post by DeepSOIC »

Hi!
OpeCascade's Booleans are slow. Trouble starts even with gears, that only have a few tens of teeth. This is not surprising this is taking forever to compute.
Try fusing them as shapes, one by one in a cumulative manner. So that you can make a progress bar. That can give you a feel of how long it's going to take.
something like...

Code: Select all

spheres = [obj.Shape for obj in App.ActiveDocument.Objects]
final_shape = spheres[0]
for sphere in spheres[1:]:
  final_shape = final_shape.fuse(sphere)
  #(insert progress-bar code here)

Part.show(final_shape)
ulrich1a
Veteran
Posts: 1957
Joined: Sun Jul 07, 2013 12:08 pm

Re: Performance of part union?

Post by ulrich1a »

In order to get a result at all, I would follow DeepSOICs approach but with a modification. It will end as an complicated script.

Explained with two spheres. Sphere1 and Sphere2.
Take the Face from Spere1 and cut the Face with Sphere2 in order to get Face1_cutted.
Take the Face from Sphere 2 and cut the Face with Sphere1 in order to get Face2_cutted.
Put Face1_cutted and Face2_cutted into a List.
Create a Shell from this List.
Create a Solid from this Shell.

For more Spheres you need to generate all the cutted Faces from those Spheres and add the cutted Faces to the List.

This approach should work. I used the same approach to generate screws with a real thread on it.

Ulrich
Post Reply