rsqsim_api.io.mesh_utils

Utilities for converting between triangulated mesh formats and NumPy arrays.

Attributes

expected_formats

Functions

change_mesh_format(in_mesh, out_format[, out_mesh])

Convert a mesh file from one format to another.

mesh_to_array(mesh)

Convert a meshio Mesh to a flat NumPy triangle array.

convert_multi(search_string, out_format)

Convert all mesh files matching a glob pattern to a target format.

array_to_mesh(triangle_array)

Convert a flat triangle array to a meshio Mesh object.

tri_slip_rake_to_mesh(in_array)

Convert a triangle array with slip and rake columns to a meshio Mesh.

quads_to_vtk(quads)

Convert a list of quadrilateral patches to a meshio Mesh for VTK export.

Module Contents

rsqsim_api.io.mesh_utils.expected_formats = ['stl', 'obj', 'e', 'txt'][source]
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_format is "txt", the mesh is converted to a flat NumPy array and saved with numpy.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_mesh does not exist or out_format is 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_array does 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_data containing "slip_rate" and "rake" arrays.

Return type:

meshio.Mesh

Raises:

AssertionError – If in_array does 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 points and "quad" cells.

Return type:

meshio.Mesh