Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

stat.c

Go to the documentation of this file.
00001 /*<html><pre>  -<a                             href="qh-stat.htm"
00002   >-------------------------------</a><a name="TOP">-</a>
00003 
00004    stat.c 
00005    contains all statistics that are collected for qhull
00006 
00007    see qh-stat.htm and stat.h
00008 
00009    copyright (c) 1993-2001, The Geometry Center
00010 */
00011 
00012 #include "qhull_a.h"
00013 
00014 /*============ global data structure ==========*/
00015 
00016 #if qh_QHpointer
00017 qhstatT *qh_qhstat=NULL;  /* global data structure */
00018 #else
00019 qhstatT qh_qhstat;   /* add "={0}" if this causes a compiler error */
00020 #endif
00021 
00022 /*========== functions in alphabetic order ================*/
00023 
00024 /*-<a                             href="qh-stat.htm#TOC"
00025   >-------------------------------</a><a name="allstatA">-</a>
00026   
00027   qh_allstatA()
00028     define statistics in groups of 20
00029 
00030   notes:
00031     (otherwise, 'gcc -O2' uses too much memory)
00032     uses qhstat.next
00033 */
00034 void qh_allstatA (void) {
00035   
00036    /* zdef_(type,name,doc,average) */
00037   zzdef_(zdoc, Zdoc2, "precision statistics", -1);
00038   zdef_(zinc, Znewvertex, NULL, -1);
00039   zdef_(wadd, Wnewvertex, "ave. distance of a new vertex to a facet (not 0s)", Znewvertex);
00040   zzdef_(wmax, Wnewvertexmax, "max. distance of a new vertex to a facet", -1);
00041   zdef_(wmax, Wvertexmax, "max. distance of an output vertex to a facet", -1);
00042   zdef_(wmin, Wvertexmin, "min. distance of an output vertex to a facet", -1);
00043   zdef_(wmin, Wmindenom, "min. denominator in hyperplane computation", -1);
00044 
00045   qhstat precision= qhstat next;  /* call qh_precision for each of these */
00046   zzdef_(zdoc, Zdoc3, "precision problems", -1);
00047   zzdef_(zinc, Zcoplanarridges, "coplanar half ridges in output", -1);
00048   zzdef_(zinc, Zconcaveridges, "concave half ridges in output", -1);
00049   zzdef_(zinc, Zflippedfacets, "flipped facets", -1);
00050   zzdef_(zinc, Zcoplanarhorizon, "coplanar horizon facets for new vertices", -1);
00051   zzdef_(zinc, Zcoplanarpart, "coplanar points during partitioning", -1);
00052   zzdef_(zinc, Zminnorm, "degenerate hyperplanes recomputed with gaussian elimination", -1);
00053   zzdef_(zinc, Znearlysingular, "nearly singular or axis-parallel hyperplanes", -1);
00054   zzdef_(zinc, Zback0, "zero divisors during back substitute", -1);
00055   zzdef_(zinc, Zgauss0, "zero divisors during gaussian elimination", -1);
00056   zzdef_(zinc, Zmultiridge, "ridges with multiple neighbors", -1);
00057 }
00058 void qh_allstatB (void) {
00059   zzdef_(zdoc, Zdoc1, "summary information", -1);
00060   zdef_(zinc, Zvertices, "number of vertices in output", -1);
00061   zdef_(zinc, Znumfacets, "number of facets in output", -1);
00062   zdef_(zinc, Znonsimplicial, "number of non-simplicial facets in output", -1);
00063   zdef_(zinc, Znowsimplicial, "number of simplicial facets that were merged", -1);
00064   zdef_(zinc, Znumridges, "number of ridges in output", -1);
00065   zdef_(zadd, Znumridges, "average number of ridges per facet", Znumfacets);
00066   zdef_(zmax, Zmaxridges, "maximum number of ridges", -1);
00067   zdef_(zadd, Znumneighbors, "average number of neighbors per facet", Znumfacets);
00068   zdef_(zmax, Zmaxneighbors, "maximum number of neighbors", -1);
00069   zdef_(zadd, Znumvertices, "average number of vertices per facet", Znumfacets);
00070   zdef_(zmax, Zmaxvertices, "maximum number of vertices", -1);
00071   zdef_(zadd, Znumvneighbors, "average number of neighbors per vertex", Zvertices);
00072   zdef_(zmax, Zmaxvneighbors, "maximum number of neighbors", -1);
00073   zdef_(wadd, Wcpu, "cpu seconds for qhull after input", -1);
00074   zdef_(zinc, Ztotvertices, "vertices created altogether", -1);
00075   zzdef_(zinc, Zsetplane, "facets created altogether", -1);
00076   zdef_(zinc, Ztotridges, "ridges created altogether", -1);
00077   zdef_(zinc, Zpostfacets, "facets before post merge", -1);
00078   zdef_(zadd, Znummergetot, "average merges per facet (at most 511)", Znumfacets);
00079   zdef_(zmax, Znummergemax, "  maximum merges for a facet (at most 511)", -1);
00080   zdef_(zinc, Zangle, NULL, -1);
00081   zdef_(wadd, Wangle, "average angle (cosine) of facet normals for all ridges", Zangle);
00082   zdef_(wmax, Wanglemax, "  maximum angle (cosine) of facet normals across a ridge", -1);
00083   zdef_(wmin, Wanglemin, "  minimum angle (cosine) of facet normals across a ridge", -1);
00084   zdef_(wadd, Wareatot, "total area of facets", -1);
00085   zdef_(wmax, Wareamax, "  maximum facet area", -1);
00086   zdef_(wmin, Wareamin, "  minimum facet area", -1);
00087 }  
00088 void qh_allstatC (void) {
00089   zdef_(zdoc, Zdoc9, "build hull statistics", -1);
00090   zzdef_(zinc, Zprocessed, "points processed", -1);
00091   zzdef_(zinc, Zretry, "retries due to precision problems", -1);
00092   zdef_(wmax, Wretrymax, "  max. random joggle", -1);
00093   zdef_(zmax, Zmaxvertex, "max. vertices at any one time", -1);
00094   zdef_(zinc, Ztotvisible, "ave. visible facets per iteration", Zprocessed);
00095   zdef_(zinc, Zinsidevisible, "  ave. visible facets without an horizon neighbor", Zprocessed);
00096   zdef_(zadd, Zvisfacettot,  "  ave. facets deleted per iteration", Zprocessed);
00097   zdef_(zmax, Zvisfacetmax,  "    maximum", -1);
00098   zdef_(zadd, Zvisvertextot, "ave. visible vertices per iteration", Zprocessed);
00099   zdef_(zmax, Zvisvertexmax, "    maximum", -1);
00100   zdef_(zadd, Zdelvertextot, "  ave. vertices deleted per iteration", Zprocessed);
00101   zdef_(zmax, Zdelvertexmax, "    maximum vertices deleted", -1);
00102   zdef_(zinc, Ztothorizon, "ave. horizon facets per iteration", Zprocessed);
00103   zdef_(zadd, Znewfacettot,  "ave. new or merged facets per iteration", Zprocessed);
00104   zdef_(zmax, Znewfacetmax,  "    maximum (includes initial simplex)", -1);
00105   zdef_(wadd, Wnewbalance, "average new facet balance", Zprocessed);
00106   zdef_(wadd, Wnewbalance2, "  standard deviation", -1);
00107   zdef_(wadd, Wpbalance, "average partition balance", Zpbalance);
00108   zdef_(wadd, Wpbalance2, "  standard deviation", -1);
00109   zdef_(zinc, Zpbalance, "  number of trials", -1);
00110   zdef_(zinc, Zsearchpoints, "searches of all points for initial simplex", -1);
00111   zdef_(zinc, Zdetsimplex, "determinants computed (area & initial hull)", -1);
00112   zdef_(zinc, Znoarea, "determinants not computed because vertex too low", -1);
00113   zdef_(zinc, Znotmax, "points ignored (not above max_outside)", -1);
00114   zdef_(zinc, Znotgood, "points ignored (not above a good facet)", -1);
00115   zdef_(zinc, Znotgoodnew, "points ignored (didn't create a good new facet)", -1);
00116   zdef_(zinc, Zgoodfacet, "good facets found", -1);
00117   zzdef_(zinc, Znumvisibility, "distance tests for facet visibility", -1);
00118   zdef_(zinc, Zdistvertex, "distance tests to report minimum vertex", -1);
00119   zdef_(zinc, Ztotcheck, "points checked for facets' outer planes", -1);
00120   zdef_(zinc, Zcheckpart, "  ave. distance tests per check", Ztotcheck);
00121 }
00122 void qh_allstatD(void) {
00123   zdef_(zdoc, Zdoc4, "partitioning statistics", -1);
00124   zdef_(zinc, Zpartinside, "inside points", -1);
00125   zdef_(zinc, Zpartnear, "  inside points kept with a facet", -1);
00126   zdef_(zinc, Zcoplanarinside, "  inside points that were coplanar with a facet", -1);
00127   zdef_(wadd, Wmaxout, "difference in max_outside at final check", -1);
00128   
00129   zzdef_(zinc, Zpartitionall, "distance tests for initial partition", -1);
00130   zdef_(zinc, Ztotpartition, "partitions of a point", -1);
00131   zzdef_(zinc, Zpartition, "distance tests for partitioning", -1);
00132   zzdef_(zinc, Zdistcheck, "distance tests for checking flipped facets", -1); 
00133   zzdef_(zinc, Zdistconvex, "distance tests for checking convexity", -1); 
00134   zdef_(zinc, Zdistgood, "distance tests for checking good point", -1); 
00135   zdef_(zinc, Zdistio, "distance tests for output", -1); 
00136   zdef_(zinc, Zdiststat, "distance tests for statistics", -1); 
00137   zdef_(zinc, Zdistplane, "total number of distance tests", -1);
00138   zdef_(zinc, Ztotpartcoplanar, "partitions of coplanar points or deleted vertices", -1);
00139   zzdef_(zinc, Zpartcoplanar, "   distance tests for these partitions", -1);
00140   zdef_(zinc, Zcomputefurthest, "distance tests for computing furthest", -1);
00141 }
00142 void qh_allstatE(void) {
00143   zdef_(zdoc, Zdoc5, "statistics for matching ridges", -1);
00144   zdef_(zinc, Zhashlookup, "total lookups for matching ridges of new facets", -1);
00145   zdef_(zinc, Zhashtests, "average number of tests to match a ridge", Zhashlookup);
00146   zdef_(zinc, Zhashridge, "total lookups of subridges (duplicates and boundary)", -1);
00147   zdef_(zinc, Zhashridgetest, "average number of tests per subridge", Zhashridge);
00148   zdef_(zinc, Zdupsame, "duplicated ridges in same merge cycle", -1);
00149   zdef_(zinc, Zdupflip, "duplicated ridges with flipped facets", -1);
00150 
00151   zdef_(zdoc, Zdoc6, "statistics for determining merges", -1);
00152   zdef_(zinc, Zangletests, "angles computed for ridge convexity", -1);
00153   zdef_(zinc, Zbestcentrum, "best merges used centrum instead of vertices",-1);
00154   zzdef_(zinc, Zbestdist, "distance tests for best merge", -1);
00155   zzdef_(zinc, Zcentrumtests, "distance tests for centrum convexity", -1);
00156   zzdef_(zinc, Zdistzero, "distance tests for checking simplicial convexity", -1);
00157   zdef_(zinc, Zcoplanarangle, "coplanar angles in getmergeset", -1);
00158   zdef_(zinc, Zcoplanarcentrum, "coplanar centrums in getmergeset", -1);
00159   zdef_(zinc, Zconcaveridge, "concave ridges in getmergeset", -1);
00160 }
00161 void qh_allstatF(void) {
00162   zdef_(zdoc, Zdoc7, "statistics for merging", -1);
00163   zdef_(zinc, Zpremergetot, "merge iterations", -1);
00164   zdef_(zadd, Zmergeinittot, "ave. initial non-convex ridges per iteration", Zpremergetot);
00165   zdef_(zadd, Zmergeinitmax, "  maximum", -1);
00166   zdef_(zadd, Zmergesettot, "  ave. additional non-convex ridges per iteration", Zpremergetot);
00167   zdef_(zadd, Zmergesetmax, "  maximum additional in one pass", -1);
00168   zdef_(zadd, Zmergeinittot2, "initial non-convex ridges for post merging", -1);
00169   zdef_(zadd, Zmergesettot2, "  additional non-convex ridges", -1);
00170   zdef_(wmax, Wmaxoutside, "max distance of vertex or coplanar point above facet (w/roundoff)", -1);
00171   zdef_(wmin, Wminvertex, "max distance of merged vertex below facet (or roundoff)", -1);
00172   zdef_(zinc, Zwidefacet, "centrums frozen due to a wide merge", -1);
00173   zdef_(zinc, Zwidevertices, "centrums frozen due to extra vertices", -1);
00174   zzdef_(zinc, Ztotmerge, "total number of facets or cycles of facets merged", -1);
00175   zdef_(zinc, Zmergesimplex, "merged a simplex", -1);
00176   zdef_(zinc, Zonehorizon, "simplices merged into coplanar horizon", -1);
00177   zzdef_(zinc, Zcyclehorizon, "cycles of facets merged into coplanar horizon", -1);
00178   zzdef_(zadd, Zcyclefacettot, "  ave. facets per cycle", Zcyclehorizon);
00179   zdef_(zmax, Zcyclefacetmax, "  max. facets", -1);
00180   zdef_(zinc, Zmergeintohorizon, "new facets merged into horizon", -1);
00181   zdef_(zinc, Zmergenew, "new facets merged", -1);
00182   zdef_(zinc, Zmergehorizon, "horizon facets merged into new facets", -1);
00183   zdef_(zinc, Zmergevertex, "vertices deleted by merging", -1);
00184   zdef_(zinc, Zcyclevertex, "vertices deleted by merging into coplanar horizon", -1);
00185   zdef_(zinc, Zdegenvertex, "vertices deleted by degenerate facet", -1);
00186   zdef_(zinc, Zmergeflipdup, "merges due to flipped facets in duplicated ridge", -1);
00187   zdef_(zinc, Zneighbor, "merges due to redundant neighbors", -1);
00188   zdef_(zadd, Ztestvneighbor, "non-convex vertex neighbors", -1); 
00189 }
00190 void qh_allstatG(void) {
00191   zdef_(zinc, Zacoplanar, "merges due to angle coplanar facets", -1);
00192   zdef_(wadd, Wacoplanartot, "  average merge distance", Zacoplanar);
00193   zdef_(wmax, Wacoplanarmax, "  maximum merge distance", -1);
00194   zdef_(zinc, Zcoplanar, "merges due to coplanar facets", -1);
00195   zdef_(wadd, Wcoplanartot, "  average merge distance", Zcoplanar);
00196   zdef_(wmax, Wcoplanarmax, "  maximum merge distance", -1);
00197   zdef_(zinc, Zconcave, "merges due to concave facets", -1);
00198   zdef_(wadd, Wconcavetot, "  average merge distance", Zconcave);
00199   zdef_(wmax, Wconcavemax, "  maximum merge distance", -1);
00200   zdef_(zinc, Zavoidold, "coplanar/concave merges due to avoiding old merge", -1);
00201   zdef_(wadd, Wavoidoldtot, "  average merge distance", Zavoidold);
00202   zdef_(wmax, Wavoidoldmax, "  maximum merge distance", -1);
00203   zdef_(zinc, Zdegen, "merges due to degenerate facets", -1);
00204   zdef_(wadd, Wdegentot, "  average merge distance", Zdegen);
00205   zdef_(wmax, Wdegenmax, "  maximum merge distance", -1);
00206   zdef_(zinc, Zflipped, "merges due to removing flipped facets", -1);
00207   zdef_(wadd, Wflippedtot, "  average merge distance", Zflipped);
00208   zdef_(wmax, Wflippedmax, "  maximum merge distance", -1);
00209   zdef_(zinc, Zduplicate, "merges due to duplicated ridges", -1);
00210   zdef_(wadd, Wduplicatetot, "  average merge distance", Zduplicate);
00211   zdef_(wmax, Wduplicatemax, "  maximum merge distance", -1);
00212 }
00213 void qh_allstatH(void) {
00214   zdef_(zdoc, Zdoc8, "renamed vertex statistics", -1);
00215   zdef_(zinc, Zrenameshare, "renamed vertices shared by two facets", -1);
00216   zdef_(zinc, Zrenamepinch, "renamed vertices in a pinched facet", -1);
00217   zdef_(zinc, Zrenameall, "renamed vertices shared by multiple facets", -1);
00218   zdef_(zinc, Zfindfail, "rename failures due to duplicated ridges", -1);
00219   zdef_(zinc, Zdupridge, "  duplicate ridges detected", -1);
00220   zdef_(zinc, Zdelridge, "deleted ridges due to renamed vertices", -1);
00221   zdef_(zinc, Zdropneighbor, "dropped neighbors due to renamed vertices", -1);
00222   zdef_(zinc, Zdropdegen, "degenerate facets due to dropped neighbors", -1);
00223   zdef_(zinc, Zdelfacetdup, "  facets deleted because of no neighbors", -1);
00224   zdef_(zinc, Zremvertex, "vertices removed from facets due to no ridges", -1);
00225   zdef_(zinc, Zremvertexdel, "  deleted", -1);
00226   zdef_(zinc, Zintersectnum, "vertex intersections for locating redundant vertices", -1);
00227   zdef_(zinc, Zintersectfail, "intersections failed to find a redundant vertex", -1);
00228   zdef_(zinc, Zintersect, "intersections found redundant vertices", -1);
00229   zdef_(zadd, Zintersecttot, "   ave. number found per vertex", Zintersect);
00230   zdef_(zmax, Zintersectmax, "   max. found for a vertex", -1);
00231   zdef_(zinc, Zvertexridge, NULL, -1);
00232   zdef_(zadd, Zvertexridgetot, "  ave. number of ridges per tested vertex", Zvertexridge);
00233   zdef_(zmax, Zvertexridgemax, "  max. number of ridges per tested vertex", -1);
00234 
00235   zdef_(zdoc, Zdoc10, "memory usage statistics (in bytes)", -1);
00236   zdef_(zadd, Zmemfacets, "for facets and their normals, neighbor and vertex sets", -1);
00237   zdef_(zadd, Zmemvertices, "for vertices and their neighbor sets", -1);
00238   zdef_(zadd, Zmempoints, "for input points and outside and coplanar sets",-1);
00239   zdef_(zadd, Zmemridges, "for ridges and their vertex sets", -1);
00240 } /* allstat */
00241 
00242 void qh_allstatI(void) {
00243   qhstat vridges= qhstat next;
00244   zzdef_(zdoc, Zdoc11, "Voronoi ridge statistics", -1);
00245   zzdef_(zinc, Zridge, "non-simplicial Voronoi vertices for all ridges", -1);
00246   zzdef_(wadd, Wridge, "  ave. distance to ridge", Zridge);
00247   zzdef_(wmax, Wridgemax, "  max. distance to ridge", -1);
00248   zzdef_(zinc, Zridgemid, "bounded ridges", -1);
00249   zzdef_(wadd, Wridgemid, "  ave. distance of midpoint to ridge", Zridgemid);
00250   zzdef_(wmax, Wridgemidmax, "  max. distance of midpoint to ridge", -1);
00251   zzdef_(zinc, Zridgeok, "bounded ridges with ok normal", -1);
00252   zzdef_(wadd, Wridgeok, "  ave. angle to ridge", Zridgeok);
00253   zzdef_(wmax, Wridgeokmax, "  max. angle to ridge", -1);
00254   zzdef_(zinc, Zridge0, "bounded ridges with near-zero normal", -1);
00255   zzdef_(wadd, Wridge0, "  ave. angle to ridge", Zridge0);
00256   zzdef_(wmax, Wridge0max, "  max. angle to ridge", -1);
00257 } /* allstat */
00258 
00259 /*-<a                             href="qh-stat.htm#TOC"
00260   >-------------------------------</a><a name="allstatistics">-</a>
00261   
00262   qh_allstatistics()
00263     reset printed flag for all statistics
00264 */
00265 void qh_allstatistics (void) {
00266   int i;
00267   
00268   for (i=ZEND; i--; ) 
00269     qhstat printed[i]= False;
00270 } /* allstatistics */
00271 
00272 #if qh_KEEPstatistics
00273 /*-<a                             href="qh-stat.htm#TOC"
00274   >-------------------------------</a><a name="collectstatistics">-</a>
00275   
00276   qh_collectstatistics()
00277     collect statistics for qh.facet_list
00278 
00279 */
00280 void qh_collectstatistics (void) {
00281   facetT *facet, *neighbor, **neighborp;
00282   vertexT *vertex, **vertexp;
00283   realT dotproduct, dist;
00284   int sizneighbors, sizridges, sizvertices, i;
00285   
00286   qh old_randomdist= qh RANDOMdist;
00287   qh RANDOMdist= False;
00288   zval_(Zmempoints)= qh num_points * qh normal_size + 
00289                              sizeof (qhT) + sizeof (qhstatT);
00290   zval_(Zmemfacets)= 0;
00291   zval_(Zmemridges)= 0;
00292   zval_(Zmemvertices)= 0;
00293   zval_(Zangle)= 0;
00294   wval_(Wangle)= 0.0;
00295   zval_(Znumridges)= 0;
00296   zval_(Znumfacets)= 0;
00297   zval_(Znumneighbors)= 0;
00298   zval_(Znumvertices)= 0;
00299   zval_(Znumvneighbors)= 0;
00300   zval_(Znummergetot)= 0;
00301   zval_(Znummergemax)= 0;
00302   zval_(Zvertices)= qh num_vertices - qh_setsize (qh del_vertices);
00303   if (qh MERGING || qh APPROXhull || qh JOGGLEmax < REALmax/2)
00304     wmax_(Wmaxoutside, qh max_outside);
00305   if (qh MERGING)
00306     wmin_(Wminvertex, qh min_vertex);
00307   FORALLfacets
00308     facet->seen= False;
00309   if (qh DELAUNAY) {
00310     FORALLfacets {
00311       if (facet->upperdelaunay != qh UPPERdelaunay)
00312         facet->seen= True; /* remove from angle statistics */
00313     }
00314   }
00315   FORALLfacets {
00316     if (facet->visible && qh NEWfacets)
00317       continue;
00318     sizvertices= qh_setsize (facet->vertices);
00319     sizneighbors= qh_setsize (facet->neighbors);
00320     sizridges= qh_setsize (facet->ridges);
00321     zinc_(Znumfacets);
00322     zadd_(Znumvertices, sizvertices);
00323     zmax_(Zmaxvertices, sizvertices);
00324     zadd_(Znumneighbors, sizneighbors);
00325     zmax_(Zmaxneighbors, sizneighbors);
00326     zadd_(Znummergetot, facet->nummerge);
00327     i= facet->nummerge; /* avoid warnings */
00328     zmax_(Znummergemax, i); 
00329     if (!facet->simplicial) {
00330       if (sizvertices == qh hull_dim) {
00331         zinc_(Znowsimplicial);
00332       }else {
00333         zinc_(Znonsimplicial);
00334       }
00335     }
00336     if (sizridges) {
00337       zadd_(Znumridges, sizridges);
00338       zmax_(Zmaxridges, sizridges);
00339     }
00340     zadd_(Zmemfacets, sizeof (facetT) + qh normal_size + 2*sizeof (setT) 
00341        + SETelemsize * (sizneighbors + sizvertices));
00342     if (facet->ridges) {
00343       zadd_(Zmemridges,
00344          sizeof (setT) + SETelemsize * sizridges + sizridges * 
00345          (sizeof (ridgeT) + sizeof (setT) + SETelemsize * (qh hull_dim-1))/2);
00346     }
00347     if (facet->outsideset)
00348       zadd_(Zmempoints, sizeof (setT) + SETelemsize * qh_setsize (facet->outsideset));
00349     if (facet->coplanarset)
00350       zadd_(Zmempoints, sizeof (setT) + SETelemsize * qh_setsize (facet->coplanarset));
00351     if (facet->seen) /* Delaunay upper envelope */
00352       continue;
00353     facet->seen= True;
00354     FOREACHneighbor_(facet) {
00355       if (neighbor == qh_DUPLICATEridge || neighbor == qh_MERGEridge
00356           || neighbor->seen || !facet->normal || !neighbor->normal)
00357         continue;
00358       dotproduct= qh_getangle(facet->normal, neighbor->normal);
00359       zinc_(Zangle);
00360       wadd_(Wangle, dotproduct);
00361       wmax_(Wanglemax, dotproduct)
00362       wmin_(Wanglemin, dotproduct)
00363     }
00364     if (facet->normal) {
00365       FOREACHvertex_(facet->vertices) {
00366         zinc_(Zdiststat);
00367         qh_distplane(vertex->point, facet, &dist);
00368         wmax_(Wvertexmax, dist);
00369         wmin_(Wvertexmin, dist);
00370       }
00371     }
00372   }
00373   FORALLvertices {
00374     if (vertex->deleted)
00375       continue;
00376     zadd_(Zmemvertices, sizeof (vertexT));
00377     if (vertex->neighbors) {
00378       sizneighbors= qh_setsize (vertex->neighbors);
00379       zadd_(Znumvneighbors, sizneighbors);
00380       zmax_(Zmaxvneighbors, sizneighbors);
00381       zadd_(Zmemvertices, sizeof (vertexT) + SETelemsize * sizneighbors);
00382     }
00383   }
00384   qh RANDOMdist= qh old_randomdist;
00385 } /* collectstatistics */
00386 #endif /* qh_KEEPstatistics */
00387 
00388 /*-<a                             href="qh-stat.htm#TOC"
00389   >-------------------------------</a><a name="freestatistics">-</a>
00390   
00391   qh_freestatistics(  )
00392     free memory used for statistics
00393 */
00394 void qh_freestatistics (void) {
00395 
00396 #if qh_QHpointer
00397   free (qh_qhstat);
00398   qh_qhstat= NULL;
00399 #endif
00400 } /* freestatistics */
00401 
00402 /*-<a                             href="qh-stat.htm#TOC"
00403   >-------------------------------</a><a name="initstatistics">-</a>
00404   
00405   qh_initstatistics(  )
00406     allocate and initialize statistics
00407 
00408   notes:
00409     uses malloc() instead of qh_memalloc() since mem.c not set up yet
00410 */
00411 void qh_initstatistics (void) {
00412   int i;
00413   realT realx;
00414   int intx;
00415 
00416 #if qh_QHpointer
00417   if (!(qh_qhstat= (qhstatT *)malloc (sizeof(qhstatT)))) {
00418     fprintf (qhmem.ferr, "qhull error (qh_initstatistics): insufficient memory\n");
00419     exit (1);  /* can not use qh_errexit() */
00420   }
00421 #endif
00422   
00423   qhstat next= 0;
00424   qh_allstatA();
00425   qh_allstatB();
00426   qh_allstatC();
00427   qh_allstatD();
00428   qh_allstatE();
00429   qh_allstatF();
00430   qh_allstatG();
00431   qh_allstatH();
00432   qh_allstatI();
00433   if (qhstat next > sizeof(qhstat id)) {
00434     fprintf (qhmem.ferr, "qhull error (qh_initstatistics): increase size of qhstat.id[].\n\
00435       qhstat.next %d should be <= sizeof(qhstat id) %d\n", qhstat next, sizeof(qhstat id));
00436 #if 0 /* for locating error, Znumridges should be duplicated */
00437     for (i=0; i < ZEND; i++) {
00438       int j;
00439       for (j=i+1; j < ZEND; j++) {
00440         if (qhstat id[i] == qhstat id[j]) {
00441           fprintf (qhmem.ferr, "qhull error (qh_initstatistics): duplicated statistic %d at indices %d and %d\n", 
00442               qhstat id[i], i, j);
00443         }
00444       }
00445     }
00446 #endif 
00447     exit (1);  /* can not use qh_errexit() */
00448   }
00449   qhstat init[zinc].i= 0;
00450   qhstat init[zadd].i= 0;
00451   qhstat init[zmin].i= INT_MAX;
00452   qhstat init[zmax].i= INT_MIN;
00453   qhstat init[wadd].r= 0;
00454   qhstat init[wmin].r= REALmax;
00455   qhstat init[wmax].r= -REALmax;
00456   for (i=0; i < ZEND; i++) {
00457     if (qhstat type[i] > ZTYPEreal) {
00458       realx= qhstat init[(unsigned char)(qhstat type[i])].r;
00459       qhstat stats[i].r= realx;
00460     }else if (qhstat type[i] != zdoc) {
00461       intx= qhstat init[(unsigned char)(qhstat type[i])].i;
00462       qhstat stats[i].i= intx;
00463     }
00464   }
00465 } /* initstatistics */
00466 
00467 /*-<a                             href="qh-stat.htm#TOC"
00468   >-------------------------------</a><a name="newstats">-</a>
00469   
00470   qh_newstats(  )
00471     returns True if statistics for zdoc
00472 
00473   returns:
00474     next zdoc
00475 */
00476 boolT qh_newstats (int index, int *nextindex) {
00477   boolT isnew= False;
00478   int start, i;
00479 
00480   if (qhstat type[qhstat id[index]] == zdoc) 
00481     start= index+1;
00482   else
00483     start= index;
00484   for (i= start; i < qhstat next && qhstat type[qhstat id[i]] != zdoc; i++) {
00485     if (!qh_nostatistic(qhstat id[i]) && !qhstat printed[qhstat id[i]])
00486         isnew= True;
00487   }
00488   *nextindex= i;
00489   return isnew;
00490 } /* newstats */
00491 
00492 /*-<a                             href="qh-stat.htm#TOC"
00493   >-------------------------------</a><a name="nostatistic">-</a>
00494   
00495   qh_nostatistic( index )
00496     true if no statistic to print
00497 */
00498 boolT qh_nostatistic (int i) {
00499   
00500   if ((qhstat type[i] > ZTYPEreal
00501        &&qhstat stats[i].r == qhstat init[(unsigned char)(qhstat type[i])].r)
00502       || (qhstat type[i] < ZTYPEreal
00503           &&qhstat stats[i].i == qhstat init[(unsigned char)(qhstat type[i])].i))
00504     return True;
00505   return False;
00506 } /* nostatistic */
00507 
00508 #if qh_KEEPstatistics
00509 /*-<a                             href="qh-stat.htm#TOC"
00510   >-------------------------------</a><a name="printallstatistics">-</a>
00511   
00512   qh_printallstatistics( fp, string )
00513     print all statistics with header 'string'
00514 */
00515 void qh_printallstatistics (FILE *fp, char *string) {
00516 
00517   qh_allstatistics();
00518   qh_collectstatistics();
00519   qh_printstatistics (fp, string);
00520   qh_memstatistics (fp);
00521 }
00522 
00523 
00524 /*-<a                             href="qh-stat.htm#TOC"
00525   >-------------------------------</a><a name="printstatistics">-</a>
00526   
00527   qh_printstatistics( fp, string )
00528     print statistics to a file with header 'string'
00529     skips statistics with qhstat.printed[] (reset with qh_allstatistics)
00530 
00531   see: 
00532     qh_printallstatistics()
00533 */
00534 void qh_printstatistics (FILE *fp, char *string) {
00535   int i, k;
00536   realT ave;
00537   
00538   if (qh num_points != qh num_vertices) {
00539     wval_(Wpbalance)= 0;
00540     wval_(Wpbalance2)= 0;
00541   }else
00542     wval_(Wpbalance2)= qh_stddev (zval_(Zpbalance), wval_(Wpbalance), 
00543                                  wval_(Wpbalance2), &ave);
00544   wval_(Wnewbalance2)= qh_stddev (zval_(Zprocessed), wval_(Wnewbalance), 
00545                                  wval_(Wnewbalance2), &ave);
00546   fprintf (fp, "\n\
00547 %s\n\
00548  qhull invoked by: %s | %s\n%s with options:\n%s\n", string, qh rbox_command, 
00549      qh qhull_command, qh_version, qh qhull_options);
00550   fprintf (fp, "\nprecision constants:\n\
00551  %6.2g max. abs. coordinate in the (transformed) input ('Qbd:n')\n\
00552  %6.2g max. roundoff error for distance computation ('En')\n\
00553  %6.2g max. roundoff error for angle computations\n\
00554  %6.2g min. distance for outside points ('Wn')\n\
00555  %6.2g min. distance for visible facets ('Vn')\n\
00556  %6.2g max. distance for coplanar facets ('Un')\n\
00557  %6.2g max. facet width for recomputing centrum and area\n\
00558 ", 
00559   qh MAXabs_coord, qh DISTround, qh ANGLEround, qh MINoutside, 
00560         qh MINvisible, qh MAXcoplanar, qh WIDEfacet);
00561   if (qh KEEPnearinside)
00562     fprintf(fp, "\
00563  %6.2g max. distance for near-inside points\n", qh NEARinside);
00564   if (qh premerge_cos < REALmax/2) fprintf (fp, "\
00565  %6.2g max. cosine for pre-merge angle\n", qh premerge_cos);
00566   if (qh PREmerge) fprintf (fp, "\
00567  %6.2g radius of pre-merge centrum\n", qh premerge_centrum);
00568   if (qh postmerge_cos < REALmax/2) fprintf (fp, "\
00569  %6.2g max. cosine for post-merge angle\n", qh postmerge_cos);
00570   if (qh POSTmerge) fprintf (fp, "\
00571  %6.2g radius of post-merge centrum\n", qh postmerge_centrum);
00572   fprintf (fp, "\
00573  %6.2g max. distance for merging two simplicial facets\n\
00574  %6.2g max. roundoff error for arithmetic operations\n\
00575  %6.2g min. denominator for divisions\n\
00576   zero diagonal for Gauss: ", qh ONEmerge, REALepsilon, qh MINdenom);
00577   for (k=0; k < qh hull_dim; k++)
00578     fprintf (fp, "%6.2e ", qh NEARzero[k]);
00579   fprintf (fp, "\n\n");
00580   for (i=0 ; i < qhstat next; ) 
00581     qh_printstats (fp, i, &i);
00582 } /* printstatistics */
00583 #endif /* qh_KEEPstatistics */
00584 
00585 /*-<a                             href="qh-stat.htm#TOC"
00586   >-------------------------------</a><a name="printstatlevel">-</a>
00587   
00588   qh_printstatlevel( fp, id )
00589     print level information for a statistic
00590 
00591   notes:
00592     nop if id >= ZEND, printed, or same as initial value
00593 */
00594 void qh_printstatlevel (FILE *fp, int id, int start) {
00595 #define NULLfield "       "
00596 
00597   if (id >= ZEND || qhstat printed[id])
00598     return;
00599   if (qhstat type[id] == zdoc) {
00600     fprintf (fp, "%s\n", qhstat doc[id]);
00601     return;
00602   }
00603   start= 0; /* not used */
00604   if (qh_nostatistic(id) || !qhstat doc[id])
00605     return;
00606   qhstat printed[id]= True;
00607   if (qhstat count[id] != -1 
00608       && qhstat stats[(unsigned char)(qhstat count[id])].i == 0)
00609     fprintf (fp, " *0 cnt*");
00610   else if (qhstat type[id] >= ZTYPEreal && qhstat count[id] == -1)
00611     fprintf (fp, "%7.2g", qhstat stats[id].r);
00612   else if (qhstat type[id] >= ZTYPEreal && qhstat count[id] != -1)
00613     fprintf (fp, "%7.2g", qhstat stats[id].r/ qhstat stats[(unsigned char)(qhstat count[id])].i);
00614   else if (qhstat type[id] < ZTYPEreal && qhstat count[id] == -1)
00615     fprintf (fp, "%7d", qhstat stats[id].i);
00616   else if (qhstat type[id] < ZTYPEreal && qhstat count[id] != -1)
00617     fprintf (fp, "%7.3g", (realT) qhstat stats[id].i / qhstat stats[(unsigned char)(qhstat count[id])].i);
00618   fprintf (fp, " %s\n", qhstat doc[id]);
00619 } /* printstatlevel */
00620 
00621 
00622 /*-<a                             href="qh-stat.htm#TOC"
00623   >-------------------------------</a><a name="printstats">-</a>
00624   
00625   qh_printstats( fp, index, nextindex )
00626     print statistics for a zdoc group
00627 
00628   returns:
00629     next zdoc if non-null
00630 */
00631 void qh_printstats (FILE *fp, int index, int *nextindex) {
00632   int j, nexti;
00633 
00634   if (qh_newstats (index, &nexti)) {
00635     fprintf (fp, "\n");
00636     for (j=index; j<nexti; j++)
00637       qh_printstatlevel (fp, qhstat id[j], 0);
00638   }
00639   if (nextindex)
00640     *nextindex= nexti;
00641 } /* printstats */
00642 
00643 #if qh_KEEPstatistics
00644 
00645 /*-<a                             href="qh-stat.htm#TOC"
00646   >-------------------------------</a><a name="stddev">-</a>
00647   
00648   qh_stddev( num, tot, tot2, ave )
00649     compute the standard deviation and average from statistics
00650 
00651     tot2 is the sum of the squares
00652   notes:
00653     computes r.m.s.: 
00654       (x-ave)^2 
00655       == x^2 - 2x tot/num +   (tot/num)^2
00656       == tot2 - 2 tot tot/num + tot tot/num 
00657       == tot2 - tot ave
00658 */
00659 realT qh_stddev (int num, realT tot, realT tot2, realT *ave) {
00660   realT stddev;
00661 
00662   *ave= tot/num;
00663   stddev= sqrt (tot2/num - *ave * *ave);
00664   return stddev;
00665 } /* stddev */
00666 
00667 #endif /* qh_KEEPstatistics */ 
00668 
00669 #if !qh_KEEPstatistics
00670 void    qh_collectstatistics (void) {}
00671 void    qh_printallstatistics (FILE *fp, char *string) {};
00672 void    qh_printstatistics (FILE *fp, char *string) {}
00673 #endif
00674 
 

Powered by Plone

This site conforms to the following standards: