capytaine.meshes.clean module

capytaine.meshes.clean.clean_mesh(vertices: ndarray, faces: List[List[int]], faces_metadata: Dict[str, ndarray], max_iter: int = 5, tol: float = 1e-08) Tuple[ndarray, List[List[int]]][source]

Iteratively clean a mesh by applying geometric simplifications.

Parameters:
  • vertices (numpy.ndarray) – Vertex coordinates of the input mesh.

  • faces (list of list of int) – Face connectivity describing the mesh panels.

  • faces_metadata (Dict[str, np.ndarray]) – Some arrays with the same first dimension (should be the number of faces) storing some fields defined on all the faces of the mesh.

  • max_iter (int, default=5) – Maximum number of cleaning iterations to perform.

  • tol (float, default=1e-8) – Tolerance used when merging near-duplicate vertices.

Returns:

The cleaned vertex array and associated face connectivity.

Return type:

tuple[numpy.ndarray, list of list of int]

capytaine.meshes.clean.clean_mesh_once(vertices: ndarray, faces: List[List[int]], faces_metadata: Dict[str, ndarray], tol: float = 1e-10) Tuple[ndarray, List[List[int]]][source]

Run a single cleaning pass on the mesh data.

Parameters:
  • vertices (numpy.ndarray) – Vertex coordinates describing the mesh geometry.

  • faces (list of list of int) – Face connectivity with indices referencing vertices.

  • faces_metadata (Dict[str, np.ndarray]) – Some arrays with the same first dimension (should be the number of faces) storing some fields defined on all the faces of the mesh.

  • tol (float, default=1e-10) – Tolerance for considering vertices as duplicates.

Returns:

Updated vertices and faces after the cleaning step.

Return type:

tuple[numpy.ndarray, list of list of int]

Raises:

ValueError – If an unsupported face configuration is encountered.

capytaine.meshes.clean.merge_near_duplicate_vertices(vertices: ndarray, faces: List[List[int]], tol: float = 1e-08) Tuple[ndarray, List[List[int]]][source]

Merge vertices that are closer than a tolerance.

Parameters:
  • vertices (numpy.ndarray) – Vertex coordinates of shape (n, 3).

  • faces (list of list of int) – Face connectivity referencing the vertices array.

  • tol (float, default=1e-8) – Distance threshold below which vertices are considered duplicates.

Returns:

Deduplicated vertices and remapped faces.

Return type:

tuple[numpy.ndarray, list of list of int]

capytaine.meshes.clean.remove_duplicate_faces(faces, faces_metadata)[source]

Eliminate duplicate faces while preserving order.

Parameters:
  • faces (list of list of int) – Face connectivity to deduplicate.

  • faces_metadata (Dict[str, np.ndarray]) – Fields associated to faces

Returns:

  • list of list of int – Face connectivity with duplicates removed.

  • Dict[str, np.ndarray] – Updated metadata

capytaine.meshes.clean.remove_duplicate_vertices(vertices: ndarray, faces: List[List[int]]) Tuple[ndarray, List[List[int]]][source]

Remove exactly repeated vertices and remap faces accordingly.

Parameters:
  • vertices (numpy.ndarray) – Vertex coordinates of shape (n, 3).

  • faces (list of list of int) – Face connectivity using indices into vertices.

Returns:

Unique vertices and faces with updated indices.

Return type:

tuple[numpy.ndarray, list of list of int]

capytaine.meshes.clean.remove_small_faces(vertices: ndarray, faces: List[List[int]], faces_metadata: Dict[str, ndarray], tol: float = 1e-08)[source]

Remove faces whose area falls below a tolerance.

Parameters:
  • vertices (numpy.ndarray) – Vertex coordinates used to evaluate surface area.

  • faces (list of list of int) – Face connectivity referencing vertices.

  • faces_metadata (Dict[str, np.ndarray]) – Fields associated to faces

  • tol (float, default=1e-8) – Minimum allowable face area.

Returns:

Faces that exceed the area threshold.

Return type:

list of list of int

capytaine.meshes.clean.remove_unused_vertices(vertices: ndarray, faces: List[List[int]]) Tuple[ndarray, List[List[int]]][source]

Remove vertices that are not referenced by any face.

Parameters:
  • vertices (numpy.ndarray) – Vertex coordinates of shape (n, 3).

  • faces (list of list of int) – Face connectivity using indices into vertices.

Returns:

Reduced vertex array and corresponding face connectivity.

Return type:

tuple[numpy.ndarray, list of list of int]