Slicing vtkPolyData read from STL file

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:


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


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:

And here is an example program that shows its use:

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

1 Like