The vtk_utils.py
module#
Summary#
Compute an average nodal area by summing surface areas of connected elements. |
|
Extrude a given polydata surface in a given direction. |
|
Get IDs of cells with centroids that are inside a given surface. |
|
Find cell IDs close to nodes. |
|
Get the boundary edges from an input surface. |
|
Get the closed/open boundary edge loops of a surface mesh. |
|
Patch boundary edges with the Delaunay algorithm. |
|
Patch boundary edges with a custom algorithm using a central node. |
|
Check whether two polydata or unstructured grid objects are connected. |
|
Add the name of the solid to the STL file. |
|
Find corresponding points between two surfaces. |
|
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_surface
vtk.vtkPolyData
VTK object describing the object.
- vtk_surface
- 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:
- surface
pv.PolyData
Surface to extrude
- extrude_by
float
, default: 1 Amount to extrude.
- extrude_direction
np.array
, default:np.empty
(0) Direction of extrusion, which should have three components. If no components are specified, it extrudes in the normal direction.
- surface
- 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:
- source
pv.UnstructuredGrid
Source object to check which cells are inside/outside the specified surface.
- surface
pv.PolyData
Surface to check whether cells are inside/outside.
- tolerance
float
, default: 1e-9 Tolerance for the
select_enclosed_points
filter.
- source
- 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.
- vtk_utils.get_boundary_edges(surface: pyvista.PolyData) pyvista.MultiBlock #
Get the boundary edges from an input surface.
- Parameters:
- surface
pv.PolyData
Surface to check for boundary edges.
- surface
- 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.
- vtk_utils.get_patches_delaunay(surface: pyvista.PolyData, closed_only: bool = True) list[pyvista.PolyData] #
Patch boundary edges with the Delaunay algorithm.
- 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:
- 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:
- mesh1
Union
[pv.PolyData
,pv.UnstructuredGrid
] First mesh.
- mesh2
Union
[pv.PolyData
,pv.UnstructuredGrid
] Second mesh.
- mesh1
- 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_surface
pv.PolyData
First surface.
- second_surface
pv.PolyData
Second surface.
- distance
float
Approximate largest distance between two surfaces.
- first_surface
- 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:
- surface1
pv.PolyData
First surface.
- surface2
pv.PolyData
Second surface.
- corresponding_points
np.ndarray
, default:None
Corresponding points array.
- surface1
- Returns:
pv.PolyData
Object contains cell data named
thickness
.