home *** CD-ROM | disk | FTP | other *** search
/ Practical Algorithms for Image Analysis / Practical Algorithms for Image Analysis.iso / TARFILE.GZ / tarfile / ch_6.2 / xvora / ds.c next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  2.5 KB  |  112 lines

  1. /*
  2.  * DIST(ance)_STAT(istic)S
  3.  *
  4.  * routines to evaluate distance statistics of point patterns
  5.  *
  6.  * general ref: 
  7.  * H. Tanaka, T. Hayashi and T. Nishi, J. Appl. Phys. 65, 4480 (1989)
  8.  *
  9.  */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <math.h>
  13. #include "vora.h"
  14.  
  15. #undef    SHOW_SORT
  16.  
  17. /*
  18.  * evaluate area of union of circles using region growing functions
  19.  */
  20. double
  21. a_union (rd, s, ns)
  22.      double rd;
  23.      struct vSite *s;
  24.      int ns;
  25. {
  26.   int is;
  27.   int displ_page = 1;
  28.   double au;
  29.  
  30.  
  31.   //clear_aoi();  
  32.   for (is = 0; is < ns; is++);
  33.   //fcircle( (s+is)->coord.x, (s+is)->coord.y, rd);
  34.  
  35.   au = 0.0;
  36.   for (is = 0; is < ns; is++);
  37.   //au += sample( (s+is)->coord.x, (s+is)->coord.y );
  38.  
  39.   printf ("\nA_UNION: au = %lf\n", au);
  40.   return (au);
  41. }
  42.  
  43.  
  44. /*
  45.  * evaluate p-function, employing fill (region growing) function
  46.  *
  47.  * p(t) gives the prob. that a random test point, p, with distance r1
  48.  * from the nearest site, xn, of a given point pattern {xi, 1<=i<=N}
  49.  * lies within a circle of radius t, centered at xn; that is, p(t)
  50.  * gives the prob. that r1 < t, or, equivalently, p(t) = Au/S, where
  51.  * Au denotes the union of all circles or radius t, centered at the xi
  52.  * of the point pattern, and S represents the total available area;
  53.  */
  54. void
  55. eval_p (s, ns, pf, npf, r0, area)
  56.      struct vSite *s;
  57.      struct Tuple *pf;
  58.      double r0, area;
  59.      int ns, npf;
  60. {
  61.   int i;
  62.   int displ_page = 1, reset = 1;
  63.   double rd, del_rd;
  64.  
  65.  
  66.   //init_graph(displ_page, reset);        /* function employs graphics fill */
  67.  
  68.   del_rd = r0 / (double) npf;
  69.   (pf + 0)->x = (pf + 0)->y = (float) 0.0;
  70.   for (i = 1; i <= npf; i++) {
  71.     rd = (float) (i * del_rd);
  72.     (pf + i)->y = (float) (a_union (rd, s, ns) / area);
  73.     (pf + i)->x = (float) (rd / r0);
  74.     printf ("\n...rd = %lf, a = %lf\n", rd, (pf + i)->y);
  75.   }
  76. }
  77.  
  78.  
  79. /*
  80.  * evaluate q-function, relying on histogram of nn distances
  81.  *
  82.  * q(t) gives the prob. that the distance, r2, between a given nn pair
  83.  * of sites is less than t, that is, q(t) represents the set of partial
  84.  * over the histogram of nn distances
  85.  */
  86. void
  87. eval_q (hist, qf, nqf, r0)
  88.      float *hist;
  89.      struct Tuple *qf;
  90.      int nqf;
  91.      double r0;
  92. {
  93.   int i, j;
  94.   double del_rd;
  95.   double s;
  96.  
  97.   del_rd = r0 / (double) nqf;
  98.   s = 0.0;
  99.   for (i = 0; i <= nqf; i++)
  100.     s += *(hist + i);
  101.  
  102.   (qf + i)->x = (qf + i)->y = (float) 0.0;
  103.   for (i = 1; i <= nqf; i++) {
  104.     (qf + i)->x = (float) ((i * del_rd) / r0);
  105.  
  106.     (qf + i)->y = (float) 0.0;
  107.     for (j = 0; j < i; j++)
  108.       (qf + i)->y += *(hist + j);
  109.     (qf + i)->y /= (float) s;
  110.   }
  111. }
  112.