Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

unix.c

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

Powered by Plone

This site conforms to the following standards: