# stl to solid mesh file

**URL:** https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379
**Category:** Support
**Created:** [April 26, 2022, 4:38am UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379 "2022-04-26T04:38:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![hye00525](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hye00525/32/4904_2.png) [@hye00525](https://discourse.vtk.org/u/hye00525)
#### Post date: [April 26, 2022, 4:38am UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/1 "2022-04-26T04:38:09Z")

</div>

Hello,  
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)?](https://www.researchgate.net/post/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](https://glvis.org/).)

Thank you

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/christos_tsolakis/32/2076_2.png) [@Christos\_Tsolakis](https://discourse.vtk.org/u/Christos_Tsolakis)
#### Post date: [April 26, 2022, 12:42pm UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/2 "2022-04-26T12:42:00Z")

</div>

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](https://doc.cgal.org/latest/Mesh_3/index.html) ( or a [python wrapper of CGAL](https://github.com/meshpro/pygalmesh)), [Gmsh](https://gmsh.info/) (or a [python wrapper of Gmsh](https://github.com/meshpro/pygmsh)) or [TetGen](https://wias-berlin.de/software/index.jsp?id=TetGen&lang=1) (or [PyVista Wrapper of TetGen](https://tetgen.pyvista.org/)) 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.

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [April 26, 2022, 6:47pm UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/3 "2022-04-26T18:47:08Z")

</div>

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)

```python
"""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)
	cids.append(cid)
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)
	pieces.append(mc)

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

```

 ![Screenshot from 2022-04-26 20-36-34](https://discourse.vtk.org/uploads/default/original/2X/2/2e0327fe5144842347c17046c91d9205f3aa75c8.png)

---

<div class="post-metadata">

### Author: ![Christos\_Tsolakis](https://discourse.vtk.org/user_avatar/discourse.vtk.org/christos_tsolakis/32/2076_2.png) [@Christos\_Tsolakis](https://discourse.vtk.org/u/Christos_Tsolakis)
#### Post date: [April 26, 2022, 8:58pm UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/4 "2022-04-26T20:58:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [April 26, 2022, 9:35pm UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/5 "2022-04-26T21:35:57Z")

</div>

yes - to [generate](https://github.com/marcomusy/vedo/blob/1a3abcf3f1e495287e8934d9b5bb07b511ab8be5/vedo/mesh.py#L2360) the internal points, and some postprocessing to prune the tets that are inside the convex hull and outside the mesh.

---

<div class="post-metadata">

### Author: ![hye00525](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hye00525/32/4904_2.png) [@hye00525](https://discourse.vtk.org/u/hye00525)
#### Post date: [April 27, 2022, 6:15am UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/6 "2022-04-27T06:15:15Z")

</div>

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

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [April 27, 2022, 7:11am UTC](https://discourse.vtk.org/t/stl-to-solid-mesh-file/8379/7 "2022-04-27T07:11:26Z")

</div>

Oh if you are in c++ you better go straight to the [tetgen](https://wias-berlin.de/software/index.jsp?id=TetGen&lang=1#Download) c++ implementation as Christos indicated.
