-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fdeed0
commit 75a591f
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import numpy as np | ||
import pyvista as pv | ||
from pytetwild import PyfTetWildWrapper | ||
from typing import Tuple | ||
|
||
def tetrahedralize_pv(mesh: pv.PolyData) -> pv.UnstructuredGrid: | ||
""" | ||
Converts a PyVista surface mesh to a PyVista unstructured grid. | ||
Parameters | ||
---------- | ||
mesh : pv.PolyData | ||
The input surface mesh. | ||
Returns | ||
------- | ||
pv.UnstructuredGrid | ||
The converted unstructured grid. | ||
""" | ||
vertices = np.array(mesh.points, dtype=np.float64) | ||
faces = np.array(mesh.faces.reshape((-1, 4))[:, 1:4], dtype=np.int32) | ||
|
||
tetrahedral_mesh_vertices, tetrahedral_mesh_tetrahedra = PyfTetWildWrapper.tetrahedralize_mesh(vertices, faces) | ||
|
||
cells = np.hstack([np.full((tetrahedral_mesh_tetrahedra.shape[0], 1), 4, dtype=np.int32), tetrahedral_mesh_tetrahedra]) | ||
cell_types = np.full(tetrahedral_mesh_tetrahedra.shape[0], 10, dtype=np.uint8) | ||
|
||
return pv.UnstructuredGrid(cells, cell_types, tetrahedral_mesh_vertices) | ||
|
||
def tetrahedralize(vertices: np.ndarray, faces: np.ndarray) -> Tuple[np.ndarray, np.ndarray]: | ||
""" | ||
Converts mesh vertices and faces to a tetrahedral mesh using PyfTetWildWrapper. | ||
Parameters | ||
---------- | ||
vertices : np.ndarray | ||
The vertices of the mesh. | ||
faces : np.ndarray | ||
The faces of the mesh. | ||
Returns | ||
------- | ||
Tuple[np.ndarray, np.ndarray] | ||
A tuple containing the vertices and tetrahedra of the tetrahedral mesh. | ||
""" | ||
return PyfTetWildWrapper.tetrahedralize_mesh(vertices, faces) |