stat_r.c 32 KB

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