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