Triangulate
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:
- Triangle home page https://www.cs.cmu.edu/~quake/triangle.html with instructions for using 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.
Copyright information
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.TriangulateError
— Typestruct TriangulateError <: Exception
Exception thrown if triangulate() encounters an error
Triangulate.TriangulateIO
— Typemutable 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 withsize(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.
Triangulate.TriangulateIO
— MethodTriangulateIO(
;
pointlist,
pointattributelist,
pointmarkerlist,
trianglelist,
triangleattributelist,
trianglearealist,
neighborlist,
segmentlist,
segmentmarkerlist,
holelist,
regionlist,
edgelist,
edgemarkerlist,
normlist
) -> TriangulateIO
Create TriangulateIO structure with empty data.
Triangulate.numberofedges
— Methodnumberofedges(tio::TriangulateIO) -> Int64
Return number of triangles in triangulateio structure.
Triangulate.numberofholes
— Methodnumberofholes(tio::TriangulateIO) -> Int64
Return number of holes in triangulateio structure.
Triangulate.numberofpoints
— Methodnumberofpoints(tio::TriangulateIO) -> Int64
Return number of points in triangulatio structure.
Triangulate.numberofregions
— Methodnumberofregions(tio::TriangulateIO) -> Int64
Return number of regions in triangulateio structure.
Triangulate.numberofsegments
— Methodnumberofsegments(tio::TriangulateIO) -> Int64
Return number of segments in triangulateio structure.
Triangulate.numberoftriangleattributes
— Methodnumberoftriangleattributes(tio::TriangulateIO) -> Int64
Return number of holes in triangulateio structure.
Triangulate.numberoftriangles
— Methodnumberoftriangles(tio::TriangulateIO) -> Int64
Return number of triangles in triangulateio structure.
Triangulate.triangulate
— Methodtriangulate(
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:
Switch | Meaning |
---|---|
-p | Triangulates a Planar Straight Line Graph (.poly file). |
-r | Refines a previously generated mesh. |
-q | Quality mesh generation. A minimum angle may be specified. |
-a | Applies a maximum triangle area constraint. |
-u | Applies a user-defined triangle constraint. |
-A | Applies attributes to identify triangles in certain regions. |
-c | Encloses the convex hull with segments. |
-D | Conforming Delaunay: all triangles are truly Delaunay. |
-j | Jettison unused vertices from output .node file. |
-e | Generates an edge list. |
-v | Generates a Voronoi diagram. |
-n | Generates a list of triangle neighbors. |
-g | Generates an .off file for Geomview. |
-B | Suppresses output of boundary information. |
-P | Suppresses output of .poly file. |
-N | Suppresses output of .node file. |
-E | Suppresses output of .ele file. |
-I | Suppresses mesh iteration numbers. |
-O | Ignores holes in .poly file. |
-X | Suppresses use of exact arithmetic. |
-z | Numbers all items starting from zero (rather than one). |
-o2 | Generates second-order subparametric elements. |
-Y | Suppresses boundary segment splitting. |
-S | Specifies maximum number of added Steiner points. |
-i | Uses incremental method, rather than divide-and-conquer. |
-F | Uses Fortune's sweepline algorithm, rather than d-and-c. |
-l | Uses vertical cuts only, rather than alternating cuts. |
-s | Force segments into mesh by splitting (instead of using CDT). |
-C | Check consistency of final mesh. |
-Q | Quiet: No terminal output except errors. |
-V | Verbose: Detailed information on what I'm doing. |
Triangulate.triunsuitable!
— Methodtriunsuitable!(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
Triangulate.ismakie
— Methodismakie(Plotter)
Heuristically check if Plotter is Makie/WGLMakie
Triangulate.ispyplot
— Methodispyplot(Plotter) -> Bool
Heuristic check if Plotter is PyPlot
Triangulate.plot_in_out
— Methodplot_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.
Triangulate.plot_triangulateio
— Methodplot_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.
Triangulate.tricircumcenter!
— Methodtricircumcenter!(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.