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