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


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:01