Skip to content
wo80 edited this page Dec 18, 2017 · 2 revisions

Porting guide from legacy triangle

If you're coming from the original triangle, the new triangle_api requires some changes. This is a first attempt to give a rough porting guide. I'm not the author of triangle_api and don't know its in's and out's, so YMMV.

Code snippets

Data types

Instead of struct triangulateio there is now a type triangleio. Additionally, the global state has been deprecated in favor of context and behavior objects.

// legacy code
struct triangulateio in, out;

becomes:

context *ctx;
triangleio in, out;

Initialization and cleanup

You still need to initialize (and free) the triangleio data structure just like struct triangulateio before.

Additionally, you need:

// init
ctx = triangle_context_create();
// cleanup
triangle_context_destroy(ctx);

Triangulation

This part has seen drastic changes: the triangulate function has been removed, which means you have to call several functions instead of one.

For this example, I leave out some details:

  • most file io was omitted. In particular, the following parts of the triangleio struct in have been filled already:
    • pointlist
    • pointmarkerlist
    • segmentlist
    • segmentmarkerlist
    • holelist
    • regionlist
  • no mesh refinement is done

A more detailed example can be found by studying the code of examples/triangle-cli/main.c.

// legacy code
char cmdline[] = "...";

triangulate(cmdline, &in, &out, (struct triangulateio *) nullptr, TriMessageFunction);

// process results
...

becomes:

char cmdline[] = "...";
int tristatus;

tristatus = triangle_context_options(ctx, cmdline);
if (tristatus != TRI_OK) handle_error();

// Triangulate the polygon
tristatus = triangle_mesh_create(ctx, &in);
if (tristatus != TRI_OK) handle_error();


// process results
...

Copyright (c) 2017 Johannes Zarl-Zierl.

SPDX-License-Identifier: CC-BY-SA-4.0 License-Filename: LICENSES/cc-by-sa-4.0.txt

This document is distributed under the Creative Commons Attribution Share Alike 4.0 license.