STL Meshing in Julia

Hi all,

As the first step in implementing an mass-spring-damper simulator in Julia, I’m trying to generate a volume mesh from .STL file type.

Hoping to achieve this using TetGen. However, I’m not sure how to process the STL file into a type usable by the TetGen function tetrahedralize(). I’ve not been successful in passing the loaded STL file directly.

My initial thought is to extract the bounding points of the STL file, generate a mesh using Meshing, which should (hopefully) be usable by TetGen to create the volume mesh.

I’m not sure how to do the extraction of points from STL file, nor if this is even the way I should go about it.

Any insight is greatly appreciated!

Short answer is you might want to pre-process in another program to generate the FEA mesh and import into Julia to solve the problem.

On the other hand it is not impossible to do it in Julia, there is not AFAIK a cohesive solution for surface mesh → volume mesh.

Meshing.jl is for generating surface meshes from gridded data in a 3D matrix or a signed distance function. It wouldn’t work without some sort of mesh-> signed distance function conversion.
FWIW STL is a poor format for this sort of thing. OBJ, OFF, or PLY have the connectivity information you need for delaunay triangulation. Normally if you are using a CAD program to generate the STL simply selecting OBJ export will get this connectivity info. If you only have an STL you will need some way to deduplicate the points and use an index mesh, since triangle and edge info are important for Tetgen. I could pull up some code for this if you are interested.

This is an example of using tetrahedralize on arbitrary points to make a call similar to delaunayn in matlab. It does not add extra points inside the mesh etc. You will need to tweak it a bit to add the boundary info and add points to the mesh interior.

function delaunayn(points)
    # M - no merge of close facets
    # J - no jettison of points
    # B - No boundary info
    # N - No node output
    # F - No face and edge info
    # I - No mesh iteration numbers
    # Q - Quiet
    tetio = tetrahedralize(TetGen.TetgenIO(points), "JBNFIQ")
    tetio
end

The command line options present in tetgen should just pass-thru to the tetrahedralize call.

2 Likes

I believe Tetgen can process input surface mesh in the STL format.

Yes, I thought it would be a nice addition to be able to import any 'ole .STL, as I’ll be working with them a lot and would like to just “drag and drop” as much as possible. Although, you’re right it would be more simple to do some pre-processing, I’m looking to automate this process as much as possible.

I would be very interested in looking at that code, it sounds like exactly what I’d need to do!

I’m not sure how to do this, do you have any examples I can follow?

Doing this:

load_mesh = load(".STL")
tetrahedralize(load_mesh)

does nothing.

No, sorry. I don’t firsthand experience . I read it somewhere.

Have a look at MeshLab. Not Julia, but it seems capable of digesting STL.