-
Notifications
You must be signed in to change notification settings - Fork 0
/
dlOpenTest.c
76 lines (61 loc) · 3.1 KB
/
dlOpenTest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <dlfcn.h> // dlopen, dlsym
#include <string.h> // memset
#define REAL double
struct triangulateio {
REAL *pointlist; /* In / out */
REAL *pointattributelist; /* In / out */
int *pointmarkerlist; /* In / out */
int numberofpoints; /* In / out */
int numberofpointattributes; /* In / out */
int *trianglelist; /* In / out */
REAL *triangleattributelist; /* In / out */
REAL *trianglearealist; /* In only */
int *neighborlist; /* Out only */
int numberoftriangles; /* In / out */
int numberofcorners; /* In / out */
int numberoftriangleattributes; /* In / out */
int *segmentlist; /* In / out */
int *segmentmarkerlist; /* In / out */
int numberofsegments; /* In / out */
REAL *holelist; /* In / pointer to array copied out */
int numberofholes; /* In / copied out */
REAL *regionlist; /* In / pointer to array copied out */
int numberofregions; /* In / copied out */
int *edgelist; /* Out only */
int *edgemarkerlist; /* Not used with Voronoi diagram; out only */
REAL *normlist; /* Used only with Voronoi diagram; out only */
int numberofedges; /* Out only */
};
int main()
{
// Signature for the triangulation function in `triangle.dylib`.
void (*triangulateFn)(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *);
// Open the library.
void* handle = dlopen("triangle.dylib", RTLD_LAZY);
// Fetch the function.
*(void**)(&triangulateFn) = dlsym(handle, "triangulate");
struct triangulateio in, out;
memset(&in, 0, sizeof(struct triangulateio));
memset(&out, 0, sizeof(struct triangulateio));
double vertices[8] = {0, 0, 512, 0, 612, 668, 100, 668};
in.numberofpoints = 4;
in.pointlist = (vertices);
int edges[8] = {0, 1, 1, 2, 2, 3, 3, 0};
in.numberofsegments = 4;
in.segmentlist = (edges);
triangulateFn("pzenQ", &in, &out, NULL);
printf("Got these many points %d\n", out.numberofpoints);
for(int i = 0; i < out.numberofpoints; i++)
{
int idx = i*2;
printf("Point %d: %.2f, %.2f\n", i, out.pointlist[idx], out.pointlist[idx+1]);
}
printf("Got these many segments: %d\n", out.numberofsegments);
for(int i = 0; i < out.numberofsegments; i++)
{
int idx = i*2;
printf("Segment %d: %d, %d\n", i, out.segmentlist[idx], out.segmentlist[idx+1]);
}
return 0;
}