qvoronoi.c
Go to the documentation of this file.
00001 /*<html><pre>  -<a                             href="../libqhull/qh-qhull.htm"
00002   >-------------------------------</a><a name="TOP">-</a>
00003 
00004    qvoronoi.c
00005      compute Voronoi diagrams and furthest-point Voronoi
00006      diagrams using qhull
00007 
00008    see unix.c for full interface
00009 
00010    Copyright (c) 1993-2011, The Geometry Center
00011 */
00012 
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <string.h>
00016 #include <ctype.h>
00017 #include <math.h>
00018 #include "libqhull.h"
00019 #include "mem.h"
00020 #include "qset.h"
00021 
00022 #if __MWERKS__ && __POWERPC__
00023 #include <SIOUX.h>
00024 #include <Files.h>
00025 #include <console.h>
00026 #include <Desk.h>
00027 
00028 #elif __cplusplus
00029 extern "C" {
00030   int isatty(int);
00031 }
00032 
00033 #elif _MSC_VER
00034 #include <io.h>
00035 #define isatty _isatty
00036 int _isatty(int);
00037 
00038 #else
00039 int isatty(int);  /* returns 1 if stdin is a tty
00040                    if "Undefined symbol" this can be deleted along with call in main() */
00041 #endif
00042 
00043 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00044   >-------------------------------</a><a name="prompt">-</a>
00045 
00046   qh_prompt
00047     long prompt for qhull
00048 
00049   notes:
00050     restricted version of libqhull.c
00051 
00052   see:
00053     concise prompt below
00054 */
00055 
00056 /* duplicated in qvoron_f.htm and qvoronoi.htm
00057    QJ and Qt are deprecated, but allowed for backwards compatibility
00058 */
00059 char hidden_options[]=" d n m v H U Qb QB Qc Qf Qg Qi Qm Qr QR Qv Qx TR E V Fa FA FC Fp FS Ft FV Pv Gt Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 ";
00060 
00061 char qh_prompta[]= "\n\
00062 qvoronoi- compute the Voronoi diagram\n\
00063     http://www.qhull.org  %s\n\
00064 \n\
00065 input (stdin):\n\
00066     first lines: dimension and number of points (or vice-versa).\n\
00067     other lines: point coordinates, best if one point per line\n\
00068     comments:    start with a non-numeric character\n\
00069 \n\
00070 options:\n\
00071     Qu   - compute furthest-site Voronoi diagram\n\
00072 \n\
00073 Qhull control options:\n\
00074     Qz   - add point-at-infinity to Voronoi diagram\n\
00075 %s%s%s%s";  /* split up qh_prompt for Visual C++ */
00076 char qh_promptb[]= "\
00077     Qs   - search all points for the initial simplex\n\
00078     QGn  - Voronoi vertices if visible from point n, -n if not\n\
00079     QVn  - Voronoi vertices for input point n, -n if not\n\
00080 \n\
00081 ";
00082 char qh_promptc[]= "\
00083 Trace options:\n\
00084     T4   - trace at level n, 4=all, 5=mem/gauss, -1= events\n\
00085     Tc   - check frequently during execution\n\
00086     Ts   - statistics\n\
00087     Tv   - verify result: structure, convexity, and in-circle test\n\
00088     Tz   - send all output to stdout\n\
00089     TFn  - report summary when n or more facets created\n\
00090     TI file - input data from file, no spaces or single quotes\n\
00091     TO file - output results to file, may be enclosed in single quotes\n\
00092     TPn  - turn on tracing when point n added to hull\n\
00093      TMn - turn on tracing at merge n\n\
00094      TWn - trace merge facets when width > n\n\
00095     TVn  - stop qhull after adding point n, -n for before (see TCn)\n\
00096      TCn - stop qhull after building cone for point n (see TVn)\n\
00097 \n\
00098 Precision options:\n\
00099     Cn   - radius of centrum (roundoff added).  Merge facets if non-convex\n\
00100      An  - cosine of maximum angle.  Merge facets if cosine > n or non-convex\n\
00101            C-0 roundoff, A-0.99/C-0.01 pre-merge, A0.99/C0.01 post-merge\n\
00102     Rn   - randomly perturb computations by a factor of [1-n,1+n]\n\
00103     Wn   - min facet width for non-coincident point (before roundoff)\n\
00104 \n\
00105 Output formats (may be combined; if none, produces a summary to stdout):\n\
00106     s    - summary to stderr\n\
00107     p    - Voronoi vertices\n\
00108     o    - OFF format (dim, Voronoi vertices, and Voronoi regions)\n\
00109     i    - Delaunay regions (use 'Pp' to avoid warning)\n\
00110     f    - facet dump\n\
00111 \n\
00112 ";
00113 char qh_promptd[]= "\
00114 More formats:\n\
00115     Fc   - count plus coincident points (by Voronoi vertex)\n\
00116     Fd   - use cdd format for input (homogeneous with offset first)\n\
00117     FD   - use cdd format for output (offset first)\n\
00118     FF   - facet dump without ridges\n\
00119     Fi   - separating hyperplanes for bounded Voronoi regions\n\
00120     FI   - ID for each Voronoi vertex\n\
00121     Fm   - merge count for each Voronoi vertex (511 max)\n\
00122     Fn   - count plus neighboring Voronoi vertices for each Voronoi vertex\n\
00123     FN   - count and Voronoi vertices for each Voronoi region\n\
00124     Fo   - separating hyperplanes for unbounded Voronoi regions\n\
00125     FO   - options and precision constants\n\
00126     FP   - nearest point and distance for each coincident point\n\
00127     FQ   - command used for qvoronoi\n\
00128     Fs   - summary: #int (8), dimension, #points, tot vertices, tot facets,\n\
00129                     for output: #Voronoi regions, #Voronoi vertices,\n\
00130                                 #coincident points, #non-simplicial regions\n\
00131                     #real (2), max outer plane and min vertex\n\
00132     Fv   - Voronoi diagram as Voronoi vertices between adjacent input sites\n\
00133     Fx   - extreme points of Delaunay triangulation (on convex hull)\n\
00134 \n\
00135 ";
00136 char qh_prompte[]= "\
00137 Geomview options (2-d only)\n\
00138     Ga   - all points as dots\n\
00139      Gp  -  coplanar points and vertices as radii\n\
00140      Gv  -  vertices as spheres\n\
00141     Gi   - inner planes only\n\
00142      Gn  -  no planes\n\
00143      Go  -  outer planes only\n\
00144     Gc   - centrums\n\
00145     Gh   - hyperplane intersections\n\
00146     Gr   - ridges\n\
00147     GDn  - drop dimension n in 3-d and 4-d output\n\
00148 \n\
00149 Print options:\n\
00150     PAn  - keep n largest Voronoi vertices by 'area'\n\
00151     Pdk:n - drop facet if normal[k] <= n (default 0.0)\n\
00152     PDk:n - drop facet if normal[k] >= n\n\
00153     Pg   - print good Voronoi vertices (needs 'QGn' or 'QVn')\n\
00154     PFn  - keep Voronoi vertices whose 'area' is at least n\n\
00155     PG   - print neighbors of good Voronoi vertices\n\
00156     PMn  - keep n Voronoi vertices with most merges\n\
00157     Po   - force output.  If error, output neighborhood of facet\n\
00158     Pp   - do not report precision problems\n\
00159 \n\
00160     .    - list of all options\n\
00161     -    - one line descriptions of all options\n\
00162 ";
00163 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
00164 
00165 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00166   >-------------------------------</a><a name="prompt2">-</a>
00167 
00168   qh_prompt2
00169     synopsis for qhull
00170 */
00171 char qh_prompt2[]= "\n\
00172 qvoronoi- compute the Voronoi diagram.  Qhull %s\n\
00173     input (stdin): dimension, number of points, point coordinates\n\
00174     comments start with a non-numeric character\n\
00175 \n\
00176 options (qvoronoi.htm):\n\
00177     Qu   - compute furthest-site Voronoi diagram\n\
00178     Tv   - verify result: structure, convexity, and in-circle test\n\
00179     .    - concise list of all options\n\
00180     -    - one-line description of all options\n\
00181 \n\
00182 output options (subset):\n\
00183     s    - summary of results (default)\n\
00184     p    - Voronoi vertices\n\
00185     o    - OFF file format (dim, Voronoi vertices, and Voronoi regions)\n\
00186     FN   - count and Voronoi vertices for each Voronoi region\n\
00187     Fv   - Voronoi diagram as Voronoi vertices between adjacent input sites\n\
00188     Fi   - separating hyperplanes for bounded regions, 'Fo' for unbounded\n\
00189     G    - Geomview output (2-d only)\n\
00190     QVn  - Voronoi vertices for input point n, -n if not\n\
00191     TO file- output results to file, may be enclosed in single quotes\n\
00192 \n\
00193 examples:\n\
00194 rbox c P0 D2 | qvoronoi s o         rbox c P0 D2 | qvoronoi Fi\n\
00195 rbox c P0 D2 | qvoronoi Fo          rbox c P0 D2 | qvoronoi Fv\n\
00196 rbox c P0 D2 | qvoronoi s Qu Fv     rbox c P0 D2 | qvoronoi Qu Fo\n\
00197 rbox c G1 d D2 | qvoronoi s p       rbox c P0 D2 | qvoronoi s Fv QV0\n\
00198 \n\
00199 ";
00200 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
00201 
00202 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00203   >-------------------------------</a><a name="prompt3">-</a>
00204 
00205   qh_prompt3
00206     concise prompt for qhull
00207 */
00208 char qh_prompt3[]= "\n\
00209 Qhull %s.\n\
00210 Except for 'F.' and 'PG', upper-case options take an argument.\n\
00211 \n\
00212  OFF_format     p_vertices     i_delaunay     summary        facet_dump\n\
00213 \n\
00214  Fcoincident    Fd_cdd_in      FD_cdd_out     FF-dump-xridge Fi_bounded\n\
00215  Fxtremes       Fmerges        Fneighbors     FNeigh_region  FOptions\n\
00216  Fo_unbounded   FPoint_near    FQvoronoi      Fsummary       Fvoronoi\n\
00217  FIDs\n\
00218 \n\
00219  Gvertices      Gpoints        Gall_points    Gno_planes     Ginner\n\
00220  Gcentrums      Ghyperplanes   Gridges        Gouter         GDrop_dim\n\
00221 \n\
00222  PArea_keep     Pdrop d0:0D0   Pgood          PFacet_area_keep\n\
00223  PGood_neighbors PMerge_keep   Poutput_forced Pprecision_not\n\
00224 \n\
00225  QG_vertex_good Qsearch_1st    Qupper_voronoi QV_point_good  Qzinfinite\n\
00226  T4_trace       Tcheck_often   Tstatistics    Tverify        Tz_stdout\n\
00227  TFacet_log     TInput_file    TPoint_trace   TMerge_trace   TOutput_file\n\
00228  TWide_trace    TVertex_stop   TCone_stop\n\
00229 \n\
00230  Angle_max      Centrum_size   Random_dist    Wide_outside\n\
00231 ";
00232 
00233 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00234   >-------------------------------</a><a name="main">-</a>
00235 
00236   main( argc, argv )
00237     processes the command line, calls qhull() to do the work, and exits
00238 
00239   design:
00240     initializes data structures
00241     reads points
00242     finishes initialization
00243     computes convex hull and other structures
00244     checks the result
00245     writes the output
00246     frees memory
00247 */
00248 int main(int argc, char *argv[]) {
00249   int curlong, totlong; /* used !qh_NOmem */
00250   int exitcode, numpoints, dim;
00251   coordT *points;
00252   boolT ismalloc;
00253 
00254 #if __MWERKS__ && __POWERPC__
00255   char inBuf[BUFSIZ], outBuf[BUFSIZ], errBuf[BUFSIZ];
00256   SIOUXSettings.showstatusline= false;
00257   SIOUXSettings.tabspaces= 1;
00258   SIOUXSettings.rows= 40;
00259   if (setvbuf(stdin, inBuf, _IOFBF, sizeof(inBuf)) < 0   /* w/o, SIOUX I/O is slow*/
00260   || setvbuf(stdout, outBuf, _IOFBF, sizeof(outBuf)) < 0
00261   || (stdout != stderr && setvbuf(stderr, errBuf, _IOFBF, sizeof(errBuf)) < 0))
00262     fprintf(stderr, "qhull internal warning (main): could not change stdio to fully buffered.\n");
00263   argc= ccommand(&argv);
00264 #endif
00265 
00266   if ((argc == 1) && isatty( 0 /*stdin*/)) {
00267     fprintf(stdout, qh_prompt2, qh_version);
00268     exit(qh_ERRnone);
00269   }
00270   if (argc > 1 && *argv[1] == '-' && !*(argv[1]+1)) {
00271     fprintf(stdout, qh_prompta, qh_version,
00272                 qh_promptb, qh_promptc, qh_promptd, qh_prompte);
00273     exit(qh_ERRnone);
00274   }
00275   if (argc >1 && *argv[1] == '.' && !*(argv[1]+1)) {
00276     fprintf(stdout, qh_prompt3, qh_version);
00277     exit(qh_ERRnone);
00278   }
00279   qh_init_A(stdin, stdout, stderr, argc, argv);  /* sets qh qhull_command */
00280   exitcode= setjmp(qh errexit); /* simple statement for CRAY J916 */
00281   if (!exitcode) {
00282     qh_option("voronoi  _bbound-last  _coplanar-keep", NULL, NULL);
00283     qh DELAUNAY= True;     /* 'v'   */
00284     qh VORONOI= True;
00285     qh SCALElast= True;    /* 'Qbb' */
00286     qh_checkflags(qh qhull_command, hidden_options);
00287     qh_initflags(qh qhull_command);
00288     points= qh_readpoints(&numpoints, &dim, &ismalloc);
00289     if (dim >= 5) {
00290       qh_option("_merge-exact", NULL, NULL);
00291       qh MERGEexact= True; /* 'Qx' always */
00292     }
00293     qh_init_B(points, numpoints, dim, ismalloc);
00294     qh_qhull();
00295     qh_check_output();
00296     qh_produce_output();
00297     if (qh VERIFYoutput && !qh FORCEoutput && !qh STOPpoint && !qh STOPcone)
00298       qh_check_points();
00299     exitcode= qh_ERRnone;
00300   }
00301   qh NOerrexit= True;  /* no more setjmp */
00302 #ifdef qh_NOmem
00303   qh_freeqhull( True);
00304 #else
00305   qh_freeqhull( False);
00306   qh_memfreeshort(&curlong, &totlong);
00307   if (curlong || totlong)
00308     fprintf(stderr, "qhull internal warning (main): did not free %d bytes of long memory(%d pieces)\n",
00309        totlong, curlong);
00310 #endif
00311   return exitcode;
00312 } /* main */
00313 


libqhull-ours
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:11