1 /*<html><pre>  -<a                             href="qh-stat.htm"
2   >-------------------------------</a><a name="TOP">-</a>
3 
4    stat.c
5    contains all statistics that are collected for qhull
6 
7    see qh-stat.htm and stat.h
8 
9    Copyright (c) 1993-2020 The Geometry Center.
10    $Id: //main/2019/qhull/src/libqhull/stat.c#9 $$Change: 2953 $
11    $DateTime: 2020/05/21 22:05:32 $$Author: bbarber $
12 */
13 
14 #include "qhull_a.h"
15 
16 /*============ global data structure ==========*/
17 
18 #if qh_QHpointer
19 qhstatT *qh_qhstat=NULL;  /* global data structure */
20 #else
21 qhstatT qh_qhstat;   /* add "={0}" if this causes a compiler error */
22 #endif
23 
24 /*========== functions in alphabetic order ================*/
25 
26 /*-<a                             href="qh-stat.htm#TOC"
27   >-------------------------------</a><a name="allstatA">-</a>
28 
29   qh_allstatA()
30     define statistics in groups of 20
31 
32   notes:
33     (otherwise, 'gcc -O2' uses too much memory)
34     uses qhstat.next
35 */
qh_allstatA(void)36 void qh_allstatA(void) {
37 
38    /* zdef_(type,name,doc,average) */
39   zzdef_(zdoc, Zdoc2, "precision statistics", -1);
40   zdef_(zinc, Znewvertex, NULL, -1);
41   zdef_(wadd, Wnewvertex, "ave. distance of a new vertex to a facet", Znewvertex);
42   zzdef_(wmax, Wnewvertexmax, "max. distance of a new vertex to a facet", -1);
43   zdef_(wmax, Wvertexmax, "max. distance of an output vertex to a facet", -1);
44   zdef_(wmin, Wvertexmin, "min. distance of an output vertex to a facet", -1);
45   zdef_(wmin, Wmindenom, "min. denominator in hyperplane computation", -1);
46 
47   qhstat precision= qhstat next;  /* usually call qh_joggle_restart, printed if Q0 or QJn */
48   zzdef_(zdoc, Zdoc3, "precision problems (corrected unless 'Q0' or an error)", -1);
49   zzdef_(zinc, Zcoplanarridges, "coplanar half ridges in output", -1);
50   zzdef_(zinc, Zconcaveridges, "concave half ridges in output", -1);
51   zzdef_(zinc, Zflippedfacets, "flipped facets", -1);
52   zzdef_(zinc, Zcoplanarhorizon, "coplanar horizon facets for new vertices", -1);
53   zzdef_(zinc, Zcoplanarpart, "coplanar points during partitioning", -1);
54   zzdef_(zinc, Zminnorm, "degenerate hyperplanes recomputed with gaussian elimination", -1);
55   zzdef_(zinc, Znearlysingular, "nearly singular or axis-parallel hyperplanes", -1);
56   zzdef_(zinc, Zback0, "zero divisors during back substitute", -1);
57   zzdef_(zinc, Zgauss0, "zero divisors during gaussian elimination", -1);
58   zzdef_(zinc, Zmultiridge, "dupridges with multiple neighbors", -1);
59   zzdef_(zinc, Zflipridge, "dupridges with flip facet into good neighbor", -1);
60   zzdef_(zinc, Zflipridge2, "dupridges with flip facet into good flip neighbor", -1);
61 }
qh_allstatB(void)62 void qh_allstatB(void) {
63   zzdef_(zdoc, Zdoc1, "summary information", -1);
64   zdef_(zinc, Zvertices, "number of vertices in output", -1);
65   zdef_(zinc, Znumfacets, "number of facets in output", -1);
66   zdef_(zinc, Znonsimplicial, "number of non-simplicial facets in output", -1);
67   zdef_(zinc, Znowsimplicial, "simplicial facets that were non-simplicial", -1);
68   zdef_(zinc, Znumridges, "number of ridges in output", -1);
69   zdef_(zadd, Znumridges, "average number of ridges per facet", Znumfacets);
70   zdef_(zmax, Zmaxridges, "maximum number of ridges", -1);
71   zdef_(zadd, Znumneighbors, "average number of neighbors per facet", Znumfacets);
72   zdef_(zmax, Zmaxneighbors, "maximum number of neighbors", -1);
73   zdef_(zadd, Znumvertices, "average number of vertices per facet", Znumfacets);
74   zdef_(zmax, Zmaxvertices, "maximum number of vertices", -1);
75   zdef_(zadd, Znumvneighbors, "average number of neighbors per vertex", Zvertices);
76   zdef_(zmax, Zmaxvneighbors, "maximum number of neighbors", -1);
77   zdef_(wadd, Wcpu, "cpu seconds for qhull after input", -1);
78   zdef_(zinc, Ztotvertices, "vertices created altogether", -1);
79   zzdef_(zinc, Zsetplane, "facets created altogether", -1);
80   zdef_(zinc, Ztotridges, "ridges created altogether", -1);
81   zdef_(zinc, Zpostfacets, "facets before post merge", -1);
82   zdef_(zadd, Znummergetot, "average merges per facet (at most 511)", Znumfacets);
83   zdef_(zmax, Znummergemax, "  maximum merges for a facet (at most 511)", -1);
84   zdef_(zinc, Zangle, NULL, -1);
85   zdef_(wadd, Wangle, "average cosine (angle) of facet normals for all ridges", Zangle);
86   zdef_(wmax, Wanglemax, "  maximum cosine of facet normals (flatest) across a ridge", -1);
87   zdef_(wmin, Wanglemin, "  minimum cosine of facet normals (sharpest) across a ridge", -1);
88   zdef_(wadd, Wareatot, "total area of facets", -1);
89   zdef_(wmax, Wareamax, "  maximum facet area", -1);
90   zdef_(wmin, Wareamin, "  minimum facet area", -1);
91 }
qh_allstatC(void)92 void qh_allstatC(void) {
93   zdef_(zdoc, Zdoc9, "build hull statistics", -1);
94   zzdef_(zinc, Zprocessed, "points processed", -1);
95   zzdef_(zinc, Zretry, "retries due to precision problems", -1);
96   zdef_(wmax, Wretrymax, "  max. random joggle", -1);
97   zdef_(zmax, Zmaxvertex, "max. vertices at any one time", -1);
98   zdef_(zinc, Ztotvisible, "ave. visible facets per iteration", Zprocessed);
99   zdef_(zinc, Zinsidevisible, "  ave. visible facets without an horizon neighbor", Zprocessed);
100   zdef_(zadd, Zvisfacettot,  "  ave. facets deleted per iteration", Zprocessed);
101   zdef_(zmax, Zvisfacetmax,  "    maximum", -1);
102   zdef_(zadd, Zvisvertextot, "ave. visible vertices per iteration", Zprocessed);
103   zdef_(zmax, Zvisvertexmax, "    maximum", -1);
104   zdef_(zinc, Ztothorizon, "ave. horizon facets per iteration", Zprocessed);
105   zdef_(zadd, Znewfacettot,  "ave. new or merged facets per iteration", Zprocessed);
106   zdef_(zmax, Znewfacetmax,  "    maximum (includes initial simplex)", -1);
107   zdef_(wadd, Wnewbalance, "average new facet balance", Zprocessed);
108   zdef_(wadd, Wnewbalance2, "  standard deviation", -1);
109   zdef_(wadd, Wpbalance, "average partition balance", Zpbalance);
110   zdef_(wadd, Wpbalance2, "  standard deviation", -1);
111   zdef_(zinc, Zpbalance,  "  count", -1);
112   zdef_(zinc, Zsearchpoints, "searches of all points for initial simplex", -1);
113   zdef_(zinc, Zdetfacetarea, "determinants for facet area", -1);
114   zdef_(zinc, Znoarea, "  determinants not computed because vertex too low", -1);
115   zdef_(zinc, Zdetsimplex, "determinants for initial hull or voronoi vertices", -1);
116   zdef_(zinc, Znotmax, "points ignored (!above max_outside)", -1);
117   zdef_(zinc, Zpinchedapex, "points ignored (pinched apex)", -1);
118   zdef_(zinc, Znotgood, "points ignored (!above a good facet)", -1);
119   zdef_(zinc, Znotgoodnew, "points ignored (didn't create a good new facet)", -1);
120   zdef_(zinc, Zgoodfacet, "good facets found", -1);
121   zzdef_(zinc, Znumvisibility, "distance tests for facet visibility", -1);
122   zdef_(zinc, Zdistvertex, "distance tests to report minimum vertex", -1);
123   zzdef_(zinc, Ztotcheck, "points checked for facets' outer planes", -1);
124   zzdef_(zinc, Zcheckpart, "  ave. distance tests per check", Ztotcheck);
125 }
qh_allstatD(void)126 void qh_allstatD(void) {
127   zdef_(zinc, Zvisit, "resets of visit_id", -1);
128   zdef_(zinc, Zvvisit, "  resets of vertex_visit", -1);
129   zdef_(zmax, Zvisit2max, "  max visit_id/2", -1);
130   zdef_(zmax, Zvvisit2max, "  max vertex_visit/2", -1);
131 
132   zdef_(zdoc, Zdoc4, "partitioning statistics (see previous for outer planes)", -1);
133   zzdef_(zadd, Zdelvertextot, "total vertices deleted", -1);
134   zdef_(zmax, Zdelvertexmax, "    maximum vertices deleted per iteration", -1);
135   zdef_(zinc, Zfindbest, "calls to findbest", -1);
136   zdef_(zadd, Zfindbesttot, " ave. facets tested", Zfindbest);
137   zdef_(zmax, Zfindbestmax, " max. facets tested", -1);
138   zdef_(zadd, Zfindcoplanar, " ave. coplanar search", Zfindbest);
139   zdef_(zinc, Zfindnew, "calls to findbestnew", -1);
140   zdef_(zadd, Zfindnewtot, " ave. facets tested", Zfindnew);
141   zdef_(zmax, Zfindnewmax, " max. facets tested", -1);
142   zdef_(zinc, Zfindnewjump, " ave. clearly better", Zfindnew);
143   zdef_(zinc, Zfindnewsharp, " calls due to qh_sharpnewfacets", -1);
144   zdef_(zinc, Zfindhorizon, "calls to findhorizon", -1);
145   zdef_(zadd, Zfindhorizontot, " ave. facets tested", Zfindhorizon);
146   zdef_(zmax, Zfindhorizonmax, " max. facets tested", -1);
147   zdef_(zinc, Zfindjump,       " ave. clearly better", Zfindhorizon);
148   zdef_(zinc, Znewbesthorizon, " new bestfacets during qh_findbesthorizon", -1);
149   zdef_(zinc, Zpartangle, "angle tests for repartitioned coplanar points", -1);
150   zdef_(zinc, Zpartcorner, "  repartitioned coplanar points above a corner facet", -1);
151   zdef_(zinc, Zparthidden, "  repartitioned coplanar points above a hidden facet", -1);
152   zdef_(zinc, Zparttwisted, "  repartitioned coplanar points above a twisted facet", -1);
153 }
qh_allstatE(void)154 void qh_allstatE(void) {
155   zdef_(zinc, Zpartinside, "inside points", -1);
156   zdef_(zinc, Zpartnear, "  near inside points kept with a facet", -1);
157   zdef_(zinc, Zcoplanarinside, "  inside points that were coplanar with a facet", -1);
158   zdef_(zinc, Zbestlower, "calls to findbestlower", -1);
159   zdef_(zinc, Zbestlowerv, "  with search of vertex neighbors", -1);
160   zdef_(zinc, Zbestlowerall, "  with rare search of all facets", -1);
161   zdef_(zmax, Zbestloweralln, "  facets per search of all facets", -1);
162   zdef_(wadd, Wmaxout, "difference in max_outside at final check", -1);
163   zzdef_(zinc, Zpartitionall, "distance tests for initial partition", -1);
164   zdef_(zinc, Ztotpartition, "partitions of a point", -1);
165   zzdef_(zinc, Zpartition, "distance tests for partitioning", -1);
166   zzdef_(zinc, Zdistcheck, "distance tests for checking flipped facets", -1);
167   zzdef_(zinc, Zdistconvex, "distance tests for checking convexity", -1);
168   zdef_(zinc, Zdistgood, "distance tests for checking good point", -1);
169   zdef_(zinc, Zdistio, "distance tests for output", -1);
170   zdef_(zinc, Zdiststat, "distance tests for statistics", -1);
171   zzdef_(zinc, Zdistplane, "total number of distance tests", -1);
172   zdef_(zinc, Ztotpartcoplanar, "partitions of coplanar points or deleted vertices", -1);
173   zzdef_(zinc, Zpartcoplanar, "   distance tests for these partitions", -1);
174   zdef_(zinc, Zcomputefurthest, "distance tests for computing furthest", -1);
175 }
qh_allstatE2(void)176 void qh_allstatE2(void) {
177   zdef_(zdoc, Zdoc5, "statistics for matching ridges", -1);
178   zdef_(zinc, Zhashlookup, "total lookups for matching ridges of new facets", -1);
179   zdef_(zinc, Zhashtests, "average number of tests to match a ridge", Zhashlookup);
180   zdef_(zinc, Zhashridge, "total lookups of subridges (duplicates and boundary)", -1);
181   zdef_(zinc, Zhashridgetest, "average number of tests per subridge", Zhashridge);
182   zdef_(zinc, Zdupsame, "duplicated ridges in same merge cycle", -1);
183   zdef_(zinc, Zdupflip, "duplicated ridges with flipped facets", -1);
184 
185   zdef_(zdoc, Zdoc6, "statistics for determining merges", -1);
186   zdef_(zinc, Zangletests, "angles computed for ridge convexity", -1);
187   zdef_(zinc, Zbestcentrum, "best merges used centrum instead of vertices",-1);
188   zzdef_(zinc, Zbestdist, "distance tests for best merge", -1);
189   zzdef_(zinc, Zcentrumtests, "distance tests for centrum convexity", -1);
190   zzdef_(zinc, Zvertextests, "distance tests for vertex convexity", -1);
191   zzdef_(zinc, Zdistzero, "distance tests for checking simplicial convexity", -1);
192   zdef_(zinc, Zcoplanarangle, "coplanar angles in getmergeset", -1);
193   zdef_(zinc, Zcoplanarcentrum, "coplanar centrums or vertices in getmergeset", -1);
194   zdef_(zinc, Zconcaveridge, "concave ridges in getmergeset", -1);
195   zdef_(zinc, Zconcavecoplanarridge, "concave-coplanar ridges in getmergeset", -1);
196   zdef_(zinc, Ztwistedridge, "twisted ridges in getmergeset", -1);
197 }
qh_allstatF(void)198 void qh_allstatF(void) {
199   zdef_(zdoc, Zdoc7, "statistics for merging", -1);
200   zdef_(zinc, Zpremergetot, "merge iterations", -1);
201   zdef_(zadd, Zmergeinittot, "ave. initial non-convex ridges per iteration", Zpremergetot);
202   zdef_(zadd, Zmergeinitmax, "  maximum", -1);
203   zdef_(zadd, Zmergesettot, "  ave. additional non-convex ridges per iteration", Zpremergetot);
204   zdef_(zadd, Zmergesetmax, "  maximum additional in one pass", -1);
205   zdef_(zadd, Zmergeinittot2, "initial non-convex ridges for post merging", -1);
206   zdef_(zadd, Zmergesettot2, "  additional non-convex ridges", -1);
207   zdef_(wmax, Wmaxoutside, "max distance of vertex or coplanar point above facet (w/roundoff)", -1);
208   zdef_(wmin, Wminvertex, "max distance of vertex below facet (or roundoff)", -1);
209   zdef_(zinc, Zwidefacet, "centrums frozen due to a wide merge", -1);
210   zdef_(zinc, Zwidevertices, "centrums frozen due to extra vertices", -1);
211   zzdef_(zinc, Ztotmerge, "total number of facets or cycles of facets merged", -1);
212   zdef_(zinc, Zmergesimplex, "merged a simplex", -1);
213   zdef_(zinc, Zonehorizon, "simplices merged into coplanar horizon", -1);
214   zzdef_(zinc, Zcyclehorizon, "cycles of facets merged into coplanar horizon", -1);
215   zzdef_(zadd, Zcyclefacettot, "  ave. facets per cycle", Zcyclehorizon);
216   zdef_(zmax, Zcyclefacetmax, "  max. facets", -1);
217   zdef_(zinc, Zmergeintocoplanar, "new facets merged into coplanar horizon", -1);
218   zdef_(zinc, Zmergeintohorizon, "new facets merged into horizon", -1);
219   zdef_(zinc, Zmergenew, "new facets merged", -1);
220   zdef_(zinc, Zmergehorizon, "horizon facets merged into new facets", -1);
221   zdef_(zinc, Zmergevertex, "vertices deleted by merging", -1);
222   zdef_(zinc, Zcyclevertex, "vertices deleted by merging into coplanar horizon", -1);
223   zdef_(zinc, Zdegenvertex, "vertices deleted by degenerate facet", -1);
224   zdef_(zinc, Zmergeflipdup, "merges due to flipped facets in duplicated ridge", -1);
225   zdef_(zinc, Zredundant, "merges due to redundant neighbors", -1);
226   zdef_(zinc, Zredundantmerge, "  detected by qh_test_nonsimplicial_merge instead of qh_test_redundant_neighbors", -1);
227   zdef_(zadd, Ztestvneighbor, "non-convex vertex neighbors", -1);
228 }
qh_allstatG(void)229 void qh_allstatG(void) {
230   zdef_(zinc, Zacoplanar, "merges due to angle coplanar facets", -1);
231   zdef_(wadd, Wacoplanartot, "  average merge distance", Zacoplanar);
232   zdef_(wmax, Wacoplanarmax, "  maximum merge distance", -1);
233   zdef_(zinc, Zcoplanar, "merges due to coplanar facets", -1);
234   zdef_(wadd, Wcoplanartot, "  average merge distance", Zcoplanar);
235   zdef_(wmax, Wcoplanarmax, "  maximum merge distance", -1);
236   zdef_(zinc, Zconcave, "merges due to concave facets", -1);
237   zdef_(wadd, Wconcavetot, "  average merge distance", Zconcave);
238   zdef_(wmax, Wconcavemax, "  maximum merge distance", -1);
239   zdef_(zinc, Zconcavecoplanar, "merges due to concave-coplanar facets", -1);
240   zdef_(wadd, Wconcavecoplanartot, "  average merge distance", Zconcavecoplanar);
241   zdef_(wmax, Wconcavecoplanarmax, "  maximum merge distance", -1);
242   zdef_(zinc, Zavoidold, "coplanar/concave merges due to avoiding old merge", -1);
243   zdef_(wadd, Wavoidoldtot, "  average merge distance", Zavoidold);
244   zdef_(wmax, Wavoidoldmax, "  maximum merge distance", -1);
245   zdef_(zinc, Zdegen, "merges due to degenerate facets", -1);
246   zdef_(wadd, Wdegentot, "  average merge distance", Zdegen);
247   zdef_(wmax, Wdegenmax, "  maximum merge distance", -1);
248   zdef_(zinc, Zflipped, "merges due to removing flipped facets", -1);
249   zdef_(wadd, Wflippedtot, "  average merge distance", Zflipped);
250   zdef_(wmax, Wflippedmax, "  maximum merge distance", -1);
251   zdef_(zinc, Zduplicate, "merges due to dupridges", -1);
252   zdef_(wadd, Wduplicatetot, "  average merge distance", Zduplicate);
253   zdef_(wmax, Wduplicatemax, "  maximum merge distance", -1);
254   zdef_(zinc, Ztwisted, "merges due to twisted facets", -1);
255   zdef_(wadd, Wtwistedtot, "  average merge distance", Ztwisted);
256   zdef_(wmax, Wtwistedmax, "  maximum merge distance", -1);
257 }
qh_allstatH(void)258 void qh_allstatH(void) {
259   zdef_(zdoc, Zdoc8, "statistics for vertex merges", -1);
260   zzdef_(zinc, Zpinchduplicate, "merge pinched vertices for a duplicate ridge", -1);
261   zzdef_(zinc, Zpinchedvertex, "merge pinched vertices for a dupridge", -1);
262   zdef_(zinc, Zrenameshare, "renamed vertices shared by two facets", -1);
263   zdef_(zinc, Zrenamepinch, "renamed vertices in a pinched facet", -1);
264   zdef_(zinc, Zrenameall, "renamed vertices shared by multiple facets", -1);
265   zdef_(zinc, Zfindfail, "rename failures due to duplicated ridges", -1);
266   zdef_(zinc, Znewvertexridge, "  found new vertex in ridge", -1);
267   zdef_(zinc, Zdelridge, "deleted ridges due to renamed vertices", -1);
268   zdef_(zinc, Zdropneighbor, "dropped neighbors due to renamed vertices", -1);
269   zdef_(zinc, Zdropdegen, "merge degenerate facets due to dropped neighbors", -1);
270   zdef_(zinc, Zdelfacetdup, "  facets deleted because of no neighbors", -1);
271   zdef_(zinc, Zremvertex, "vertices removed from facets due to no ridges", -1);
272   zdef_(zinc, Zremvertexdel, "  deleted", -1);
273   zdef_(zinc, Zretryadd, "retry qh_addpoint after merge pinched vertex", -1);
274   zdef_(zadd, Zretryaddtot, "  tot. merge pinched vertex due to dupridge", -1);
275   zdef_(zmax, Zretryaddmax, "  max. merge pinched vertex for a qh_addpoint", -1);
276   zdef_(zinc, Zintersectnum, "vertex intersections for locating redundant vertices", -1);
277   zdef_(zinc, Zintersectfail, "intersections failed to find a redundant vertex", -1);
278   zdef_(zinc, Zintersect, "intersections found redundant vertices", -1);
279   zdef_(zadd, Zintersecttot, "   ave. number found per vertex", Zintersect);
280   zdef_(zmax, Zintersectmax, "   max. found for a vertex", -1);
281   zdef_(zinc, Zvertexridge, NULL, -1);
282   zdef_(zadd, Zvertexridgetot, "  ave. number of ridges per tested vertex", Zvertexridge);
283   zdef_(zmax, Zvertexridgemax, "  max. number of ridges per tested vertex", -1);
284 
285   zdef_(zdoc, Zdoc10, "memory usage statistics (in bytes)", -1);
286   zdef_(zadd, Zmemfacets, "for facets and their normals, neighbor and vertex sets", -1);
287   zdef_(zadd, Zmemvertices, "for vertices and their neighbor sets", -1);
288   zdef_(zadd, Zmempoints, "for input points, outside and coplanar sets, and qhT",-1);
289   zdef_(zadd, Zmemridges, "for ridges and their vertex sets", -1);
290 } /* allstat */
291 
qh_allstatI(void)292 void qh_allstatI(void) {
293   qhstat vridges= qhstat next; /* printed in qh_produce_output2 if non-zero Zridge or Zridgemid */
294   zzdef_(zdoc, Zdoc11, "Voronoi ridge statistics", -1);
295   zzdef_(zinc, Zridge, "non-simplicial Voronoi vertices for all ridges", -1);
296   zzdef_(wadd, Wridge, "  ave. distance to ridge", Zridge);
297   zzdef_(wmax, Wridgemax, "  max. distance to ridge", -1);
298   zzdef_(zinc, Zridgemid, "bounded ridges", -1);
299   zzdef_(wadd, Wridgemid, "  ave. distance of midpoint to ridge", Zridgemid);
300   zzdef_(wmax, Wridgemidmax, "  max. distance of midpoint to ridge", -1);
301   zzdef_(zinc, Zridgeok, "bounded ridges with ok normal", -1);
302   zzdef_(wadd, Wridgeok, "  ave. angle to ridge", Zridgeok);
303   zzdef_(wmax, Wridgeokmax, "  max. angle to ridge", -1);
304   zzdef_(zinc, Zridge0, "bounded ridges with near-zero normal", -1);
305   zzdef_(wadd, Wridge0, "  ave. angle to ridge", Zridge0);
306   zzdef_(wmax, Wridge0max, "  max. angle to ridge", -1);
307 
308   zdef_(zdoc, Zdoc12, "Triangulation statistics ('Qt')", -1);
309   zdef_(zinc, Ztricoplanar, "non-simplicial facets triangulated", -1);
310   zdef_(zadd, Ztricoplanartot, "  ave. new facets created (may be deleted)", Ztricoplanar);
311   zdef_(zmax, Ztricoplanarmax, "  max. new facets created", -1);
312   zdef_(zinc, Ztrinull, "null new facets deleted (duplicated vertex)", -1);
313   zdef_(zinc, Ztrimirror, "mirrored pairs of new facets deleted (same vertices)", -1);
314   zdef_(zinc, Ztridegen, "degenerate new facets in output (same ridge)", -1);
315 } /* allstat */
316 
317 /*-<a                             href="qh-stat.htm#TOC"
318   >-------------------------------</a><a name="allstatistics">-</a>
319 
320   qh_allstatistics()
321     reset printed flag for all statistics
322 */
qh_allstatistics(void)323 void qh_allstatistics(void) {
324   int i;
325 
326   for(i=ZEND; i--; )
327     qhstat printed[i]= False;
328 } /* allstatistics */
329 
330 #if qh_KEEPstatistics
331 /*-<a                             href="qh-stat.htm#TOC"
332   >-------------------------------</a><a name="collectstatistics">-</a>
333 
334   qh_collectstatistics()
335     collect statistics for qh.facet_list
336 
337 */
qh_collectstatistics(void)338 void qh_collectstatistics(void) {
339   facetT *facet, *neighbor, **neighborp;
340   vertexT *vertex, **vertexp;
341   realT dotproduct, dist;
342   int sizneighbors, sizridges, sizvertices, i;
343 
344   qh old_randomdist= qh RANDOMdist;
345   qh RANDOMdist= False;
346   zval_(Zmempoints)= qh num_points * qh normal_size + (int)sizeof(qhT) + (int)sizeof(qhstatT);
347   zval_(Zmemfacets)= 0;
348   zval_(Zmemridges)= 0;
349   zval_(Zmemvertices)= 0;
350   zval_(Zangle)= 0;
351   wval_(Wangle)= 0.0;
352   zval_(Znumridges)= 0;
353   zval_(Znumfacets)= 0;
354   zval_(Znumneighbors)= 0;
355   zval_(Znumvertices)= 0;
356   zval_(Znumvneighbors)= 0;
357   zval_(Znummergetot)= 0;
358   zval_(Znummergemax)= 0;
359   zval_(Zvertices)= qh num_vertices - qh_setsize(qh del_vertices);
360   if (qh MERGING || qh APPROXhull || qh JOGGLEmax < REALmax/2)
361     wmax_(Wmaxoutside, qh max_outside);
362   if (qh MERGING)
363     wmin_(Wminvertex, qh min_vertex);
364   if (!qh_checklists(qh facet_list)) {
365     qh_fprintf(qh ferr, 6373, "qhull internal error: qh_checklists failed on qh_collectstatistics\n");
366     if (!qh ERREXITcalled)
367       qh_errexit(qh_ERRqhull, NULL, NULL);
368   }
369   FORALLfacets
370     facet->seen= False;
371   if (qh DELAUNAY) {
372     FORALLfacets {
373       if (facet->upperdelaunay != qh UPPERdelaunay)
374         facet->seen= True; /* remove from angle statistics */
375     }
376   }
377   FORALLfacets {
378     if (facet->visible && qh NEWfacets)
379       continue;
380     sizvertices= qh_setsize(facet->vertices);
381     sizneighbors= qh_setsize(facet->neighbors);
382     sizridges= qh_setsize(facet->ridges);
383     zinc_(Znumfacets);
384     zadd_(Znumvertices, sizvertices);
385     zmax_(Zmaxvertices, sizvertices);
386     zadd_(Znumneighbors, sizneighbors);
387     zmax_(Zmaxneighbors, sizneighbors);
388     zadd_(Znummergetot, facet->nummerge);
389     i= facet->nummerge; /* avoid warnings */
390     zmax_(Znummergemax, i);
391     if (!facet->simplicial) {
392       if (sizvertices == qh hull_dim) {
393         zinc_(Znowsimplicial);
394       }else {
395         zinc_(Znonsimplicial);
396       }
397     }
398     if (sizridges) {
399       zadd_(Znumridges, sizridges);
400       zmax_(Zmaxridges, sizridges);
401     }
402     zadd_(Zmemfacets, (int)sizeof(facetT) + qh normal_size + 2*(int)sizeof(setT)
403        + SETelemsize * (sizneighbors + sizvertices));
404     if (facet->ridges) {
405       zadd_(Zmemridges,
406         (int)sizeof(setT) + SETelemsize * sizridges + sizridges *
407          ((int)sizeof(ridgeT) + (int)sizeof(setT) + SETelemsize * (qh hull_dim-1))/2);
408     }
409     if (facet->outsideset)
410       zadd_(Zmempoints, (int)sizeof(setT) + SETelemsize * qh_setsize(facet->outsideset));
411     if (facet->coplanarset)
412       zadd_(Zmempoints, (int)sizeof(setT) + SETelemsize * qh_setsize(facet->coplanarset));
413     if (facet->seen) /* Delaunay upper envelope */
414       continue;
415     facet->seen= True;
416     FOREACHneighbor_(facet) {
417       if (neighbor == qh_DUPLICATEridge || neighbor == qh_MERGEridge
418           || neighbor->seen || !facet->normal || !neighbor->normal)
419         continue;
420       dotproduct= qh_getangle(facet->normal, neighbor->normal);
421       zinc_(Zangle);
422       wadd_(Wangle, dotproduct);
423       wmax_(Wanglemax, dotproduct)
424       wmin_(Wanglemin, dotproduct)
425     }
426     if (facet->normal) {
427       FOREACHvertex_(facet->vertices) {
428         zinc_(Zdiststat);
429         qh_distplane(vertex->point, facet, &dist);
430         wmax_(Wvertexmax, dist);
431         wmin_(Wvertexmin, dist);
432       }
433     }
434   }
435   FORALLvertices {
436     if (vertex->deleted)
437       continue;
438     zadd_(Zmemvertices, (int)sizeof(vertexT));
439     if (vertex->neighbors) {
440       sizneighbors= qh_setsize(vertex->neighbors);
441       zadd_(Znumvneighbors, sizneighbors);
442       zmax_(Zmaxvneighbors, sizneighbors);
443       zadd_(Zmemvertices, (int)sizeof(vertexT) + SETelemsize * sizneighbors);
444     }
445   }
446   qh RANDOMdist= qh old_randomdist;
447 } /* collectstatistics */
448 #endif /* qh_KEEPstatistics */
449 
450 /*-<a                             href="qh-stat.htm#TOC"
451   >-------------------------------</a><a name="freestatistics">-</a>
452 
453   qh_freestatistics(  )
454     free memory used for statistics
455 */
qh_freestatistics(void)456 void qh_freestatistics(void) {
457 
458 #if qh_QHpointer
459   qh_free(qh_qhstat);
460   qh_qhstat= NULL;
461 #endif
462 } /* freestatistics */
463 
464 /*-<a                             href="qh-stat.htm#TOC"
465   >-------------------------------</a><a name="initstatistics">-</a>
466 
467   qh_initstatistics( )
468     allocate and initialize statistics
469 
470   notes:
471     uses qh_malloc() instead of qh_memalloc() since mem.c not set up yet
472     NOerrors -- qh_initstatistics can not use qh_errexit(), qh_fprintf, or qh.ferr
473     On first call, only qhmem.ferr is defined.  qh_memalloc is not setup.
474     Also invoked by QhullQh().
475 */
qh_initstatistics(void)476 void qh_initstatistics(void) {
477   int i;
478   realT realx;
479   int intx;
480 
481 #if qh_QHpointer
482   if(qh_qhstat){  /* qh_initstatistics may be called from Qhull::resetStatistics() */
483     qh_free(qh_qhstat);
484     qh_qhstat= 0;
485   }
486   if (!(qh_qhstat= (qhstatT *)qh_malloc(sizeof(qhstatT)))) {
487     qh_fprintf_stderr(6183, "qhull error (qh_initstatistics): insufficient memory\n");
488     qh_exit(qh_ERRmem);  /* can not use qh_errexit() */
489   }
490 #endif
491 
492   qh_allstatistics();
493   qhstat next= 0;
494   qh_allstatA();
495   qh_allstatB();
496   qh_allstatC();
497   qh_allstatD();
498   qh_allstatE();
499   qh_allstatE2();
500   qh_allstatF();
501   qh_allstatG();
502   qh_allstatH();
503   qh_allstatI();
504   if (qhstat next > (int)sizeof(qhstat id)) {
505     qh_fprintf_stderr(6184, "qhull internal error (qh_initstatistics): increase size of qhstat.id[].  qhstat.next %d should be <= sizeof(qhstat id) %d\n",
506           qhstat next, (int)sizeof(qhstat id));
507 #if 0 /* for locating error, Znumridges should be duplicated */
508     for(i=0; i < ZEND; i++) {
509       int j;
510       for(j=i+1; j < ZEND; j++) {
511         if (qhstat id[i] == qhstat id[j]) {
512           qh_fprintf_stderr(6185, "qhull error (qh_initstatistics): duplicated statistic %d at indices %d and %d\n",
513               qhstat id[i], i, j);
514         }
515       }
516     }
517 #endif
518     qh_exit(qh_ERRqhull);  /* can not use qh_errexit() */
519   }
520   qhstat init[zinc].i= 0;
521   qhstat init[zadd].i= 0;
522   qhstat init[zmin].i= INT_MAX;
523   qhstat init[zmax].i= INT_MIN;
524   qhstat init[wadd].r= 0;
525   qhstat init[wmin].r= REALmax;
526   qhstat init[wmax].r= -REALmax;
527   for(i=0; i < ZEND; i++) {
528     if (qhstat type[i] > ZTYPEreal) {
529       realx= qhstat init[(unsigned char)(qhstat type[i])].r;
530       qhstat stats[i].r= realx;
531     }else if (qhstat type[i] != zdoc) {
532       intx= qhstat init[(unsigned char)(qhstat type[i])].i;
533       qhstat stats[i].i= intx;
534     }
535   }
536 } /* initstatistics */
537 
538 /*-<a                             href="qh-stat.htm#TOC"
539   >-------------------------------</a><a name="newstats">-</a>
540 
541   qh_newstats( )
542     returns True if statistics for zdoc
543 
544   returns:
545     next zdoc
546 */
qh_newstats(int idx,int * nextindex)547 boolT qh_newstats(int idx, int *nextindex) {
548   boolT isnew= False;
549   int start, i;
550 
551   if (qhstat type[qhstat id[idx]] == zdoc)
552     start= idx+1;
553   else
554     start= idx;
555   for(i= start; i < qhstat next && qhstat type[qhstat id[i]] != zdoc; i++) {
556     if (!qh_nostatistic(qhstat id[i]) && !qhstat printed[qhstat id[i]])
557         isnew= True;
558   }
559   *nextindex= i;
560   return isnew;
561 } /* newstats */
562 
563 /*-<a                             href="qh-stat.htm#TOC"
564   >-------------------------------</a><a name="nostatistic">-</a>
565 
566   qh_nostatistic( index )
567     true if no statistic to print
568 */
qh_nostatistic(int i)569 boolT qh_nostatistic(int i) {
570 
571   if ((qhstat type[i] > ZTYPEreal
572        &&qhstat stats[i].r == qhstat init[(unsigned char)(qhstat type[i])].r)
573       || (qhstat type[i] < ZTYPEreal
574           &&qhstat stats[i].i == qhstat init[(unsigned char)(qhstat type[i])].i))
575     return True;
576   return False;
577 } /* nostatistic */
578 
579 #if qh_KEEPstatistics
580 /*-<a                             href="qh-stat.htm#TOC"
581   >-------------------------------</a><a name="printallstatistics">-</a>
582 
583   qh_printallstatistics( fp, string )
584     print all statistics with header 'string'
585 */
qh_printallstatistics(FILE * fp,const char * string)586 void qh_printallstatistics(FILE *fp, const char *string) {
587 
588   qh_allstatistics();
589   qh_collectstatistics();
590   qh_printstatistics(fp, string);
591   qh_memstatistics(fp);
592 }
593 
594 
595 /*-<a                             href="qh-stat.htm#TOC"
596   >-------------------------------</a><a name="printstatistics">-</a>
597 
598   qh_printstatistics( fp, string )
599     print statistics to a file with header 'string'
600     skips statistics with qhstat.printed[] (reset with qh_allstatistics)
601 
602   see:
603     qh_printallstatistics()
604 */
qh_printstatistics(FILE * fp,const char * string)605 void qh_printstatistics(FILE *fp, const char *string) {
606   int i, k;
607   realT ave; /* ignored */
608 
609   if (qh num_points != qh num_vertices || zval_(Zpbalance) == 0) {
610     wval_(Wpbalance)= 0.0;
611     wval_(Wpbalance2)= 0.0;
612   }else
613     wval_(Wpbalance2)= qh_stddev(zval_(Zpbalance), wval_(Wpbalance),
614                                  wval_(Wpbalance2), &ave);
615   if (zval_(Zprocessed) == 0)
616     wval_(Wnewbalance2)= 0.0;
617   else
618     wval_(Wnewbalance2)= qh_stddev(zval_(Zprocessed), wval_(Wnewbalance),
619                                  wval_(Wnewbalance2), &ave);
620   qh_fprintf(fp, 9350, "\n\
621 %s\n\
622 qhull invoked by: %s | %s\n  %s with options:\n%s\n",
623     string, qh rbox_command, qh qhull_command, qh_version, qh qhull_options);
624 
625   qh_fprintf(fp, 9351, "\nprecision constants:\n\
626  %6.2g max. abs. coordinate in the (transformed) input ('Qbd:n')\n\
627  %6.2g max. roundoff error for distance computation ('En')\n\
628  %6.2g max. roundoff error for angle computations\n\
629  %6.2g min. distance for outside points ('Wn')\n\
630  %6.2g min. distance for visible facets ('Vn')\n\
631  %6.2g max. distance for coplanar facets ('Un')\n\
632  %6.2g max. facet width for recomputing centrum and area\n\
633 ",
634   qh MAXabs_coord, qh DISTround, qh ANGLEround, qh MINoutside,
635         qh MINvisible, qh MAXcoplanar, qh WIDEfacet);
636   if (qh KEEPnearinside)
637     qh_fprintf(fp, 9352, "\
638  %6.2g max. distance for near-inside points\n", qh NEARinside);
639   if (qh premerge_cos < REALmax/2) qh_fprintf(fp, 9353, "\
640  %6.2g max. cosine for pre-merge angle\n", qh premerge_cos);
641   if (qh PREmerge) qh_fprintf(fp, 9354, "\
642  %6.2g radius of pre-merge centrum\n", qh premerge_centrum);
643   if (qh postmerge_cos < REALmax/2) qh_fprintf(fp, 9355, "\
644  %6.2g max. cosine for post-merge angle\n", qh postmerge_cos);
645   if (qh POSTmerge) qh_fprintf(fp, 9356, "\
646  %6.2g radius of post-merge centrum\n", qh postmerge_centrum);
647   qh_fprintf(fp, 9357, "\
648  %6.2g max. distance for merging two simplicial facets\n\
649  %6.2g max. roundoff error for arithmetic operations\n\
650  %6.2g min. denominator for division\n\
651   zero diagonal for Gauss: ", qh ONEmerge, REALepsilon, qh MINdenom);
652   for(k=0; k < qh hull_dim; k++)
653     qh_fprintf(fp, 9358, "%6.2e ", qh NEARzero[k]);
654   qh_fprintf(fp, 9359, "\n\n");
655   for(i=0 ; i < qhstat next; )
656     qh_printstats(fp, i, &i);
657 } /* printstatistics */
658 #endif /* qh_KEEPstatistics */
659 
660 /*-<a                             href="qh-stat.htm#TOC"
661   >-------------------------------</a><a name="printstatlevel">-</a>
662 
663   qh_printstatlevel( fp, id )
664     print level information for a statistic
665 
666   notes:
667     nop if id >= ZEND, printed, or same as initial value
668 */
qh_printstatlevel(FILE * fp,int id)669 void qh_printstatlevel(FILE *fp, int id) {
670 
671   if (id >= ZEND || qhstat printed[id])
672     return;
673   if (qhstat type[id] == zdoc) {
674     qh_fprintf(fp, 9360, "%s\n", qhstat doc[id]);
675     return;
676   }
677   if (qh_nostatistic(id) || !qhstat doc[id])
678     return;
679   qhstat printed[id]= True;
680   if (qhstat count[id] != -1
681       && qhstat stats[(unsigned char)(qhstat count[id])].i == 0)
682     qh_fprintf(fp, 9361, " *0 cnt*");
683   else if (qhstat type[id] >= ZTYPEreal && qhstat count[id] == -1)
684     qh_fprintf(fp, 9362, "%7.2g", qhstat stats[id].r);
685   else if (qhstat type[id] >= ZTYPEreal && qhstat count[id] != -1)
686     qh_fprintf(fp, 9363, "%7.2g", qhstat stats[id].r/ qhstat stats[(unsigned char)(qhstat count[id])].i);
687   else if (qhstat type[id] < ZTYPEreal && qhstat count[id] == -1)
688     qh_fprintf(fp, 9364, "%7d", qhstat stats[id].i);
689   else if (qhstat type[id] < ZTYPEreal && qhstat count[id] != -1)
690     qh_fprintf(fp, 9365, "%7.3g", (realT) qhstat stats[id].i / qhstat stats[(unsigned char)(qhstat count[id])].i);
691   qh_fprintf(fp, 9366, " %s\n", qhstat doc[id]);
692 } /* printstatlevel */
693 
694 
695 /*-<a                             href="qh-stat.htm#TOC"
696   >-------------------------------</a><a name="printstats">-</a>
697 
698   qh_printstats( fp, index, nextindex )
699     print statistics for a zdoc group
700 
701   returns:
702     next zdoc if non-null
703 */
qh_printstats(FILE * fp,int idx,int * nextindex)704 void qh_printstats(FILE *fp, int idx, int *nextindex) {
705   int j, nexti;
706 
707   if (qh_newstats(idx, &nexti)) {
708     qh_fprintf(fp, 9367, "\n");
709     for (j=idx; j<nexti; j++)
710       qh_printstatlevel(fp, qhstat id[j]);
711   }
712   if (nextindex)
713     *nextindex= nexti;
714 } /* printstats */
715 
716 #if qh_KEEPstatistics
717 
718 /*-<a                             href="qh-stat.htm#TOC"
719   >-------------------------------</a><a name="stddev">-</a>
720 
721   qh_stddev( num, tot, tot2, ave )
722     compute the standard deviation and average from statistics
723 
724     tot2 is the sum of the squares
725   notes:
726     computes r.m.s.:
727       (x-ave)^2
728       == x^2 - 2x tot/num +   (tot/num)^2
729       == tot2 - 2 tot tot/num + tot tot/num
730       == tot2 - tot ave
731 */
qh_stddev(int num,realT tot,realT tot2,realT * ave)732 realT qh_stddev(int num, realT tot, realT tot2, realT *ave) {
733   realT stddev;
734 
735   if (num <= 0) {
736     qh_fprintf(qh ferr, 7101, "qhull warning (qh_stddev): expecting num > 0.  Got num %d, tot %4.4g, tot2 %4.4g.  Returning 0.0\n",
737       num, tot, tot2);
738     return 0.0;
739   }
740   *ave= tot/num;
741   stddev= sqrt(fabs(tot2/num - *ave * *ave));
742   return stddev;
743 } /* stddev */
744 #else
qh_stddev(int num,realT tot,realT tot2,realT * ave)745 realT qh_stddev(int num, realT tot, realT tot2, realT *ave) { /* for qhull-exports.def */
746   QHULL_UNUSED(num)
747   QHULL_UNUSED(tot)
748   QHULL_UNUSED(tot2)
749   QHULL_UNUSED(ave)
750 
751   return 0.0;
752 }
753 #endif /* qh_KEEPstatistics */
754 
755 #if !qh_KEEPstatistics
qh_collectstatistics(void)756 void    qh_collectstatistics(void) {}
qh_printallstatistics(FILE * fp,const char * string)757 void    qh_printallstatistics(FILE *fp, const char *string) {}
qh_printstatistics(FILE * fp,const char * string)758 void    qh_printstatistics(FILE *fp, const char *string) {}
759 #endif
760 
761