Triangulate

Build status PkgEval

Julia wrapper for Jonathan Richard Shewchuk's Triangle mesh generator. The package tries to provide a 1:1 mapping of Triangle's functionality to Julia.

Useful information about Triangle:

Licensing

When installing Triangulate.jl, a compiled library version of the Triangle library will be downloaded from the Triangle_jll.jl repository. This library is freely available with Commercial Use Restriction, but the bindings to the library in this package, Triangulate.jl, are licensed under MIT. This means that code using the Triangle library via the Triangulate.jl bindings is subject to Triangle's licensing terms reproduced here:

These programs may be freely redistributed under the condition that the
copyright notices (including the copy of this notice in the code comments
and the copyright notice printed when the `-h' switch is selected) are
not removed, and no compensation is received.  Private, research, and
institutional use is free.  You may distribute modified versions of this
code UNDER THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT
IN THE SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH
SOURCE AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND
CLEAR NOTICE IS GIVEN OF THE MODIFICATIONS.  Distribution of this code as
part of a commercial system is permissible ONLY BY DIRECT ARRANGEMENT
WITH THE AUTHOR.  (If you are not directly supplying this code to a
customer, and you are instead telling them how they can obtain it for
free, then you are not required to make any arrangement with me.)

Acknowledgement

This package uses ideas from TriangleMesh.jl and Triangle.jl.

This is the copyright information of the original Triangle code.

These programs may be freely redistributed under the condition that the
copyright notices (including the copy of this notice in the code comments
and the copyright notice printed when the `-h' switch is selected) are
not removed, and no compensation is received.  Private, research, and
institutional use is free.  You may distribute modified versions of this
code UNDER THE CONDITION THAT THIS CODE AND ANY MODIFICATIONS MADE TO IT
IN THE SAME FILE REMAIN UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH
SOURCE AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT CHARGE, AND
CLEAR NOTICE IS GIVEN OF THE MODIFICATIONS.  Distribution of this code as
part of a commercial system is permissible ONLY BY DIRECT ARRANGEMENT
WITH THE AUTHOR.  (If you are not directly supplying this code to a
customer, and you are instead telling them how they can obtain it for
free, then you are not required to make any arrangement with me.)

triangle -h output

Structures and methods

Significant parts of the documentation text has been taken from the documentation of Triangle.

Triangulate.TriangulateIOType
mutable struct TriangulateIO

Julia version of Triangle's triangulateio structure.

Used to pass data into and out of the triangulate() procedure. The arrays are stored in column major order with the first index being the local number in a triangle or segment and the second index being the index in the element count. This exactly corresponds to the layout used in Triangle. This means that all data in this structure are passed from/to triangle without copying.

Arrays are used to store points, triangles, markers, and so forth.

Description of fields:

  • pointlist::Matrix{Float64}: An array of point coordinates with size(pointlist,1)==2. `pointlist' must always point to a list of points. Mandatory.
  • pointattributelist::Matrix{Float64}: An array of point attributes. There can be several attributes per point. Optional for input.
  • pointmarkerlist::Vector{Int32}: An array of point markers. Optional for input.
  • trianglelist::Matrix{Int32}: An array of triangle corners. The first three entries of each column describe the three nodes of the triangle in counterclockwise manner. They are followd by any other nodes if the triangle represents a nonlinear element. This means that without specfiying the 'o2' switch, each column contains three node indices, while in the opposite case, each column contains six entries: the three triangle vertices and the three edge mindpoint nodes.

    Mandatory if the 'r' switch is used. In this case `trianglelist' must point to a list of triangles with optional higher order nodes.

  • triangleattributelist::Matrix{Float64}: An array of triangle attributes. There can be several attributes per triangle. Optional on input.
  • trianglearealist::Vector{Float64}: An array of triangle area constraints. Input only.

    Mandatory if both the 'r' and the 'a' switch (with no number following) are used.

  • neighborlist::Matrix{Int32}: An array of triangle neighbors. size(neighborlist,1)==3 triangle. Output only.
  • segmentlist::Matrix{Int32}: An array of segment endpoints. size(segmentlist,1)==2

    Mandatory if the 'p' switch is used.

  • segmentmarkerlist::Vector{Int32}: An array of segment markers. Optional on input. If not set then segment markers on output default to zero.
  • holelist::Matrix{Float64}: An array of holes. Holes are marked by some point from within the hole. Input only, although the array pointer is copied to the output structure for convenience.

    Used if the 'p' switch is used without the 'r' switch.

  • regionlist::Matrix{Float64}: An array of regional attributes and area constraints.

    Used if the 'p' switch is used without the 'r' switch.

    Each of the columns of this array contains the constraint's x and y coordinates are at indices [1] and [2], followed by the regional attribute at index [3], followed by the maximum area at index [4]. So we have size(regionlist,1)==4. Note that each regional attribute is used only if you select the 'A' switch, and each area constraint is used only if you select the 'a' switch (with no number following), but omitting one of these switches does not change the memory layout. Input only, although the pointer is copied to the output structure for convenience.

  • edgelist::Matrix{Int32}: An array of edge endpoints. sizeof(edgelist,1)==2. Output only.
  • edgemarkerlist::Vector{Int32}: An array of edge markers; Output only.
  • normlist::Matrix{Float64}: An array of normal vectors, used for infinite rays in Voronoi diagrams. For each finite edge in a Voronoi diagram, the normal vector written is the zero vector. sizeof(normlist,1)==2. Output only.
source
Triangulate.TriangulateIOMethod
TriangulateIO(
;
    pointlist,
    pointattributelist,
    pointmarkerlist,
    trianglelist,
    triangleattributelist,
    trianglearealist,
    neighborlist,
    segmentlist,
    segmentmarkerlist,
    holelist,
    regionlist,
    edgelist,
    edgemarkerlist,
    normlist
) -> TriangulateIO

Create TriangulateIO structure with empty data.

source
Triangulate.triangulateMethod
triangulate(
    switches::String,
    tri_in::TriangulateIO
) -> Tuple{TriangulateIO, TriangulateIO}

Create triangulation. Returns tuple (out::TriangulateIO, vor_out::TriangulateIO) containing the output triangulation and the optional Voronoi tesselation.

After a call to triangulate(), the valid fields of out and vorout will depend, in an obvious way, on the choice of switches used. Note that when the 'p' switch is used, the pointers holelist and regionlist are copied from tri_in to the output, but no new space is allocated; On the other hand, Triangle will never copy the pointlist pointer (or any others); new space is allocated for out.pointlist, or if the 'N' switch is used, out.pointlist remains uninitialized.

This is the list of switches used by triangle:

SwitchMeaning
-pTriangulates a Planar Straight Line Graph (.poly file).
-rRefines a previously generated mesh.
-qQuality mesh generation. A minimum angle may be specified.
-aApplies a maximum triangle area constraint.
-uApplies a user-defined triangle constraint.
-AApplies attributes to identify triangles in certain regions.
-cEncloses the convex hull with segments.
-DConforming Delaunay: all triangles are truly Delaunay.
-jJettison unused vertices from output .node file.
-eGenerates an edge list.
-vGenerates a Voronoi diagram.
-nGenerates a list of triangle neighbors.
-gGenerates an .off file for Geomview.
-BSuppresses output of boundary information.
-PSuppresses output of .poly file.
-NSuppresses output of .node file.
-ESuppresses output of .ele file.
-ISuppresses mesh iteration numbers.
-OIgnores holes in .poly file.
-XSuppresses use of exact arithmetic.
-zNumbers all items starting from zero (rather than one).
-o2Generates second-order subparametric elements.
-YSuppresses boundary segment splitting.
-SSpecifies maximum number of added Steiner points.
-iUses incremental method, rather than divide-and-conquer.
-FUses Fortune's sweepline algorithm, rather than d-and-c.
-lUses vertical cuts only, rather than alternating cuts.
-sForce segments into mesh by splitting (instead of using CDT).
-CCheck consistency of final mesh.
-QQuiet: No terminal output except errors.
-VVerbose: Detailed information on what I'm doing.
source
Triangulate.triunsuitable!Method
triunsuitable!(unsuitable::Function; check_signature)

Set triunsuitable callback used by Triangle if the '-u' flag is set.

This is a function called by Triangle with the coordinates of the vertices of a triangle in order to learn if that triangle needs further refinement (i.e. 'true' returned) or not ('false' returned).

Other checks (e.g. maximum edge lengths) are possible here as well.

Note, that the handling of this function is currently not thread safe.

function unsuitable(x1,y1,x2,y2,x3,y3,area)
    myarea=locally_desired_area(x1,y1,x2,y2,x3,y3)
    if area>myarea 
       return true
    else 
       return false
    end
end
source
Triangulate.plot_in_outMethod
plot_in_out(
    Plotter,
    triin,
    triout;
    figure,
    voronoi,
    circumcircles,
    title
) -> Any

Plot pair of triangulateio structures arranged in two subplots. This is intendd for visualizing both input and output data.

source
Triangulate.plot_triangulateioMethod
plot_triangulateio(
    Plotter,
    tio::TriangulateIO;
    axis,
    voronoi,
    aspect,
    circumcircles
) -> Any

Plot contents of triangulateio structure. The plot module is passed as parameter. This allows to keep the package free of heavy plot package dependencies.

source
Triangulate.tricircumcenter!Method
tricircumcenter!(circumcenter, a, b, c)

Find the circumcenter of a triangle.

Created from C source of Jonathan R Shewchuk <jrs@cs.cmu.edu>

Modified to return absolute coordinates.

source