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


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