For 2D, uses input of a 2D planar polygon (convex or nonconvex) to create a set of uniform or variable spaced points using 2D Poisson Disk sampling. Optionally the vertices can be connected using Delaunay triangulation. For 3D, the command generates a point distribution within a 3D volume using a Poisson-Disk sampling algorithm. This ensures a minimum distance between points, resulting in a “blue noise” distribution that is ideal for high-quality tetrahedralization.
This poisson_disk command is available for LaGriT versions V3.3.3 or greater.
createpts / poisson_disk / 2d_polygon / mo_out / mo_polygon / h_spacing_scalar / [connect | no_connect] / [user_resolution.mlgi] / [ poisson_seed integer ] [ number_of_samples integer ] [ resample_sweeps integer ] createpts / poisson_disk / 3d_box / mo_out / h_spacing_scalar / [connect | no_connect] / [user_resolution.mlgi] / [ poisson_seed integer ] [ number_of_samples integer ] [ resample_sweeps integer ] [ h_lookup hex_grid | octree ] [ octree_k_factor real ] [ octree_batch integer ] [ octree_dump file ]
The 3D form has no mo_polygon: the box is given by define variables set before the command (see 3D Box and Edge Buffer), so every argument after mo_out is one position earlier than in 2D. The argument numbers below are those of the 2D form.
2d_polygon character type indicating geometry for a 2D planar polygon, convex or nonconvex, in the XY plane. If the polygon you wish to distribute points in is not in XY plane, user must rotate it into XY plane.If the polygon is nonconvex, the algorithm may alter some small features depending on the details of the polygon and the user controlled input parameters. See examples below.
3d_box character type indicating geometry for a 3D box with faces parallel to the coordinate planes, from (POI_XMIN, POI_YMIN, POI_ZMIN) to (POI_XMAX, POI_YMAX, POI_ZMAX). These six define variables must be set before the command; see 3D Box and Edge Buffer. This is currently the only 3D geometry.
mo_out name of output mesh object. This user defined mesh object will contain the vertex distribution or triangulation created by the poisson_disk algorithm.
mo_out must not exist yet: poisson_disk creates it. If a mesh object of that name already exists, the command stops with an error and leaves it unchanged; remove it first with cmo / delete / mo_out.
For 2D, a second mesh object for mo_polygon name of input mesh object that contains a 2D planar polygon in the XY plane.
h_spacing_scalar of type real. In the case of uniform resolution, this user provided real number defines the target spacing between vertices created by the Poisson-Disk algorithm. h_spacing_scalar is the smallest distance allowed between two vertices, so the spacing you get is a little larger: the nearest neighbour of a vertex is typically 1.0 to 1.2 times h away, and the edges of the connected triangles are typically 1.1 to 1.8 times h long (median about 1.4 h). In the case of variable resolution, h_spacing_scalar is used as a multiplier in the function defined in user_resolution.mlgi.
connect connects the vertices generated by the Poisson disk algorithm. The output mesh object mo_out will be a Delaunay triangulation (2D) or a Delaunay tetrahedral mesh (3D).
In 3D, connect can leave a few vertices out of the tets (they fail its minimum volume test; about 1 in 20,000 in a strongly graded mesh). These vertices are removed with rmpoint / compress, as in 2D, so every vertex of mo_out is in a tet; the output shows the line N points removed.
no_connect the output mesh object mo_out will contain the vertices generated by Poisson disk algorithm without triangle connectivity.
Default if this option is not used, the mesh will be uniform resolution defined by Argument 5 h_spacing_scalar.
user_resolution.mlgi is the name of a LaGriT control file for user defined resolution.
The control file defines a function h(x,y) (2D) or h(x,y,z) (3D) that will be used to control vertex spacing in a variable resolution mesh. See examples below.
When the variable option is utilized, internal to the module a mesh object, ** mo_poi_h_field, with a real scalar attribute, **h_field_att, is created. By default for uniform resolution, h_field_att, is set to a constant value of h_spacing_scalar, however, when this option is exercised, the user must fill h_field_att with their own scalar field h(x,y) or h(x,y,z). In 3D with h_lookup hex_grid, mo_poi_h_field is a hex mesh covering the box, so the field must be set on every z layer, not only the first. With h_lookup octree (the default in 3D with a control file) it is a mesh object of vertices only, with no cells, and the control file runs on it several times, once for each batch of octree vertices (see 3D h Lookup: Octree). In addition, internal to the code the command:
define / POI_H_FACTOR / h_spacing_scalar
so one can access the value of h_spacing_scalar by using the variable POI_H_FACTOR in the LaGriT control file user_resolution.mlgi for setting variable resolution.
If a user script is provided as Argument 7, the sampling algorithm will query a local spacing value for every candidate point.
The algorithm looks for an attribute named h_field_att within a temporary mesh object named mo_poi_h_field. You can populate this attribute within your .mlgi script using several methods:
For a worked 2D example with a piecewise linear h(x), a plot of h(x) against the vertex spacing it gives, and rules of thumb for how fast h may change, see EXAMPLE 2D Piecewise Linear Resolution.
For 3d_box, the sampling domain and the treatment of the box faces are set with define variables before the command. In 2D a polygon mesh object gives the domain; in 3D these variables do.
Box limits (required). All six must be set:
define / POI_XMIN / 0.0 define / POI_YMIN / 0.0 define / POI_ZMIN / 0.0 define / POI_XMAX / 1.0 define / POI_YMAX / 1.0 define / POI_ZMAX / 1.0
1.0) or an integer (1). A word is an error.3d_box command reuses them unless they are defined again.Edge buffer (optional, but set them). Two define variables decide how the box faces are meshed:
define / IF_POI_EDGE_BUFFER / 1 define / POI_EDGE_BUFFER / 1.0
IF_POI_EDGE_BUFFER (0 or 1, default 1).
POI_EDGE_BUFFER * h_spacing_scalar on every face. Then a regular lattice of vertices, about h_spacing_scalar apart, is added on the six faces of the full box. The faces get regularly spaced vertices, and no sampled vertex lies closer than POI_EDGE_BUFFER * h_spacing_scalar to a face.POI_EDGE_BUFFER (real, 0 or greater, default 1.0) is the width of the gap between the faces and the sampled interior, in units of h_spacing_scalar. It is used only when IF_POI_EDGE_BUFFER is 1.If either variable is not set, the command uses the default and writes a warning naming it. Set both explicitly, so the face treatment is a decision rather than a default.
With the edge buffer on, the box must be wider than 2 * h_spacing_scalar * POI_EDGE_BUFFER in x, y and z. Otherwise the shrunk sampling box would be flat or inverted, and the command stops with an error. Make the box larger, make h_spacing_scalar or POI_EDGE_BUFFER smaller, or set IF_POI_EDGE_BUFFER to 0.
Names used internally. The command also defines POI_H_FACTOR and variables beginning with POI_3D_, and creates the temporary mesh object mo_poi_h_field. Do not use these names for your own variables or mesh objects.
There are three optional parameters that are for advanced users only. They are keyword driven and can come in any order after the connect option, or after user_resolution.mlgi if it is given (2D: token 8 or 9; 3D: token 7 or 8). The user can specify none, one, two, or all three keyword driven parameters.
poisson_seed (integer default 1) is the seed for the random number generator. If once runs this module with the same input, by default each run will give the same result. However, if the user would like to produce multiple realizations with the same input (same input polygon, same resolution, etc.) but a different output mesh, then the user can change the value of poisson_seed for each realization.
number_of_samples (integer default:10) Number of new candidate points that are sampled around an accepted node. Lower values reduce overall sampling time, but can lead to holes in the final point distribution. Higher value lead to better density and converge but takes more time.
resample_sweeps (integer default:1) Number of additional sampling attempts in the domain. If there exists holes in the point distribution, increasing this value should fill in these holes.
It is suggested that the user should have the minimum value of h(x,y)= h_spacing_scalar, and then vary resolution by setting values greater than h_spacing_scalar. If one intends to have high resolution near objects and features and lower resolution away from the objects, then use of the compute/distance_field is a good way to define h(x,y).
createpts / poisson_disk / 2d_polygon / mo_poisson_pts / mo_polygon &
/ 0.01 / connect / user_h_field_att.mlgi &
poisson_seed 3 / resample_sweeps 4 / number_of_samples 20
createpts / poisson_disk / 2d_polygon / mo_poisson_pts / mo_polygon &
/ 0.01 / connect / user_h_field_att.mlgi &
poisson_seed 3
createpts / poisson_disk / 2d_polygon / mo_poisson_pts / mo_polygon &
/ 0.01 / connect / poisson_seed 3
With h_lookup hex_grid the 3D form reads h from a hex mesh covering the box at about h_spacing_scalar / 1.5, and keeps track of the vertices on a grid of cells h_spacing_scalar / √3 over the whole box. Both grow with the box volume / h_spacing_scalar3, whatever h is. With h_lookup octree, both are replaced by an octree adapted to h, so memory and time follow the number of vertices instead. The octree is the one to use when h ranges over more than about a factor of 10, or when the box is large compared with h_spacing_scalar.
The default (when h_lookup is not given):
user_resolution.mlgi, a variable h): octree. A hex grid fine enough for the smallest h can need far more memory and time; on the example below, 150 s and 550 MB against 1 s and 15 MB.hex_grid, the mesh LaGriT made before V3.4.0. For a uniform h the octree places about 20 to 27% more vertices and is slower (see The vertices below).octree_k_factor, octree_batch or octree_dump: octree.LaGriT says which it used, for example poisson_disk 3d_box: h_lookup octree (the default with a control file). Give h_lookup to choose. Before V3.4.0 the default was always hex_grid: a deck with a control file and no h_lookup now uses the octree, and gives a different, somewhat denser set of vertices. A control file that uses the cells of mo_poi_h_field (the hex mesh) needs h_lookup hex_grid, since the octree’s mo_poi_h_field has no cells.
| keyword | value | default |
|---|---|---|
h_lookup |
hex_grid or octree |
octree with a control file, hex_grid without (above) |
octree_k_factor |
real > 0: an octree leaf is at most h / K; a larger K is a finer, more accurate octree | 0.75 |
octree_batch |
the most octree vertices given to the control file in one run | 8000000 (about 2 GB) |
octree_dump |
a file name: the octree leaves are written there as an AVS hex mesh, with h_field_att on the vertices and the level itetlev on the cells |
not written |
These keywords are for 3d_box only; 2d_polygon refuses them.
The control file. It is the same file as for hex_grid, run on batches of octree vertices instead of one hex mesh. The field must therefore be a function of the position only: xic, yic, zic, distance fields (compute / distance_field), interpolate from another mesh object, math. It must not use the cells of mo_poi_h_field, which has none. h must be positive everywhere; the checks on h (at least 0.49 h_spacing_scalar, a warning above 100 times) are the same as with hex_grid.
The vertices. A candidate vertex is rejected only when it is closer than max(h(x), h(q)) to an accepted vertex q. The fill of empty space is maximal: it stops only when every part of the box is either shown to be covered or smaller than h / 16. At the end of each fill, LaGriT prints where any vertex could still be added, for example:
maximality: 7357200 boxes looked at; any vertex that could
still be added is in the 55951 boxes left, each at most 0.0625 h
(volume fraction 5.3e-05)
So h_lookup octree can place more vertices than hex_grid for the same h: about 20 to 27% more where h is close to h_spacing_scalar (constant h, or the finest part of a graded mesh), and about the same where h is many times larger. There, the edges of the tetrahedra are about 1.36 h long (median) instead of about 1.45 h. Raise h by about 7% to keep the same vertex count.
The edge buffer. With IF_POI_EDGE_BUFFER 1, the box faces get vertices on a regular grid at h_spacing_scalar, whatever the field. When h is much larger than h_spacing_scalar, set IF_POI_EDGE_BUFFER to 0.
Polygon input file: unit_square.poly
4 0 0 0 0
1 -0.5 -0.5 0
2 0.5 -0.5 0
3 0.5 0.5 0
4 -0.5 0.5 0
LaGriT control file
#
# Mesh a unit square with uniform and variable resolution tringles.
#
# Read polygon from a file.
#
read / avs / unit_square.poly / mo_polygon
#
# Uniform resolution, unit square polygon, vertex spacing 0.05:
#
createpts / poisson_disk / 2d_polygon / mo_poisson_pts / mo_polygon &
/ 0.05 / connect
dump / avs / output01_unit_square_uniform.inp / mo_poisson_pts
cmo / delete / mo_poisson_pts
#
# Variable resolution, unit square polygon, vertex spacing 0.01:
#
# WIDTH_FACTOR is used in user_h_field_att.mlgi
#
define / WIDTH_FACTOR / 10.0
createpts / poisson_disk / 2d_polygon / mo_poisson_pts / mo_polygon &
/ 0.01 / connect / user_h_field_att.mlgi
dump / avs / output02_unit_square_var.inp / mo_poisson_pts
cmo / delete / mo_poisson_pts
define / WIDTH_FACTOR / 20.0
createpts / poisson_disk / 2d_polygon / mo_poisson_pts / mo_polygon &
/ 0.01 / connect / user_h_field_att.mlgi
dump / avs / output03_unit_square_var.inp / mo_poisson_pts
cmo / delete / mo_poisson_pts
finish
Variable resolution defined in LaGriT control file: user_h_field_att.mlgi
Used in the example above, the resolution is set using the X coordinate (xic), the user defined POI_H_FACTOR = h_spacing_scalar = 0.01, and a floor function to ensure no values are below h_spacing_scalar.
#####################################################
# User defined h field function assignment
#####################################################
#
# h_field_att is already set to POI_H_FACTOR
#
define / MO_H_FIELD / mo_poi_h_field
#
# x**2
math / power / MO_H_FIELD / h_field_att / 1,0,0 / &
MO_H_FIELD / xic / 2.0
cmo/printatt/MO_H_FIELD/h_field_att/minmax
# sqrt(x**2)
math / power / MO_H_FIELD / h_field_att / 1,0,0 / &
MO_H_FIELD / h_field_att / 0.5
cmo / printatt/MO_H_FIELD/h_field_att/minmax
# POI_H_FACTOR*sqrt(x**2)
math/multiply/MO_H_FIELD/h_field_att/1,0,0/ &
MO_H_FIELD/h_field_att/ POI_H_FACTOR
math/multiply/MO_H_FIELD/h_field_att/1,0,0/ &
MO_H_FIELD/h_field_att/ WIDTH_FACTOR
cmo / printatt/MO_H_FIELD/h_field_att/minmax
math / floor / MO_H_FIELD/h_field_att/1,0,0/ &
MO_H_FIELD/h_field_att/POI_H_FACTOR
cmo/printatt/MO_H_FIELD/h_field_att/minmax
cmo / status / brief
#
# As a diagnostic one can output MO_H_FIELD and view
# the h(x,y) attribute that will be used to set resolution.
#
dump / avs / h_field_out.inp / MO_H_FIELD
#
finish
A simple way to vary the resolution is to make h a function of one coordinate, built from a few straight segments h = a x + b. Here a 10 x 4 rectangle is fine (h = 0.05) for x < 2, coarsens at slope a = 0.1 to h = 0.25 at x = 4, stays at 0.25 to x = 6, coarsens again at slope 0.2 to h = 0.65 at x = 8, and stays at 0.65 to the end.
| segment | x | h = a x + b | a | b |
|---|---|---|---|---|
| 1 | x < 2 | 0.05 | 0 | 0.05 |
| 2 | 2 ≤ x < 4 | 0.1 x − 0.15 | 0.1 | −0.15 |
| 3 | 4 ≤ x < 6 | 0.25 | 0 | 0.25 |
| 4 | 6 ≤ x < 8 | 0.2 x − 0.95 | 0.2 | −0.95 |
| 5 | x ≥ 8 | 0.65 | 0 | 0.65 |
Choose b so the segments meet: at each breakpoint X the two formulas must give the same h (a jump is an infinite slope, see below).
Top: h(x) as set (blue) and, for every vertex, the distance to its nearest neighbour (orange): the vertices follow h(x) through both slopes, about 1.0 to 1.2 times h apart. Bottom: the triangulation (2330 vertices, 4428 triangles; smallest aspect ratio 0.40).
Polygon: rect.poly
4 0 0 0 0
1 0.0 0.0 0.0
2 10.0 0.0 0.0
3 10.0 4.0 0.0
4 0.0 4.0 0.0
LaGriT control file
read / avs / rect.poly / mo_poly
createpts / poisson_disk / 2d_polygon / mo_pts / mo_poly &
/ 0.05 / connect / h_piecewise.mlgi
quality
dump / avs / piecewise_tri.inp / mo_pts
finish
Resolution control file: h_piecewise.mlgi
Each segment k is a pset of the lookup vertices with x ≥ Xk, set to a x + b with math / multiply and math / add. The segments are applied from left to right, so each one overwrites everything to its right and the last one written wins.
define / MOH / mo_poi_h_field
# segment 1: everywhere
math / multiply / MOH / h_field_att / 1,0,0 / MOH / xic / 0.0
math / add / MOH / h_field_att / 1,0,0 / MOH / h_field_att / 0.05
# segment 2: x >= 2, h = 0.1 x - 0.15
pset / ps2 / attribute / xic / 1,0,0 / ge 2.0
math / multiply / MOH / h_field_att / pset,get,ps2 / MOH / xic / 0.1
math / add / MOH / h_field_att / pset,get,ps2 / &
MOH / h_field_att / -0.15
# segment 3: x >= 4, h = 0.25
pset / ps3 / attribute / xic / 1,0,0 / ge 4.0
math / multiply / MOH / h_field_att / pset,get,ps3 / MOH / xic / 0.0
math / add / MOH / h_field_att / pset,get,ps3 / &
MOH / h_field_att / 0.25
# segment 4: x >= 6, h = 0.2 x - 0.95
pset / ps4 / attribute / xic / 1,0,0 / ge 6.0
math / multiply / MOH / h_field_att / pset,get,ps4 / MOH / xic / 0.2
math / add / MOH / h_field_att / pset,get,ps4 / &
MOH / h_field_att / -0.95
# segment 5: x >= 8, h = 0.65
pset / ps5 / attribute / xic / 1,0,0 / ge 8.0
math / multiply / MOH / h_field_att / pset,get,ps5 / MOH / xic / 0.0
math / add / MOH / h_field_att / pset,get,ps5 / &
MOH / h_field_att / 0.65
pset / ps2 / delete
pset / ps3 / delete
pset / ps4 / delete
pset / ps5 / delete
cmo / printatt / MOH / h_field_att / minmax
# a picture of h(x, y), to check the field before sampling
dump / avs / h_field_out.inp / MOH
finish
Keep every line of a control file within 80 columns and continue long commands with &. LaGriT drops the characters past column 80 without a warning; a file name cut off this way is read as a different, shorter name.
The slope a = dh/dx has no units. Over one spacing h, the spacing changes by a h, so each “layer” of vertices is about (1 + a) times as far apart as the one before: a = 0.2 means each layer about 20% larger. That ratio is what the triangles see, so the same rules hold at every scale.
Measured in 2D on a 6 high strip, h = 0.05 + a (x − 1) capped at 0.5 (a tenfold change), connected, three random seeds per slope, counting only the triangles in the graded zone at least two coarse spacings from the long sides:
| slope a | smallest angle | triangles with an angle under 30° | under 20° | do the vertices follow h(x)? |
|---|---|---|---|---|
| 0.1 or less | 28 to 32°, as for uniform h | 0.2% or fewer | none | yes |
| 0.15 to 0.2 | 24 to 27° | 0.5 to 2% | none | yes |
| 0.3 | 21 to 23° | 7 to 9% | none | yes |
| 0.4 to 0.5 | 15 to 20° | 12 to 25% | 0.5 to 3% | mostly: the shortest 5% of edges under 0.9 h |
| 0.75 and more | 7 to 13° | 31 to 47% | 12 to 22% | no: the shortest 5% of edges at 0.4 to 0.9 h |
| **Keep | a | ≤ 0.2** for a mesh as good as a uniform one; up to 0.3 is acceptable. Avoid more than 0.5: the sampler can no longer place vertices at the requested spacing, and the triangles in the transition get thin. |
h_spacing_scalar to the minimum of h(x). The command stops with an error if h_field_att falls below 0.49 times h_spacing_scalar anywhere, and warns if it rises above 100 times.h_spacing_scalar / 1.5, so a breakpoint is placed to that accuracy and a narrower feature in h is not seen.| 3D: these numbers are measured in 2D. Start 3D meshes at | a | ≤ 0.2 and check them with quality. |
A 1 x 1 x 0.5 box with vertex spacing 0.05, the edge buffer on, and a Delaunay tetrahedral mesh of the vertices:
define / POI_XMIN / 0.0
define / POI_YMIN / 0.0
define / POI_ZMIN / 0.0
define / POI_XMAX / 1.0
define / POI_YMAX / 1.0
define / POI_ZMAX / 0.5
define / IF_POI_EDGE_BUFFER / 1
define / POI_EDGE_BUFFER / 1.0
createpts / poisson_disk / 3d_box / mo_poisson_tet / 0.05 / connect
quality
dump / avs / output_box_3d.inp / mo_poisson_tet
cmo / delete / mo_poisson_tet
finish
To keep only the vertices, use no_connect. To vary the resolution, add a control file as the next argument. That file sets h_field_att on the 3D mesh object mo_poi_h_field, for example as a function of zic.
The unit box, h = 0.01 at the point (0.3, 0.6, 0.45), growing by 0.2 per unit of distance up to 0.2: a range of 20 in h. With hex_grid this takes about 150 s and 550 MB; with h_lookup octree, about 1 s and 15 MB.
cmo / create / mo_src / / / tet
createpts / xyz / 1 1 1 / 0.3 0.6 0.45 / 0.3 0.6 0.45 / 1 1 1
define / POI_XMIN / 0.0
define / POI_YMIN / 0.0
define / POI_ZMIN / 0.0
define / POI_XMAX / 1.0
define / POI_YMAX / 1.0
define / POI_ZMAX / 1.0
define / IF_POI_EDGE_BUFFER / 0
define / POI_EDGE_BUFFER / 1.0
createpts / poisson_disk / 3d_box / mo_pts / 0.01 / connect / &
h_point.mlgi / h_lookup octree / octree_dump octree_leaves.inp
quality
dump / avs / output_point_3d.inp / mo_pts
finish
The control file h_point.mlgi:
compute / distance_field / mo_poi_h_field / mo_src / d_src
math / multiply / mo_poi_h_field / h_field_att / 1,0,0 / &
mo_poi_h_field / d_src / 0.2
math / add / mo_poi_h_field / h_field_att / 1,0,0 / &
mo_poi_h_field / h_field_att / 0.01
math / ceiling / mo_poi_h_field / h_field_att / 1,0,0 / &
mo_poi_h_field / h_field_att / 0.2
cmo / DELATT / mo_poi_h_field / d_src
finish
octree_leaves.inp shows the octree: small leaves near the point, larger ones away from it.
See also the tutorial Tet Mesh Graded by a Surface’s Edge Lengths: tets sized from the triangle edges of a surface such as a dfnWorks fracture mesh.