Triangle
Triangle copied to clipboard
Usage examples?
It would be great if some sample code were provided that showed usage. I can run the tests but the syntax and underlying structures seem rather different than the original library... I spent a few hours trying to cross reference how to iterate triangles/verts from the old showme.c program and this adaptation with no luck.
Many thanks for your efforts, regardless :)
Creating a mesh
Using the new API, you'd first create a context:
context* triangle_context_create();
The context contains pointers to behavior and mesh objects. You can pass in quality options either by using the old style Triangle commandline syntax
triangle_context_options(context* ctx, char *options);
or by directly using the behavior struct:
triangle_context_set_behavior(context* ctx, behavior *in);
Setup your geometry (triangleio struct) by either using the file IO routines for reading node or poly files, or setup the geomerty in code (see examples util.c). Triangulate the input geometry using
triangle_mesh_create(context* ctx, triangleio *in);
You can then get mesh statistics and quality info using
triangle_mesh_quality(context *ctx, quality *q);
triangle_mesh_statistics(context *ctx, statistics *s);
If you aren't satisfied with quality, update the behavior and refine the mesh using
triangle_context_set_behavior(context* ctx, behavior *in);
triangle_mesh_refine(context* ctx);
Accessing mesh data
You can either copy the mesh to a triangleio struct (the format is the same as with the original Triangle code)
triangle_mesh_copy(context* ctx, triangleio *out, int edges, int neighbors);
or access the mesh directly using the context. Take a look at triangle_io.c
to see how vertices, triangles or segments can be traversed.
A small remark, in case you need node numbering (for example for FEM):
Vertices aren't numbered by default (see issue #23). The file_writenodes method shows how to setup numbering using setvertexmark. You could also use point attributes for numbering.
Many thanks! I know this is not a support channel, but maybe you can help me with one more question: I am able to triangulate an arbitrary region but I cannot seem to get it to not generate the convex hull. When I remove the "c" switch from the triangle_context_options call, nothing generates. I've also tried setting the behavior via behavior.convex but it seems to have no effect. Any advice appreciated, thanks!
Oh - I also tried to define a segmentlist of the bounding segment vertices but that also did not seem to have an effect. Was not able to find documentation on this, so may have done it incorrectly.
Please read the original documentation at http://www.cs.cmu.edu/~quake/triangle.html
Here are some hints:
- Triangulation of point sets will always include the convex hull.
- Adding the c switch will return boundary segments for the convex hull.
- If you want to triangulate polygons, add the p switch.
- If you want to triangulate non-convex polygons, you have to add segments for all of the boundary (and omit the c switch, unless you want the convex hull to be included).