Convert a surface mesh to a volumetric mesh in 3D Slicer

Hello everyone,
When I use 3D SLICER, I only have a surface mesh in here. But, I want to do this file in a Finite Element Sofware, I need a volumetric mesh.
Can you tell me how to convert a surface mesh to a volumetric mesh in 3DSLICER?
Thank you so much,
Van Sy,

You can use the recently added SegmentMesher extension (https://github.com/lassoan/SlicerSegmentMesher) to segments (surface meshes or labelmaps) to volumetric meshes that are suitable for FEM analysis. The extension’s packaging is not fully worked out yet, so you may need to install the mesher software (Cleaver2 and/or Tetgen) and set it in the extension manually. What operating system do you use?

1 Like

Dear Mr. Andras,
I will use Ansys Software. Thank you for your information, I will try to use these tools, but I think that it is very useful if you make a video to teach everyone “how to use these tools to convert to a volumetric mesh from a surface mesh”. I think that this topic is very powerful.
Best,

3 Likes

Hi Andras,
When I save the results of segment mesher. I see .vtk file. when I open it it dont show me exact volumetric mesh which segment mesher generated.

Is there a specific way to save the files.

I think it is volumetric mesh.

Dear Andras,
I used segment mesher. It is generating surface mesh instead of volumetric mesh. I used segment editor for segmenting tumor and brain. then I switched to segment mesher. It always generate surface mesh. I opened the *.vtk file of the generated model into paraview but dont see a volumetric mesh.

Please see the screen shot.

Does segmentmesher do not produce volumetric mesh? if yes what am I doing wrong? would you please correct me?

image

Segment mesher extension generates a volumetric mesh (unstructured grid containing tetrahedron and maybe also wedge cells). Why do you think the mesh is not a volumetric mesh?

1 Like

Hi Van Sy,
I think I have met with the similar problem. I want to segment a structure (breast tumor) from MR image and then import the model to Ansys Software for finite element analysis. But I found the result of segmentation was surface mesh, which can’t be imported to ICEM for meshing (it needs to be geometry?). I wonder if you were meshing directly in Slicer (using Segment Mesher?) and then importing the volumetric mesh to Ansys just for subsequent analysis. Whatif I want to get a “geometry” from surface mesh in Slicer?
Hope for some advice, thank you!
Crayon

ICEM can import surface meshes (STL files) - see for example this old forum topic. Segment Mesher can generate tetrahedral meshes that you can save in VTK unstructured grid (.vtu) file format. You may need a mesh conversion utility to convert it to a file format that can be read by your FEM software.

This is a useful tool with a source code.

The issue is not that we wouldn’t have volumetric mesh generators in Slicer. We can generate volumetric meshes in Slicer using Cleaver2 or Tetgen via Segment Mesher extension. The issue is that the output file format (vtk unstructured grid) cannot be directly read by the commercial solvers or pre-processors.

The robust_hex_dominant_meshing mesh generator referenced above does not solve this issue, as it generates files in the same VTK file format (.vtu), medit (.mesh) file format, or a custom internal (.hybrid) file format. I think ICEM cannot read any of these.

Solution can be to use mesh converter tools, such as meshio, which can read VTK volumetric mesh from .vtu file and can write it as an Ansys .msh file.

1 Like

Thank you all for the discussion. ICEM can indeed import mesh from unstructured grid, but in fact failed to import from vtu or vtk format. Meshio can successfully convert .vtu file to .msh file which can read by the ICEM. Another way I tried was to convert the surface mesh created by Slicer segmentation module to solid geometry in Solidworks (IGES format). One more question please, I wonder if the output results of Slicer segmentation module just contain two types (surface mesh named model and labelmap)?

Best regards,
Crayon

Yes the most typical exported formats from segmentation are closed surface (model node) and binary labelmap. You can also export to planar contours and fractional labelmap with the current version.

Maybe we could add segmentation converter rules that use Cleaver2 / Tetgen and can generate volumetric mesh within the segmentation.

1 Like

Dear Andras,
I am trying to convert .vtk file into inp file using meshio.

the vtk file is not read by meshio. it gives error
assert section == “FIELD”, “Unknown section ‘{}’.”.format(section)

AssertionError: Unknown section ’

how to resolve this error. please help.

Meshio does not support binary .vtk files. You can save ascii .vtk file by checking “Show options” and unchecking “Compress” in Save data dialog.

This worked for me in the Python interactor of a recent Preview Release:

pip_install('meshio')
import meshio
mesh = meshio.read(r"c:\tmp\Model.vtk")
meshio.write(r"c:\tmp\Model.inp", mesh)
1 Like

Yes after unchecking compress in options it worked. thanks Andras

1 Like

Hi andras,
I am getting the following error when i import meshio. could you please help.

Thanks

Regards,
Saima safdar

>>> pip_install("meshio==3.3.1")
Collecting meshio==3.3.1
  Using cached meshio-3.3.1-py3-none-any.whl (106 kB)
Requirement already satisfied: numpy in ./lib/Python/lib/python3.6/site-packages (from meshio==3.3.1) (1.17.3)
Installing collected packages: meshio
  Attempting uninstall: meshio
    Found existing installation: meshio 3.0.0
    Uninstalling meshio-3.0.0:
      Successfully uninstalled meshio-3.0.0
  WARNING: The scripts meshio-convert and meshio-info are installed in '/home/saima/Slicer-4.11.0-2020-02-25-linux-amd64/lib/Python/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed meshio-3.3.1
>>> import meshio
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/saima/Slicer-4.11.0-2020-02-25-linux-amd64/lib/Python/lib/python3.6/site-packages/meshio/__init__.py", line 1, in <module>
    from . import (
  File "/home/saima/Slicer-4.11.0-2020-02-25-linux-amd64/lib/Python/lib/python3.6/site-packages/meshio/_cli.py", line 9, in <module>
    from .__about__ import __copyright__, __version__
ImportError: cannot import name '__copyright__'
>>>

Uninstall/reinstall a different version while the application is runnning may not work. Restarting Slicer (or restarting Slicer after uninstalling the old meshio version) should work.

1 Like

OH BOY this saved me today! Thank you a lot, with cleaver it worked very good. What’s the difference between Cleaver and Tetgen? Maybe you can post a link on it. I tested both and only cleaver had an output.

What are the analysis software used for simulating geometries generated using 3D Slicer segmentation.
I was using the following pattern,
3D Slicer(segmentation)> FreeCAD(removing mesh errors)>FEBio (static analysis)
I could not mesh the imported geometry in Ansys (student version) and were not able to check the contact features of assemblies. FEBio has limited analysis options.

You can create FE mesh directly from segmentation (without generating surface mesh and all associated meshing problems) using Segment Mesher module.

FEBio can read this mesh directly. FEBio does not have as many options as huge (and extremely expensive) commercial solvers, but it is free and should be suitable for many biomedical simulation problems.

If you want to use other solvers, you can convert Segment Mesher modules’s output from VTK unstructured grid to other formats that commercial solvers can use, using meshio.

1 Like