TETGENLINK TUTORIAL

File Formats

There are a number of file formats for working with meshes. They are useful since they can be used as interchange formats between CAD programs. Some of these are supported by TetGen and some by Mathematica. This section reviews the formats that are supported and shows how you can work with them.

TetGen File Formats

TetGen supports its own formats and also some standard formats. More information on the details of its formats and samples can be found on the TetGen website (http://tetgen.org).

The following table gives a description of TetGen's own formats.

extensionmodedescription
.nodeinput/outputa list of nodes
.polyinputa piecewise linear complex
.smeshinput/outputa simple piecewise linear complex
.eleinput/outputa list of tetrahedra
.faceinput/outputa list of triangular faces
.edgeoutputa list of boundary faces
.volinputa list of maximum volumes
.varinputa list of variant constraints for facets/segments
.neighoutputa list of neighbors

File formats specific to TetGen.

To demonstrate loading a data file, the application must first be loaded as shown below.

In[1]:=
Click for copyable input

This finds a sample data file in the TetGenLink installation.

In[2]:=
Click for copyable input
Out[2]=

To load the data file, you must first create an instance of a TetGen expression to hold the result.

In[3]:=
Click for copyable input
Out[3]=

This loads the data file into the instance.

In[4]:=
Click for copyable input

This extracts the points from the instance.

In[5]:=
Click for copyable input
Out[5]=

This extracts the vertices from the instance.

In[6]:=
Click for copyable input
Out[6]=

Here, the shape is plotted.

In[7]:=
Click for copyable input
Out[7]=

Finally, the TetGen instance is deleted.

In[8]:=
Click for copyable input

In addition to TetGen-specific formats, TetGen supports a number of other file formats. Note that STL is also supported by Mathematica's Import command.

extensionmodedescription
.offinput/outputGeomview's polyhedral file format
.plyinputpolyhedral file format
.stlinputstereolithography format
.meshinput/outputMedit's surface mesh file format

General file formats that can be used by TetGen.

Mathematica File Formats

Mathematica supports a number of formats that are useful for working with meshes.

nameextensionmodedescription
STL.stlinput/outputcomputer-aided design and manufacturing format
3DS.3dsinput/outputAutodesk format for scene description and 3D modeling
DXF.dxfinput/outputAutoCAD format for 3D geometry

Formats supported by Mathematica for working with meshes.

These formats are often supported by CAD and other engineering applications, sometimes using them as interchange formats. Also, there are many samples of these files available on websites; one of these is http://www-roc.inria.fr/gamma/download, which has a large collection of files. For example, the gear10 example shown below comes from the "MECHANICAL" section.

To demonstrate loading a data file and working with it in TetGen, you must first load TetGenLink as shown below.

In[1]:=
Click for copyable input

This is a sample 3DS data file. You would need to obtain it from the http://www-roc.inria.fr site described above.

In[2]:=
Click for copyable input

The following loads vertex and polygon data from the file.

In[3]:=
Click for copyable input

The resulting data is set up for multiple objects.

In[5]:=
Click for copyable input
Out[5]=
In[6]:=
Click for copyable input
Out[6]=

Therefore, you should extract the first for each set.

In[7]:=
Click for copyable input

Now you can plot the mesh as shown below.

In[9]:=
Click for copyable input
Out[9]=

If you want to tetrahedralize this mesh, you can do so. First, the coordinates and facets are loaded into a TetGen instance as shown below.

In[10]:=
Click for copyable input

Second, TetGenSetMessages is used to enable messages. Then the tetrahedralization is done. It creates a lot of information, including messages that there are duplicate points in the dataset. This can sometimes create problems.

Now the new coordinates and facets on the surface can be extracted.

In[16]:=
Click for copyable input

Finally, the new data is plotted. You can see that there are more points created in the object.

In[18]:=
Click for copyable input
Out[18]=

This last step frees resources from the TetGen instances.

In[19]:=
Click for copyable input
New to Mathematica? Find your learning path »
Have a question? Ask support »