unix.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    unix.c
00005      command line interface to qhull
00006          includes SIOUX interface for Macintoshes
00007 
00008    see qh-qhull.htm
00009 
00010    Copyright (c) 1993-2011 The Geometry Center.
00011    $Id: //main/2011/qhull/src/qhull/unix.c#4 $$Change: 1372 $
00012    $DateTime: 2011/04/17 19:32:21 $$Author: bbarber $
00013 */
00014 
00015 #include "mem.h"
00016 #include "qset.h"
00017 #include "libqhull.h"
00018 
00019 #include <ctype.h>
00020 #include <math.h>
00021 #include <string.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 
00025 #if __MWERKS__ && __POWERPC__
00026 #include <SIOUX.h>
00027 #include <Files.h>
00028 #include <console.h>
00029 #include <Desk.h>
00030 
00031 #elif __cplusplus
00032 extern "C" {
00033   int isatty(int);
00034 }
00035 
00036 #elif _MSC_VER
00037 #include <io.h>
00038 #define isatty _isatty
00039 int _isatty(int);
00040 
00041 #else
00042 int isatty(int);  /* returns 1 if stdin is a tty
00043                    if "Undefined symbol" this can be deleted along with call in main() */
00044 #endif
00045 
00046 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00047   >-------------------------------</a><a name="prompt">-</a>
00048 
00049   qh_prompt
00050     long prompt for qhull
00051 
00052   see:
00053     concise prompt below
00054 */
00055 char qh_prompta[]= "\n\
00056 qhull- compute convex hulls and related structures.\n\
00057     http://www.qhull.org  %s\n\
00058 \n\
00059 input (stdin):\n\
00060     first lines: dimension and number of points (or vice-versa).\n\
00061     other lines: point coordinates, best if one point per line\n\
00062     comments:    start with a non-numeric character\n\
00063     halfspaces:  use dim plus one and put offset after coefficients.\n\
00064                  May be preceeded by a single interior point ('H').\n\
00065 \n\
00066 options:\n\
00067     d    - Delaunay triangulation by lifting points to a paraboloid\n\
00068     d Qu - furthest-site Delaunay triangulation (upper convex hull)\n\
00069     v    - Voronoi diagram (dual of the Delaunay triangulation)\n\
00070     v Qu - furthest-site Voronoi diagram\n\
00071     Hn,n,... - halfspace intersection about point [n,n,0,...]\n\
00072     Qt   - triangulated output\n\
00073     QJ   - joggled input instead of merged facets\n\
00074     Qc   - keep coplanar points with nearest facet\n\
00075     Qi   - keep interior points with nearest facet\n\
00076 \n\
00077 Qhull control options:\n\
00078     Qbk:n   - scale coord k so that low bound is n\n\
00079       QBk:n - scale coord k so that upper bound is n (QBk is %2.2g)\n\
00080     QbB  - scale input to unit cube centered at the origin\n\
00081     Qbb  - scale last coordinate to [0,m] for Delaunay triangulations\n\
00082     Qbk:0Bk:0 - remove k-th coordinate from input\n\
00083     QJn  - randomly joggle input in range [-n,n]\n\
00084     QRn  - random rotation (n=seed, n=0 time, n=-1 time/no rotate)\n\
00085 %s%s%s%s";  /* split up qh_prompt for Visual C++ */
00086 char qh_promptb[]= "\
00087     Qf   - partition point to furthest outside facet\n\
00088     Qg   - only build good facets (needs 'QGn', 'QVn', or 'PdD')\n\
00089     Qm   - only process points that would increase max_outside\n\
00090     Qr   - process random outside points instead of furthest ones\n\
00091     Qs   - search all points for the initial simplex\n\
00092     Qu   - for 'd' or 'v', compute upper hull without point at-infinity\n\
00093               returns furthest-site Delaunay triangulation\n\
00094     Qv   - test vertex neighbors for convexity\n\
00095     Qx   - exact pre-merges (skips coplanar and angle-coplanar facets)\n\
00096     Qz   - add point-at-infinity to Delaunay triangulation\n\
00097     QGn  - good facet if visible from point n, -n for not visible\n\
00098     QVn  - good facet if it includes point n, -n if not\n\
00099     Q0   - turn off default premerge with 'C-0'/'Qx'\n\
00100     Q1     - sort merges by type instead of angle\n\
00101     Q2   - merge all non-convex at once instead of independent sets\n\
00102     Q3   - do not merge redundant vertices\n\
00103     Q4   - avoid old->new merges\n\
00104     Q5   - do not correct outer planes at end of qhull\n\
00105     Q6   - do not pre-merge concave or coplanar facets\n\
00106     Q7   - depth-first processing instead of breadth-first\n\
00107     Q8   - do not process near-inside points\n\
00108     Q9   - process furthest of furthest points\n\
00109     Q10  - no special processing for narrow distributions\n\
00110     Q11  - copy normals and recompute centrums for tricoplanar facets\n\
00111 \n\
00112 ";
00113 char qh_promptc[]= "\
00114 Topts- Trace options:\n\
00115     T4   - trace at level n, 4=all, 5=mem/gauss, -1= events\n\
00116     Ta   - annotate output with message codes\n\
00117     Tc   - check frequently during execution\n\
00118     Ts   - print statistics\n\
00119     Tv   - verify result: structure, convexity, and point inclusion\n\
00120     Tz   - send all output to stdout\n\
00121     TFn  - report summary when n or more facets created\n\
00122     TI file - input data from file, no spaces or single quotes\n\
00123     TO file - output results to file, may be enclosed in single quotes\n\
00124     TPn  - turn on tracing when point n added to hull\n\
00125      TMn - turn on tracing at merge n\n\
00126      TWn - trace merge facets when width > n\n\
00127     TRn  - rerun qhull n times.  Use with 'QJn'\n\
00128     TVn  - stop qhull after adding point n, -n for before (see TCn)\n\
00129      TCn - stop qhull after building cone for point n (see TVn)\n\
00130 \n\
00131 Precision options:\n\
00132     Cn   - radius of centrum (roundoff added).  Merge facets if non-convex\n\
00133      An  - cosine of maximum angle.  Merge facets if cosine > n or non-convex\n\
00134            C-0 roundoff, A-0.99/C-0.01 pre-merge, A0.99/C0.01 post-merge\n\
00135     En   - max roundoff error for distance computation\n\
00136     Rn   - randomly perturb computations by a factor of [1-n,1+n]\n\
00137     Vn   - min distance above plane for a visible facet (default 3C-n or En)\n\
00138     Un   - max distance below plane for a new, coplanar point (default Vn)\n\
00139     Wn   - min facet width for outside point (before roundoff, default 2Vn)\n\
00140 \n\
00141 Output formats (may be combined; if none, produces a summary to stdout):\n\
00142     f    - facet dump\n\
00143     G    - Geomview output (see below)\n\
00144     i    - vertices incident to each facet\n\
00145     m    - Mathematica output (2-d and 3-d)\n\
00146     o    - OFF format (dim, points and facets; Voronoi regions)\n\
00147     n    - normals with offsets\n\
00148     p    - vertex coordinates or Voronoi vertices (coplanar points if 'Qc')\n\
00149     s    - summary (stderr)\n\
00150 \n\
00151 ";
00152 char qh_promptd[]= "\
00153 More formats:\n\
00154     Fa   - area for each facet\n\
00155     FA   - compute total area and volume for option 's'\n\
00156     Fc   - count plus coplanar points for each facet\n\
00157            use 'Qc' (default) for coplanar and 'Qi' for interior\n\
00158     FC   - centrum or Voronoi center for each facet\n\
00159     Fd   - use cdd format for input (homogeneous with offset first)\n\
00160     FD   - use cdd format for numeric output (offset first)\n\
00161     FF   - facet dump without ridges\n\
00162     Fi   - inner plane for each facet\n\
00163            for 'v', separating hyperplanes for bounded Voronoi regions\n\
00164     FI   - ID of each facet\n\
00165     Fm   - merge count for each facet (511 max)\n\
00166     FM   - Maple output (2-d and 3-d)\n\
00167     Fn   - count plus neighboring facets for each facet\n\
00168     FN   - count plus neighboring facets for each point\n\
00169     Fo   - outer plane (or max_outside) for each facet\n\
00170            for 'v', separating hyperplanes for unbounded Voronoi regions\n\
00171     FO   - options and precision constants\n\
00172     Fp   - dim, count, and intersection coordinates (halfspace only)\n\
00173     FP   - nearest vertex and distance for each coplanar point\n\
00174     FQ   - command used for qhull\n\
00175     Fs   - summary: #int (8), dimension, #points, tot vertices, tot facets,\n\
00176                       output: #vertices, #facets, #coplanars, #nonsimplicial\n\
00177                     #real (2), max outer plane, min vertex\n\
00178     FS   - sizes:   #int (0)\n\
00179                     #real (2) tot area, tot volume\n\
00180     Ft   - triangulation with centrums for non-simplicial facets (OFF format)\n\
00181     Fv   - count plus vertices for each facet\n\
00182            for 'v', Voronoi diagram as Voronoi vertices for pairs of sites\n\
00183     FV   - average of vertices (a feasible point for 'H')\n\
00184     Fx   - extreme points (in order for 2-d)\n\
00185 \n\
00186 ";
00187 char qh_prompte[]= "\
00188 Geomview options (2-d, 3-d, and 4-d; 2-d Voronoi)\n\
00189     Ga   - all points as dots\n\
00190      Gp  -  coplanar points and vertices as radii\n\
00191      Gv  -  vertices as spheres\n\
00192     Gi   - inner planes only\n\
00193      Gn  -  no planes\n\
00194      Go  -  outer planes only\n\
00195     Gc   - centrums\n\
00196     Gh   - hyperplane intersections\n\
00197     Gr   - ridges\n\
00198     GDn  - drop dimension n in 3-d and 4-d output\n\
00199     Gt   - for 3-d 'd', transparent outer ridges\n\
00200 \n\
00201 Print options:\n\
00202     PAn  - keep n largest facets by area\n\
00203     Pdk:n - drop facet if normal[k] <= n (default 0.0)\n\
00204     PDk:n - drop facet if normal[k] >= n\n\
00205     Pg   - print good facets (needs 'QGn' or 'QVn')\n\
00206     PFn  - keep facets whose area is at least n\n\
00207     PG   - print neighbors of good facets\n\
00208     PMn  - keep n facets with most merges\n\
00209     Po   - force output.  If error, output neighborhood of facet\n\
00210     Pp   - do not report precision problems\n\
00211 \n\
00212     .    - list of all options\n\
00213     -    - one line descriptions of all options\n\
00214 ";
00215 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
00216 
00217 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00218   >-------------------------------</a><a name="prompt2">-</a>
00219 
00220   qh_prompt2
00221     synopsis for qhull
00222 */
00223 char qh_prompt2[]= "\n\
00224 qhull- compute convex hulls and related structures.  Qhull %s\n\
00225     input (stdin): dimension, n, point coordinates\n\
00226     comments start with a non-numeric character\n\
00227     halfspace: use dim+1 and put offsets after coefficients\n\
00228 \n\
00229 options (qh-quick.htm):\n\
00230     d    - Delaunay triangulation by lifting points to a paraboloid\n\
00231     d Qu - furthest-site Delaunay triangulation (upper convex hull)\n\
00232     v    - Voronoi diagram as the dual of the Delaunay triangulation\n\
00233     v Qu - furthest-site Voronoi diagram\n\
00234     H1,1 - Halfspace intersection about [1,1,0,...] via polar duality\n\
00235     Qt   - triangulated output\n\
00236     QJ   - joggled input instead of merged facets\n\
00237     Tv   - verify result: structure, convexity, and point inclusion\n\
00238     .    - concise list of all options\n\
00239     -    - one-line description of each option\n\
00240 \n\
00241 Output options (subset):\n\
00242     s    - summary of results (default)\n\
00243     i    - vertices incident to each facet\n\
00244     n    - normals with offsets\n\
00245     p    - vertex coordinates (if 'Qc', includes coplanar points)\n\
00246            if 'v', Voronoi vertices\n\
00247     Fp   - halfspace intersections\n\
00248     Fx   - extreme points (convex hull vertices)\n\
00249     FA   - compute total area and volume\n\
00250     o    - OFF format (if 'v', outputs Voronoi regions)\n\
00251     G    - Geomview output (2-d, 3-d and 4-d)\n\
00252     m    - Mathematica output (2-d and 3-d)\n\
00253     QVn  - print facets that include point n, -n if not\n\
00254     TO file- output results to file, may be enclosed in single quotes\n\
00255 \n\
00256 examples:\n\
00257     rbox c d D2 | qhull Qc s f Fx | more      rbox 1000 s | qhull Tv s FA\n\
00258     rbox 10 D2 | qhull d QJ s i TO result     rbox 10 D2 | qhull v Qbb Qt p\n\
00259     rbox 10 D2 | qhull d Qu QJ m              rbox 10 D2 | qhull v Qu QJ o\n\
00260     rbox c | qhull n                          rbox c | qhull FV n | qhull H Fp\n\
00261     rbox d D12 | qhull QR0 FA                 rbox c D7 | qhull FA TF1000\n\
00262     rbox y 1000 W0 | qhull                    rbox 10 | qhull v QJ o Fv\n\
00263 \n\
00264 ";
00265 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
00266 
00267 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00268   >-------------------------------</a><a name="prompt3">-</a>
00269 
00270   qh_prompt3
00271     concise prompt for qhull
00272 */
00273 char qh_prompt3[]= "\n\
00274 Qhull %s.\n\
00275 Except for 'F.' and 'PG', upper-case options take an argument.\n\
00276 \n\
00277  delaunay       voronoi        Geomview       Halfspace      facet_dump\n\
00278  incidences     mathematica    normals        OFF_format     points\n\
00279  summary\n\
00280 \n\
00281  Farea          FArea-total    Fcoplanars     FCentrums      Fd-cdd-in\n\
00282  FD-cdd-out     FF-dump-xridge Finner         FIDs           Fmerges\n\
00283  Fneighbors     FNeigh-vertex  Fouter         FOptions       Fpoint-intersect\n\
00284  FPoint_near    FQhull         Fsummary       FSize          Ftriangles\n\
00285  Fvertices      Fvoronoi       FVertex-ave    Fxtremes       FMaple\n\
00286 \n\
00287  Gvertices      Gpoints        Gall_points    Gno_planes     Ginner\n\
00288  Gcentrums      Ghyperplanes   Gridges        Gouter         GDrop_dim\n\
00289  Gtransparent\n\
00290 \n\
00291  PArea-keep     Pdrop d0:0D0   Pgood          PFacet_area_keep\n\
00292  PGood_neighbors PMerge-keep   Poutput_forced Pprecision_not\n\
00293 \n\
00294  QbBound 0:0.5  Qbk:0Bk:0_drop QbB-scale-box  Qbb-scale-last Qcoplanar\n\
00295  Qfurthest      Qgood_only     QGood_point    Qinterior      Qmax_out\n\
00296  QJoggle        Qrandom        QRotate        Qsearch_1st    Qtriangulate\n\
00297  QupperDelaunay QVertex_good   Qvneighbors    Qxact_merge    Qzinfinite\n\
00298 \n\
00299  Q0_no_premerge Q1_no_angle    Q2_no_independ Q3_no_redundant Q4_no_old\n\
00300  Q5_no_check_out Q6_no_concave Q7_depth_first Q8_no_near_in  Q9_pick_furthest\n\
00301  Q10_no_narrow  Q11_trinormals\n\
00302 \n\
00303  T4_trace       Tannotate      Tcheck_often   Tstatistics    Tverify\n\
00304  Tz_stdout      TFacet_log     TInput_file    TPoint_trace   TMerge_trace\n\
00305  TOutput_file   TRerun         TWide_trace    TVertex_stop   TCone_stop\n\
00306 \n\
00307  Angle_max      Centrum_size   Error_round    Random_dist    Visible_min\n\
00308  Ucoplanar_max  Wide_outside\n\
00309 ";
00310 
00311 /*-<a                             href="../libqhull/qh-qhull.htm#TOC"
00312   >-------------------------------</a><a name="main">-</a>
00313 
00314   main( argc, argv )
00315     processes the command line, calls qhull() to do the work, and exits
00316 
00317   design:
00318     initializes data structures
00319     reads points
00320     finishes initialization
00321     computes convex hull and other structures
00322     checks the result
00323     writes the output
00324     frees memory
00325 */
00326 int main(int argc, char *argv[]) {
00327   int curlong, totlong; /* used !qh_NOmem */
00328   int exitcode, numpoints, dim;
00329   coordT *points;
00330   boolT ismalloc;
00331 
00332 #if __MWERKS__ && __POWERPC__
00333   char inBuf[BUFSIZ], outBuf[BUFSIZ], errBuf[BUFSIZ];
00334   SIOUXSettings.showstatusline= false;
00335   SIOUXSettings.tabspaces= 1;
00336   SIOUXSettings.rows= 40;
00337   if (setvbuf(stdin, inBuf, _IOFBF, sizeof(inBuf)) < 0   /* w/o, SIOUX I/O is slow*/
00338   || setvbuf(stdout, outBuf, _IOFBF, sizeof(outBuf)) < 0
00339   || (stdout != stderr && setvbuf(stderr, errBuf, _IOFBF, sizeof(errBuf)) < 0))
00340     fprintf(stderr, "qhull internal warning (main): could not change stdio to fully buffered.\n");
00341   argc= ccommand(&argv);
00342 #endif
00343 
00344   if ((argc == 1) && isatty( 0 /*stdin*/)) {
00345     fprintf(stdout, qh_prompt2, qh_version);
00346     exit(qh_ERRnone);
00347   }
00348   if (argc > 1 && *argv[1] == '-' && !*(argv[1]+1)) {
00349     fprintf(stdout, qh_prompta, qh_version, qh_DEFAULTbox,
00350                 qh_promptb, qh_promptc, qh_promptd, qh_prompte);
00351     exit(qh_ERRnone);
00352   }
00353   if (argc >1 && *argv[1] == '.' && !*(argv[1]+1)) {
00354     fprintf(stdout, qh_prompt3, qh_version);
00355     exit(qh_ERRnone);
00356   }
00357   qh_init_A(stdin, stdout, stderr, argc, argv);  /* sets qh qhull_command */
00358   exitcode= setjmp(qh errexit); /* simple statement for CRAY J916 */
00359   if (!exitcode) {
00360     qh_initflags(qh qhull_command);
00361     points= qh_readpoints(&numpoints, &dim, &ismalloc);
00362     qh_init_B(points, numpoints, dim, ismalloc);
00363     qh_qhull();
00364     qh_check_output();
00365     qh_produce_output();
00366     if (qh VERIFYoutput && !qh FORCEoutput && !qh STOPpoint && !qh STOPcone)
00367       qh_check_points();
00368     exitcode= qh_ERRnone;
00369   }
00370   qh NOerrexit= True;  /* no more setjmp */
00371 #ifdef qh_NOmem
00372   qh_freeqhull( True);
00373 #else
00374   qh_freeqhull( False);
00375   qh_memfreeshort(&curlong, &totlong);
00376   if (curlong || totlong)
00377     fprintf(stderr, "qhull internal warning (main): did not free %d bytes of long memory(%d pieces)\n",
00378        totlong, curlong);
00379 #endif
00380   return exitcode;
00381 } /* main */
00382 


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