_mesh module¶
Mesh geometry (Mesh) that implements the Geometry API.
Inherits
Geometryonly (no simulation behaviour).Stores vertices and triangle connectivity in NumPy arrays.
Uses
open3doptionally for file I/O of non-.npzformats.Save/load is driven by
Geometryvia_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:
ModelTriangle mesh that implements the
Geometryinterface.This class stores vertices and triangle connectivity as NumPy arrays and provides small geometry utilities (segment/split and 2D slicing into
Geometrypolylines). It has no simulation behaviour.- Parameters:
points – Optional initial vertex coordinates of shape
(N, 3)or(N, 2). If 2D is provided, a zerozcolumn 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 dimensionN.normals – Optional per-vertex normals, attached as attribute
"normals". Must have first dimensionN.attrs – Optional mapping of additional per-vertex attributes. Each array must have first dimension
Nand shape(N,)or(N, k).
Notes
Vertices are stored as
float64by 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 theattributesargument on those base methods.
- 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
scoordinate of their centroid in the curvilinear frame (seeModel.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.
- 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
minPercof the triangles on each side. A wall without a bend is cut at the mediansof the triangle centroids, which balances the two parts.
- slopeGeometry(*, label: str, nodes_std: ndarray | None = None) Geometry[source]¶
Construct a
Geometryusing labels from a mesh attribute.The attribute
labelcan be either: - Per-triangle (length == E): used directly asmaterialIDs; or - Per-vertex (length == N): converted to per-triangle IDs by:if all three vertex labels are equal → use that value;
if exactly two are equal → use the repeated label;
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-elementmaterialIDsconsistent withmaterials.- Return type:
- Raises:
ValueError – If the mesh is empty, label shape is invalid, or derived IDs fall outside
materialsrange.
- 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
sof the curvilinear frame (seeslice()), 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
Geometryper 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
PointCloudwith 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
sof the curvilinear frame (seeModel.sde()) and the returned 2D nodes are(d, e). With adirectionthe slices are parallel planes normal to it and the nodes are the two remaining axes of the points rotated so thatdirectionis +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 –
Noneto 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
Geometryobjects and the slice positions (s, or the distance alongdirection).