unix.c
Go to the documentation of this file.
1 /*<html><pre> -<a href="../libqhull/qh-qhull.htm"
2  >-------------------------------</a><a name="TOP">-</a>
3 
4  unix.c
5  command line interface to qhull
6  includes SIOUX interface for Macintoshes
7 
8  see qh-qhull.htm
9 
10  Copyright (c) 1993-2015 The Geometry Center.
11  $Id: //main/2015/qhull/src/qhull/unix.c#4 $$Change: 2066 $
12  $DateTime: 2016/01/18 19:29:17 $$Author: bbarber $
13 */
14 
15 #include "libqhull/libqhull.h"
16 #include "libqhull/qset.h"
17 
18 #include <ctype.h>
19 #include <math.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #if __cplusplus
25 extern "C" {
26  int isatty(int);
27 }
28 
29 #elif _MSC_VER
30 #include <io.h>
31 #define isatty _isatty
32 /* int _isatty(int); */
33 
34 #else
35 int isatty(int); /* returns 1 if stdin is a tty
36  if "Undefined symbol" this can be deleted along with call in main() */
37 #endif
38 
39 /*-<a href="../libqhull/qh-qhull.htm#TOC"
40  >-------------------------------</a><a name="prompt">-</a>
41 
42  qh_prompt
43  long prompt for qhull
44 
45  see:
46  concise prompt below
47 */
48 char qh_prompta[]= "\n\
49 qhull- compute convex hulls and related structures.\n\
50  http://www.qhull.org %s\n\
51 \n\
52 input (stdin):\n\
53  first lines: dimension and number of points (or vice-versa).\n\
54  other lines: point coordinates, best if one point per line\n\
55  comments: start with a non-numeric character\n\
56  halfspaces: use dim plus one and put offset after coefficients.\n\
57  May be preceded by a single interior point ('H').\n\
58 \n\
59 options:\n\
60  d - Delaunay triangulation by lifting points to a paraboloid\n\
61  d Qu - furthest-site Delaunay triangulation (upper convex hull)\n\
62  v - Voronoi diagram (dual of the Delaunay triangulation)\n\
63  v Qu - furthest-site Voronoi diagram\n\
64  Hn,n,... - halfspace intersection about point [n,n,0,...]\n\
65  Qt - triangulated output\n\
66  QJ - joggled input instead of merged facets\n\
67  Qc - keep coplanar points with nearest facet\n\
68  Qi - keep interior points with nearest facet\n\
69 \n\
70 Qhull control options:\n\
71  Qbk:n - scale coord k so that low bound is n\n\
72  QBk:n - scale coord k so that upper bound is n (QBk is %2.2g)\n\
73  QbB - scale input to unit cube centered at the origin\n\
74  Qbb - scale last coordinate to [0,m] for Delaunay triangulations\n\
75  Qbk:0Bk:0 - remove k-th coordinate from input\n\
76  QJn - randomly joggle input in range [-n,n]\n\
77  QRn - random rotation (n=seed, n=0 time, n=-1 time/no rotate)\n\
78 %s%s%s%s"; /* split up qh_prompt for Visual C++ */
79 char qh_promptb[]= "\
80  Qf - partition point to furthest outside facet\n\
81  Qg - only build good facets (needs 'QGn', 'QVn', or 'PdD')\n\
82  Qm - only process points that would increase max_outside\n\
83  Qr - process random outside points instead of furthest ones\n\
84  Qs - search all points for the initial simplex\n\
85  Qu - for 'd' or 'v', compute upper hull without point at-infinity\n\
86  returns furthest-site Delaunay triangulation\n\
87  Qv - test vertex neighbors for convexity\n\
88  Qx - exact pre-merges (skips coplanar and angle-coplanar facets)\n\
89  Qz - add point-at-infinity to Delaunay triangulation\n\
90  QGn - good facet if visible from point n, -n for not visible\n\
91  QVn - good facet if it includes point n, -n if not\n\
92  Q0 - turn off default premerge with 'C-0'/'Qx'\n\
93  Q1 - sort merges by type instead of angle\n\
94  Q2 - merge all non-convex at once instead of independent sets\n\
95  Q3 - do not merge redundant vertices\n\
96  Q4 - avoid old->new merges\n\
97  Q5 - do not correct outer planes at end of qhull\n\
98  Q6 - do not pre-merge concave or coplanar facets\n\
99  Q7 - depth-first processing instead of breadth-first\n\
100  Q8 - do not process near-inside points\n\
101  Q9 - process furthest of furthest points\n\
102  Q10 - no special processing for narrow distributions\n\
103  Q11 - copy normals and recompute centrums for tricoplanar facets\n\
104  Q12 - no error on wide merge due to duplicate ridge\n\
105 \n\
106 ";
107 char qh_promptc[]= "\
108 Topts- Trace options:\n\
109  T4 - trace at level n, 4=all, 5=mem/gauss, -1= events\n\
110  Ta - annotate output with message codes\n\
111  Tc - check frequently during execution\n\
112  Ts - print statistics\n\
113  Tv - verify result: structure, convexity, and point inclusion\n\
114  Tz - send all output to stdout\n\
115  TFn - report summary when n or more facets created\n\
116  TI file - input data from file, no spaces or single quotes\n\
117  TO file - output results to file, may be enclosed in single quotes\n\
118  TPn - turn on tracing when point n added to hull\n\
119  TMn - turn on tracing at merge n\n\
120  TWn - trace merge facets when width > n\n\
121  TRn - rerun qhull n times. Use with 'QJn'\n\
122  TVn - stop qhull after adding point n, -n for before (see TCn)\n\
123  TCn - stop qhull after building cone for point n (see TVn)\n\
124 \n\
125 Precision options:\n\
126  Cn - radius of centrum (roundoff added). Merge facets if non-convex\n\
127  An - cosine of maximum angle. Merge facets if cosine > n or non-convex\n\
128  C-0 roundoff, A-0.99/C-0.01 pre-merge, A0.99/C0.01 post-merge\n\
129  En - max roundoff error for distance computation\n\
130  Rn - randomly perturb computations by a factor of [1-n,1+n]\n\
131  Vn - min distance above plane for a visible facet (default 3C-n or En)\n\
132  Un - max distance below plane for a new, coplanar point (default Vn)\n\
133  Wn - min facet width for outside point (before roundoff, default 2Vn)\n\
134 \n\
135 Output formats (may be combined; if none, produces a summary to stdout):\n\
136  f - facet dump\n\
137  G - Geomview output (see below)\n\
138  i - vertices incident to each facet\n\
139  m - Mathematica output (2-d and 3-d)\n\
140  o - OFF format (dim, points and facets; Voronoi regions)\n\
141  n - normals with offsets\n\
142  p - vertex coordinates or Voronoi vertices (coplanar points if 'Qc')\n\
143  s - summary (stderr)\n\
144 \n\
145 ";
146 char qh_promptd[]= "\
147 More formats:\n\
148  Fa - area for each facet\n\
149  FA - compute total area and volume for option 's'\n\
150  Fc - count plus coplanar points for each facet\n\
151  use 'Qc' (default) for coplanar and 'Qi' for interior\n\
152  FC - centrum or Voronoi center for each facet\n\
153  Fd - use cdd format for input (homogeneous with offset first)\n\
154  FD - use cdd format for numeric output (offset first)\n\
155  FF - facet dump without ridges\n\
156  Fi - inner plane for each facet\n\
157  for 'v', separating hyperplanes for bounded Voronoi regions\n\
158  FI - ID of each facet\n\
159  Fm - merge count for each facet (511 max)\n\
160  FM - Maple output (2-d and 3-d)\n\
161  Fn - count plus neighboring facets for each facet\n\
162  FN - count plus neighboring facets for each point\n\
163  Fo - outer plane (or max_outside) for each facet\n\
164  for 'v', separating hyperplanes for unbounded Voronoi regions\n\
165  FO - options and precision constants\n\
166  Fp - dim, count, and intersection coordinates (halfspace only)\n\
167  FP - nearest vertex and distance for each coplanar point\n\
168  FQ - command used for qhull\n\
169  Fs - summary: #int (8), dimension, #points, tot vertices, tot facets,\n\
170  output: #vertices, #facets, #coplanars, #nonsimplicial\n\
171  #real (2), max outer plane, min vertex\n\
172  FS - sizes: #int (0)\n\
173  #real (2) tot area, tot volume\n\
174  Ft - triangulation with centrums for non-simplicial facets (OFF format)\n\
175  Fv - count plus vertices for each facet\n\
176  for 'v', Voronoi diagram as Voronoi vertices for pairs of sites\n\
177  FV - average of vertices (a feasible point for 'H')\n\
178  Fx - extreme points (in order for 2-d)\n\
179 \n\
180 ";
181 char qh_prompte[]= "\
182 Geomview options (2-d, 3-d, and 4-d; 2-d Voronoi)\n\
183  Ga - all points as dots\n\
184  Gp - coplanar points and vertices as radii\n\
185  Gv - vertices as spheres\n\
186  Gi - inner planes only\n\
187  Gn - no planes\n\
188  Go - outer planes only\n\
189  Gc - centrums\n\
190  Gh - hyperplane intersections\n\
191  Gr - ridges\n\
192  GDn - drop dimension n in 3-d and 4-d output\n\
193  Gt - for 3-d 'd', transparent outer ridges\n\
194 \n\
195 Print options:\n\
196  PAn - keep n largest facets by area\n\
197  Pdk:n - drop facet if normal[k] <= n (default 0.0)\n\
198  PDk:n - drop facet if normal[k] >= n\n\
199  Pg - print good facets (needs 'QGn' or 'QVn')\n\
200  PFn - keep facets whose area is at least n\n\
201  PG - print neighbors of good facets\n\
202  PMn - keep n facets with most merges\n\
203  Po - force output. If error, output neighborhood of facet\n\
204  Pp - do not report precision problems\n\
205 \n\
206  . - list of all options\n\
207  - - one line descriptions of all options\n\
208  -V - version\n\
209 ";
210 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
211 
212 /*-<a href="../libqhull/qh-qhull.htm#TOC"
213  >-------------------------------</a><a name="prompt2">-</a>
214 
215  qh_prompt2
216  synopsis for qhull
217 */
218 char qh_prompt2[]= "\n\
219 qhull- compute convex hulls and related structures. Qhull %s\n\
220  input (stdin): dimension, n, point coordinates\n\
221  comments start with a non-numeric character\n\
222  halfspace: use dim+1 and put offsets after coefficients\n\
223 \n\
224 options (qh-quick.htm):\n\
225  d - Delaunay triangulation by lifting points to a paraboloid\n\
226  d Qu - furthest-site Delaunay triangulation (upper convex hull)\n\
227  v - Voronoi diagram as the dual of the Delaunay triangulation\n\
228  v Qu - furthest-site Voronoi diagram\n\
229  H1,1 - Halfspace intersection about [1,1,0,...] via polar duality\n\
230  Qt - triangulated output\n\
231  QJ - joggled input instead of merged facets\n\
232  Tv - verify result: structure, convexity, and point inclusion\n\
233  . - concise list of all options\n\
234  - - one-line description of each option\n\
235  -V - version\n\
236 \n\
237 Output options (subset):\n\
238  s - summary of results (default)\n\
239  i - vertices incident to each facet\n\
240  n - normals with offsets\n\
241  p - vertex coordinates (if 'Qc', includes coplanar points)\n\
242  if 'v', Voronoi vertices\n\
243  Fp - halfspace intersections\n\
244  Fx - extreme points (convex hull vertices)\n\
245  FA - compute total area and volume\n\
246  o - OFF format (if 'v', outputs Voronoi regions)\n\
247  G - Geomview output (2-d, 3-d and 4-d)\n\
248  m - Mathematica output (2-d and 3-d)\n\
249  QVn - print facets that include point n, -n if not\n\
250  TO file- output results to file, may be enclosed in single quotes\n\
251 \n\
252 examples:\n\
253  rbox D4 | qhull Tv rbox 1000 s | qhull Tv s FA\n\
254  rbox 10 D2 | qhull d QJ s i TO result rbox 10 D2 | qhull v Qbb Qt p\n\
255  rbox 10 D2 | qhull d Qu QJ m rbox 10 D2 | qhull v Qu QJ o\n\
256  rbox c d D2 | qhull Qc s f Fx | more rbox c | qhull FV n | qhull H Fp\n\
257  rbox d D12 | qhull QR0 FA rbox c D7 | qhull FA TF1000\n\
258  rbox y 1000 W0 | qhull rbox c | qhull n\n\
259 \n\
260 ";
261 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
262 
263 /*-<a href="../libqhull/qh-qhull.htm#TOC"
264  >-------------------------------</a><a name="prompt3">-</a>
265 
266  qh_prompt3
267  concise prompt for qhull
268 */
269 char qh_prompt3[]= "\n\
270 Qhull %s.\n\
271 Except for 'F.' and 'PG', upper-case options take an argument.\n\
272 \n\
273  delaunay voronoi Geomview Halfspace facet_dump\n\
274  incidences mathematica normals OFF_format points\n\
275  summary\n\
276 \n\
277  Farea FArea-total Fcoplanars FCentrums Fd-cdd-in\n\
278  FD-cdd-out FF-dump-xridge Finner FIDs Fmerges\n\
279  Fneighbors FNeigh-vertex Fouter FOptions Fpoint-intersect\n\
280  FPoint_near FQhull Fsummary FSize Ftriangles\n\
281  Fvertices Fvoronoi FVertex-ave Fxtremes FMaple\n\
282 \n\
283  Gvertices Gpoints Gall_points Gno_planes Ginner\n\
284  Gcentrums Ghyperplanes Gridges Gouter GDrop_dim\n\
285  Gtransparent\n\
286 \n\
287  PArea-keep Pdrop d0:0D0 Pgood PFacet_area_keep\n\
288  PGood_neighbors PMerge-keep Poutput_forced Pprecision_not\n\
289 \n\
290  QbBound 0:0.5 Qbk:0Bk:0_drop QbB-scale-box Qbb-scale-last Qcoplanar\n\
291  Qfurthest Qgood_only QGood_point Qinterior Qmax_out\n\
292  QJoggle Qrandom QRotate Qsearch_1st Qtriangulate\n\
293  QupperDelaunay QVertex_good Qvneighbors Qxact_merge Qzinfinite\n\
294 \n\
295  Q0_no_premerge Q1_no_angle Q2_no_independ Q3_no_redundant Q4_no_old\n\
296  Q5_no_check_out Q6_no_concave Q7_depth_first Q8_no_near_in Q9_pick_furthest\n\
297  Q10_no_narrow Q11_trinormals Q12_no_wide_dup\n\
298 \n\
299  T4_trace Tannotate Tcheck_often Tstatistics Tverify\n\
300  Tz_stdout TFacet_log TInput_file TPoint_trace TMerge_trace\n\
301  TOutput_file TRerun TWide_trace TVertex_stop TCone_stop\n\
302 \n\
303  Angle_max Centrum_size Error_round Random_dist Visible_min\n\
304  Ucoplanar_max Wide_outside\n\
305 ";
306 
307 /*-<a href="../libqhull/qh-qhull.htm#TOC"
308  >-------------------------------</a><a name="main">-</a>
309 
310  main( argc, argv )
311  processes the command line, calls qhull() to do the work, and exits
312 
313  design:
314  initializes data structures
315  reads points
316  finishes initialization
317  computes convex hull and other structures
318  checks the result
319  writes the output
320  frees memory
321 */
322 int main(int argc, char *argv[]) {
323  int curlong, totlong; /* used !qh_NOmem */
324  int exitcode, numpoints, dim;
325  coordT *points;
326  boolT ismalloc;
327 
328  QHULL_LIB_CHECK /* Check for compatible library */
329 
330  if ((argc == 1) && isatty( 0 /*stdin*/)) {
331  fprintf(stdout, qh_prompt2, qh_version);
332  exit(qh_ERRnone);
333  }
334  if (argc > 1 && *argv[1] == '-' && !*(argv[1]+1)) {
335  fprintf(stdout, qh_prompta, qh_version, qh_DEFAULTbox,
337  exit(qh_ERRnone);
338  }
339  if (argc > 1 && *argv[1] == '.' && !*(argv[1]+1)) {
340  fprintf(stdout, qh_prompt3, qh_version);
341  exit(qh_ERRnone);
342  }
343  if (argc > 1 && *argv[1] == '-' && *(argv[1]+1)=='V') {
344  fprintf(stdout, "%s\n", qh_version2);
345  exit(qh_ERRnone);
346  }
347  qh_init_A(stdin, stdout, stderr, argc, argv); /* sets qh qhull_command */
348  exitcode= setjmp(qh errexit); /* simple statement for CRAY J916 */
349  if (!exitcode) {
350  qh_initflags(qh qhull_command);
351  points= qh_readpoints(&numpoints, &dim, &ismalloc);
352  qh_init_B(points, numpoints, dim, ismalloc);
353  qh_qhull();
354  qh_check_output();
356  if (qh VERIFYoutput && !qh FORCEoutput && !qh STOPpoint && !qh STOPcone)
357  qh_check_points();
358  exitcode= qh_ERRnone;
359  }
360  qh NOerrexit= True; /* no more setjmp */
361 #ifdef qh_NOmem
363 #else
364  qh_freeqhull( !qh_ALL);
365  qh_memfreeshort(&curlong, &totlong);
366  if (curlong || totlong)
367  qh_fprintf_stderr(6263, "qhull internal warning (main): did not free %d bytes of long memory(%d pieces)\n",
368  totlong, curlong);
369 #endif
370  return exitcode;
371 } /* main */
372 
qh_prompt2
char qh_prompt2[]
Definition: unix.c:218
qh_version
const char qh_version[]
Definition: global.c:50
QHULL_LIB_CHECK
#define QHULL_LIB_CHECK
Definition: libqhull.h:462
coordT
#define coordT
Definition: libqhull.h:80
qh_DEFAULTbox
#define qh_DEFAULTbox
Definition: user.h:486
qh_fprintf_stderr
void qh_fprintf_stderr(int msgcode, const char *fmt,...)
Definition: usermem.c:57
qh_ALL
#define qh_ALL
Definition: libqhull.h:180
qh_check_output
void qh_check_output(void)
Definition: poly2.c:302
qh_version2
const char qh_version2[]
Definition: global.c:51
libqhull.h
boolT
#define boolT
Definition: libqhull.h:121
qh_check_points
void qh_check_points(void)
Definition: poly2.c:365
qh_ERRnone
#define qh_ERRnone
Definition: libqhull.h:193
isatty
int isatty(int)
qh_init_A
void qh_init_A(FILE *infile, FILE *outfile, FILE *errfile, int argc, char *argv[])
Definition: global.c:487
qh
#define qh
Definition: libqhull.h:457
qh_freeqhull
void qh_freeqhull(boolT allmem)
Definition: global.c:425
qh_prompt3
char qh_prompt3[]
Definition: unix.c:269
qh_promptd
char qh_promptd[]
Definition: unix.c:146
qh_promptc
char qh_promptc[]
Definition: unix.c:107
qh_readpoints
coordT * qh_readpoints(int *numpoints, int *dimension, boolT *ismalloc)
Definition: io.c:3673
qh_promptb
char qh_promptb[]
Definition: unix.c:79
qh_produce_output
void qh_produce_output(void)
Definition: io.c:39
main
int main(int argc, char *argv[])
Definition: unix.c:322
qh_qhull
void qh_qhull(void)
Definition: libqhull.c:60
qh_memfreeshort
void qh_memfreeshort(int *curlong, int *totlong)
Definition: mem.c:288
qh_prompta
char qh_prompta[]
Definition: unix.c:48
qh_initflags
void qh_initflags(char *command)
Definition: global.c:615
io.h
qh_prompte
char qh_prompte[]
Definition: unix.c:181
qset.h
dim
int dim
qh_init_B
void qh_init_B(coordT *points, int numpoints, int dim, boolT ismalloc)
Definition: global.c:534
True
#define True
Definition: libqhull.h:129


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:15