include/triangle.h

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

Generated on Fri Nov 3 21:59:02 2006 for Triangle++ by  doxygen 1.4.6