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