# 62. `plugins.tetgen` — Interface with tetgen

A collection of functions to read/write tetgen files and to run the tetgen program

tetgen is a quality tetrahedral mesh generator and a 3D Delaunay triangulator. See http://tetgen.org

## 62.1. Functions defined in module plugins.tetgen

`plugins.tetgen.``readNodeFile`(fn)

  Read a tetgen .node file.

  Returns a tuple as described in readNodesBlock.

`plugins.tetgen.``readEleFile`(fn)

  Read a tetgen .ele file.

  Returns a tuple as described in readElemsBlock.

`plugins.tetgen.``readFaceFile`(fn)

  Read a tetgen .face file.

  Returns a tuple as described in readFacesBlock.

`plugins.tetgen.``readSmeshFile`(fn)

  Read a tetgen .smesh file.

  Returns an array of triangle elements.

`plugins.tetgen.``readPolyFile`(fn)

  Read a tetgen .poly file.

  Returns an array of triangle elements.

`plugins.tetgen.``readSurface`(fn)

  Read a tetgen surface from a .node/.face file pair.

  The given filename is either the .node or .face file. Returns a tuple of (nodes,elems).

`plugins.tetgen.``skipComments`(fil)

  Skip comments and blank lines on a tetgen file.

  Reads from a file until the first non-comment and non-empty line. Then returns the non-empty, non-comment line, stripped from possible trailing comments. Returns None if end of file is reached.

`plugins.tetgen.``stripLine`(line)

  Strip blanks, newline and comments from a line of text.

`plugins.tetgen.``getInts`(line, nint)

  Read a number of ints from a line, adding zero for omitted values.

  line is a string with b;anks separated integer values. Returns a list of nint integers. The trailing ones are set to zero if the strings contains less values.

`plugins.tetgen.``addElem`(elems, nrs, e, n, nplex)

  Add an element to a collection.

`plugins.tetgen.``readNodesBlock`(fil, npts, ndim, nattr, nbmark)

  Read a tetgen nodes block.

  Returns a tuple with:

  - coords: Coords array with nodal coordinates
  - nrs: node numbers
  - attr: node attributes
  - bmrk: node boundary marker

  The last two may be None.

`plugins.tetgen.``readElemsBlock`(fil, nelems, nplex, nattr)

  Read a tetgen elems block.

  Returns a tuple with:

  - elems: Connectivity of type ‘tet4’ or ‘tet10’
  - nrs: the element numbers
  - attr: the element attributes

  The last can be None.

`plugins.tetgen.``readFacesBlock`(fil, nelems, nbmark)

  Read a tetgen faces block.

  Returns a a tuple with:

  - elems: Connectivity of type ‘tri3’
  - nrs: face numbers
  - bmrk: face boundary marker

  The last can be None.

`plugins.tetgen.``readSmeshFacetsBlock`(fil, nfacets, nbmark)

  Read a tetgen .smesh facets bock.

  Returns a tuple of dictionaries with plexitudes as keys:

  - elems: for each plexitude a Connectivity array
  - nrs: for each plexitude a list of element numbers in corresponding elems

`plugins.tetgen.``readNeigh`(fn)

  Read a tetgen .neigh file.

  Returns an arrays containing the tetrahedra neighbours:

`plugins.tetgen.``writeNodes`(fn, coords, offset=0)

  Write a tetgen .node file.

`plugins.tetgen.``writeSmesh`(fn, facets, coords=None, holes=None, regions=None)

  Write a tetgen .smesh file.

  Currently it only writes the facets of a triangular surface mesh. Coords should be written independently to a .node file.

`plugins.tetgen.``writeTmesh`(fn, elems, offset=0)

  Write a tetgen .ele file.

  Writes elements of a tet4 mesh.

`plugins.tetgen.``writeSurface`(fn, coords, elems)

  Write a tetgen surface model to .node and .smesh files.

  The provided file name is either the .node or the .smesh filename, or else it is the basename where .node and .smesh extensions will be appended.

`plugins.tetgen.``writeTetMesh`(fn, coords, elems)

  Write a tetgen tetrahedral mesh model to .node and .ele files.

  The provided file name is either the .node or the .smesh filename, or else it is the basename where .node and .ele extensions will be appended.

`plugins.tetgen.``nextFilename`(fn)

  Returns the next file name in a family of tetgen file names.

`plugins.tetgen.``runTetgen`(fn, options='')

  Run tetgen mesher on the specified file.

  The input file is a closed triangulated surface. tetgen will generate a volume tetraeder mesh inside the surface, and create a new approximation of the surface as a by-product.

`plugins.tetgen.``readTetgen`(fn)

  Read and draw a tetgen file.

  This is an experimental function for the geometry import menu.

`plugins.tetgen.``checkSelfIntersectionsWithTetgen`(self, verbose=False)

  check self intersections using tetgen

  Returns pairs of intersecting triangles

`plugins.tetgen.``tetMesh`(surfacefile, quality=False, volume=None, outputdir=None)

  Create a tetrahedral mesh inside a surface

  - surfacefile: a file representing a surface. It can be an .off or .stl file (or other?)
  - quality: if True, the output will be a quality mesh The circumradius-to-shortest-edge ratio can be constrained by specifying a float value for quality (default is 2.0)
  - volume: float: applies a maximum tetrahedron volume constraint
  - outputdir: if specified, the results will be placed in this directory. The default is to place the results in the same directory as the input file.

  If the creation of the tetrahedral model is succesful, the results are read back using readTetgen and returned.