stat_r.h 13 KB

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