qhalf_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  qhalf.c
5  compute the intersection of halfspaces about a point
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 qhull
40 
41  notes:
42  restricted version of libqhull.c
43 
44  see:
45  concise prompt below
46 */
47 
48 /* duplicated in qhalf.htm */
49 char hidden_options[]=" d n v Qbb QbB Qf Qg Qm Qr QR Qv Qx Qz TR E V Fa FA FC FD FS Ft FV Gt Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 ";
50 
51 char qh_prompta[]= "\n\
52 qhalf- compute the intersection of halfspaces about a point\n\
53  http://www.qhull.org %s\n\
54 \n\
55 input (stdin):\n\
56  optional interior point: dimension, 1, coordinates\n\
57  first lines: dimension+1 and number of halfspaces\n\
58  other lines: halfspace coefficients followed by offset\n\
59  comments: start with a non-numeric character\n\
60 \n\
61 options:\n\
62  Hn,n - specify coordinates of interior point\n\
63  Qt - triangulated output\n\
64  QJ - joggled input instead of merged facets\n\
65  Qc - keep coplanar halfspaces\n\
66  Qi - keep other redundant halfspaces\n\
67 \n\
68 Qhull control options:\n\
69  QJn - randomly joggle input in range [-n,n]\n\
70 %s%s%s%s"; /* split up qh_prompt for Visual C++ */
71 char qh_promptb[]= "\
72  Qbk:0Bk:0 - remove k-th coordinate from input\n\
73  Qs - search all halfspaces for the initial simplex\n\
74  QGn - print intersection if visible to halfspace n, -n for not\n\
75  QVn - print intersections for halfspace n, -n if not\n\
76 \n\
77 ";
78 char qh_promptc[]= "\
79 Trace options:\n\
80  T4 - trace at level n, 4=all, 5=mem/gauss, -1= events\n\
81  Tc - check frequently during execution\n\
82  Ts - print statistics\n\
83  Tv - verify result: structure, convexity, and redundancy\n\
84  Tz - send all output to stdout\n\
85  TFn - report summary when n or more facets created\n\
86  TI file - input data from file, no spaces or single quotes\n\
87  TO file - output results to file, may be enclosed in single quotes\n\
88  TPn - turn on tracing when halfspace n added to intersection\n\
89  TMn - turn on tracing at merge n\n\
90  TWn - trace merge facets when width > n\n\
91  TVn - stop qhull after adding halfspace n, -n for before (see TCn)\n\
92  TCn - stop qhull after building cone for halfspace n (see TVn)\n\
93 \n\
94 Precision options:\n\
95  Cn - radius of centrum (roundoff added). Merge facets if non-convex\n\
96  An - cosine of maximum angle. Merge facets if cosine > n or non-convex\n\
97  C-0 roundoff, A-0.99/C-0.01 pre-merge, A0.99/C0.01 post-merge\n\
98  Rn - randomly perturb computations by a factor of [1-n,1+n]\n\
99  Un - max distance below plane for a new, coplanar halfspace\n\
100  Wn - min facet width for outside halfspace (before roundoff)\n\
101 \n\
102 Output formats (may be combined; if none, produces a summary to stdout):\n\
103  f - facet dump\n\
104  G - Geomview output (dual convex hull)\n\
105  i - non-redundant halfspaces incident to each intersection\n\
106  m - Mathematica output (dual convex hull)\n\
107  o - OFF format (dual convex hull: dimension, points, and facets)\n\
108  p - vertex coordinates of dual convex hull (coplanars if 'Qc' or 'Qi')\n\
109  s - summary (stderr)\n\
110 \n\
111 ";
112 char qh_promptd[]= "\
113 More formats:\n\
114  Fc - count plus redundant halfspaces for each intersection\n\
115  - Qc (default) for coplanar and Qi for other redundant\n\
116  Fd - use cdd format for input (homogeneous with offset first)\n\
117  FF - facet dump without ridges\n\
118  FI - ID of each intersection\n\
119  Fm - merge count for each intersection (511 max)\n\
120  FM - Maple output (dual convex hull)\n\
121  Fn - count plus neighboring intersections for each intersection\n\
122  FN - count plus intersections for each non-redundant halfspace\n\
123  FO - options and precision constants\n\
124  Fp - dim, count, and intersection coordinates\n\
125  FP - nearest halfspace and distance for each redundant halfspace\n\
126  FQ - command used for qhalf\n\
127  Fs - summary: #int (8), dim, #halfspaces, #non-redundant, #intersections\n\
128  for output: #non-redundant, #intersections, #coplanar\n\
129  halfspaces, #non-simplicial intersections\n\
130  #real (2), max outer plane, min vertex\n\
131  Fv - count plus non-redundant halfspaces for each intersection\n\
132  Fx - non-redundant halfspaces\n\
133 \n\
134 ";
135 char qh_prompte[]= "\
136 Geomview output (2-d, 3-d and 4-d; dual convex hull)\n\
137  Ga - all points (i.e., transformed halfspaces) as dots\n\
138  Gp - coplanar points and vertices as radii\n\
139  Gv - vertices (i.e., non-redundant halfspaces) as spheres\n\
140  Gi - inner planes (i.e., halfspace intersections) only\n\
141  Gn - no planes\n\
142  Go - outer planes only\n\
143  Gc - centrums\n\
144  Gh - hyperplane intersections\n\
145  Gr - ridges\n\
146  GDn - drop dimension n in 3-d and 4-d output\n\
147 \n\
148 Print options:\n\
149  PAn - keep n largest facets (i.e., intersections) by area\n\
150  Pdk:n- drop facet if normal[k] <= n (default 0.0)\n\
151  PDk:n- drop facet if normal[k] >= n\n\
152  Pg - print good facets (needs 'QGn' or 'QVn')\n\
153  PFn - keep facets whose area is at least n\n\
154  PG - print neighbors of good facets\n\
155  PMn - keep n facets with most merges\n\
156  Po - force output. If error, output neighborhood of facet\n\
157  Pp - do not report precision problems\n\
158 \n\
159  . - list of all options\n\
160  - - one line descriptions of all options\n\
161  -V - version\n\
162 ";
163 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
164 
165 /*-<a href="../libqhull/qh-qhull.htm#TOC"
166  >-------------------------------</a><a name="prompt2">-</a>
167 
168  qh_prompt2
169  synopsis for qhull
170 */
171 char qh_prompt2[]= "\n\
172 qhalf- halfspace intersection about a point. Qhull %s\n\
173  input (stdin): [dim, 1, interior point], dim+1, n, coefficients+offset\n\
174  comments start with a non-numeric character\n\
175 \n\
176 options (qhalf.htm):\n\
177  Hn,n - specify coordinates of interior point\n\
178  Qt - triangulated output\n\
179  QJ - joggled input instead of merged facets\n\
180  Tv - verify result: structure, convexity, and redundancy\n\
181  . - concise list of all options\n\
182  - - one-line description of all options\n\
183  -V - version\n\
184 \n\
185 output options (subset):\n\
186  s - summary of results (default)\n\
187  Fp - intersection coordinates\n\
188  Fv - non-redundant halfspaces incident to each intersection\n\
189  Fx - non-redundant halfspaces\n\
190  o - OFF file format (dual convex hull)\n\
191  G - Geomview output (dual convex hull)\n\
192  m - Mathematica output (dual convex hull)\n\
193  QVn - print intersections for halfspace n, -n if not\n\
194  TO file - output results to file, may be enclosed in single quotes\n\
195 \n\
196 examples:\n\
197  rbox d | qconvex FQ n | qhalf s H0,0,0 Fp\n\
198  rbox c | qconvex FQ FV n | qhalf s i\n\
199  rbox c | qconvex FQ FV n | qhalf s o\n\
200 \n\
201 ";
202 /* for opts, don't assign 'e' or 'E' to a flag (already used for exponent) */
203 
204 /*-<a href="../libqhull/qh-qhull.htm#TOC"
205  >-------------------------------</a><a name="prompt3">-</a>
206 
207  qh_prompt3
208  concise prompt for qhull
209 */
210 char qh_prompt3[]= "\n\
211 Qhull %s.\n\
212 Except for 'F.' and 'PG', upper_case options take an argument.\n\
213 \n\
214  incidences Geomview mathematica OFF_format point_dual\n\
215  summary facet_dump\n\
216 \n\
217  Fc_redundant Fd_cdd_in FF_dump_xridge FIDs Fmerges\n\
218  Fneighbors FN_intersect FOptions Fp_coordinates FP_nearest\n\
219  FQhalf Fsummary Fv_halfspace FMaple Fx_non_redundant\n\
220 \n\
221  Gvertices Gpoints Gall_points Gno_planes Ginner\n\
222  Gcentrums Ghyperplanes Gridges Gouter GDrop_dim\n\
223 \n\
224  PArea_keep Pdrop d0:0D0 Pgood PFacet_area_keep\n\
225  PGood_neighbors PMerge_keep Poutput_forced Pprecision_not\n\
226 \n\
227  Qbk:0Bk:0_drop Qcoplanar QG_half_good Qi_redundant QJoggle\n\
228  Qsearch_1st Qtriangulate QVertex_good\n\
229 \n\
230  T4_trace Tcheck_often Tstatistics Tverify Tz_stdout\n\
231  TFacet_log TInput_file TPoint_trace TMerge_trace TOutput_file\n\
232  TWide_trace TVertex_stop TCone_stop\n\
233 \n\
234  Angle_max Centrum_size Random_dist Ucoplanar_max Wide_outside\n\
235 ";
236 
237 /*-<a href="../libqhull/qh-qhull.htm#TOC"
238  >-------------------------------</a><a name="main">-</a>
239 
240  main( argc, argv )
241  processes the command line, calls qhull() to do the work, and exits
242 
243  design:
244  initializes data structures
245  reads points
246  finishes initialization
247  computes convex hull and other structures
248  checks the result
249  writes the output
250  frees memory
251 */
252 int main(int argc, char *argv[]) {
253  int curlong, totlong; /* used !qh_NOmem */
254  int exitcode, numpoints, dim;
255  coordT *points;
256  boolT ismalloc;
257  qhT qh_qh;
258  qhT *qh= &qh_qh;
259 
260  QHULL_LIB_CHECK /* Check for compatible library */
261 
262  if ((argc == 1) && isatty( 0 /*stdin*/)) {
263  fprintf(stdout, qh_prompt2, qh_version);
264  exit(qh_ERRnone);
265  }
266  if (argc > 1 && *argv[1] == '-' && !*(argv[1]+1)) {
267  fprintf(stdout, qh_prompta, qh_version,
269  exit(qh_ERRnone);
270  }
271  if (argc > 1 && *argv[1] == '.' && !*(argv[1]+1)) {
272  fprintf(stdout, qh_prompt3, qh_version);
273  exit(qh_ERRnone);
274  }
275  if (argc > 1 && *argv[1] == '-' && *(argv[1]+1)=='V') {
276  fprintf(stdout, "%s\n", qh_version2);
277  exit(qh_ERRnone);
278  }
279  qh_init_A(qh, stdin, stdout, stderr, argc, argv); /* sets qh->qhull_command */
280  exitcode= setjmp(qh->errexit); /* simple statement for CRAY J916 */
281  if (!exitcode) {
282  qh->NOerrexit = False;
283  qh_option(qh, "Halfspace", NULL, NULL);
284  qh->HALFspace= True; /* 'H' */
285  qh_checkflags(qh, qh->qhull_command, hidden_options);
286  qh_initflags(qh, qh->qhull_command);
287  if (qh->SCALEinput) {
288  fprintf(qh->ferr, "\
289 qhull error: options 'Qbk:n' and 'QBk:n' are not used with qhalf.\n\
290  Use 'Qbk:0Bk:0 to drop dimension k.\n");
291  qh_errexit(qh, qh_ERRinput, NULL, NULL);
292  }
293  points= qh_readpoints(qh, &numpoints, &dim, &ismalloc);
294  if (dim >= 5) {
295  qh_option(qh, "Qxact_merge", NULL, NULL);
296  qh->MERGEexact= True; /* 'Qx' always */
297  }
298  qh_init_B(qh, points, numpoints, dim, ismalloc);
299  qh_qhull(qh);
302  if (qh->VERIFYoutput && !qh->FORCEoutput && !qh->STOPpoint && !qh->STOPcone)
304  exitcode= qh_ERRnone;
305  }
306  qh->NOerrexit= True; /* no more setjmp */
307 #ifdef qh_NOmem
309 #else
311  qh_memfreeshort(qh, &curlong, &totlong);
312  if (curlong || totlong)
313  qh_fprintf_stderr(6263, "qhull internal warning (main): did not free %d bytes of long memory(%d pieces)\n",
314  totlong, curlong);
315 #endif
316  return exitcode;
317 } /* main */
318 
qh_ERRinput
#define qh_ERRinput
Definition: libqhull.h:194
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
hidden_options
char hidden_options[]
Definition: qhalf_r.c:49
isatty
int isatty(int)
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_promptc
char qh_promptc[]
Definition: qhalf_r.c:78
qh_check_output
void qh_check_output(void)
Definition: poly2.c:302
qh_checkflags
void qh_checkflags(char *command, char *hiddenflags)
Definition: global.c:86
qhT
Definition: libqhull.h:465
qh_version2
const char qh_version2[]
Definition: global.c:51
qh_prompt3
char qh_prompt3[]
Definition: qhalf_r.c:210
qh_prompte
char qh_prompte[]
Definition: qhalf_r.c:135
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
main
int main(int argc, char *argv[])
Definition: qhalf_r.c:252
qh_ERRnone
#define qh_ERRnone
Definition: libqhull.h:193
dim
int dim
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
libqhull_r.h
qh
#define qh
Definition: libqhull.h:457
qh_freeqhull
void qh_freeqhull(boolT allmem)
Definition: global.c:425
qh_errexit
void qh_errexit(int exitcode, facetT *facet, ridgeT *ridge)
Definition: user.c:213
qh_option
void qh_option(const char *option, int *i, realT *r)
Definition: global.c:2115
qh_readpoints
coordT * qh_readpoints(int *numpoints, int *dimension, boolT *ismalloc)
Definition: io.c:3673
qh_prompt2
char qh_prompt2[]
Definition: qhalf_r.c:171
qh_promptd
char qh_promptd[]
Definition: qhalf_r.c:112
qh_produce_output
void qh_produce_output(void)
Definition: io.c:39
qh_qhull
void qh_qhull(void)
Definition: libqhull.c:60
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_prompta
char qh_prompta[]
Definition: qhalf_r.c:51
qh_init_B
void qh_init_B(coordT *points, int numpoints, int dim, boolT ismalloc)
Definition: global.c:534
qh_promptb
char qh_promptb[]
Definition: qhalf_r.c:71
True
#define True
Definition: libqhull.h:129


hpp-fcl
Author(s):
autogenerated on Fri Jan 26 2024 03:46:14