Skip to content

compas_cgal.meshing ¤

Functions:¤

trimesh_dual ¤

trimesh_dual(
    mesh: VerticesFaces,
    length_factor: float = 1.0,
    number_of_iterations: int = 10,
    angle_radians: float = 0.9,
    scale_factor: float = 1.0,
    fixed_vertices: list[int] = [],
) -> tuple[ndarray, list[list[int]]]

Create a dual mesh from a triangular mesh with variable-length faces.

Parameters:

Name Type Description Default
mesh VerticesFaces

The mesh to create a dual from.

required
angle_radians float

Angle limit in radians for boundary vertices to remove.

0.9
length_factor float

Length factor for remeshing.

1.0
number_of_iterations int

Number of remeshing iterations.

10
scale_factor float

Scale factor for inner vertices.

1.0
fixed_vertices list[int]

List of vertex indices to keep fixed during remeshing.

[]

Returns:

Type Description
tuple

A tuple containing:

  • Remeshed mesh vertices as an Nx3 numpy array.
  • Remeshed mesh faces as an Mx3 numpy array.
  • Dual mesh vertices as an Nx3 numpy array.
  • Variable-length faces as a list of lists of vertex indices.
Notes

This dual mesh implementation includes proper boundary handling by: 1. Creating vertices at face centroids of the primal mesh 2. Creating additional vertices at boundary edge midpoints 3. Creating proper connections for boundary edges

trimesh_remesh ¤

trimesh_remesh(
    mesh: VerticesFaces,
    target_edge_length: float,
    number_of_iterations: int = 10,
    do_project: bool = True,
    protect_boundary: bool = False,
    protect_sharp_edges_angle_deg: float = 0.0,
    keep_points=None,
) -> VerticesFacesNumpy

Remeshing of a triangle mesh.

Parameters:

Name Type Description Default
mesh VerticesFaces

The mesh to remesh.

required
target_edge_length float

The target edge length.

required
number_of_iterations int

Number of remeshing iterations.

10
do_project bool

If True, reproject vertices onto the input surface when they are created or displaced.

True
protect_boundary bool

If True, constrain all boundary edges so they are NOT split, collapsed, or flipped during remeshing. Use this to preserve the input mesh's boundary curve verbatim — including sharp corners that the default smoothing pass would otherwise round.

False
protect_sharp_edges_angle_deg float

Dihedral threshold in degrees for interior feature detection. Edges whose adjacent faces form a dihedral angle ≥ this value are marked constrained and preserved. 0.0 disables interior-feature detection (default).

0.0
keep_points array - like

An Nx3 array of points. The mesh vertex coincident with each point (matched by coordinate, within tolerance) is pinned: it is neither moved nor removed during remeshing, while the edges between such points are still re-sampled. Use this to keep only specific vertices — e.g. the four corners of an open patch — rather than the whole boundary. None disables (default).

None

Returns:

Type Description
VerticesFacesNumpy
Notes

Without protect_boundary or protect_sharp_edges_angle_deg set, boundary edges follow CGAL's default remeshing behaviour: re-sampled to target_edge_length (visible corner rounding is the cost).

Examples:

>>> from compas.geometry import Sphere, Polyhedron
>>> from compas_cgal.meshing import mesh_remesh
>>> sphere = Sphere(0.5, point=[1, 1, 1])
>>> mesh = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
>>> V, F = mesh_remesh(mesh, 1.0)
>>> shape = Polyhedron(V.tolist(), F.tolist())