triangle.h

Go to the documentation of this file.
00001 
00008 /*****************************************************************************/
00009 /*                                                                           */
00010 /*  (triangle.h)                                                             */
00011 /*                                                                           */
00012 /*  Include file for programs that call Triangle.                            */
00013 /*                                                                           */
00014 /*  Accompanies Triangle Version 1.6                                         */
00015 /*  July 28, 2005                                                            */
00016 /*                                                                           */
00017 /*  Copyright 1996, 2005                                                     */
00018 /*  Jonathan Richard Shewchuk                                                */
00019 /*  2360 Woolsey #H                                                          */
00020 /*  Berkeley, California  94705-1927                                         */
00021 /*  jrs@cs.berkeley.edu                                                      */
00022 /*                                                                           */
00023 /*****************************************************************************/
00024 
00025 /*****************************************************************************/
00026 /*                                                                           */
00027 /*  How to call Triangle from another program                                */
00028 /*                                                                           */
00029 /*                                                                           */
00030 /*  If you haven't read Triangle's instructions (run "triangle -h" to read   */
00031 /*  them), you won't understand what follows.                                */
00032 /*                                                                           */
00033 /*  Triangle must be compiled into an object file (triangle.o) with the      */
00034 /*  TRILIBRARY symbol defined (generally by using the -DTRILIBRARY compiler  */
00035 /*  switch).  The makefile included with Triangle will do this for you if    */
00036 /*  you run "make trilibrary".  The resulting object file can be called via  */
00037 /*  the procedure triangulate().                                             */
00038 /*                                                                           */
00039 /*  If the size of the object file is important to you, you may wish to      */
00040 /*  generate a reduced version of triangle.o.  The REDUCED symbol gets rid   */
00041 /*  of all features that are primarily of research interest.  Specifically,  */
00042 /*  the -DREDUCED switch eliminates Triangle's -i, -F, -s, and -C switches.  */
00043 /*  The CDT_ONLY symbol gets rid of all meshing algorithms above and beyond  */
00044 /*  constrained Delaunay triangulation.  Specifically, the -DCDT_ONLY switch */
00045 /*  eliminates Triangle's -r, -q, -a, -u, -D, -Y, -S, and -s switches.       */
00046 /*                                                                           */
00047 /*  IMPORTANT:  These definitions (TRILIBRARY, REDUCED, CDT_ONLY) must be    */
00048 /*  made in the makefile or in triangle.c itself.  Putting these definitions */
00049 /*  in this file (triangle.h) will not create the desired effect.            */
00050 /*                                                                           */
00051 /*                                                                           */
00052 /*  The calling convention for triangulate() follows.                        */
00053 /*                                                                           */
00054 /*      void triangulate(triswitches, in, out, vorout)                       */
00055 /*      char *triswitches;                                                   */
00056 /*      struct triangulateio *in;                                            */
00057 /*      struct triangulateio *out;                                           */
00058 /*      struct triangulateio *vorout;                                        */
00059 /*                                                                           */
00060 /*  `triswitches' is a string containing the command line switches you wish  */
00061 /*  to invoke.  No initial dash is required.  Some suggestions:              */
00062 /*                                                                           */
00063 /*  - You'll probably find it convenient to use the `z' switch so that       */
00064 /*    points (and other items) are numbered from zero.  This simplifies      */
00065 /*    indexing, because the first item of any type always starts at index    */
00066 /*    [0] of the corresponding array, whether that item's number is zero or  */
00067 /*    one.                                                                   */
00068 /*  - You'll probably want to use the `Q' (quiet) switch in your final code, */
00069 /*    but you can take advantage of Triangle's printed output (including the */
00070 /*    `V' switch) while debugging.                                           */
00071 /*  - If you are not using the `q', `a', `u', `D', `j', or `s' switches,     */
00072 /*    then the output points will be identical to the input points, except   */
00073 /*    possibly for the boundary markers.  If you don't need the boundary     */
00074 /*    markers, you should use the `N' (no nodes output) switch to save       */
00075 /*    memory.  (If you do need boundary markers, but need to save memory, a  */
00076 /*    good nasty trick is to set out->pointlist equal to in->pointlist       */
00077 /*    before calling triangulate(), so that Triangle overwrites the input    */
00078 /*    points with identical copies.)                                         */
00079 /*  - The `I' (no iteration numbers) and `g' (.off file output) switches     */
00080 /*    have no effect when Triangle is compiled with TRILIBRARY defined.      */
00081 /*                                                                           */
00082 /*  `in', `out', and `vorout' are descriptions of the input, the output,     */
00083 /*  and the Voronoi output.  If the `v' (Voronoi output) switch is not used, */
00084 /*  `vorout' may be NULL.  `in' and `out' may never be NULL.                 */
00085 /*                                                                           */
00086 /*  Certain fields of the input and output structures must be initialized,   */
00087 /*  as described below.                                                      */
00088 /*                                                                           */
00089 /*****************************************************************************/
00090 
00091 /*****************************************************************************/
00092 /*                                                                           */
00093 /*  The `triangulateio' structure.                                           */
00094 /*                                                                           */
00095 /*  Used to pass data into and out of the triangulate() procedure.           */
00096 /*                                                                           */
00097 /*                                                                           */
00098 /*  Arrays are used to store points, triangles, markers, and so forth.  In   */
00099 /*  all cases, the first item in any array is stored starting at index [0].  */
00100 /*  However, that item is item number `1' unless the `z' switch is used, in  */
00101 /*  which case it is item number `0'.  Hence, you may find it easier to      */
00102 /*  index points (and triangles in the neighbor list) if you use the `z'     */
00103 /*  switch.  Unless, of course, you're calling Triangle from a Fortran       */
00104 /*  program.                                                                 */
00105 /*                                                                           */
00106 /*  Description of fields (except the `numberof' fields, which are obvious): */
00107 /*                                                                           */
00108 /*  `pointlist':  An array of point coordinates.  The first point's x        */
00109 /*    coordinate is at index [0] and its y coordinate at index [1], followed */
00110 /*    by the coordinates of the remaining points.  Each point occupies two   */
00111 /*    REALs.                                                                 */
00112 /*  `pointattributelist':  An array of point attributes.  Each point's       */
00113 /*    attributes occupy `numberofpointattributes' REALs.                     */
00114 /*  `pointmarkerlist':  An array of point markers; one int per point.        */
00115 /*                                                                           */
00116 /*  `trianglelist':  An array of triangle corners.  The first triangle's     */
00117 /*    first corner is at index [0], followed by its other two corners in     */
00118 /*    counterclockwise order, followed by any other nodes if the triangle    */
00119 /*    represents a nonlinear element.  Each triangle occupies                */
00120 /*    `numberofcorners' ints.                                                */
00121 /*  `triangleattributelist':  An array of triangle attributes.  Each         */
00122 /*    triangle's attributes occupy `numberoftriangleattributes' REALs.       */
00123 /*  `trianglearealist':  An array of triangle area constraints; one REAL per */
00124 /*    triangle.  Input only.                                                 */
00125 /*  `neighborlist':  An array of triangle neighbors; three ints per          */
00126 /*    triangle.  Output only.                                                */
00127 /*                                                                           */
00128 /*  `segmentlist':  An array of segment endpoints.  The first segment's      */
00129 /*    endpoints are at indices [0] and [1], followed by the remaining        */
00130 /*    segments.  Two ints per segment.                                       */
00131 /*  `segmentmarkerlist':  An array of segment markers; one int per segment.  */
00132 /*                                                                           */
00133 /*  `holelist':  An array of holes.  The first hole's x and y coordinates    */
00134 /*    are at indices [0] and [1], followed by the remaining holes.  Two      */
00135 /*    REALs per hole.  Input only, although the pointer is copied to the     */
00136 /*    output structure for your convenience.                                 */
00137 /*                                                                           */
00138 /*  `regionlist':  An array of regional attributes and area constraints.     */
00139 /*    The first constraint's x and y coordinates are at indices [0] and [1], */
00140 /*    followed by the regional attribute at index [2], followed by the       */
00141 /*    maximum area at index [3], followed by the remaining area constraints. */
00142 /*    Four REALs per area constraint.  Note that each regional attribute is  */
00143 /*    used only if you select the `A' switch, and each area constraint is    */
00144 /*    used only if you select the `a' switch (with no number following), but */
00145 /*    omitting one of these switches does not change the memory layout.      */
00146 /*    Input only, although the pointer is copied to the output structure for */
00147 /*    your convenience.                                                      */
00148 /*                                                                           */
00149 /*  `edgelist':  An array of edge endpoints.  The first edge's endpoints are */
00150 /*    at indices [0] and [1], followed by the remaining edges.  Two ints per */
00151 /*    edge.  Output only.                                                    */
00152 /*  `edgemarkerlist':  An array of edge markers; one int per edge.  Output   */
00153 /*    only.                                                                  */
00154 /*  `normlist':  An array of normal vectors, used for infinite rays in       */
00155 /*    Voronoi diagrams.  The first normal vector's x and y magnitudes are    */
00156 /*    at indices [0] and [1], followed by the remaining vectors.  For each   */
00157 /*    finite edge in a Voronoi diagram, the normal vector written is the     */
00158 /*    zero vector.  Two REALs per edge.  Output only.                        */
00159 /*                                                                           */
00160 /*                                                                           */
00161 /*  Any input fields that Triangle will examine must be initialized.         */
00162 /*  Furthermore, for each output array that Triangle will write to, you      */
00163 /*  must either provide space by setting the appropriate pointer to point    */
00164 /*  to the space you want the data written to, or you must initialize the    */
00165 /*  pointer to NULL, which tells Triangle to allocate space for the results. */
00166 /*  The latter option is preferable, because Triangle always knows exactly   */
00167 /*  how much space to allocate.  The former option is provided mainly for    */
00168 /*  people who need to call Triangle from Fortran code, though it also makes */
00169 /*  possible some nasty space-saving tricks, like writing the output to the  */
00170 /*  same arrays as the input.                                                */
00171 /*                                                                           */
00172 /*  Triangle will not free() any input or output arrays, including those it  */
00173 /*  allocates itself; that's up to you.  You should free arrays allocated by */
00174 /*  Triangle by calling the trifree() procedure defined below.  (By default, */
00175 /*  trifree() just calls the standard free() library procedure, but          */
00176 /*  applications that call triangulate() may replace trimalloc() and         */
00177 /*  trifree() in triangle.c to use specialized memory allocators.)           */
00178 /*                                                                           */
00179 /*  Here's a guide to help you decide which fields you must initialize       */
00180 /*  before you call triangulate().                                           */
00181 /*                                                                           */
00182 /*  `in':                                                                    */
00183 /*                                                                           */
00184 /*    - `pointlist' must always point to a list of points; `numberofpoints'  */
00185 /*      and `numberofpointattributes' must be properly set.                  */
00186 /*      `pointmarkerlist' must either be set to NULL (in which case all      */
00187 /*      markers default to zero), or must point to a list of markers.  If    */
00188 /*      `numberofpointattributes' is not zero, `pointattributelist' must     */
00189 /*      point to a list of point attributes.                                 */
00190 /*    - If the `r' switch is used, `trianglelist' must point to a list of    */
00191 /*      triangles, and `numberoftriangles', `numberofcorners', and           */
00192 /*      `numberoftriangleattributes' must be properly set.  If               */
00193 /*      `numberoftriangleattributes' is not zero, `triangleattributelist'    */
00194 /*      must point to a list of triangle attributes.  If the `a' switch is   */
00195 /*      used (with no number following), `trianglearealist' must point to a  */
00196 /*      list of triangle area constraints.  `neighborlist' may be ignored.   */
00197 /*    - If the `p' switch is used, `segmentlist' must point to a list of     */
00198 /*      segments, `numberofsegments' must be properly set, and               */
00199 /*      `segmentmarkerlist' must either be set to NULL (in which case all    */
00200 /*      markers default to zero), or must point to a list of markers.        */
00201 /*    - If the `p' switch is used without the `r' switch, then               */
00202 /*      `numberofholes' and `numberofregions' must be properly set.  If      */
00203 /*      `numberofholes' is not zero, `holelist' must point to a list of      */
00204 /*      holes.  If `numberofregions' is not zero, `regionlist' must point to */
00205 /*      a list of region constraints.                                        */
00206 /*    - If the `p' switch is used, `holelist', `numberofholes',              */
00207 /*      `regionlist', and `numberofregions' is copied to `out'.  (You can    */
00208 /*      nonetheless get away with not initializing them if the `r' switch is */
00209 /*      used.)                                                               */
00210 /*    - `edgelist', `edgemarkerlist', `normlist', and `numberofedges' may be */
00211 /*      ignored.                                                             */
00212 /*                                                                           */
00213 /*  `out':                                                                   */
00214 /*                                                                           */
00215 /*    - `pointlist' must be initialized (NULL or pointing to memory) unless  */
00216 /*      the `N' switch is used.  `pointmarkerlist' must be initialized       */
00217 /*      unless the `N' or `B' switch is used.  If `N' is not used and        */
00218 /*      `in->numberofpointattributes' is not zero, `pointattributelist' must */
00219 /*      be initialized.                                                      */
00220 /*    - `trianglelist' must be initialized unless the `E' switch is used.    */
00221 /*      `neighborlist' must be initialized if the `n' switch is used.  If    */
00222 /*      the `E' switch is not used and (`in->numberofelementattributes' is   */
00223 /*      not zero or the `A' switch is used), `elementattributelist' must be  */
00224 /*      initialized.  `trianglearealist' may be ignored.                     */
00225 /*    - `segmentlist' must be initialized if the `p' or `c' switch is used,  */
00226 /*      and the `P' switch is not used.  `segmentmarkerlist' must also be    */
00227 /*      initialized under these circumstances unless the `B' switch is used. */
00228 /*    - `edgelist' must be initialized if the `e' switch is used.            */
00229 /*      `edgemarkerlist' must be initialized if the `e' switch is used and   */
00230 /*      the `B' switch is not.                                               */
00231 /*    - `holelist', `regionlist', `normlist', and all scalars may be ignored.*/
00232 /*                                                                           */
00233 /*  `vorout' (only needed if `v' switch is used):                            */
00234 /*                                                                           */
00235 /*    - `pointlist' must be initialized.  If `in->numberofpointattributes'   */
00236 /*      is not zero, `pointattributelist' must be initialized.               */
00237 /*      `pointmarkerlist' may be ignored.                                    */
00238 /*    - `edgelist' and `normlist' must both be initialized.                  */
00239 /*      `edgemarkerlist' may be ignored.                                     */
00240 /*    - Everything else may be ignored.                                      */
00241 /*                                                                           */
00242 /*  After a call to triangulate(), the valid fields of `out' and `vorout'    */
00243 /*  will depend, in an obvious way, on the choice of switches used.  Note    */
00244 /*  that when the `p' switch is used, the pointers `holelist' and            */
00245 /*  `regionlist' are copied from `in' to `out', but no new space is          */
00246 /*  allocated; be careful that you don't free() the same array twice.  On    */
00247 /*  the other hand, Triangle will never copy the `pointlist' pointer (or any */
00248 /*  others); new space is allocated for `out->pointlist', or if the `N'      */
00249 /*  switch is used, `out->pointlist' remains uninitialized.                  */
00250 /*                                                                           */
00251 /*  All of the meaningful `numberof' fields will be properly set; for        */
00252 /*  instance, `numberofedges' will represent the number of edges in the      */
00253 /*  triangulation whether or not the edges were written.  If segments are    */
00254 /*  not used, `numberofsegments' will indicate the number of boundary edges. */
00255 /*                                                                           */
00256 /*****************************************************************************/
00257 
00258 struct triangulateio {
00259   REAL *pointlist;                                               /* In / out */
00260   REAL *pointattributelist;                                      /* In / out */
00261   int *pointmarkerlist;                                          /* In / out */
00262   int numberofpoints;                                            /* In / out */
00263   int numberofpointattributes;                                   /* In / out */
00264 
00265   int *trianglelist;                                             /* In / out */
00266   REAL *triangleattributelist;                                   /* In / out */
00267   REAL *trianglearealist;                                         /* In only */
00268   int *neighborlist;                                             /* Out only */
00269   int numberoftriangles;                                         /* In / out */
00270   int numberofcorners;                                           /* In / out */
00271   int numberoftriangleattributes;                                /* In / out */
00272 
00273   int *segmentlist;                                              /* In / out */
00274   int *segmentmarkerlist;                                        /* In / out */
00275   int numberofsegments;                                          /* In / out */
00276 
00277   REAL *holelist;                        /* In / pointer to array copied out */
00278   int numberofholes;                                      /* In / copied out */
00279 
00280   REAL *regionlist;                      /* In / pointer to array copied out */
00281   int numberofregions;                                    /* In / copied out */
00282 
00283   int *edgelist;                                                 /* Out only */
00284   int *edgemarkerlist;            /* Not used with Voronoi diagram; out only */
00285   REAL *normlist;                /* Used only with Voronoi diagram; out only */
00286   int numberofedges;                                             /* Out only */
00287 };
00288 
00289 #ifdef ANSI_DECLARATORS
00290 void triangulate(char *, struct triangulateio *, struct triangulateio *,
00291                  struct triangulateio *);
00292 void trifree(VOID *memptr);
00293 #else /* not ANSI_DECLARATORS */
00294 void triangulate();
00295 void trifree();
00296 #endif /* not ANSI_DECLARATORS */

Generated on Tue Aug 4 16:10:23 2009 for Chaste by  doxygen 1.5.5