rsqsim_api.io.mesh_utils
Utilities for converting between triangulated mesh formats and NumPy arrays.
Attributes
Functions
|
Convert a mesh file from one format to another. |
|
Convert a meshio Mesh to a flat NumPy triangle array. |
|
Convert all mesh files matching a glob pattern to a target format. |
|
Convert a flat triangle array to a meshio Mesh object. |
|
Convert a triangle array with slip and rake columns to a meshio Mesh. |
|
Convert a list of quadrilateral patches to a meshio Mesh for VTK export. |
Module Contents
- rsqsim_api.io.mesh_utils.change_mesh_format(in_mesh, out_format, out_mesh=None)[source]
Convert a mesh file from one format to another.
Reads the input mesh with meshio and writes it in the requested output format. If
out_formatis"txt", the mesh is converted to a flat NumPy array and saved withnumpy.savetxt.- Parameters:
in_mesh (str) – Path to the input mesh file (any format supported by meshio).
out_format (str) – Target format. Must be one of
"stl","obj","e", or"txt".out_mesh (str) – Output file path. If
None, the input file stem is reused with the new extension.
- Raises:
AssertionError – If
in_meshdoes not exist orout_formatis not in the allowed list.
- rsqsim_api.io.mesh_utils.mesh_to_array(mesh)[source]
Convert a meshio Mesh to a flat NumPy triangle array.
Expands the indexed triangle representation into a dense array where each row contains the (x, y, z) coordinates of all three corner vertices of one triangle.
- Parameters:
mesh (meshio.Mesh) – meshio Mesh object containing at least one set of triangular cells.
- Returns:
Each row is
[x1,y1,z1, x2,y2,z2, x3,y3,z3].- Return type:
numpy.ndarray of shape (n_triangles, 9)
- Raises:
AssertionError – If the mesh contains no triangular cells.
- rsqsim_api.io.mesh_utils.convert_multi(search_string, out_format)[source]
Convert all mesh files matching a glob pattern to a target format.
- Parameters:
search_string (str) – Glob pattern used to find input mesh files, e.g.
"/path/to/meshes/*.stl".out_format (str) – Target format passed to
change_mesh_format().
- Raises:
AssertionError – If no files match
search_string.
- rsqsim_api.io.mesh_utils.array_to_mesh(triangle_array)[source]
Convert a flat triangle array to a meshio Mesh object.
Deduplicates the vertices across all triangles and builds an indexed meshio Mesh with a single set of triangular cells.
- Parameters:
triangle_array (numpy.ndarray of shape (n_triangles, 9)) – Each row contains the (x, y, z) coordinates of the three corner vertices of one triangle:
[x1,y1,z1, x2,y2,z2, x3,y3,z3].- Returns:
Mesh with unique
points(shape(n_unique_verts, 3)) and triangular cells referencing them by index.- Return type:
meshio.Mesh
- Raises:
AssertionError – If
triangle_arraydoes not have exactly 9 columns.
- rsqsim_api.io.mesh_utils.tri_slip_rake_to_mesh(in_array)[source]
Convert a triangle array with slip and rake columns to a meshio Mesh.
Builds a mesh from the first 9 columns (vertex coordinates) and attaches the slip rate and rake columns as cell data.
- Parameters:
in_array (numpy.ndarray of shape (n_triangles, 11)) – Columns 0–8 are the (x,y,z) coordinates of the three triangle corners (as in
array_to_mesh()). Column 9 is slip rate in m/s and column 10 is rake in degrees.- Returns:
Mesh with triangular cells and
cell_datacontaining"slip_rate"and"rake"arrays.- Return type:
meshio.Mesh
- Raises:
AssertionError – If
in_arraydoes not have exactly 11 columns.
- rsqsim_api.io.mesh_utils.quads_to_vtk(quads)[source]
Convert a list of quadrilateral patches to a meshio Mesh for VTK export.
Deduplicates vertices across all quads and builds an indexed meshio Mesh with quad cells.
- Parameters:
quads – Iterable of quadrilateral patches. Each element should be an array-like of shape (4, 3) giving the four corner (x, y, z) coordinates in NZTM (metres).
- Returns:
Mesh with unique
pointsand"quad"cells.- Return type:
meshio.Mesh