1 /*<html><pre>  -<a                             href="qh-stat_r.htm"
2   >-------------------------------</a><a name="TOP">-</a>
3 
4    stat_r.h
5      contains all statistics that are collected for qhull
6 
7    see qh-stat_r.htm and stat_r.c
8 
9    Copyright (c) 1993-2020 The Geometry Center.
10    $Id: //main/2019/qhull/src/libqhull_r/stat_r.h#4 $$Change: 2953 $
11    $DateTime: 2020/05/21 22:05:32 $$Author: bbarber $
12 
13    recompile qhull if you change this file
14 
15    Integer statistics are Z* while real statistics are W*.
16 
17    define MAYdebugx to call a routine at every statistic event
18 
19 */
20 
21 #ifndef qhDEFstat
22 #define qhDEFstat 1
23 
24 /* Depends on realT.  Do not include "libqhull_r" to avoid circular dependency */
25 
26 #ifndef DEFqhT
27 #define DEFqhT 1
28 typedef struct qhT qhT;         /* Defined by libqhull_r.h */
29 #endif
30 
31 #ifndef DEFqhstatT
32 #define DEFqhstatT 1
33 typedef struct qhstatT qhstatT; /* Defined here */
34 #endif
35 
36 /*-<a                             href="qh-stat_r.htm#TOC"
37   >-------------------------------</a><a name="KEEPstatistics">-</a>
38 
39   qh_KEEPstatistics
40     0 turns off statistic reporting and gathering (except zzdef/zzinc/zzadd/zzval/wwval)
41 
42   set qh_KEEPstatistics in user_r.h to 0 to turn off statistics
43 */
44 #ifndef qh_KEEPstatistics
45 #define qh_KEEPstatistics 1
46 #endif
47 
48 /*-<a                             href="qh-stat_r.htm#TOC"
49   >-------------------------------</a><a name="statistics">-</a>
50 
51   Zxxx for integers, Wxxx for reals
52 
53   notes:
54     be sure that all statistics are defined in stat_r.c
55       otherwise initialization may core dump
56     can pick up all statistics by:
57       grep '[zw].*_[(][ZW]' *.c >z.x
58     remove trailers with query">-</a>
59     remove leaders with  query-replace-regexp [ ^I]+  (
60 */
61 #if qh_KEEPstatistics
62 enum qh_statistics {     /* alphabetical after Z/W */
63     Zacoplanar,
64     Wacoplanarmax,
65     Wacoplanartot,
66     Zangle,
67     Wangle,
68     Wanglemax,
69     Wanglemin,
70     Zangletests,
71     Wareatot,
72     Wareamax,
73     Wareamin,
74     Zavoidold,
75     Wavoidoldmax,
76     Wavoidoldtot,
77     Zback0,
78     Zbestcentrum,
79     Zbestdist,
80     Zbestlower,
81     Zbestlowerall,
82     Zbestloweralln,
83     Zbestlowerv,
84     Zcentrumtests,
85     Zcheckpart,
86     Zcomputefurthest,
87     Zconcave,
88     Wconcavemax,
89     Wconcavetot,
90     Zconcavecoplanar,
91     Wconcavecoplanarmax,
92     Wconcavecoplanartot,
93     Zconcavecoplanarridge,
94     Zconcaveridge,
95     Zconcaveridges,
96     Zcoplanar,
97     Wcoplanarmax,
98     Wcoplanartot,
99     Zcoplanarangle,
100     Zcoplanarcentrum,
101     Zcoplanarhorizon,
102     Zcoplanarinside,
103     Zcoplanarpart,
104     Zcoplanarridges,
105     Wcpu,
106     Zcyclefacetmax,
107     Zcyclefacettot,
108     Zcyclehorizon,
109     Zcyclevertex,
110     Zdegen,
111     Wdegenmax,
112     Wdegentot,
113     Zdegenvertex,
114     Zdelfacetdup,
115     Zdelridge,
116     Zdelvertextot,
117     Zdelvertexmax,
118     Zdetfacetarea,
119     Zdetsimplex,
120     Zdistcheck,
121     Zdistconvex,
122     Zdistgood,
123     Zdistio,
124     Zdistplane,
125     Zdiststat,
126     Zdistvertex,
127     Zdistzero,
128     Zdoc1,
129     Zdoc2,
130     Zdoc3,
131     Zdoc4,
132     Zdoc5,
133     Zdoc6,
134     Zdoc7,
135     Zdoc8,
136     Zdoc9,
137     Zdoc10,
138     Zdoc11,
139     Zdoc12,
140     Zdropdegen,
141     Zdropneighbor,
142     Zdupflip,
143     Zduplicate,
144     Wduplicatemax,
145     Wduplicatetot,
146     Zdupsame,
147     Zflipped,
148     Wflippedmax,
149     Wflippedtot,
150     Zflippedfacets,
151     Zflipridge,
152     Zflipridge2,
153     Zfindbest,
154     Zfindbestmax,
155     Zfindbesttot,
156     Zfindcoplanar,
157     Zfindfail,
158     Zfindhorizon,
159     Zfindhorizonmax,
160     Zfindhorizontot,
161     Zfindjump,
162     Zfindnew,
163     Zfindnewmax,
164     Zfindnewtot,
165     Zfindnewjump,
166     Zfindnewsharp,
167     Zgauss0,
168     Zgoodfacet,
169     Zhashlookup,
170     Zhashridge,
171     Zhashridgetest,
172     Zhashtests,
173     Zinsidevisible,
174     Zintersect,
175     Zintersectfail,
176     Zintersectmax,
177     Zintersectnum,
178     Zintersecttot,
179     Zmaxneighbors,
180     Wmaxout,
181     Wmaxoutside,
182     Zmaxridges,
183     Zmaxvertex,
184     Zmaxvertices,
185     Zmaxvneighbors,
186     Zmemfacets,
187     Zmempoints,
188     Zmemridges,
189     Zmemvertices,
190     Zmergeflipdup,
191     Zmergehorizon,
192     Zmergeinittot,
193     Zmergeinitmax,
194     Zmergeinittot2,
195     Zmergeintocoplanar,
196     Zmergeintohorizon,
197     Zmergenew,
198     Zmergesettot,
199     Zmergesetmax,
200     Zmergesettot2,
201     Zmergesimplex,
202     Zmergevertex,
203     Wmindenom,
204     Wminvertex,
205     Zminnorm,
206     Zmultiridge,
207     Znearlysingular,
208     Zredundant,
209     Wnewbalance,
210     Wnewbalance2,
211     Znewbesthorizon,
212     Znewfacettot,
213     Znewfacetmax,
214     Znewvertex,
215     Wnewvertex,
216     Wnewvertexmax,
217     Znewvertexridge,
218     Znoarea,
219     Znonsimplicial,
220     Znowsimplicial,
221     Znotgood,
222     Znotgoodnew,
223     Znotmax,
224     Znumfacets,
225     Znummergemax,
226     Znummergetot,
227     Znumneighbors,
228     Znumridges,
229     Znumvertices,
230     Znumvisibility,
231     Znumvneighbors,
232     Zonehorizon,
233     Zpartangle,
234     Zpartcoplanar,
235     Zpartcorner,
236     Zparthidden,
237     Zpartinside,
238     Zpartition,
239     Zpartitionall,
240     Zpartnear,
241     Zparttwisted,
242     Zpbalance,
243     Wpbalance,
244     Wpbalance2,
245     Zpinchduplicate,
246     Zpinchedapex,
247     Zpinchedvertex,
248     Zpostfacets,
249     Zpremergetot,
250     Zprocessed,
251     Zremvertex,
252     Zremvertexdel,
253     Zredundantmerge,
254     Zrenameall,
255     Zrenamepinch,
256     Zrenameshare,
257     Zretry,
258     Wretrymax,
259     Zretryadd,
260     Zretryaddmax,
261     Zretryaddtot,
262     Zridge,
263     Wridge,
264     Wridgemax,
265     Zridge0,
266     Wridge0,
267     Wridge0max,
268     Zridgemid,
269     Wridgemid,
270     Wridgemidmax,
271     Zridgeok,
272     Wridgeok,
273     Wridgeokmax,
274     Zsearchpoints,
275     Zsetplane,
276     Ztestvneighbor,
277     Ztotcheck,
278     Ztothorizon,
279     Ztotmerge,
280     Ztotpartcoplanar,
281     Ztotpartition,
282     Ztotridges,
283     Ztotvertices,
284     Ztotvisible,
285     Ztricoplanar,
286     Ztricoplanarmax,
287     Ztricoplanartot,
288     Ztridegen,
289     Ztrimirror,
290     Ztrinull,
291     Ztwisted,
292     Wtwistedtot,
293     Wtwistedmax,
294     Ztwistedridge,
295     Zvertextests,
296     Wvertexmax,
297     Wvertexmin,
298     Zvertexridge,
299     Zvertexridgetot,
300     Zvertexridgemax,
301     Zvertices,
302     Zvisfacettot,
303     Zvisfacetmax,
304     Zvisit,
305     Zvisit2max,
306     Zvisvertextot,
307     Zvisvertexmax,
308     Zvvisit,
309     Zvvisit2max,
310     Zwidefacet,
311     Zwidevertices,
312     ZEND};
313 
314 /*-<a                             href="qh-stat_r.htm#TOC"
315   >-------------------------------</a><a name="ZZstat">-</a>
316 
317   Zxxx/Wxxx statistics that remain defined if qh_KEEPstatistics=0
318 
319   notes:
320     be sure to use zzdef, zzinc, etc. with these statistics (no double checking!)
321 */
322 #else
323 enum qh_statistics {     /* for zzdef etc. macros */
324   Zback0,
325   Zbestdist,
326   Zcentrumtests,
327   Zcheckpart,
328   Zconcaveridges,
329   Zcoplanarhorizon,
330   Zcoplanarpart,
331   Zcoplanarridges,
332   Zcyclefacettot,
333   Zcyclehorizon,
334   Zdelvertextot,
335   Zdistcheck,
336   Zdistconvex,
337   Zdistplane,
338   Zdistzero,
339   Zdoc1,
340   Zdoc2,
341   Zdoc3,
342   Zdoc11,
343   Zflippedfacets,
344   Zflipridge,
345   Zflipridge2,
346   Zgauss0,
347   Zminnorm,
348   Zmultiridge,
349   Znearlysingular,
350   Wnewvertexmax,
351   Znumvisibility,
352   Zpartcoplanar,
353   Zpartition,
354   Zpartitionall,
355   Zpinchduplicate,
356   Zpinchedvertex,
357   Zprocessed,
358   Zretry,
359   Zridge,
360   Wridge,
361   Wridgemax,
362   Zridge0,
363   Wridge0,
364   Wridge0max,
365   Zridgemid,
366   Wridgemid,
367   Wridgemidmax,
368   Zridgeok,
369   Wridgeok,
370   Wridgeokmax,
371   Zsetplane,
372   Ztotcheck,
373   Ztotmerge,
374   Zvertextests,
375   ZEND};
376 #endif
377 
378 /*-<a                             href="qh-stat_r.htm#TOC"
379   >-------------------------------</a><a name="ztype">-</a>
380 
381   ztype
382     the type of a statistic sets its initial value.
383 
384   notes:
385     The type should be the same as the macro for collecting the statistic
386 */
387 enum ztypes {zdoc,zinc,zadd,zmax,zmin,ZTYPEreal,wadd,wmax,wmin,ZTYPEend};
388 
389 /*========== macros and constants =============*/
390 
391 /*-<a                             href="qh-stat_r.htm#TOC"
392   >--------------------------------</a><a name="MAYdebugx">-</a>
393 
394   MAYdebugx
395     define as maydebug() to be called frequently for error trapping
396 */
397 #define MAYdebugx
398 
399 /*-<a                             href="qh-stat_r.htm#TOC"
400   >--------------------------------</a><a name="zdef_">-</a>
401 
402   zzdef_, zdef_( type, name, doc, -1)
403     define a statistic (assumes 'qhstat.next= 0;')
404 
405   zdef_( type, name, doc, count)
406     define an averaged statistic
407     printed as name/count
408 */
409 #define zzdef_(stype,name,string,cnt) qh->qhstat.id[qh->qhstat.next++]=name; \
410    qh->qhstat.doc[name]= string; qh->qhstat.count[name]= cnt; qh->qhstat.type[name]= stype
411 #if qh_KEEPstatistics
412 #define zdef_(stype,name,string,cnt) qh->qhstat.id[qh->qhstat.next++]=name; \
413    qh->qhstat.doc[name]= string; qh->qhstat.count[name]= cnt; qh->qhstat.type[name]= stype
414 #else
415 #define zdef_(type,name,doc,count)
416 #endif
417 
418 /*-<a                             href="qh-stat_r.htm#TOC"
419   >--------------------------------</a><a name="zinc_">-</a>
420 
421   zzinc_( name ), zinc_( name)
422     increment an integer statistic
423 */
424 #define zzinc_(id) {MAYdebugx; qh->qhstat.stats[id].i++;}
425 #if qh_KEEPstatistics
426 #define zinc_(id) {MAYdebugx; qh->qhstat.stats[id].i++;}
427 #else
428 #define zinc_(id) {}
429 #endif
430 
431 /*-<a                             href="qh-stat_r.htm#TOC"
432   >--------------------------------</a><a name="zadd_">-</a>
433 
434   zzadd_( name, value ), zadd_( name, value ), wadd_( name, value )
435     add value to an integer or real statistic
436 */
437 #define zzadd_(id, val) {MAYdebugx; qh->qhstat.stats[id].i += (val);}
438 #define wwadd_(id, val) {MAYdebugx; qh->qhstat.stats[id].r += (val);}
439 #if qh_KEEPstatistics
440 #define zadd_(id, val) {MAYdebugx; qh->qhstat.stats[id].i += (val);}
441 #define wadd_(id, val) {MAYdebugx; qh->qhstat.stats[id].r += (val);}
442 #else
443 #define zadd_(id, val) {}
444 #define wadd_(id, val) {}
445 #endif
446 
447 /*-<a                             href="qh-stat_r.htm#TOC"
448   >--------------------------------</a><a name="zval_">-</a>
449 
450   zzval_( name ), zval_( name ), wwval_( name )
451     set or return value of a statistic
452 */
453 #define zzval_(id) ((qh->qhstat.stats[id]).i)
454 #define wwval_(id) ((qh->qhstat.stats[id]).r)
455 #if qh_KEEPstatistics
456 #define zval_(id) ((qh->qhstat.stats[id]).i)
457 #define wval_(id) ((qh->qhstat.stats[id]).r)
458 #else
459 #define zval_(id) qh->qhstat.tempi
460 #define wval_(id) qh->qhstat.tempr
461 #endif
462 
463 /*-<a                             href="qh-stat_r.htm#TOC"
464   >--------------------------------</a><a name="zmax_">-</a>
465 
466   zmax_( id, val ), wmax_( id, value )
467     maximize id with val
468 */
469 #define wwmax_(id, val) {MAYdebugx; maximize_(qh->qhstat.stats[id].r,(val));}
470 #if qh_KEEPstatistics
471 #define zmax_(id, val) {MAYdebugx; maximize_(qh->qhstat.stats[id].i,(val));}
472 #define wmax_(id, val) {MAYdebugx; maximize_(qh->qhstat.stats[id].r,(val));}
473 #else
474 #define zmax_(id, val) {}
475 #define wmax_(id, val) {}
476 #endif
477 
478 /*-<a                             href="qh-stat_r.htm#TOC"
479   >--------------------------------</a><a name="zmin_">-</a>
480 
481   zmin_( id, val ), wmin_( id, value )
482     minimize id with val
483 */
484 #if qh_KEEPstatistics
485 #define zmin_(id, val) {MAYdebugx; minimize_(qh->qhstat.stats[id].i,(val));}
486 #define wmin_(id, val) {MAYdebugx; minimize_(qh->qhstat.stats[id].r,(val));}
487 #else
488 #define zmin_(id, val) {}
489 #define wmin_(id, val) {}
490 #endif
491 
492 /*================== stat_r.h types ==============*/
493 
494 
495 /*-<a                             href="qh-stat_r.htm#TOC"
496   >--------------------------------</a><a name="intrealT">-</a>
497 
498   intrealT
499     union of integer and real, used for statistics
500 */
501 typedef union intrealT intrealT;    /* union of int and realT */
502 union intrealT {
503     int i;
504     realT r;
505 };
506 
507 /*-<a                             href="qh-stat_r.htm#TOC"
508   >--------------------------------</a><a name="qhstat">-</a>
509 
510   qhstat
511     Data structure for statistics, similar to qh and qhrbox
512 
513     Allocated as part of qhT (libqhull_r.h)
514 */
515 
516 struct qhstatT {
517   intrealT   stats[ZEND];     /* integer and real statistics */
518   unsigned char id[ZEND+10];  /* id's in print order */
519   const char *doc[ZEND];      /* array of documentation strings */
520   short int  count[ZEND];     /* -1 if none, else index of count to use */
521   char       type[ZEND];      /* type, see ztypes above */
522   char       printed[ZEND];   /* true, if statistic has been printed */
523   intrealT   init[ZTYPEend];  /* initial values by types, set initstatistics */
524 
525   int        next;            /* next index for zdef_ */
526   int        precision;       /* index for precision problems, printed on qh_errexit and qh_produce_output2/Q0/QJn */
527   int        vridges;         /* index for Voronoi ridges, printed on qh_produce_output2 */
528   int        tempi;
529   realT      tempr;
530 };
531 
532 /*========== function prototypes ===========*/
533 
534 #ifdef __cplusplus
535 extern "C" {
536 #endif
537 
538 void    qh_allstatA(qhT *qh);
539 void    qh_allstatB(qhT *qh);
540 void    qh_allstatC(qhT *qh);
541 void    qh_allstatD(qhT *qh);
542 void    qh_allstatE(qhT *qh);
543 void    qh_allstatE2(qhT *qh);
544 void    qh_allstatF(qhT *qh);
545 void    qh_allstatG(qhT *qh);
546 void    qh_allstatH(qhT *qh);
547 void    qh_allstatI(qhT *qh);
548 void    qh_allstatistics(qhT *qh);
549 void    qh_collectstatistics(qhT *qh);
550 void    qh_initstatistics(qhT *qh);
551 boolT   qh_newstats(qhT *qh, int idx, int *nextindex);
552 boolT   qh_nostatistic(qhT *qh, int i);
553 void    qh_printallstatistics(qhT *qh, FILE *fp, const char *string);
554 void    qh_printstatistics(qhT *qh, FILE *fp, const char *string);
555 void    qh_printstatlevel(qhT *qh, FILE *fp, int id);
556 void    qh_printstats(qhT *qh, FILE *fp, int idx, int *nextindex);
557 realT   qh_stddev(qhT *qh, int num, realT tot, realT tot2, realT *ave);
558 
559 #ifdef __cplusplus
560 } /* extern "C" */
561 #endif
562 
563 #endif   /* qhDEFstat */
564