cells_within_bounds.py 950 B

1234567891011121314151617181920212223242526272829
  1. """Find cells within specified bounds in x, y and/or z."""
  2. from vedo import Mesh, dataurl, printc, Plane, show
  3. # Load a mesh of a shark and normalize it
  4. mesh = Mesh(dataurl+'shark.ply').normalize().compute_normals()
  5. # Set the color of the mesh and the line width to 1
  6. mesh.color('aqua').linewidth(1)
  7. # Define the lower and upper bounds for the z-axis
  8. z1, z2 = -1.5, -0.5
  9. # Find the cell IDs of cells within the z-axis bounds
  10. ids = mesh.find_cells_in_bounds(zbounds=(z1,z2))
  11. # Print the cell IDs in green to the console
  12. printc('IDs of cells within bounds:\n', ids, c='g')
  13. # Create two Plane objects at the specified z-positions
  14. p1 = Plane(normal=(0,0,1), s=[2,2]).z(z1).alpha(0.5)
  15. p2 = p1.clone().z(z2)
  16. # Set the color of cells within the bounds to red
  17. mesh.cellcolors[ids] = [200,10,10, 255] #RGBA
  18. labels = mesh.labels("cellid", scale=0.01)
  19. # Show the mesh, the two planes, the docstring
  20. show(mesh, p1, p2, labels, __doc__, axes=1).close()