STL version of Brep Model.

I am trying to produce a minimum Mesh in Gmsh which is using OpenCASCADE to provide a STL version of a Brep File.

Gmsh script as follows

def setMinMeshParms():
gmsh.option.setNumber("Mesh.StlLinearDeflection", 1)
gmsh.option.setNumber("Mesh.StlLinearDeflectionRelative", 0)
gmsh.option.setNumber("Mesh.StlAngularDeflection", 0.5)
gmsh.option.setNumber("Mesh.RecombinationAlgorithm", 0)
gmsh.option.setNumber("Mesh.RecombineOptimizeTopology", 0)
gmsh.option.setNumber("Mesh.RecombineNodeRepositioning", 0)
gmsh.option.setNumber("Mesh.RecombineMinimumQuality", 1e-3)

inputFile = sys.argv[1]
print(f"Processing file : {inputFile}")
print(f'Gmsh version {gmsh.GMSH_API_VERSION}')
# gmsh.option.setNumber('Mesh.Algorithm',6)
gmsh.option.setNumber("Mesh.Algorithm3D", 1)
# gmsh.option.setNumber("Geometry.OCCFixDegenerated", 1)
gmsh.option.setNumber("Mesh.SaveGroupsOfNodes", 1)
gmsh.option.setNumber("Mesh.SaveAll", 0)
# gmsh.option.setNumber("Mesh.OptimizeNetgen", 1)
# Netgen crashes
threads = max(1, os.cpu_count() - 2)
threads = 1

print("Gmsh to use " + str(threads) + " threads")
gmsh.option.setNumber("Mesh.MaxNumThreads2D", threads)
gmsh.option.setNumber("Mesh.MaxNumThreads3D", threads)
gmsh.option.setString("Geometry.OCCTargetUnit", "mm")
gmsh.option.setString("General.ErrorFileName", "/tmp/error.log")
gmsh.option.setNumber("General.Terminal", 1)
gmsh.option.setNumber("Mesh.Algorithm", 6)
gmsh.option.setNumber("Mesh.CharacteristicLengthMax", 11)
gmsh.option.setNumber("Mesh.CharacteristicLengthFromCurvature", 10)
gmsh.option.setNumber("Mesh.CharacteristicLengthFromPoints", 10)
gmsh.option.setNumber("Mesh.CharacteristicLengthMin", 1e-3)
gmsh.model.mesh.removeDuplicateNodes() # optional

This works fine on some Brep files for example Cube.brep and Cylinder.brep but on a number it produces degenerate STL meshes e.g. TestShield-Gmsh-Min.brep is there anything that can be done about this?

Keith Sloan's picture

Adding the saved Stl and msh files from running python3 TestShield-Gmsh-Min.brep

Dmitrii Pasukhin's picture

Hello, Can you reproduce this problem on OCCT(c++) environmental?

You can see the same ticket: step file conversion obj example - Forum Open Cascade Technology.

If problem can be reproduced, We will try to analyze it. If not - there is can be problem with your SDK or python wrapper.

Best regards, Dmitrii.

Keith Sloan's picture

Okay I tried adding the following options before the importSTL

gmsh.option.setNumber("Geometry.OCCBoundsUseStl", 1)
gmsh.option.setNumber("Geometry.OCCFixDegenerated", 1)
gmsh.option.setNumber("Geometry.OCCFixSmallFaces", 1)

Which seems to have helped a bit but when I process the mesh I still get a lot of errors when I try to create FreeCAD faces

17:27:51 Vertex : 906 Facets : 1102
17:27:51 Invalid triangle area -2.7755575615628914e-17
17:27:51 Invalid triangle area 0.07708739451076287
17:27:51 Invalid triangle area 0.0
17:27:51 Invalid triangle area 8.104628079763643e-15
17:27:51 Invalid triangle area 8.021361352916756e-15
17:27:51 Invalid triangle area 0.07708739451075194
17:27:51 Invalid triangle area 1.3877787807814457e-17
17:27:51 Invalid triangle area -5.412337245047638e-16
17:27:51 Invalid triangle area 0.07708739451075147
17:27:51 Invalid triangle area -2.7755575615628914e-17
17:27:51 Invalid triangle area 0.07708739451076306
17:27:51 Invalid triangle area 2.7755575615628914e-17
17:27:52 Invalid triangle area 3.885780586188048e-15
17:27:52 Invalid triangle area -1.5543122344752192e-15
17:27:52 Invalid triangle area 0.077087394510751
17:27:52 Invalid triangle area 1.609823385706477e-15
17:27:52 Invalid triangle area -1.3877787807814457e-17
17:27:52 Invalid triangle area 0.07708739451075249
17:27:52 Invalid triangle area 4.551914400963142e-15
17:27:52 Invalid triangle area 3.497202527569243e-15
17:27:52 Invalid triangle area -3.469446951953614e-17
17:27:52 Invalid triangle area 0.07708739451075253
17:27:52 Invalid triangle area 4.454769886308441e-15
17:27:52 Invalid triangle area -8.326672684688674e-17
17:27:52 Invalid triangle area 3.3029134982598407e-15
17:27:52 Invalid triangle area 5.162537064506978e-15
17:27:52 Invalid triangle area 0.07708739451075113
17:27:52 Invalid triangle area 1.3877787807814457e-17
17:27:52 Invalid triangle area 4.9404924595819466e-15
17:27:52 Invalid triangle area 3.0808688933348094e-15
17:27:52 Invalid triangle area 0.07708739451075132
17:27:52 Invalid triangle area 1.4432899320127035e-15
17:27:52 Invalid triangle area -2.7755575615628914e-17
17:27:52 Invalid triangle area 0.07708739451075255
17:27:52 Invalid triangle area 3.219646771412954e-15
17:27:52 Invalid triangle area 5.995204332975845e-15
17:27:52 Invalid triangle area 0.0

Dmitrii Pasukhin's picture

It looks like a problem with triangulation (modeling in your Gmsh SDK).

We will try to convert this file in the last master branch to check our mesher. But it can takes a some time.

Best regards, Dmitrii.

Keith Sloan's picture


Keith Sloan's picture

I have asked in the Gmsh github but is there anything that Gmsh can pass to its importSTL request that influences the size of the Mesh, like how fine it is etc.