Slicing vtkPolyData read from STL file

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

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

captura2

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.

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

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

Thanks a lot Dave, that was exactly what i was looking for :+1:

1 Like