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

**URL:** <https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416>\
**Category:** Support\
**Created:** [November 9, 2017, 11:56am UTC](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416 "2017-11-09T11:56:22Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [December 8, 2020, 4:14am UTC](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416/24 "2020-12-08T04:14:31Z")

</div>

Hi Andras,  
I am writing vtk file from within slicer using meshio. I am getting the following error. Is there any solution?

mesh = n.GetMesh()

> > > points = mesh.GetPoints()  
> > > cells = mesh.GetCells()  
> > > import meshio  
> > > meshio.write\_points\_cells(“example.vtk”, points, cells)  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > File “/home/saima/Slicer-4.11.0-2020-02-25-linux-amd64/lib/Python/lib/python3.6/site-packages/meshio/\_helpers.py”, line 81, in write\_points\_cells  
> > > cells = {key: numpy.asarray(value) for key, value in cells.items()}  
> > > AttributeError: ‘vtkCommonDataModelPython.vtkCellArray’ object has no attribute ‘items’

thank you

Regards,  
Saima Safdar

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 8, 2020, 4:28am UTC](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416/25 "2020-12-08T04:28:52Z")

</div>

I don’t recall seeing this error. Please report it to meshio developers. They are very responsive. Attach a sample data set that reproduces the issue.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [December 9, 2020, 4:48am UTC](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416/26 "2020-12-09T04:48:32Z")

</div>

Hi Andras,  
I have a vtkcellArray with two types of cells in it, triangle and tetra. How can I extract cell array within slicer like following.

In meshio if the mesh.cells is called it gives the following. I need to get the cells from within 3d slicer for a mesh and give it to meshio. Any idea? I got the points and converted to numpy array but for cells I dont know how to get the arrays.

{‘triangle’: array([[0, 1, 2],  
[0, 19, 1],  
[4, 0, 2],  
…,  
[1989, 1984, 1991],  
[1996, 1991, 1984],  
[1987, 1993, 1994]], dtype=int32), ‘tetra’: array([[2600, 3531, 2730, 3868],  
[2254, 2779, 2382, 2911],  
[2242, 3405, 2782, 3546],  
…,  
[3710, 1693, 1478, 1477],  
[544, 4188, 584, 3182],  
[544, 584, 4188, 1388]], dtype=int32)}

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 9, 2020, 2:05pm UTC](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416/27 "2020-12-09T14:05:03Z")

</div>

You can save the mesh as .vtk and you should be able to load it using meshio. If there is any error then report it to meshio developers (attach the file that cannot be imported or converted).

If you want, then of course you can recreate the data meshio data structure from a VTK object in memory (vtkCellArray class is Python-wrapped, so you can access all methods from Python), but it is expected to be about a magnitude slower than the C++ implementation (that writes to file).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [March 5, 2021, 4:50pm UTC](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416/28 "2021-03-05T16:50:56Z")

</div>

A post was split to a new topic: [How to visualize volumetric mesh?](https://discourse.slicer.org/t/how-to-visualize-volumetric-mesh/16392)

[Previous page](https://discourse.slicer.org/t/convert-a-surface-mesh-to-a-volumetric-mesh-in-3d-slicer/1416.md?page=1)
