qvoronoi.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/libqhull.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 
249  QHULL_LIB_CHECK /* Check for compatible library */
250 
251  if ((argc == 1) && isatty( 0 /*stdin*/)) {
252  fprintf(stdout, qh_prompt2, qh_version);
253  exit(qh_ERRnone);
254  }
255  if (argc > 1 && *argv[1] == '-' && !*(argv[1]+1)) {
256  fprintf(stdout, qh_prompta, qh_version,
258  exit(qh_ERRnone);
259  }
260  if (argc > 1 && *argv[1] == '.' && !*(argv[1]+1)) {
261  fprintf(stdout, qh_prompt3, qh_version);
262  exit(qh_ERRnone);
263  }
264  if (argc > 1 && *argv[1] == '-' && *(argv[1]+1)=='V') {
265  fprintf(stdout, "%s\n", qh_version2);
266  exit(qh_ERRnone);
267  }
268  qh_init_A(stdin, stdout, stderr, argc, argv); /* sets qh qhull_command */
269  exitcode= setjmp(qh errexit); /* simple statement for CRAY J916 */
270  if (!exitcode) {
271  qh NOerrexit= False;
272  qh_option("voronoi _bbound-last _coplanar-keep", NULL, NULL);
273  qh DELAUNAY= True; /* 'v' */
274  qh VORONOI= True;
275  qh SCALElast= True; /* 'Qbb' */
276  qh_checkflags(qh qhull_command, hidden_options);
277  qh_initflags(qh qhull_command);
278  points= qh_readpoints(&numpoints, &dim, &ismalloc);
279  if (dim >= 5) {
280  qh_option("_merge-exact", NULL, NULL);
281  qh MERGEexact= True; /* 'Qx' always */
282  }
283  qh_init_B(points, numpoints, dim, ismalloc);
284  qh_qhull();
285  qh_check_output();
287  if (qh VERIFYoutput && !qh FORCEoutput && !qh STOPpoint && !qh STOPcone)
288  qh_check_points();
289  exitcode= qh_ERRnone;
290  }
291  qh NOerrexit= True; /* no more setjmp */
292 #ifdef qh_NOmem
294 #else
296  qh_memfreeshort(&curlong, &totlong);
297  if (curlong || totlong)
298  qh_fprintf_stderr(6263, "qhull internal warning (main): did not free %d bytes of long memory(%d pieces)\n",
299  totlong, curlong);
300 #endif
301  return exitcode;
302 } /* main */
303 
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_promptc
char qh_promptc[]
Definition: qvoronoi.c:75
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_promptd
char qh_promptd[]
Definition: qvoronoi.c:106
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
main
int main(int argc, char *argv[])
Definition: qvoronoi.c:243
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_promptb
char qh_promptb[]
Definition: qvoronoi.c:69
hidden_options
char hidden_options[]
Definition: qvoronoi.c:52
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
#define qh
Definition: libqhull.h:457
qh_freeqhull
void qh_freeqhull(boolT allmem)
Definition: global.c:425
qh_prompte
char qh_prompte[]
Definition: qvoronoi.c:129
qh_option
void qh_option(const char *option, int *i, realT *r)
Definition: global.c:2115
qh_prompt2
char qh_prompt2[]
Definition: qvoronoi.c:165
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_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: qvoronoi.c:54
dim
int dim
qh_init_B
void qh_init_B(coordT *points, int numpoints, int dim, boolT ismalloc)
Definition: global.c:534
isatty
int isatty(int)
qh_prompt3
char qh_prompt3[]
Definition: qvoronoi.c:203
True
#define True
Definition: libqhull.h:129


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