stl to solid mesh file

I have two questions.

  1. I have a .stl mesh file that is hollow inside. Can I change this to a solid mesh file in vtk? (e.g., Convert stl file to solid (from Magics to Solidworks or Catia)?)

Or can I save vtkpolydata as a solid mesh file?
If yes, any sample code?

  1. Does the .vtu extension provide the solid mesh format? (I want to use it in glvis.)

Thank you

1 Like
  1. No, VTK does not have general 3D meshing capabilities. vtkDelaunay3D can fill the volume but it will output the convex hull of your input. You may look at CGAL ( or a python wrapper of CGAL), Gmsh (or a python wrapper of Gmsh) or TetGen (or PyVista Wrapper of TetGen) for more general mesh generation capabilities. All three can output to VTK formats.

  2. Yes, you can store a vtkUnstructuredGrid (which can be used to represent a 3D mesh) into a vtu file.

1 Like

I actually wrote a small function (for vedo) where the vtkDelaunay3D alone seems to do a very good job! (not sure how it compares to tetgen)

"""Tetralize a closed surface mesh
Click on the mesh and press ↓ or x to toggle a piece"""
from vedo import *

surf = Mesh(dataurl+'bunny.obj', c='g3').cap().smooth()

tmesh = surf.tetralize(side=0.015)

# Assign an id to each tetrahedron to visualize regions
seeds = surf.clone().subsample(0.3)
cids = []
for p in tmesh.cellCenters():
	cid = seeds.closestPoint(p, returnPointId=True)
tmesh.celldata["fragments"] = cids

pieces = []
for i in range(seeds.NPoints()):
	tc = tmesh.clone().threshold("fragments", above=i-0.1, below=i+0.1)
	mc = tc.tomesh().color(i)

show(__doc__, pieces, axes=1)
# tmesh.write('mytetmesh.vtu')  # save to disk

1 Like

This is really nice ! I guess vedo does some kind of preprocessing on the input before passing the result to vtkDelaunay3D ?


yes - to generate the internal points, and some postprocessing to prune the tets that are inside the convex hull and outside the mesh.


Thank you both for the detailed guide!!
Is it possible to use vedo in c++? :cry:

1 Like

Oh if you are in c++ you better go straight to the tetgen c++ implementation as Christos indicated.