triangle.h
Go to the documentation of this file.
1 #ifndef OOMPH_SHEWCHUK_TRIANGLE_MESH_HEADER
2 #define OOMPH_SHEWCHUK_TRIANGLE_MESH_HEADER
3 
4 
5 // This is the triangle.h file from Shewchuk's distribution
6 // but modified once and for all (for oomph-lib anyway) to
7 // interpret REAL as double.
8 #define REAL double
9 
10 #define ANSI_DECLARATORS
11 #define TRILIBRARY
12 #define LINUX
13 
14 /*****************************************************************************/
15 /* */
16 /* (triangle.h) */
17 /* */
18 /* Include file for programs that call Triangle. */
19 /* */
20 /* Accompanies Triangle Version 1.6 */
21 /* July 28, 2005 */
22 /* */
23 /* Copyright 1996, 2005 */
24 /* Jonathan Richard Shewchuk */
25 /* 2360 Woolsey #H */
26 /* Berkeley, California 94705-1927 */
27 /* jrs@cs.berkeley.edu */
28 /* */
29 /*****************************************************************************/
30 
31 /*****************************************************************************/
32 /* */
33 /* How to call Triangle from another program */
34 /* */
35 /* */
36 /* If you haven't read Triangle's instructions (run "triangle -h" to read */
37 /* them), you won't understand what follows. */
38 /* */
39 /* Triangle must be compiled into an object file (triangle.o) with the */
40 /* TRILIBRARY symbol defined (generally by using the -DTRILIBRARY compiler */
41 /* switch). The makefile included with Triangle will do this for you if */
42 /* you run "make trilibrary". The resulting object file can be called via */
43 /* the procedure triangulate(). */
44 /* */
45 /* If the size of the object file is important to you, you may wish to */
46 /* generate a reduced version of triangle.o. The REDUCED symbol gets rid */
47 /* of all features that are primarily of research interest. Specifically, */
48 /* the -DREDUCED switch eliminates Triangle's -i, -F, -s, and -C switches. */
49 /* The CDT_ONLY symbol gets rid of all meshing algorithms above and beyond */
50 /* constrained Delaunay triangulation. Specifically, the -DCDT_ONLY switch */
51 /* eliminates Triangle's -r, -q, -a, -u, -D, -Y, -S, and -s switches. */
52 /* */
53 /* IMPORTANT: These definitions (TRILIBRARY, REDUCED, CDT_ONLY) must be */
54 /* made in the makefile or in triangle.c itself. Putting these definitions */
55 /* in this file (triangle.h) will not create the desired effect. */
56 /* */
57 /* */
58 /* The calling convention for triangulate() follows. */
59 /* */
60 /* void triangulate(triswitches, in, out, vorout) */
61 /* char *triswitches; */
62 /* struct triangulateio *in; */
63 /* struct triangulateio *out; */
64 /* struct triangulateio *vorout; */
65 /* */
66 /* `triswitches' is a string containing the command line switches you wish */
67 /* to invoke. No initial dash is required. Some suggestions: */
68 /* */
69 /* - You'll probably find it convenient to use the `z' switch so that */
70 /* points (and other items) are numbered from zero. This simplifies */
71 /* indexing, because the first item of any type always starts at index */
72 /* [0] of the corresponding array, whether that item's number is zero or */
73 /* one. */
74 /* - You'll probably want to use the `Q' (quiet) switch in your final code, */
75 /* but you can take advantage of Triangle's printed output (including the */
76 /* `V' switch) while debugging. */
77 /* - If you are not using the `q', `a', `u', `D', `j', or `s' switches, */
78 /* then the output points will be identical to the input points, except */
79 /* possibly for the boundary markers. If you don't need the boundary */
80 /* markers, you should use the `N' (no nodes output) switch to save */
81 /* memory. (If you do need boundary markers, but need to save memory, a */
82 /* good nasty trick is to set out->pointlist equal to in->pointlist */
83 /* before calling triangulate(), so that Triangle overwrites the input */
84 /* points with identical copies.) */
85 /* - The `I' (no iteration numbers) and `g' (.off file output) switches */
86 /* have no effect when Triangle is compiled with TRILIBRARY defined. */
87 /* */
88 /* `in', `out', and `vorout' are descriptions of the input, the output, */
89 /* and the Voronoi output. If the `v' (Voronoi output) switch is not used, */
90 /* `vorout' may be NULL. `in' and `out' may never be NULL. */
91 /* */
92 /* Certain fields of the input and output structures must be initialized, */
93 /* as described below. */
94 /* */
95 /*****************************************************************************/
96 
97 /*****************************************************************************/
98 /* */
99 /* The `triangulateio' structure. */
100 /* */
101 /* Used to pass data into and out of the triangulate() procedure. */
102 /* */
103 /* */
104 /* Arrays are used to store points, triangles, markers, and so forth. In */
105 /* all cases, the first item in any array is stored starting at index [0]. */
106 /* However, that item is item number `1' unless the `z' switch is used, in */
107 /* which case it is item number `0'. Hence, you may find it easier to */
108 /* index points (and triangles in the neighbor list) if you use the `z' */
109 /* switch. Unless, of course, you're calling Triangle from a Fortran */
110 /* program. */
111 /* */
112 /* Description of fields (except the `numberof' fields, which are obvious): */
113 /* */
114 /* `pointlist': An array of point coordinates. The first point's x */
115 /* coordinate is at index [0] and its y coordinate at index [1], followed */
116 /* by the coordinates of the remaining points. Each point occupies two */
117 /* REALs. */
118 /* `pointattributelist': An array of point attributes. Each point's */
119 /* attributes occupy `numberofpointattributes' REALs. */
120 /* `pointmarkerlist': An array of point markers; one int per point. */
121 /* */
122 /* `trianglelist': An array of triangle corners. The first triangle's */
123 /* first corner is at index [0], followed by its other two corners in */
124 /* counterclockwise order, followed by any other nodes if the triangle */
125 /* represents a nonlinear element. Each triangle occupies */
126 /* `numberofcorners' ints. */
127 /* `triangleattributelist': An array of triangle attributes. Each */
128 /* triangle's attributes occupy `numberoftriangleattributes' REALs. */
129 /* `trianglearealist': An array of triangle area constraints; one REAL per */
130 /* triangle. Input only. */
131 /* `neighborlist': An array of triangle neighbors; three ints per */
132 /* triangle. Output only. */
133 /* */
134 /* `segmentlist': An array of segment endpoints. The first segment's */
135 /* endpoints are at indices [0] and [1], followed by the remaining */
136 /* segments. Two ints per segment. */
137 /* `segmentmarkerlist': An array of segment markers; one int per segment. */
138 /* */
139 /* `holelist': An array of holes. The first hole's x and y coordinates */
140 /* are at indices [0] and [1], followed by the remaining holes. Two */
141 /* REALs per hole. Input only, although the pointer is copied to the */
142 /* output structure for your convenience. */
143 /* */
144 /* `regionlist': An array of regional attributes and area constraints. */
145 /* The first constraint's x and y coordinates are at indices [0] and [1], */
146 /* followed by the regional attribute at index [2], followed by the */
147 /* maximum area at index [3], followed by the remaining area constraints. */
148 /* Four REALs per area constraint. Note that each regional attribute is */
149 /* used only if you select the `A' switch, and each area constraint is */
150 /* used only if you select the `a' switch (with no number following), but */
151 /* omitting one of these switches does not change the memory layout. */
152 /* Input only, although the pointer is copied to the output structure for */
153 /* your convenience. */
154 /* */
155 /* `edgelist': An array of edge endpoints. The first edge's endpoints are */
156 /* at indices [0] and [1], followed by the remaining edges. Two ints per */
157 /* edge. Output only. */
158 /* `edgemarkerlist': An array of edge markers; one int per edge. Output */
159 /* only. */
160 /* `normlist': An array of normal vectors, used for infinite rays in */
161 /* Voronoi diagrams. The first normal vector's x and y magnitudes are */
162 /* at indices [0] and [1], followed by the remaining vectors. For each */
163 /* finite edge in a Voronoi diagram, the normal vector written is the */
164 /* zero vector. Two REALs per edge. Output only. */
165 /* */
166 /* */
167 /* Any input fields that Triangle will examine must be initialized. */
168 /* Furthermore, for each output array that Triangle will write to, you */
169 /* must either provide space by setting the appropriate pointer to point */
170 /* to the space you want the data written to, or you must initialize the */
171 /* pointer to NULL, which tells Triangle to allocate space for the results. */
172 /* The latter option is preferable, because Triangle always knows exactly */
173 /* how much space to allocate. The former option is provided mainly for */
174 /* people who need to call Triangle from Fortran code, though it also makes */
175 /* possible some nasty space-saving tricks, like writing the output to the */
176 /* same arrays as the input. */
177 /* */
178 /* Triangle will not free() any input or output arrays, including those it */
179 /* allocates itself; that's up to you. You should free arrays allocated by */
180 /* Triangle by calling the trifree() procedure defined below. (By default, */
181 /* trifree() just calls the standard free() library procedure, but */
182 /* applications that call triangulate() may replace trimalloc() and */
183 /* trifree() in triangle.c to use specialized memory allocators.) */
184 /* */
185 /* Here's a guide to help you decide which fields you must initialize */
186 /* before you call triangulate(). */
187 /* */
188 /* `in': */
189 /* */
190 /* - `pointlist' must always point to a list of points; `numberofpoints' */
191 /* and `numberofpointattributes' must be properly set. */
192 /* `pointmarkerlist' must either be set to NULL (in which case all */
193 /* markers default to zero), or must point to a list of markers. If */
194 /* `numberofpointattributes' is not zero, `pointattributelist' must */
195 /* point to a list of point attributes. */
196 /* - If the `r' switch is used, `trianglelist' must point to a list of */
197 /* triangles, and `numberoftriangles', `numberofcorners', and */
198 /* `numberoftriangleattributes' must be properly set. If */
199 /* `numberoftriangleattributes' is not zero, `triangleattributelist' */
200 /* must point to a list of triangle attributes. If the `a' switch is */
201 /* used (with no number following), `trianglearealist' must point to a */
202 /* list of triangle area constraints. `neighborlist' may be ignored. */
203 /* - If the `p' switch is used, `segmentlist' must point to a list of */
204 /* segments, `numberofsegments' must be properly set, and */
205 /* `segmentmarkerlist' must either be set to NULL (in which case all */
206 /* markers default to zero), or must point to a list of markers. */
207 /* - If the `p' switch is used without the `r' switch, then */
208 /* `numberofholes' and `numberofregions' must be properly set. If */
209 /* `numberofholes' is not zero, `holelist' must point to a list of */
210 /* holes. If `numberofregions' is not zero, `regionlist' must point to */
211 /* a list of region constraints. */
212 /* - If the `p' switch is used, `holelist', `numberofholes', */
213 /* `regionlist', and `numberofregions' is copied to `out'. (You can */
214 /* nonetheless get away with not initializing them if the `r' switch is */
215 /* used.) */
216 /* - `edgelist', `edgemarkerlist', `normlist', and `numberofedges' may be */
217 /* ignored. */
218 /* */
219 /* `out': */
220 /* */
221 /* - `pointlist' must be initialized (NULL or pointing to memory) unless */
222 /* the `N' switch is used. `pointmarkerlist' must be initialized */
223 /* unless the `N' or `B' switch is used. If `N' is not used and */
224 /* `in->numberofpointattributes' is not zero, `pointattributelist' must */
225 /* be initialized. */
226 /* - `trianglelist' must be initialized unless the `E' switch is used. */
227 /* `neighborlist' must be initialized if the `n' switch is used. If */
228 /* the `E' switch is not used and (`in->numberofelementattributes' is */
229 /* not zero or the `A' switch is used), `elementattributelist' must be */
230 /* initialized. `trianglearealist' may be ignored. */
231 /* - `segmentlist' must be initialized if the `p' or `c' switch is used, */
232 /* and the `P' switch is not used. `segmentmarkerlist' must also be */
233 /* initialized under these circumstances unless the `B' switch is used. */
234 /* - `edgelist' must be initialized if the `e' switch is used. */
235 /* `edgemarkerlist' must be initialized if the `e' switch is used and */
236 /* the `B' switch is not. */
237 /* - `holelist', `regionlist', `normlist', and all scalars may be ignored.*/
238 /* */
239 /* `vorout' (only needed if `v' switch is used): */
240 /* */
241 /* - `pointlist' must be initialized. If `in->numberofpointattributes' */
242 /* is not zero, `pointattributelist' must be initialized. */
243 /* `pointmarkerlist' may be ignored. */
244 /* - `edgelist' and `normlist' must both be initialized. */
245 /* `edgemarkerlist' may be ignored. */
246 /* - Everything else may be ignored. */
247 /* */
248 /* After a call to triangulate(), the valid fields of `out' and `vorout' */
249 /* will depend, in an obvious way, on the choice of switches used. Note */
250 /* that when the `p' switch is used, the pointers `holelist' and */
251 /* `regionlist' are copied from `in' to `out', but no new space is */
252 /* allocated; be careful that you don't free() the same array twice. On */
253 /* the other hand, Triangle will never copy the `pointlist' pointer (or any */
254 /* others); new space is allocated for `out->pointlist', or if the `N' */
255 /* switch is used, `out->pointlist' remains uninitialized. */
256 /* */
257 /* All of the meaningful `numberof' fields will be properly set; for */
258 /* instance, `numberofedges' will represent the number of edges in the */
259 /* triangulation whether or not the edges were written. If segments are */
260 /* not used, `numberofsegments' will indicate the number of boundary edges. */
261 /* */
262 /*****************************************************************************/
263 
265  REAL *pointlist; /* In / out */
266  REAL *pointattributelist; /* In / out */
267  int *pointmarkerlist; /* In / out */
268  int numberofpoints; /* In / out */
269  int numberofpointattributes; /* In / out */
270 
271  int *trianglelist; /* In / out */
272  REAL *triangleattributelist; /* In / out */
273  REAL *trianglearealist; /* In only */
274  int *neighborlist; /* Out only */
275  int numberoftriangles; /* In / out */
276  int numberofcorners; /* In / out */
277  int numberoftriangleattributes; /* In / out */
278 
279  int *segmentlist; /* In / out */
280  int *segmentmarkerlist; /* In / out */
281  int numberofsegments; /* In / out */
282 
283  REAL *holelist; /* In / pointer to array copied out */
284  int numberofholes; /* In / copied out */
285 
286  REAL *regionlist; /* In / pointer to array copied out */
287  int numberofregions; /* In / copied out */
288 
289  int *edgelist; /* Out only */
290  int *edgemarkerlist; /* Not used with Voronoi diagram; out only */
291  REAL *normlist; /* Used only with Voronoi diagram; out only */
292  int numberofedges; /* Out only */
293 };
294 
295 #ifdef ANSI_DECLARATORS
296 void triangulate(char *, struct triangulateio *, struct triangulateio *,
297  struct triangulateio *);
298 void trifree(int *memptr); // MH hacked!
299 #else /* not ANSI_DECLARATORS */
300 void triangulate();
301 void trifree();
302 #endif /* not ANSI_DECLARATORS */
303 
304 #endif
Definition: triangle.h:264
REAL * pointattributelist
Definition: triangle.h:266
int * neighborlist
Definition: triangle.h:274
int numberoftriangleattributes
Definition: triangle.h:277
int numberofpoints
Definition: triangle.h:268
int * edgemarkerlist
Definition: triangle.h:290
int numberofsegments
Definition: triangle.h:281
REAL * normlist
Definition: triangle.h:291
int numberoftriangles
Definition: triangle.h:275
REAL * trianglearealist
Definition: triangle.h:273
int * trianglelist
Definition: triangle.h:271
REAL * pointlist
Definition: triangle.h:265
int * segmentmarkerlist
Definition: triangle.h:280
int numberofholes
Definition: triangle.h:284
REAL * regionlist
Definition: triangle.h:286
int numberofpointattributes
Definition: triangle.h:269
int numberofcorners
Definition: triangle.h:276
int numberofregions
Definition: triangle.h:287
int numberofedges
Definition: triangle.h:292
int * pointmarkerlist
Definition: triangle.h:267
int * segmentlist
Definition: triangle.h:279
REAL * triangleattributelist
Definition: triangle.h:272
REAL * holelist
Definition: triangle.h:283
int * edgelist
Definition: triangle.h:289
void trifree(int *memptr)
#define REAL
Definition: triangle.h:8
void triangulate(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *)