Delaunay triangulation

Description

Build a mesh from a cloud of points: a triangular surface or a tetrahedral volume.

Two triangulations are available and method selects between them, either explicitly or from the shape of the cloud:

  • a 2D triangulation, which projects the points onto their best-fitting plane, triangulates there and maps the connectivity back onto the original three dimensional points.

  • a 3D tetrahedralization, which connects the points into tetrahedra and, for a surface, keeps the boundary of the generated volume.

Both triangulations fill the convex hull of the points. alpha is what makes them follow a concave shape: see the Alpha section below.

A triangulation is Delaunay when the circumscribed circle of every triangle — the circle passing through its three vertices — contains no other point of the set. The same holds in three dimensions with circumscribed spheres and tetrahedra. This property makes the mesh unique for points in general position, and gives the fattest cells any triangulation of those points admits: among all the ways of connecting them, the Delaunay one maximises the smallest angle.

The mesh is built one point at a time, by the Bowyer–Watson algorithm. Starting from a cloud with no cells at all, the steps are:

  1. Merge coincident points. Two points at the same place give a circle of undefined radius and make every later test on them meaningless.

  2. Build a bounding simplex. A point can only be inserted into an existing triangulation, so an empty mesh is not a valid starting state. Three vertices, four in three dimensions, are placed around the cloud at a distance of offset times its radius, and the single cell they form is the initial mesh. These vertices belong to no data and are usually called ghost vertices.

  3. Insert each point p in turn:

    1. Collect every cell whose circumscribed circle contains p. Those cells break the Delaunay property now that p exists, so none of them can survive.

    2. Delete them. The hole they leave is star-shaped seen from p, which is what makes the next step always valid. Its boundary is found by counting: an edge shared by two deleted cells is interior to the hole, an edge belonging to exactly one is on its boundary.

    3. Join p to every boundary edge of the hole. The new cells fill it exactly and overlap nowhere.

    A point closer to an already inserted one than tolerance is skipped at this stage, and therefore ends up in the output without belonging to any cell.

    Each insertion removes k cells and creates k + 2, so the mesh grows by exactly two cells per point.

  4. Delete the bounding simplex, and with it every cell having a ghost vertex as a corner. What remains triangulates the points exactly and fills their convex hull. This is where offset matters: a simplex placed too close to the cloud shares cells with the outermost points, and those cells are lost together with it.

  5. Filter by alpha, when asked. Cells whose circumscribed circle is larger than alpha are discarded. Nothing is recomputed: the Delaunay mesh is built whole, then thinned, and the result is always a subset of it.

Added in version 2.7.0.

Parameters

  • base: Base

    Bases holding the points to triangulate. All points of all zones and instants are gathered into a single cloud.

  • coordinates: list[str], default= None

    Names of the three variables used as the x, y and z coordinates of the points. If None, the coordinate variables declared by the base are used.

  • kind: str, default= "surface"

    Nature of the cells of the output mesh.

    • "surface" — triangles;

    • "volume" — tetrahedra.

  • method: str, default= "auto"

    Which triangulation to apply.

    • "auto" — measure the flatness of the cloud and choose (see the Method selection section below);

    • "delaunay2d" — 2D triangulation on the best-fitting plane;

    • "delaunay3d" — 3D tetrahedralization; with kind="surface" the boundary of the tetrahedra is extracted.

    If kind is "volume" then 'delaunay3d is automatically used regardless of the user input.

  • alpha: str or float, default= "auto"

    Ceiling on the radius of the circumscribed circle or sphere of a cell. Cells larger than this are discarded, which opens concavities and holes.

    • "auto" — computed as alpha_scale times the mean distance between a point and its nearest neighbour, so that the value follows the sampling density of the cloud;

    • a float — used as it is, in the unit of the coordinates;

    • 0 — no filtering at all, and the mesh fills the convex hull.

    See the Alpha section below.

  • alpha_scale: float, default= 3.5

    Multiplier applied to the mean nearest-neighbour distance when alpha is "auto". Ignored otherwise, in which case the mean nearest-neighbour distance is not computed at all.

    Values below about 2 erode the outer boundary of the mesh before they open its interior holes, and may fragment it. The useful range is roughly 3 to 6; the wider that range is, the more uniform the sampling density of the cloud.

  • tolerance: float, default= None

    Tolerance to exclude points that are too close. If two points are closer than tolerance times the diagonal of the bounding box of the data then one of them is excluded from the triangulation algorithm. If None, then all points are used.

  • planarity_threshold: float, default= 0.05

    Only used when method is "auto". Ratio of the smallest to the largest eigenvalue of the covariance matrix of the points, below which the cloud is considered flat enough for the 2D triangulation. See the Method selection section below.

  • offset: float, default= None

    Multiplier controlling the size of the bounding simplex the triangulation starts from, expressed in multiples of the radius of the cloud, and therefore independent of the unit and of the position of the points.

    Both triangulations are incremental: they first build a triangle, or a tetrahedron, large enough to enclose every point, insert the points one by one, then delete that simplex together with every cell that touches it. A simplex too close to the points takes a layer of real cells with it when it is deleted; a simplex too far away ruins the conditioning of the circumscribed-sphere predicates and corrupts the mesh.

    None keeps the default of the underlying filter, 1.0 for the 2D triangulation and 2.5 for the 3D one. These defaults slightly under-fill the convex hull, by about half a percent in 2D and under two percent in 3D. Values between 1e2 and 1e6 fill it exactly; beyond 1e9 the mesh degenerates.

  • progress_bar: bool, default= False

    Display a progress bar while the mesh is built.

  • progress_bar_label: str, default= "Delaunay triangulation"

    Label shown next to the progress bar.

Preconditions

  • base must hold at least four points that are distinct once coincident points have been merged, otherwise a ValueError is raised.

  • alpha must be "auto" or a non-negative float, and alpha_scale must be strictly positive.

  • tolerance, when given, must lie between 0 and 1.

  • offset, when given, must be at least 0.75 for the 2D triangulation and at least 2.5 for the 3D one, these being the minima accepted by the underlying filters.

  • planarity_threshold must lie between 0 and 1.

Postconditions

  • A new base is returned, holding one zone of triangles when kind is "surface" and one zone of tetrahedra when it is "volume".

  • Coincident points are merged, so the output may hold fewer points than the input. Points merged away, and points excluded by tolerance, keep their coordinates and variables but belong to no cell.

  • With kind="surface" and the 3D triangulation, only the points lying on the boundary of the tetrahedra are kept: the interior points of the cloud, and their variables, are absent from the returned base.

Alpha

Every cell of a Delaunay triangulation has a circumscribed circle, in 2D, or sphere, in 3D, passing through its vertices. Cells built from points close to one another have a small one; cells stretching across an empty region have a large one, because their vertices are far apart. alpha is the radius above which a cell is discarded.

The result is an alpha shape, a family of meshes ranging from the convex hull to nothing at all as alpha decreases. It is the only mechanism by which a concavity or a hole is recovered, and it works by inference: nothing is declared, so a hole is found only where the cloud is sampled densely enough around it for the cells spanning it to exceed the ceiling.

Two consequences are worth keeping in mind. A single value is applied to the whole cloud, so a cloud whose sampling density varies has no value that suits all of it at once. And the boundary follows the sampled points, so it is faceted, and slightly inside the true boundary of the object.

Mesh kinds

The following table summarises the combinations of kind and method and what they produce.

kind

method

Output cells

Notes

surface

delaunay2d

Triangles

surface

delaunay3d

Triangles, boundary of the tetrahedra

Only the boundary points are kept. Needs a cloud sampled through the volume, not only on its skin.

volume

forced to delaunay3d

Tetrahedra

Every point of the cloud is kept. Yields very few cells on a flat cloud, which has no volume to fill.

Example 1: Delaunay triangulation of a random list of points

The following examples shows how to triangulate a random 2D list of points

import os
import numpy as np
import antares

OUTPUT_FODER = os.path.join('OUTPUT', "TreatmentDelaunayTriangulation")
os.makedirs(OUTPUT_FODER, exist_ok=True)

rng = np.random.default_rng(0)
n = 100
points = rng.uniform(-1.0, 1.0, size=(n, 2))   # shape (n, 2): columns are x, y

base = antares.Base()
base.init()

base[0][0]['x'] = points[:, 0]
base[0][0]['y'] = points[:, 1]
base.compute('z=0')

delaunay_base = antares.treatment.DelaunayTriangulation(base=base)

plot = antares.Treatment('plotbases')
plot['bases'] = [base, delaunay_base]
plot['pane_layout'] = 'split vertical'
plot['point_radius'] = 0.025
plot['color_by'] = 'zones'
plot['colorbar'] = False
plot['show_mesh'] = True
plot['mesh_color'] = 'gray'
plot['mesh_linewidth'] = 2
plot['show'] = False
plot['texts'] = [
    {'text': 'Random 2D points', 'position': [0.5, 0.9], 'anchor': 'center', 'pane': 0},
    {'text': 'Delaunay triangulation', 'position': [0.5, 0.9], 'anchor': 'center', 'pane': 1},
]
plot['output_file'] = os.path.join(OUTPUT_FODER, "delaunay.jpeg")
plot.execute()

../../../../_images/delaunay.jpeg

Example 2: Delaunay triangulation of a random list of points with a whole

import os
import numpy as np
import antares

DATA_FOLDER = os.path.join('..', 'data', 'DELAUNAY')
OUTPUT_FODER = os.path.join('OUTPUT', "TreatmentDelaunayTriangulation")
os.makedirs(OUTPUT_FODER, exist_ok=True)

base = antares.io.Read(
    filename = os.path.join(DATA_FOLDER, 'cloud_points_hole.h5'), 
    format = 'hdf_antares',
)

# alpha=0 disables the filtering, so the triangulation fills the convex hull
# and the hole is bridged by a fan of large triangles.
hull_base = antares.treatment.DelaunayTriangulation(base=base, alpha=0)

# The default alpha="auto" sets the ceiling from the sampling density of the
# cloud, so those triangles are discarded and the hole is kept.
alpha_base = antares.treatment.DelaunayTriangulation(base=base)

plot = antares.Treatment('plotbases')
plot['bases'] = [base, hull_base, alpha_base]
plot['pane_layout'] = 'split vertical'
plot['point_radius'] = 0.012
plot['color_by'] = 'r'
plot['colorbar'] = True
plot['colorbar_panes'] = {('r', 'node'): [1]}
plot['colorbar_title'] = r'$r$'
plot['colorbar_position'] = [0.3, 0.05]
plot['colorbar_nb_labels'] = 2
plot['colorbar_width'] = 0.5
plot['colorbar_horizontal'] = True
plot['show_mesh'] = True
plot['lights_effects'] = False
plot['show'] = False
plot['texts'] = [
    {'text': 'Point cloud', 'position': [0.5, 0.9], 'anchor': 'center', 'pane': 0},
    {'text': r'$\alpha = 0$', 'position': [0.5, 0.9], 'anchor': 'center', 'pane': 1},
    {'text': r'$\alpha=$"auto"', 'position': [0.5, 0.9], 'anchor': 'center', 'pane': 2},
]
plot['output_file'] = os.path.join(OUTPUT_FODER, "delaunay_hole.jpeg")
plot.execute()
../../../../_images/delaunay_hole.jpeg