I have a 3D grid for representing shapes/meshes which is represented in python using an ndarray(20,20,20) of type bool. Each element in the grid represents the presence or absence of material. I want to be able to check if a given grid represents a shape that is connected all the way from the top of the grid to the bottom. I want to be able to discard those that are either disconnected or not occupying continuous series of cells from top of the grid to the bottom.
At a later stage I convert the grids into meshes using trimesh. Is there any way to identify the above either directly in python or through trimesh?
I'd first write a helper function
bucket_fill_2d()
that takes a slice withmaterial
info and, given a starting index(i,j)
, bucket fills the material like in any old drawing program.connected
of the shape.True
wherever thematerial
array's bottom slice isTrue
.bucket_fill_2d()
, starting with everyconnected
(i,j)
from the previous step.connected
at the top slice.Note that trimesh, as the name suggests, only supports triangular cells.