# Slicing vtkPolyData read from STL file

**URL:** https://discourse.vtk.org/t/slicing-vtkpolydata-read-from-stl-file/7746
**Category:** Support
**Created:** [January 31, 2022, 4:49pm UTC](https://discourse.vtk.org/t/slicing-vtkpolydata-read-from-stl-file/7746 "2022-01-31T16:49:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LuisFco](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/779978/32.png) [@LuisFco](https://discourse.vtk.org/u/LuisFco)
#### Post date: [January 31, 2022, 4:49pm UTC](https://discourse.vtk.org/t/slicing-vtkpolydata-read-from-stl-file/7746/1 "2022-01-31T16:49:02Z")

</div>

Hi!  
I’m trying to create slices of an STL bone model and obtaining binary masks of each slice to be exported into numpy for further processing. I’m quite new in VTK and I’m a bit lost. My STL model to be sliced looks like this:

![captura1](https://discourse.vtk.org/uploads/default/original/2X/b/bc5c0ee27ca9156e3c5d98532c68f4b12d104e73.png)

And I’m trying to create binary masks for those slices similar to this:

![captura2](https://discourse.vtk.org/uploads/default/original/2X/8/8974611451f8cbfa68bf567f5a91d9164a4f7f4b.png)

I’ve found examples for slicing Images but not PolyData. I need this to be done programatically without any external application. Could you give me any clue? It’s been a while that I’m stuck.

Thanks a lot!!  
Luis f.

---

<div class="post-metadata">

### Author: ![dave3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dave3d/32/1157_2.png) [@dave3d](https://discourse.vtk.org/u/dave3d)
#### Post date: [January 31, 2022, 5:20pm UTC](https://discourse.vtk.org/t/slicing-vtkpolydata-read-from-stl-file/7746/2 "2022-01-31T17:20:08Z")

</div>

You want to use VTK’s PolyDataToImageStencil filter to create a binary image from a surface mesh.

Here are the docs for the class:  
[https://vtk.org/doc/nightly/html/classvtkPolyDataToImageStencil.html](https://vtk.org/doc/nightly/html/classvtkPolyDataToImageStencil.html)

And here is an example program that shows its use:  
[https://kitware.github.io/vtk-examples/site/Cxx/PolyData/PolyDataToImageData/](https://kitware.github.io/vtk-examples/site/Cxx/PolyData/PolyDataToImageData/)

---

<div class="post-metadata">

### Author: ![LuisFco](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/779978/32.png) [@LuisFco](https://discourse.vtk.org/u/LuisFco)
#### Post date: [January 31, 2022, 8:00pm UTC](https://discourse.vtk.org/t/slicing-vtkpolydata-read-from-stl-file/7746/3 "2022-01-31T20:00:16Z")

</div>

Thanks a lot Dave, that was exactly what i was looking for 👍
