Meshing without GUI
- Francesco Cascone
- Posts: 1
- Joined: Sat Jun 01, 2019 12:24 am
Meshing without GUI
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.
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.
- David Parker
- Posts: 1677
- Joined: Tue Aug 23, 2005 2:43 pm
Re: Meshing without GUI
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
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
- marisa bazzi
- Posts: 15
- Joined: Wed Aug 28, 2019 3:46 pm
Re: Meshing without GUI
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
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 20 times
-
- error.PNG (16.73 KiB) Viewed 380 times
- David Parker
- Posts: 1677
- Joined: Tue Aug 23, 2005 2:43 pm
Re: Meshing without GUI
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
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
- marisa bazzi
- Posts: 15
- Joined: Wed Aug 28, 2019 3:46 pm
Re: Meshing without GUI
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
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
- David Parker
- Posts: 1677
- Joined: Tue Aug 23, 2005 2:43 pm
Re: Meshing without GUI
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().
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
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)
Cheers,
Dave
- marisa bazzi
- Posts: 15
- Joined: Wed Aug 28, 2019 3:46 pm
Re: Meshing without GUI
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
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 (13.87 KiB) Viewed 336 times
- David Parker
- Posts: 1677
- Joined: Tue Aug 23, 2005 2:43 pm
Re: Meshing without GUI
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
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
- marisa bazzi
- Posts: 15
- Joined: Wed Aug 28, 2019 3:46 pm
Re: Meshing without GUI
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
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
- David Parker
- Posts: 1677
- Joined: Tue Aug 23, 2005 2:43 pm
Re: Meshing without GUI
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
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
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.
'''
Cheers,
Dave