~ubuntu-branches/ubuntu/trusty/qhull/trusty-proposed

« back to all changes in this revision

Viewing changes to src/qvoronoi/qvoronoi.c

  • Committer: Package Import Robot
  • Author(s): Barak A. Pearlmutter
  • Date: 2014-02-13 11:09:12 UTC
  • mfrom: (8.1.4 sid)
  • Revision ID: package-import@ubuntu.com-20140213110912-ifwyxorlsnnl1ebh
Tags: 2012.1-4
Add convenience link to #include <qhull/qhull.h> to simplify transition.

Show diffs side-by-side

added added

removed removed

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