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


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