Page 1 of 1

Example scripts for command-line meshing

Posted: Thu Jul 11, 2024 9:55 am
by gupta_akash
Hello,
I have a bunch of patient geometries that I need to mesh, and I'd like to script the meshing process. Are there any example scripts that I could refer to that would do the following:
  • Import an STL file
  • Generate faces
  • Mesh using TetGen
  • Export surface and volume meshes
I've seached this forum, and I've found links to scripts in the SimVascular-Tests Github repository for meshing. I'm not sure of how to import the stl and generate faces though. Also, the repository seems to be about 3 years old now. Are there any up to date example scripts available? Thanks!

Re: Example scripts for command-line meshing

Posted: Thu Jul 11, 2024 10:19 am
by davep
Hello,

This script https://github.com/SimVascular/SimVascu ... l-model.py reads an STL file and meshes it.

Meshing STL files can be difficult because the STL triangulation of CAD models is typically poor, try to create an STL file with triangles that have a good aspect ratio. Image isosurfaces should be ok.

Cheers,
Dave

Re: Example scripts for command-line meshing

Posted: Thu Jul 11, 2024 11:47 am
by gupta_akash
Thank you for the quick reply! These are patient geometries so it's something I have to work with. If I could control the file format for my models, which ones would work best with SimVascular?

Re: Example scripts for command-line meshing

Posted: Thu Jul 11, 2024 2:10 pm
by davep
Hello,

It is not really the file format that matters but the geometry (triangles) that are stored there. The geometry obtained from imaging data needs to be well-defined: manifold, no zero areas, decent aspect ratios.

Cheers,
Dave

Re: Example scripts for command-line meshing

Posted: Wed Aug 07, 2024 3:39 pm
by gupta_akash
Hello,

I had a follow up question about writing out the mesh files. I've managed to execute the python script file you had suggested in for tetgen meshing at: https://github.com/SimVascular/SimVascu ... l-model.py.

The script exports the generated mesh as a volume mesh (vtu) only. I also need the faces to be exported as surface meshes (vtp) files with facenames(vtp.facenames) info. I've looked up the SimVascular Python documentation for the TetGen class and I couldn't find an option to export the extracted faces as surface meshes. In the older versions of SimVascular, the surface and volume meshes were written out during meshing.

Do you have any examples or suggestions to make this possible with the Python interface?

Thanks!

Re: Example scripts for command-line meshing

Posted: Fri Aug 09, 2024 1:54 pm
by davep
Hello,

The TetGen (see https://simvascular.github.io/documenta ... ing_module) describes the get_surface() method for the TetGen class that returns a vtkPolyData object containing the surface mesh with face IDs.

Code: Select all

    mesh_surface = mesher.get_surface()
    file_name = "cylinder-mesh.vtp"
    writer = vtk.vtkXMLPolyDataWriter()
    writer.SetFileName(file_name)
    writer.SetInputData(mesh_surface)
    writer.Update()
    writer.Write()
And the tetgen-set-stl-model.py script uses the get_model_polydata() method to extract the surface mesh for a face

Code: Select all

   face1_polydata = mesher.get_face_polydata(1)
    gr.add_geometry(renderer, face1_polydata, color=[1.0, 0.0, 0.0], wire=False, edges=True)
Cheers,
Dave