Meshing without GUI

Provides a system for patient-specific cardiovascular modeling and simulation.
POST REPLY
User avatar
Francesco Cascone
Posts: 1
Joined: Sat Jun 01, 2019 12:24 am

Meshing without GUI

Post by Francesco Cascone » Fri Aug 09, 2019 10:42 am

Hello,

i would need to generate meshes starting from a .stl file without using the SimVascular GUI.
It's useful for me because i have to use many similar models (about 25) and I'd like to automate the process.

I tried using VMTK but crashes every time i generate a volume mesh.

I'm using Windows 10.

Thanks.

User avatar
David Parker
Posts: 1719
Joined: Tue Aug 23, 2005 2:43 pm

Re: Meshing without GUI

Post by David Parker » Tue Aug 20, 2019 7:24 pm

Hi Francesco,

SV has a Python API that can be used to perform mesh generation from the command line. The API is currently undergoing some redesign but I think you can use it for meshing your STL models.

Meshing STL can sometimes be a bit tricky if the files do not describe a valid solid (i.e. a closed surface with non-intersecting triangles). If you can put your STL file (the one that crashed vmtk) someplace I can download it I'll try to mesh it using the Python API. The API also has functions for geometric modeling that might be useful for fixing or smoothing the model.

Cheers,
Dave

User avatar
marisa bazzi
Posts: 15
Joined: Wed Aug 28, 2019 3:46 pm

Re: Meshing without GUI

Post by marisa bazzi » Mon Nov 30, 2020 8:41 pm

Hey Dave,

I am interested in meshing STL models using command line. I couldnt fine a easy to do it yet. Ive found a sample project in SimVascular Github (part of the code is attached) but it doesn't seem to be working (error attached).
Do you have a suggestions or a sample project on how to create meshes using command line, but starting from a STL model?

Thanks,
Marisa
Attachments
stl_reader.txt
(1.14 KiB) Downloaded 26 times
error.PNG
error.PNG (16.73 KiB) Viewed 527 times

User avatar
David Parker
Posts: 1719
Joined: Tue Aug 23, 2005 2:43 pm

Re: Meshing without GUI

Post by David Parker » Tue Dec 01, 2020 4:10 pm

Hi Marisa,

It seems that your script was not able to read in the aorta.vtp file correctly, reader.GetOutput() is returning None.

I've added an example of meshing an STL model here https://github.com/SimVascular/SimVascu ... l-model.py. This uses the new SV Python API available in the SV beta release.

Note that models based on STL can be a bit tricky to mesh, need to make sure you have a good surface representation (i.e. triangles with aspect ratio 0.3 to 1.0). You may need to remesh the STL model, the example scripts does this.

Cheers,
Dave

User avatar
marisa bazzi
Posts: 15
Joined: Wed Aug 28, 2019 3:46 pm

Re: Meshing without GUI

Post by marisa bazzi » Wed Dec 02, 2020 4:39 pm

Thanks so much Dave.

I am running into a problem:
Line 48 mesher.get_model(model) -- and it is complaining that meshing.TetGen doesnt have this attribute.
print(dir(sv.meshing.TetGen))
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'compute_model_boundary_faces', 'generate_mesh', 'get_face_polydata', 'get_kernel', 'get_mesh', 'get_model_face_ids', 'get_model_polydata', 'get_surface', 'load_mesh', 'load_model', 'set_boundary_layer_options', 'set_walls', 'write_mesh']

I also tried get_model_polydata and the msg was "No volume mesh has been generated" and I finally tried "load_model" but it seems the input needs to a strg.

I checked, and I am using the newest SV version.

Could you help me how to proceed about this?

Best,
Marisa

User avatar
David Parker
Posts: 1719
Joined: Tue Aug 23, 2005 2:43 pm

Re: Meshing without GUI

Post by David Parker » Wed Dec 02, 2020 7:25 pm

Hi Marisa,

I forgot that the mesher.set_model() method is not in the SV beta release, I added it later, sorry!

A workaround is to read in the STL file, compute faces for it and then write it out as a .vtp file. The
.vtp file can then be loaded into the mesher using mesher.load_model().

Code: Select all

from os import path
import sv
import vtk

# Read STL file.
file_name = 'cylinder.stl'
filename, file_extension = path.splitext(file_name)
reader = vtk.vtkSTLReader()
reader.SetFileName(file_name)
reader.Update()
polydata = reader.GetOutput()
model = sv.modeling.PolyData(surface=polydata)

# Create the 'ModelFaceID' array.
face_ids = model.compute_boundary_faces(angle=60.0)
print("Model face IDs: " + str(face_ids))

# Write out the model as a .vtp file.
new_file_name = filename + "-stl"
file_format = "vtp"
model.write(file_name=new_file_name, format=file_format)
Have a look at this https://github.com/SimVascular/SimVascu ... en-mesh.py script, I updated it to mesh STL files using the above workaround.

Cheers,
Dave

User avatar
marisa bazzi
Posts: 15
Joined: Wed Aug 28, 2019 3:46 pm

Re: Meshing without GUI

Post by marisa bazzi » Thu Dec 03, 2020 2:17 pm

Thanks Dave.

Sorry for bothering you again. But now I am running into other problem. I am getting an error when it tries to create the faces IDS. I tried with different models, to make check if maybe my model was problematic.
face_ids = model.compute_boundary_faces(angle=60.0)

Best,
Marisa
Attachments
faces_id.PNG
faces_id.PNG (13.87 KiB) Viewed 483 times

User avatar
David Parker
Posts: 1719
Joined: Tue Aug 23, 2005 2:43 pm

Re: Meshing without GUI

Post by David Parker » Thu Dec 03, 2020 8:06 pm

Hi Marisa,

Are you able to mesh the cylinder.stl model in SimVascular-Tests/new-api-tests/data/model ? If not then there is something going on with API and Windows.

If you are able to mesh cylinder.stl then please upload the STL model that is failing someplace I can download it or email it to me and I'll have a look.

Cheers,
Dave

User avatar
marisa bazzi
Posts: 15
Joined: Wed Aug 28, 2019 3:46 pm

Re: Meshing without GUI

Post by marisa bazzi » Mon Dec 07, 2020 2:13 pm

Hi Dave,

I am having the same problem for the cylinder.stl. I tried in my Linux machine too, and I got again the same msg.
"Array name 'ModelFaceID' does not exist. Regions must be identified and named 'ModelFaceID' prior to this function call
Traceback (most recent call last):
File "c:/users/mmbaz/Google Drive/PhD/Remodeling/Edge_mouse/Python/SimVascular-Tests-master/new-api-tests/meshing/tetgen-mesh.py", line 47, in <module>
face_ids = model.compute_boundary_faces(angle=80.0)
modeling.Error: ModelingModel.compute_boundary_faces() The model has no face IDs."

What do you think it could be?

Thanks,
Marisa

User avatar
David Parker
Posts: 1719
Joined: Tue Aug 23, 2005 2:43 pm

Re: Meshing without GUI

Post by David Parker » Mon Dec 07, 2020 3:14 pm

Hi Marisa,

It's not clear what is going on. Did you pull down the latest version of tetgen-mesh.py ? The top of the script should look like

Code: Select all

''Test the TetGen class interface.
  
   Writes: 'cylinder-mesh.vtu'

   Note: Be careful with global_edge_size, must match model Remesh Size resolution.

   Note: Loading an STL model does not work because the 'ModelFaceID' vtk array is not 
         set in compute_model_boundary_faces(). 

         I added a workaround to read in the STL as a model, compute its faces and write 
         it out as an .vtp file. The .vtp file is then loaded by the mesher. 
'''
If this is not the problem then send me an email and let's meet on Zoom so we can figure out what's going on.

Cheers,
Dave

POST REPLY