Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage examples? #41

Open
vaporstack opened this issue Jul 17, 2019 · 4 comments
Open

Usage examples? #41

vaporstack opened this issue Jul 17, 2019 · 4 comments

Comments

@vaporstack
Copy link

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 :)

@wo80
Copy link
Owner

wo80 commented Jul 17, 2019

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.

@vaporstack
Copy link
Author

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!

Screen Shot 2019-07-22 at 5 50 33 PM

@vaporstack
Copy link
Author

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.

@wo80
Copy link
Owner

wo80 commented Jul 22, 2019

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).

ramcdona pushed a commit to ramcdona/OpenVSP that referenced this issue Dec 8, 2020
Porting to the new version requires relatively limited changes.
Primarily, the data structure names, setup, and closeout
functionsare slightly different. The trinagulation function
returns an error code that is checked before using the
output mesh data. For more information on library porting:
wo80/Triangle#41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants