Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
gringene
Posts: 2
Joined: Sat Aug 07, 2021 3:26 am

Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post by gringene »

I have a little niggle regarding technically closed / watertight meshes that OpenSCAD refuses to process. It would be great if FreeCAD could identify and repair such meshes so that I don't have to do a manual hunt with Blender to patch up the mesh.

The issue is that some vertices can intersect (or be very close to) line boundaries, and CGAL doesn't like this, even if the vertex points and all edges lie precisely on other lines. I have included an example cube which has this issue (as well as the generating OpenSCAD code), where one face is composed of three triangles that join at a point half-way down an edge on another face. All points on the cube are integer values, and all edges are aligned to other edges.

[FWIW, I did try a tetrahedron version of this, but FreeCAD complained about surface folds]

The way I fix this in Blender is to tediously inspect the mesh for these situations (Blender's sharpness mesh analysis helps), delete the offending intersecting vertex, then re-triangulate the space to make sure that no triangle points lie in the middle of an edge. This makes sure that all triangles have positive areas.

An alternative fix would be to insert a very thin triangle that connects the offending vertex to the extents of the edge it is near. Such a fix would preserve the mesh shape, but could lead to thin triangles with zero area.

... but the fix is less important than the search. Just finding where these situations happen would save me a lot of time in fixing them.

I'm using the most recent Debian version of FreeCAD, v0.19.1+dfsg1-2.
Attachments
break_openscad.stl
Broken STL file (as ASCII STL)
(1.59 KiB) Downloaded 34 times
break_openscad.scad
OpenSCAD source to create the broken STL file
(484 Bytes) Downloaded 28 times
OpenSCAD screenshot demonstrating that CGAL reports a non-closed mesh
OpenSCAD screenshot demonstrating that CGAL reports a non-closed mesh
break_openSCAD.png (149.43 KiB) Viewed 1294 times
OpenSCAD screenshot demonstrating that the polyhedron alone renders fine
OpenSCAD screenshot demonstrating that the polyhedron alone renders fine
openscad_noBreak.png (143.26 KiB) Viewed 1294 times
FreeCAD v0.19 screenshot demonstrating that "Evaluate & Repair Mesh" reports no errors
FreeCAD v0.19 screenshot demonstrating that "Evaluate & Repair Mesh" reports no errors
freecad_mesh_fine.png (213.37 KiB) Viewed 1294 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post by Kunda1 »

gringene wrote: Sat Aug 07, 2021 3:56 am I'm using the most recent Debian version of FreeCAD, v0.19.1+dfsg1-2.
Debian is behind. Do you mind trying the development AppImage instead?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
gringene
Posts: 2
Joined: Sat Aug 07, 2021 3:26 am

Re: Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post by gringene »

I've confirmed that this feature is not yet implemented in AppImage 25352 [FreeCAD 0.20, Libs: 0.20R25352], and still reports no errors in the STL file.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post by wmayer »

gringene wrote: Sat Aug 07, 2021 3:56 am ... but the fix is less important than the search. Just finding where these situations happen would save me a lot of time in fixing them.
There is one way to find such triangles visually. With the mesh structure in FreeCAD this kind of triangles won't have an adjacent triangle on this edge and we call it an "open" edge.

In the View property tab you will find the option "Open Edges" that is set to false. When changing it to true FreeCAD will render open edges. To see them more easily you should set the Display Mode to Shaded and if needed you can even hide the mesh -- the open edges are still displayed.
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post by wmayer »

There is now a function in Python to remove triangles where one of its corners lie on an edge.

Code: Select all

mesh = App.ActiveDocument.ActiveObject.Mesh.copy()
mesh.removePointsOnEdge()
In your case it will find this one point that lies on the middle of the triangle and by removing this point three triangles will be removed, too.
To fill the hole (of four boundary edges) you can call:

Code: Select all

mesh.fillupHoles(4)
git commit 0a9d08218aa
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Mesh Design: identify vertices intersecting (or near) lines [feature request]

Post by wmayer »

With git commit e1c5bfab1f there is now in improvement which allows you to fill the hole in one go.

Code: Select all

mesh = App.ActiveDocument.ActiveObject.Mesh.copy()
mesh.removePointsOnEdge(FillBoundary = True)
The algorithm only considers boundaries where a point is lying on an edge. Other boundaries are not supposed to be filled.

With your simple example STL file it works very well. Please try it also with some more complex meshes.
Post Reply