The vtk_utils.py module#

Summary#

compute_surface_nodal_area_pyvista

Compute an average nodal area by summing surface areas of connected elements.

extrude_polydata

Extrude a given polydata surface in a given direction.

cell_ids_inside_enclosed_surface

Get IDs of cells with centroids that are inside a given surface.

find_cells_close_to_nodes

Find cell IDs close to nodes.

get_boundary_edges

Get the boundary edges from an input surface.

get_boundary_edge_loops

Get the closed/open boundary edge loops of a surface mesh.

get_patches_delaunay

Patch boundary edges with the Delaunay algorithm.

get_patches_with_centroid

Patch boundary edges with a custom algorithm using a central node.

are_connected

Check whether two polydata or unstructured grid objects are connected.

add_solid_name_to_stl

Add the name of the solid to the STL file.

find_corresponding_points

Find corresponding points between two surfaces.

generate_thickness_lines

Generate lines from points on surface 1 to corresponding points on surface 2.

Description#

Module containing methods for mesh operations related to the VTK library.

Module detail#

vtk_utils.compute_surface_nodal_area_pyvista(surface: pyvista.PolyData) numpy.ndarray#

Compute an average nodal area by summing surface areas of connected elements.

Parameters:
vtk_surfacevtk.vtkPolyData

VTK object describing the object.

Returns:
np.array

NumPy array with nodal areas of length number of points.

Notes

This method adds the partial areas of connected elements/cells to each node.

vtk_utils.extrude_polydata(surface: pyvista.PolyData, extrude_by: float = 1, extrude_direction: numpy.ndarray = np.empty(0)) pyvista.PolyData#

Extrude a given polydata surface in a given direction.

Parameters:
surfacepv.PolyData

Surface to extrude

extrude_byfloat, default: 1

Amount to extrude.

extrude_directionnp.array, default: np.empty(0)

Direction of extrusion, which should have three components. If no components are specified, it extrudes in the normal direction.

Returns:
pv.PolyData

Extruded polydata object.

vtk_utils.cell_ids_inside_enclosed_surface(source: pyvista.UnstructuredGrid | pyvista.PolyData, surface: pyvista.PolyData, tolerance: float = 1e-09) numpy.ndarray#

Get IDs of cells with centroids that are inside a given surface.

Parameters:
sourcepv.UnstructuredGrid

Source object to check which cells are inside/outside the specified surface.

surfacepv.PolyData

Surface to check whether cells are inside/outside.

tolerancefloat, default: 1e-9

Tolerance for the select_enclosed_points filter.

Returns:
np.ndarray

Array with cell IDs that are inside the enclosed surface.

Notes

This method also accepts a source that represents the cell centroids. In this case, computing the cell centers is skipped.

vtk_utils.find_cells_close_to_nodes(mesh: pyvista.UnstructuredGrid, node_ids: list[int], radius: float = 2) numpy.ndarray#

Find cell IDs close to nodes.

Parameters:
meshpv.UnstructuredGrid

Target mesh.

node_idslist[int]

Node IDs.

radiusfloat, default: 2

Influence radius.

Returns:
np.ndarray

Cell IDs.

vtk_utils.get_boundary_edges(surface: pyvista.PolyData) pyvista.MultiBlock#

Get the boundary edges from an input surface.

Parameters:
surfacepv.PolyData

Surface to check for boundary edges.

Returns:
pv.MultiBlock

Multi-block data, where each block represents connected edges.

vtk_utils.get_boundary_edge_loops(surface: pyvista.PolyData, remove_open_edge_loops: bool = True, return_types: bool = False) dict | tuple[dict, dict]#

Get the closed/open boundary edge loops of a surface mesh.

Parameters:
surfacepv.PolyData

Surface mesh to check for boundary edges.

remove_open_edge_loopsbool, default: True

Whether to remove open edge loops from the returned dictionary.

Returns:
dict

Dictionary with the edges that make up the open/closed loop.

vtk_utils.get_patches_delaunay(surface: pyvista.PolyData, closed_only: bool = True) list[pyvista.PolyData]#

Patch boundary edges with the Delaunay algorithm.

Parameters:
surfacepv.PolyData

Surface with boundary edges to find patches for.

closed_onlybool, default: True

Whether to return patches for closed loops of boundary edges.

Returns:
List[pv.PolyData]

List of patches that close the open surface.

vtk_utils.get_patches_with_centroid(surface: pyvista.PolyData, closed_only: bool = True) list[pyvista.PolyData] | None#

Patch boundary edges with a custom algorithm using a central node.

Parameters:
surfacepv.PolyData

Surface with boundary edges to find patches for.

closed_onlybool, default: True

Whether to return patches for closed loops of boundary edges.

Returns:
List[pv.PolyData]

List of patches that close the open surface.

Notes

Edges must be sorted properly for this method to return sensible patches.

vtk_utils.are_connected(mesh1: pyvista.PolyData | pyvista.UnstructuredGrid, mesh2: pyvista.PolyData | pyvista.UnstructuredGrid) bool#

Check whether two polydata or unstructured grid objects are connected.

Parameters:
mesh1Union[pv.PolyData, pv.UnstructuredGrid]

First mesh.

mesh2Union[pv.PolyData, pv.UnstructuredGrid]

Second mesh.

vtk_utils.add_solid_name_to_stl(filename, solid_name, file_type: str = 'ascii') None#

Add the name of the solid to the STL file.

Notes

This method supports only a single block.

vtk_utils.find_corresponding_points(first_surface: pyvista.PolyData, second_surface: pyvista.PolyData, distance: float = 20) numpy.ndarray#

Find corresponding points between two surfaces.

Parameters:
first_surfacepv.PolyData

First surface.

second_surfacepv.PolyData

Second surface.

distancefloat

Approximate largest distance between two surfaces.

Returns:
np.ndarray

2*N array The first row contains node IDs of the first surface. The second row contains corresponding node IDs on the second surface. If no corresponding node is found, None is returned.

Notes

This method uses ray tracing. The two surfaces are assumed to be close and nearly parallel. As a result, the correspondence is not one to one. Some points might have no corresponding match, while others might share the same corresponding point.

vtk_utils.generate_thickness_lines(surface1: pyvista.PolyData, surface2: pyvista.PolyData, corresponding_points: numpy.ndarray = None) pyvista.PolyData#

Generate lines from points on surface 1 to corresponding points on surface 2.

Parameters:
surface1pv.PolyData

First surface.

surface2pv.PolyData

Second surface.

corresponding_pointsnp.ndarray, default: None

Corresponding points array.

Returns:
pv.PolyData

Object contains cell data named thickness.