Skip to main content

Python interface to pytetgen

Project description

This python module is a python interface to Hang Si’s tetgen C++ software. This module combines speed of C++ with the portability and ease of installation of Python along integration with the visualization toolkit VTK . See the tetgen GitHub page for more details on the creator.

The last update to the original C++ software was on 19 January 2011, but the software remains relevant today. Brief description from Weierstrass Institute Software:

TetGen is a program to generate tetrahedral meshes of any 3D polyhedral domains. TetGen generates exact constrained Delaunay tetrahedralization, boundary conforming Delaunay meshes, and Voronoi partitions.

TetGen provides various features to generate good quality and adaptive tetrahedral meshes suitable for numerical methods, such as finite element or finite volume methods. For more information of TetGen, please take a look at a list of features.


From PyPI

pip install tetgen --user

From source at GitHub

git clone
cd tetgen
pip install . --user

Basic Example

The features of the C++ TetGen software implemented in this module are primarily focused on the tetrahedralization a manifold triangular surface. This basic example demonstrates how to tetrahedralize a manifold surface and plot part of the mesh.

from vtkInterface import examples
import vtkInterface as vtki
import tetgen
import numpy as np

sphere = vtki.PolyData(examples.spherefile)
tet = tetgen.TetGen(sphere)
tet.Tetrahedralize(order=1, mindihedral=20, minratio=1.5)
grid = tet.grid

Tetrahedralized Sphere

Extract a portion of the sphere’s tetrahedral mesh below the xy plane and plot the mesh quality.

# get cell centroids
cells = grid.cells.reshape(-1, 5)[:, 1:]
cell_center = grid.points[cells].mean(1)

# extract cells below the 0 xy plane
mask = cell_center[:, 2] < 0
cell_ind = mask.nonzero()[0]
subgrid = grid.ExtractSelectionCells(cell_ind)

# advanced plotting
plotter = vtki.PlotClass()
plotter.AddMesh(subgrid, 'lightgrey', lighting=True)
plotter.AddMesh(sphere, 'r', 'wireframe')
plotter.AddLegend([[' Input Mesh ', 'r'],
                   [' Tesselated Mesh ', 'black']])

Cell quality scalars can be obtained and plotted with:

cell_qual = subgrid.quality

# plot quality
subgrid.Plot(scalars=cell_qual, stitle='quality', colormap='bwr', flipscalars=True)


Software was originally created by Hang Si based on work published in TetGen, a Delaunay-Based Quality Tetrahedral Mesh Generator.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tetgen, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size tetgen-0.2.0-cp27-cp27m-manylinux1_x86_64.whl (1.4 MB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size tetgen-0.2.0-cp27-cp27mu-manylinux1_x86_64.whl (1.4 MB) File type Wheel Python version cp27 Upload date Hashes View
Filename, size tetgen-0.2.0-cp35-cp35m-manylinux1_x86_64.whl (1.4 MB) File type Wheel Python version cp35 Upload date Hashes View
Filename, size tetgen-0.2.0-cp36-cp36m-manylinux1_x86_64.whl (1.5 MB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size tetgen-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (1.5 MB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size tetgen-0.2.0.tar.gz (275.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page