_mesh module

Mesh geometry (Mesh) that implements the Geometry API.

  • Inherits Geometry only (no simulation behaviour).

  • Stores vertices and triangle connectivity in NumPy arrays.

  • Uses open3d optionally for file I/O of non-.npz formats.

  • Save/load is driven by Geometry via _save_core_dict() / _load_core().

class pyrockfall._mesh.Mesh(points: ndarray | None = None, triangles: ndarray | None = None, *, colors: ndarray | None = None, normals: ndarray | None = None, attrs: Mapping[str, ndarray] | None = None)[source]

Bases: Model

Triangle mesh that implements the Geometry interface.

This class stores vertices and triangle connectivity as NumPy arrays and provides small geometry utilities (segment/split and 2D slicing into Geometry polylines). It has no simulation behaviour.

Parameters:
  • points – Optional initial vertex coordinates of shape (N, 3) or (N, 2). If 2D is provided, a zero z column is appended internally.

  • triangles – Optional initial triangle connectivity of shape (E, 3) with 0-based indices.

  • colors – Optional per-vertex colors, attached as attribute "colors". Must have first dimension N.

  • normals – Optional per-vertex normals, attached as attribute "normals". Must have first dimension N.

  • attrs – Optional mapping of additional per-vertex attributes. Each array must have first dimension N and shape (N,) or (N, k).

Notes

  • Vertices are stored as float64 by default.

  • Triangles are stored as int32.

  • Persistence is handled by save / load, which call _save_core_dict() and _load_core() to serialize only the geometry. Per-vertex attributes are included/excluded via the attributes argument on those base methods.

property points: NDArray[floating]

Vertices as an array of shape (N, 3).

property triangles: NDArray[integer]

Triangle connectivity as an array of shape (E, 3) (int32).

apply_point_mask_(mask: ndarray) → None[source]

Keep only points[mask]. Triangles that reference a dropped point are removed and the remaining connectivity is reindexed. Per-point and per-triangle attributes are kept consistent.

segment(dx: float, du: float = 0.0) → List[Mesh][source]

Split the mesh along the strike into windows of length dx.

Triangles are assigned to a window using the s coordinate of their centroid in the curvilinear frame (see Model.sde()), so the windows follow the wall around bends. Each window becomes an independent submesh that keeps the attributes and shares the frame of this mesh.

Parameters:
  • dx – Window length along the strike (must be > 0).

  • du – Overlap between consecutive windows (0 <= du < dx).

Returns:

Independent submeshes (0 or more), ordered by increasing s.

Return type:

list[Mesh]

split(dx: float = 0.5, minPerc: float = 0.05) → List[Mesh][source]

Split the mesh into two parts at the sharpest bend of the wall.

The cut is made at the vertex of the frame’s polyline with the largest turning angle that leaves at least minPerc of the triangles on each side. A wall without a bend is cut at the median s of the triangle centroids, which balances the two parts.

Parameters:
  • dx – Unused; kept for backward compatibility.

  • minPerc – Minimum fraction of triangles per side (default 0.05).

Returns:

[before, after] along increasing s (or an empty list if no valid split exists).

Return type:

list[Mesh]

slopeGeometry(*, label: str, nodes_std: ndarray | None = None) → Geometry[source]

Construct a Geometry using labels from a mesh attribute.

The attribute label can be either: - Per-triangle (length == E): used directly as materialIDs; or - Per-vertex (length == N): converted to per-triangle IDs by:

  1. if all three vertex labels are equal → use that value;

  2. if exactly two are equal → use the repeated label;

  3. if all different → use the label of the vertex closest to the triangle’s barycentre.

Parameters:
  • materials – Material table (indexable by the derived integer IDs).

  • label – Name of the mesh attribute containing material IDs. (shape (N,), (N,1), (E,) or (E,1)).

  • nodes_std – Optional node standard deviations, shape (N, 3).

Returns:

A slope geometry with elements = triangles, and per-element materialIDs consistent with materials.

Return type:

Geometry

Raises:

ValueError – If the mesh is empty, label shape is invalid, or derived IDs fall outside materials range.

to_tri_attr(attr: str, *, method: str = 'mean', mode_tol: float = 1e-07, out: str | None = None) → ndarray[source]

Convert a per-point attribute to a per-triangle attribute.

Parameters:
  • attr – Name of a per-point attribute. Supports shapes (N,) or (N,k).

  • method – ‘mean’ for arithmetic mean; ‘mode’ for most-common label with barycentre tie-break (requires integer, 1-D).

  • mode_tol – Tolerance for mode equality (only used if method=’mode’).

  • out – If provided, stores the result as a mesh attribute with this name.

Returns:

Per-triangle attribute of shape (E,) or (E,k).

Return type:

np.ndarray

Raises:

ValueError – If attribute is missing/shape-mismatched, or ‘mode’ used on non-integer / non-1D data.

to_point_attr(attr: str, *, method: str = 'mean', out: str | None = None, fill: float | int | None = None) → ndarray[source]

Convert a per-triangle attribute to a per-point attribute.

Parameters:
  • attr – Name of a per-triangle attribute. Supports shapes (E,) or (E,k).

  • method – ‘mean’ for arithmetic mean of incident triangles; ‘mode’ for most-common integer label among incident triangles. Ties are broken by picking the label of the adjacent triangle whose centroid is closest to the point.

  • out – If provided, stores the result as a mesh attribute with this name.

  • fill – Value for isolated points (not referenced by any triangle). Defaults to np.nan for float arrays, and -1 for integer arrays.

Returns:

Per-point attribute of shape (N,) or (N,k).

Return type:

np.ndarray

Raises:

ValueError – If attribute is missing/shape-mismatched, or ‘mode’ used on non-integer / non-1D data.

section(increment: float, label: str, *, frame: CurvilinearFrame | None = None, **kwargs)[source]

Extract 2D profiles along the strike of the mesh, and their points in 3D.

Each section is the exact cut of the triangles by a surface of constant s of the curvilinear frame (see slice()), so every node lies on a triangle edge and every segment carries the material of the triangle it crosses. The mesh itself is not modified.

Parameters:
  • increment – Spacing between consecutive sections along the strike. A section must not pass exactly through mesh vertices; change the spacing slightly if slice() reports that.

  • label – Name of the attribute containing material IDs (per point or per triangle).

  • frame – Frame to slice in. Defaults to the frame of the mesh.

Returns:

One 2D Geometry per section, crest to toe, with nodes as (horizontal distance from the crest node, height above the lowest node) and material IDs per segment.

sections_pc: A PointCloud with all section nodes in the mesh’s coordinates, the material attribute (label) and a "Profile" attribute numbering the sections.

Return type:

profiles

Raises:

ValueError – If no valid sections are found.

slice(direction: NDArray[floating] | None = None, increment: float | None = None, label: str | None = None, *, frame: CurvilinearFrame | None = None, **kwargs) → Tuple[List[Geometry], NDArray][source]

Per-triangle slicing with a simple local-walk ordering.

By default the slices follow the strike of the wall: they are surfaces of constant s of the curvilinear frame (see Model.sde()) and the returned 2D nodes are (d, e). With a direction the slices are parallel planes normal to it and the nodes are the two remaining axes of the points rotated so that direction is +X.

Segment labels come from triangle materials. Triangles are intersected in the slicing coordinates, where a triangle spanning a bend of the wall is only approximately planar (the error is second order in its size).

Parameters:
  • direction – None to slice along the strike, or a fixed direction.

  • increment – Spacing between consecutive slices.

  • label – Name of the attribute containing material IDs (per point or per triangle).

  • frame – Frame to slice in. Defaults to the frame of the mesh.

Returns:

Profiles as Geometry objects and the slice positions (s, or the distance along direction).