Check if 3D grid is filled from top to bottom

141 Views Asked by At

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?

1

There are 1 best solutions below

0
On

I'd first write a helper function bucket_fill_2d() that takes a slice with material info and, given a starting index (i,j), bucket fills the material like in any old drawing program.

  1. Introduce an empty Boolean array connected of the shape.
  2. Set the bottom slice True wherever the material array's bottom slice is True.
  3. Then go up one step up and bucket_fill_2d(), starting with every connected (i,j) from the previous step.
  4. Repeat (3) until you reach the top.
  5. Check if anything is connected at the top slice.

Note that trimesh, as the name suggests, only supports triangular cells.