Module Reference

PyVista Features

pyvista_features is a module that provides high level features for working with pyvista objects. These features should transform or create pyvista objects. They are intended to be useful on their own as part of a workflow that makes use of pyvista objects.

pyvista_tools.pyvista_features.remove_shared_faces_with_merge(meshes, keep_one=False, return_removed_faces=False)[source]

Merge a list of meshes and remove shared faces. Optionally keep one of each duplicate face (leaving shared wall intact). Optionally return list of removed faces.

Parameters
  • meshes (List[pv.PolyData]) –

  • keep_one – Keep one of each duplicate face instead of removing both

  • return_removed_faces – Return a list of faces that were removed

Returns

merged – Merged mesh with shared faces removed

Return type

pv.PolyData | Tuple[pv.PolyData, list]

pyvista_tools.pyvista_features.rewind_faces_to_normals(mesh, inplace=False)[source]

Re-order the faces of a Pyvista Polydata to match the face normals

Parameters
  • mesh (PolyData) – Mesh to reorder the faces of

  • inplace – Update mesh inplace

Returns

mesh_c – Updated mesh

Return type

Optional[PolyData]

pyvista_tools.pyvista_features.extract_outer_surface(surface, return_removed_faces=False, inplace=False)[source]

An algorithm to refine a surface mesh by keeping only faces on the outer surface of the mesh, thereby removing any inner walls that would be left by the Pyvista extract surface algorithm.

This algorithm starts by identifying a known surface face, then recursively adds connected faces which lie on the surface. This is necessary instead of iterating through each face because the method for determining a surface face on a non-manifold line requires knowledge of another surface face.

Parameters
  • surface (pv.PolyData) – Surface to refine

  • return_removed_faces – return removed faces

  • inplace – Update mesh inplace

Returns

  • r_surface – Refined surface

  • removed_faces – Faces that were removed

Return type

Optional[pv.PolyData] | Tuple[Optional[pv.PolyData], list]

pyvista_tools.pyvista_features.remove_boundary_faces_recursively(mesh, inplace=False)[source]

Remove boundary faces, then re-check for boundary faces and continue removing recursively until no boundary faces remain.

Parameters
  • mesh (PolyData) –

  • inplace

Returns

r_mesh – Mesh with boundary faces removed

Return type

Optional[PolyData]

pyvista_tools.pyvista_features.extract_enclosed_regions(mesh)[source]

Extract enclosed regions from a surface mesh.

Todo: To avoid using large amounts of memory, potentially resulting in a stack overflow, this should me implemented using a while loop that records where it’s been in order to decide where to go next, instead of using recursion.

Parameters

mesh (PolyData) –

Returns

regions

Return type

List[PolyData]

PyVista Tools

pyvista_tools is a module that provides tools for working with pyvista objects. This module should contain functions that are not necessarily useful on their own, but can be used to support development of pyvista features.

pyvista_tools.pyvista_tools.pyvista_faces_to_2d(faces)[source]

Convert pyvista faces from the native 1d array to a 2d array with one face per row. Padding is trimmed.

Only works on a list of faces with all the same number of points per face.

Parameters

faces (ArrayLike) – Faces to be reshaped

Returns

2d array of faces

Return type

ndarray[Any, dtype[ScalarType]]

pyvista_tools.pyvista_tools.pyvista_faces_to_1d(faces)[source]

Convert 2d array of faces to the pyvista native 1d format, inserting the padding.

Only works on a list of faces with all the same number of points per face.

Parameters

faces (ndarray[Any, dtype[ScalarType]]) – Faces to be reshaped

Returns

1d array of faces

Return type

ndarray[Any, dtype[ScalarType]]

pyvista_tools.pyvista_tools.select_shared_faces(mesh_a, mesh_b, tolerance=None)[source]

Select that faces that two meshes share. Shared faces are determined by selecting the faces that use shared points.

Parameters
  • mesh_a (PolyData) – First mesh

  • mesh_b (PolyData) – Second mesh

  • tolerance (Optional[float]) – Tolerance for selecting shared points

Returns

Tuple of lists containing the indices of the shared faces in mesh_a and mesh_b

Return type

Tuple[list, list]

pyvista_tools.pyvista_tools.select_faces_using_points(mesh, points)[source]

Select all faces in a mesh that contain only the specified points.

Parameters
  • mesh (PolyData) – Mesh to select from

  • points (list) – The only points in the given mesh that the selected faces may contain

Returns

mesh_faces – List of indices of the selected faces in the mesh

Return type

List[int]

pyvista_tools.pyvista_tools.select_points_used_by_faces(mesh, points=None, faces=None, exclusive=False)[source]

Select points used in the faces of a mesh. Optionally specify a subset of points and/or faces to check. When exclusive is set to True, selects only points that are not used in the remaining faces.

Only works on meshes with all the same number of points per face.

Todo: not crash if you don’t specify points (till then you can use list(range(len(mesh.points)))

Parameters
  • mesh (PolyData) – Mesh to select from

  • points (Optional[List[int]]) – Optional subset of points in mesh to select from

  • faces (Optional[List[int]]) – Optional subset of faces in mesh to test

  • exclusive (bool) – If true, selects only points exclusively used in the specified faces

Returns

List of points used in the specified faces

Return type

List[int]

pyvista_tools.pyvista_tools.select_faces_using_edges(mesh, edges)[source]

Extract all the faces of a Pyvista Polydata object that use a given set of edges

Parameters
  • mesh (PolyData) – Mesh to extract edges from

  • edges (PolyData) – Edges to use

Returns

faces_using_edges – List of faces in mesh that use edges

Return type

List[int]

pyvista_tools.pyvista_tools.select_intersecting_triangles(mesh, quiet=False, *args, **kwargs)[source]

Wrapper around the pymeshfix function for selecting self intersecting triangles

Parameters
  • mesh (PolyData) – Mesh to select from

  • quiet – Enable or disable verbose output from pymehsfix NOTE pymeshfix seems to have this backward. Quiet=True makes it loud. Quiet=False makes it quiet

  • args – args for PyTMesh.select_intersecting_triangles

  • kwargs – kwargs for PyTMesh.select_intersecting_Triangles

Returns

intersecting – NDArray of intersecting triangles

Return type

ndarray[Any, dtype[int]]

pyvista_tools.pyvista_tools.identify_neighbors(surface)[source]

Identify neighbors of each face in a surface. Returns a dict of faces with each face’s neighbors, grouped by the lines that the faces share. Also returns a dict of lines in the surface with each face that uses each line.

Parameters

surface (PolyData) –

Returns

neighbors_dict, lines_dict

Return type

Tuple[Dict, Dict]

pyvista_tools.pyvista_tools.find_face_on_outer_surface(surface)[source]

Find a face on the outer surface by casting a long ray from the first surface and choosing the last face it hits

Parameters

surface (PolyData) –

Returns

face – A face guaranteed to be on the outer surface of the input surface mesh

Return type

int

Geometry Tools

geometry_tools is a module that provides functions for making geometric calculations in support of pyvista_tools. These functions should not rely on pyvista specific types or data structures.

pyvista_tools.geometry_tools.find_sequence(array, sequence, check_reverse=False)[source]

Find the start index of a subsequence in an array.

Parameters
  • array (ArrayLike) – Array in which to search for sequence

  • sequence (ArrayLike) – Sequence to search for

  • check_reverse – Also search for the reverse of the sequence. The forward sequence is still given precedence.

Returns

Location – Start index of sequnce in array. -1 represents not found.

Return type

int

pyvista_tools.geometry_tools.compute_normal(points)[source]

Compute a vector that is normal to a plane defined by a list of three points

Parameters

points (ArrayLike) – Points defining a plane

Returns

normal – Vector that is normal to the plane defined by the input points

Return type

ndarray

pyvista_tools.geometry_tools.dihedral_angle(normal_a, normal_b, plane_normal=None, degrees=False)[source]

Calculate dihedral angle between two faces specified by their normal vectors, with 0 < angle < pi. Optionally, an additional normal can be given, defining a plane on which normal_a and normal_b lie. With this information, the dihedral angle can be given as 0 < angle < 2*pi

Parameters
  • normal_a (ArrayLike) – Normal vector A

  • normal_b (ArrayLike) – Normal vector B

  • plane_normal (ArrayLike) – Vector that is normal to the plane that normal_a and normal_b lie on (it is perpendicular to both). The direction of this vector will be used to determine if the dihedral angle is positive or negative, thus allowing the output to be between 0 and 2pi

  • degrees – Return the angle in degrees

Returns

angle – Dihedral angle in radians (or optionally degrees)

Return type

float