stat.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /* stat.h - contains all statistics that are collected for qhull
  2. see README and stat.c
  3. copyright (c) 1993, 1997, The Geometry Center
  4. recompile qhull if you change this file
  5. Integer statistics are Z* while real statistics are W*.
  6. qh_KEEPstatistics=0 turns off statistic gathering (except zzdef/zzinc/zzadd)
  7. define maydebugx to call a routine at every statistic event
  8. */
  9. #ifndef qhDEFstat
  10. #define qhDEFstat 1
  11. #ifndef qh_KEEPstatistics
  12. #define qh_KEEPstatistics 1
  13. #endif
  14. /*----------------------------------------------------
  15. -statistics, Zxxx for integers, Wxxx for reals
  16. can pick up all statistics by:
  17. grep '[zw].*_[(][ZW]' *.c >z.x
  18. remove trailers with query-replace-regexp [,)].*
  19. remove leaders with query-replace-regexp [ ^I]+ (
  20. */
  21. #if qh_KEEPstatistics
  22. enum statistics { /* alphabetical after Z/W */
  23. Zacoplanar,
  24. Wacoplanarmax,
  25. Wacoplanartot,
  26. Zangle,
  27. Wangle,
  28. Wanglemax,
  29. Wanglemin,
  30. Zangletests,
  31. Wareatot,
  32. Wareamax,
  33. Wareamin,
  34. Zavoidold,
  35. Wavoidoldmax,
  36. Wavoidoldtot,
  37. Zback0,
  38. Zbestcentrum,
  39. Zbestdist,
  40. Zcentrumtests,
  41. Zcheckpart,
  42. Zcomputefurthest,
  43. Zconcave,
  44. Wconcavemax,
  45. Wconcavetot,
  46. Zconcaveridges,
  47. Zconcaveridge,
  48. Zcoplanar,
  49. Wcoplanarmax,
  50. Wcoplanartot,
  51. Zcoplanarangle,
  52. Zcoplanarcentrum,
  53. Zcoplanarhorizon,
  54. Zcoplanarinside,
  55. Zcoplanarpart,
  56. Zcoplanarridges,
  57. Wcpu,
  58. Zcyclefacetmax,
  59. Zcyclefacettot,
  60. Zcyclehorizon,
  61. Wcyclemax,
  62. Wcycletot,
  63. Zcyclevertex,
  64. Zdegen,
  65. Wdegenmax,
  66. Wdegentot,
  67. Zdegenvertex,
  68. Zdelfacetdup,
  69. Zdelridge,
  70. Zdelvertextot,
  71. Zdelvertexmax,
  72. Zdetsimplex,
  73. Zdistcheck,
  74. Zdistconvex,
  75. Zdistgood,
  76. Zdistio,
  77. Zdistplane,
  78. Zdiststat,
  79. Zdistvertex,
  80. Zdistzero,
  81. Zdoc1,
  82. Zdoc2,
  83. Zdoc3,
  84. Zdoc4,
  85. Zdoc5,
  86. Zdoc6,
  87. Zdoc7,
  88. Zdoc8,
  89. Zdoc9,
  90. Zdoc10,
  91. Zdropdegen,
  92. Zdropneighbor,
  93. Zdupflip,
  94. Zduplicate,
  95. Wduplicatemax,
  96. Wduplicatetot,
  97. Zdupridge,
  98. Zdupsame,
  99. Zfindfail,
  100. Zflipped,
  101. Wflippedmax,
  102. Wflippedtot,
  103. Zflippedfacets,
  104. Zgauss0,
  105. Zgoodfacet,
  106. Zhashlookup,
  107. Zhashridge,
  108. Zhashridgetest,
  109. Zhashtests,
  110. Zinsidevisible,
  111. Zintersect,
  112. Zintersectfail,
  113. Zintersectmax,
  114. Zintersectnum,
  115. Zintersecttot,
  116. Zmaxneighbors,
  117. Wmaxout,
  118. Wmaxoutside,
  119. Zmaxridges,
  120. Zmaxvertex,
  121. Zmaxvertices,
  122. Zmaxvneighbors,
  123. Zmemfacets,
  124. Zmempoints,
  125. Zmemridges,
  126. Zmemvertices,
  127. Zmergeflipdup,
  128. Zmergehorizon,
  129. Zmergeinittot,
  130. Zmergeinitmax,
  131. Zmergeinittot2,
  132. Zmergeintohorizon,
  133. Zmergenew,
  134. Zmergesettot,
  135. Zmergesetmax,
  136. Zmergesettot2,
  137. Zmergesimplex,
  138. Zmergevertex,
  139. Wmindenom,
  140. Wminvertex,
  141. Zminnorm,
  142. Zmultiridge,
  143. Znearlysingular,
  144. Zneighbor,
  145. Wnewbalance,
  146. Wnewbalance2,
  147. Znewfacettot,
  148. Znewfacetmax,
  149. Znewvertex,
  150. Wnewvertex,
  151. Wnewvertexmax,
  152. Znoarea,
  153. Znotgood,
  154. Znotgoodnew,
  155. Znotmax,
  156. Znumfacets,
  157. Znummergemax,
  158. Znummergetot,
  159. Znumneighbors,
  160. Znumridges,
  161. Znumvertices,
  162. Znumvisibility,
  163. Znumvneighbors,
  164. Zonehorizon,
  165. Zpartcoplanar,
  166. Zpartinside,
  167. Zpartition,
  168. Zpartitionall,
  169. Zpartnear,
  170. Zpbalance,
  171. Wpbalance,
  172. Wpbalance2,
  173. Zpostfacets,
  174. Zpremergetot,
  175. Zprocessed,
  176. Zremvertex,
  177. Zremvertexdel,
  178. Zrenameall,
  179. Zrenamepinch,
  180. Zrenameshare,
  181. Zsamevertices,
  182. Zsearchpoints,
  183. Zsetplane,
  184. Ztestvneighbor,
  185. Ztotcheck,
  186. Ztothorizon,
  187. Ztotmerge,
  188. Ztotpartcoplanar,
  189. Ztotpartition,
  190. Ztotridges,
  191. Ztotvertices,
  192. Ztotvisible,
  193. Wvertexmax,
  194. Wvertexmin,
  195. Zvertexridge,
  196. Zvertexridgetot,
  197. Zvertexridgemax,
  198. Zvertices,
  199. Zvisfacettot,
  200. Zvisfacetmax,
  201. Zvisvertextot,
  202. Zvisvertexmax,
  203. Zwidefacet,
  204. Zwidevertices,
  205. ZEND};
  206. #else
  207. enum statistics { /* for zzdef etc. macros */
  208. Zback0,
  209. Zbestdist,
  210. Zcentrumtests,
  211. Zconcaveridges,
  212. Zcoplanarhorizon,
  213. Zcoplanarpart,
  214. Zcoplanarridges,
  215. Zcyclefacettot,
  216. Zcyclehorizon,
  217. Zdistcheck,
  218. Zdistconvex,
  219. Zdistzero,
  220. Zdoc1,
  221. Zdoc2,
  222. Zdoc3,
  223. Zflippedfacets,
  224. Zgauss0,
  225. Zminnorm,
  226. Zmultiridge,
  227. Znearlysingular,
  228. Znumvisibility,
  229. Zpartcoplanar,
  230. Zpartition,
  231. Zpartitionall,
  232. Zprocessed,
  233. Zsetplane,
  234. Ztotmerge,
  235. ZEND};
  236. #endif
  237. /* ------------ -ztypes- ---------------------
  238. the type of a statistic sets its initial value. The type should
  239. be the same as the macro for collecting the statistic
  240. */
  241. enum ztypes {zdoc,zinc,zadd,zmax,zmin,ZTYPEreal,wadd,wmax,wmin,ZTYPEend};
  242. /*------------ -macros -------------
  243. macros:
  244. zdef_(type, name, doc, -1) define a statistic (assumes 'qhstat next= 0;')
  245. zdef_(type, name, doc, count) printed as name/count
  246. zinc_(name) integer statistic is count
  247. zadd/wadd_(name, value) integer or real statistic is total value
  248. zmax/wmax_(name, value) integer or real statistic is max value
  249. zmin/wmin_(name, value) integer or real statistic is min value
  250. zval/wval_(name) set or return value of statistic
  251. */
  252. #define MAYdebugx /* maydebug() is called frequently to trap an error */
  253. #define zzinc_(id) {MAYdebugx; qhstat stats[id].i++;}
  254. #define zzadd_(id, val) {MAYdebugx; qhstat stats[id].i += (val);}
  255. #define zzval_(id) ((qhstat stats[id]).i)
  256. #define wwval_(id) ((qhstat stats[id]).r)
  257. #define zzdef_(stype,name,string,cnt) qhstat id[qhstat next++]=name; \
  258. qhstat doc[name]= string; qhstat count[name]= cnt; qhstat type[name]= stype
  259. #if qh_KEEPstatistics
  260. #define zinc_(id) {MAYdebugx; qhstat stats[id].i++;}
  261. #define zadd_(id, val) {MAYdebugx; qhstat stats[id].i += (val);}
  262. #define wadd_(id, val) {MAYdebugx; qhstat stats[id].r += (val);}
  263. #define zmax_(id, val) {MAYdebugx; maximize_(qhstat stats[id].i,(val));}
  264. #define wmax_(id, val) {MAYdebugx; maximize_(qhstat stats[id].r,(val));}
  265. #define zmin_(id, val) {MAYdebugx; minimize_(qhstat stats[id].i,(val));}
  266. #define wmin_(id, val) {MAYdebugx; minimize_(qhstat stats[id].r,(val));}
  267. #define zval_(id) ((qhstat stats[id]).i)
  268. #define wval_(id) ((qhstat stats[id]).r)
  269. #define zdef_(stype,name,string,cnt) qhstat id[qhstat next++]=name; \
  270. qhstat doc[name]= string; qhstat count[name]= cnt; qhstat type[name]= stype
  271. #else /* !qh_KEEPstatistics */
  272. #define zinc_(id) {}
  273. #define zadd_(id, val) {}
  274. #define wadd_(id, val) {}
  275. #define zmax_(id, val) {}
  276. #define wmax_(id, val) {}
  277. #define zmin_(id, val) {}
  278. #define wmin_(id, val) {}
  279. #define zval_(id) qhstat tempi
  280. #define wval_(id) qhstat tempr
  281. #define zdef_(type,name,doc,count)
  282. #define ZMAXlevel 1
  283. #endif
  284. /* -typedef and extern- types are defined below */
  285. typedef struct qhstatT qhstatT; /* global data structure for statistics */
  286. typedef union intrealT intrealT; /* union of int and realT */
  287. /* -qhstat-
  288. access to qh_qhstat is via the "qhstat" macro. There are two choices
  289. qh_QHpointer = 1 access globals via a pointer
  290. enables qh_saveqhull() and qh_restoreqhull()
  291. = 0 qh_qhstat is a static data structure
  292. only one instance of qhull() can be active at a time
  293. default value
  294. qh_QHpointer is defined in qhull.h
  295. */
  296. #if qh_QHpointer
  297. #define qhstat qh_qhstat->
  298. extern qhstatT *qh_qhstat; /* allocated in stat.c */
  299. #else
  300. #define qhstat qh_qhstat.
  301. extern qhstatT qh_qhstat; /* allocated in stat.c */
  302. #endif
  303. /*-------------------------------------------
  304. -intrealT- union of integer and real, used for statistics
  305. */
  306. union intrealT {
  307. int i;
  308. realT r;
  309. };
  310. /*--------------------------------------------
  311. -qhstatT- global data structure for statistics
  312. */
  313. struct qhstatT {
  314. intrealT stats[ZEND]; /* integer and real statistics */
  315. unsigned char id[ZEND]; /* id's in print order */
  316. char *doc[ZEND]; /* array of documentation strings */
  317. short int count[ZEND]; /* -1 if none, else index of count to use */
  318. char type[ZEND]; /* type, see ztypes above */
  319. char printed[ZEND]; /* true, if statistic has been printed */
  320. intrealT init[ZTYPEend]; /* initial values by types, set initstatistics */
  321. int next; /* next index for zdef_ */
  322. int precision; /* index for precision problems */
  323. int tempi;
  324. realT tempr;
  325. };
  326. /* ========== -functions- ===========
  327. see also qhull.h
  328. -allstatA define statistics in groups of 20
  329. -qh_allstatistics reset printed flag for all statistics
  330. -collectstatistics collect statistics for qh facet_list
  331. -freestatistics free memory used for statistics
  332. -initstatistics allocate and initialize statistics
  333. -newstats returns True if statistics for zdoc
  334. -nostatistic true if no statistic to print
  335. -printallstatistics print all statistics
  336. -printstatistics print statistics to a file
  337. -printstatlevel print level information for a statistic
  338. -printstats print statistics for a zdoc group
  339. -stddev compute the standard deviation and average from statistics
  340. */
  341. void qh_allstatA(void);
  342. void qh_allstatB(void);
  343. void qh_allstatC(void);
  344. void qh_allstatD(void);
  345. void qh_allstatE(void);
  346. void qh_allstatF(void);
  347. void qh_allstatG(void);
  348. void qh_allstatH(void);
  349. void qh_allstatistics (void);
  350. void qh_collectstatistics (void);
  351. void qh_freestatistics (void);
  352. void qh_initstatistics (void);
  353. boolT qh_newstats (int index, int *nextindex);
  354. boolT qh_nostatistic (int i);
  355. void qh_printallstatistics (FILE *fp, char *string);
  356. void qh_printstatistics (FILE *fp, char *string);
  357. void qh_printstatlevel (FILE *fp, int id, int start);
  358. void qh_printstats (FILE *fp, int index, int *nextindex);
  359. realT qh_stddev (int num, realT tot, realT tot2, realT *ave);
  360. #endif /* qhDEFstat */