Using TetGenLink

This section shows some of the ways that TetGenLink can be applied.

Convex Hull

To use TetGenLink, it must first be loaded.

Next, some random points are generated and displayed.

Now you can compute the convex hull of the 3D points. TetGenConvexHull will return a list of points and surface triangles.

Each surface triangle is a list of three integers. These integers refer to the coordinates. You can plot them by using GraphicsComplex.

To visualize the surface mesh as a wireframe, you can use a Line rather than a Polygon.

Delaunay Tetrahedralization

To use TetGenLink, it must first be loaded.

This creates some 3D data.

You can compute the Delaunay tetrahedralization of the data with TetGenDelaunay.

The result is a list of points and tetrahedra. The list of tetrahedra is a list of four integers that refer to the coordinate positions. To visualize the tetrahedra as a wireframe, you can use a supporting function.

To create a surface triangulation of the point data, you first create a TetGen instance.

To set the points in the TetGen instance, use TetGenSetPoints.

The tetrahedralization is done with TetGenTetrahedralize.

To extract the surface coordinates and surface triangles, use TetGenGetPoints and TetGenGetFaces.

The surface mesh can then be visualized.

Meshing a Box (Basic)

To generate a tetrahedra mesh from a box, you first set up the corner points of the box.

To specify how the corner points are connected to each other, you specify facets.

To use TetGenLink, it must first be loaded.

In order to create a mesh, an instance of TetGen is created. This input instance will hold the points and facets that describe the surface of the object to be tetrahedralized.

To set the corner points and the facets in the TetGen instance, you use TetGenSetPoints and TetGenSetFacets, respectively.

When the operation of setting the points and facets has completed successfully, 0 is returned.

The tetrahedralization is then done with the TetGenTetrahedralize command. The tetrahedralization works on the TetGen input instance. A string of parameters (TetGen string codes) may be given to specify requirements on the resulting mesh. The "p" string tetrahedralizes a piecewise linear complex, and the "q" switch requests a quality mesh generation. A minimum radius-edge ratio may be specified (the default is 2.0). The "a" switch followed by a number applies a maximum tetrahedron volume constraint. Once TetGen has completed the mesh generation process, a new TetGen instance is returned. The output instance contains all the data of the mesh.

To extract the coordinates and the surface triangles from the output instance, you use TetGenGetPoints and TetGenGetFaces.

A visualization of the triangulated surface can be done with a GraphicsComplex.

To extract the tetrahedra you use TetGenGetElements.

A simple support function allows you to visualize the wireframe mesh.

A list of all TetGen instances is accessible through TetGenExpressions.

To clean up, you delete the input instance and the output instance of TetGen with the TetGenDelete command.

Meshing a Box (Advanced)

To use TetGenLink, it must first be loaded.

What follows is a more detailed example of meshing a box. Here you will see how to specify the input to TetGen to create a hole in the box, an opening in the surface with a cavity, different (material) regions, and attribute markers to coordinates, faces, and elements. Also, a refinement of the mesh is shown.

You start by specifying the coordinates and displaying them.

Then you create the input instance and set the points.

Next, the list of facets is created. If a facet list has more than one entry, like the third facet in this example, the first facet represents the bounding facet and the subsequent facets indicate where the bounding facet should have an opening.

Here you can see one facet with an outline of where the facet should be open.

You can set the facets in the input instance of TetGen.

For TetGen to open the facet, you set up a facet hole.

Then set the facet holes in the TetGen input instance with the TetGenSetFacetHoles command.

Here is the bounding facet and the facet hole position.

In the next step you can specify markers. TetGen provides you with the ability to propagate so-called markers. Markers are a convenient way to access grouped parts of the mesh object. This grouping can then be used to specify boundary conditions and regions in the mesh. TetGen allows you to specify markers for points, faces, and elements.

You start by assigning each coordinate point an integer, also called a marker. Once the mesh is created, TetGen will mark each newly created coordinate point according to the markers specified in the input instance of TetGen. In a similar manner, facets and regions are marked.

For each node and facet, you assign an integer according to the following table. This will group different parts of the surface representation together.
1 bottom part
2 top part
3 side walls
4 cavity/hole
9 middle part

The point markers are set up and visualized in the following manner.

You can attribute integer markers to each of the facets.

Both the point markers and the facet markers are set in the TetGen input instance.

To visually explore the facets and the attributed markers, you can use a Manipulate. By selecting and deselecting you can visualize facets according to the markers they have been assigned.

TetGen works by meshing the entire object first and then in a second step removing the mesh from holes and cavities. Note that the cavity also needs a point to specify where it is situated. The point that specifies the opening is not sufficient. To specify where TetGen should put holes, you use TetGenSetHoles.

You can specify two different material domains by placing a point in each of them and then assigning a region number to them. Contrary to the point and facet markers, the region attributes are real numbers. With a region constraint you can additionally specify the required coarseness of the mesh in the different regions.

Here is the position of all the different points specified.

To generate a mesh from the facets, you give the options "p" and "q" as above, and the options "a" and "A" are needed for the maximum element size you specified with the region attribute. The switch "n" directs TetGen to compute the neighbors and the switch "e" directs it to compute the edges. For a complete list of switches, visit http://tetgen.org.

The extraction of the coordinates and the coordinate markers can be done with TetGenGetPoints and TetGenGetPointMarkers.

Note that the marker 0 is present. Coordinates that have been attributed the marker 0 are interior coordinates.

To extract the faces and visualize them, you use TetGenGetFaces.

To extract the face markers, you use TetGenGetFaceMarkers.

You can explore the facets and their markers with a Manipulate.

TetGenGetElements gets the tetrahedra from the output instance.

To efficiently visualize them, you use the following supporting function. This sorts each face of every tetrahedron, and, by finding the union of all sorted faces, the duplicate interior faces are removed. For very large meshes, making use of this technique will result in a shorter rendering time for the graphics.

Please note that the lower part is meshed finer than the upper part. This is the result of specifying different region constraints.

To extract the attributes of the elements, you use TetGenGetElementAttributes.

You can pick the elements that belong to the region with attribute 10.; those are the elements in the lower part of the box.

TetGen can also provide the edges of the object. To have TetGen compute them, the option "e" needs to be specified in the tetrahedralization step above.

Also, the list of neighboring elements can be retrieved. Each entry in the neighbor list is a list of four neighboring tetrahedra. Should a tetrahedron be on a boundary, then the respective entry is set to .

For illustration, the position of the boundary tetrahedra are:

To refine an existing mesh, TetGenTetrahedralize is called once more on a TetGen instance. Now, however, with the "r" switch to request a refinement and the "a" switch with a new maximum tetrahedron volume. The "a" switch will now override the region constraints.

Now clean up the created TetGen instances.

Engineering Example

To use TetGenLink, it must first be loaded.


Download an engineering surface mesh of a mechanical object. This will allow you to retrieve the data from the web and subsequently use the data without further internet access.

To make the tetrahedralization, you create an instance of TetGen.

The data in the surface mesh is imported into the TetGen instance.

You can access the points and facets in the TetGen instance.

The tetrahedralization step is then given as follows.

To extract the coordinates from the output instance, you use TetGenGetPoints and TetGenGetFaces.

The surface of the meshed object can be displayed through a GraphicsComplex.

You extract the tetrahedron elements with the TetGenGetElements command.

To compute the volume of each of the tetrahedra of the object, you write a support function first.

The total volume can then be computed in the following manner.

The center of mass can be computed with a compiled function.

You can visualize the center of mass as a red point within the object.

To color the surface of the object according to the distance to the center of mass, you write a support function that computes the distance from each coordinate to the center of mass.

The list of distances is then rescaled.

The surface is colored by specifying the VertexColors and making use of ColorData.

To compute the surface, you write a compiled function.

The total surface of the object can then be calculated.

If you have a C compiler, you also might want to give the option CompilationTarget->"C" to gain further speedups.

Possible Issues

To use TetGenLink, it must first be loaded.

A potential issue that will result in a failed tetrahedralization can be caused by intersecting facets. To detect if a surface mesh has intersecting facets, TetGenDetectIntersectingFacets can be used. TetGenDetectIntersectingFacets returns a list of points and intersecting facets, should there be any.

You can then display the intersecting facets.