GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
findzc.c
Go to the documentation of this file.
1 
27 #include <stdio.h>
28 #include <math.h>
29 
30 
32 #define TINY 1.0e-3
33 
34 
55 int
56 G_math_findzc(double conv[], int size, double zc[], double thresh,
57  int num_orients)
58 {
59  int i, j, p;
60 
61  /* go through entire conv image - but skip border rows and cols */
62  for (i = 1; i < size - 1; i++) {
63  for (p = i * size + 1, j = 1; j < size - 1; j++, p++) {
64  int nbr[4];
65  int ni;
66 
67  /* examine the 4-neighbors of position p */
68  nbr[0] = p - 1; /* left */
69  nbr[1] = p + 1; /* right */
70  nbr[2] = p - size; /* up */
71  nbr[3] = p + size; /* down */
72 
73  zc[p] = 0;
74 
75  for (ni = 0; ni < 4; ni++) {
76  /* condition for a zc: sign is different than a neighbor
77  * and the absolute value is less than that neighbor.
78  * Also, threshold magnitudes to eliminate noise
79  */
80  if ((((conv[p] > 0) && (conv[nbr[ni]] < 0)) ||
81  ((conv[p] < 0) && (conv[nbr[ni]] > 0))) &&
82  (fabs(conv[p]) < fabs(conv[nbr[ni]])) &&
83  (fabs(conv[p] - conv[nbr[ni]]) > thresh)) {
84  double ang;
85  int dir;
86 
87  /* found a zc here, get angle of gradient */
88  if (fabs(conv[nbr[1]] - conv[nbr[0]]) < TINY) {
89  ang = M_PI_2;
90 
91  if (conv[nbr[2]] - conv[nbr[3]] < 0)
92  ang = -ang;
93  }
94  else
95  ang = atan2(conv[nbr[2]] - conv[nbr[3]],
96  conv[nbr[1]] - conv[nbr[0]]);
97 
98  /* scale -PI..PI to 0..num_orients - 1 */
99  dir =
100  num_orients * ((ang + M_PI) / (M_PI * 2.0)) + 0.4999;
101 
102  /* shift scale so that 0 (not 8) is straight down */
103  dir = (3 * num_orients / 4 + dir) % num_orients;
104 
105  /* add to differentiate between no zc and an orientation */
106  zc[p] = 1 + dir;
107  break; /* quit looking at neighbors */
108  }
109  } /* for ni */
110  } /* for p */
111  }
112 
113  return 0;
114 }
int G_math_findzc(double conv[], int size, double zc[], double thresh, int num_orients)
Finds locations and orientations of zero crossings.
Definition: findzc.c:56
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
#define TINY
Definition: findzc.c:32