~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/vision/edge/edgerect.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 /* edgerect.c
  4  * 
  5  * functions for manipulating Imrects that represent edgerects
  6  * 
  7  */
  8 
  9 #include <tina/sys.h>
 10 #include <tina/sysfuncs.h>
 11 #include <tina/math.h>
 12 #include <tina/vision.h>
 13 #include <tina/visionfuncs.h>
 14 
 15 void    er_apply_to_all_edges(Imrect * edgerect, void (*edgefunc) ( /* ??? */ ), void *data)
 16 {
 17     Rindex *row_index;
 18     int     lx, ly, ux, uy;
 19     int     i, j;
 20 
 21     if (edgerect == NULL)
 22         return;
 23 
 24     row_index = prop_get(edgerect->props, ER_ROWS);
 25 
 26     if (row_index != NULL)
 27     {
 28         List   *ptr;
 29         List  **index = (List **) row_index->index;
 30         Imregion *roi = row_index->region;
 31 
 32         ly = roi->ly;
 33         uy = roi->uy;
 34 
 35         for (i = ly; i < uy; ++i)
 36             for (ptr = index[i]; ptr != NULL; ptr = ptr->next)
 37                 edgefunc(ptr->to, EDGE, data, i, ptr->type);
 38         return;
 39     }
 40     lx = edgerect->region->lx;
 41     ly = edgerect->region->ly;
 42     ux = edgerect->region->ux;
 43     uy = edgerect->region->uy;
 44 
 45     for (i = ly; i < uy; ++i)
 46         for (j = lx; j < ux; ++j)
 47         {
 48             Edgel  *edge = (Edgel *) IM_PTR(edgerect, i, j);
 49 
 50             if (edge != NULL)
 51                 edgefunc(edge, EDGE, data, i, j);
 52         }
 53 }
 54 
 55 void    er_apply_to_all_strings(Imrect * er, void (*func) ( /* ??? */ ), void *data)
 56 {
 57     if (er == NULL)
 58         return;
 59     list_apply_func((List *) prop_get(er->props, STRING), func, data);
 60 }
 61 
 62 void    es_apply_to_all_edges(Imrect * er, void (*func) ( /* ??? */ ), void *data)
 63 {
 64     List   *strings;
 65     List   *lptr;
 66 
 67     if (er == NULL)
 68         return;
 69 
 70     strings = (List *) prop_get(er->props, STRING);
 71 
 72     for (lptr = strings; lptr != NULL; lptr = lptr->next)
 73         str_apply_func((Tstring *) lptr->to, func, data);
 74 }
 75 
 76 void    er_rm_edges(Imrect * edgerect, unsigned int mask, unsigned int type)    /* rm all edges of
 77                                                                                  * specified type */
 78 
 79 
 80 {
 81     int     lx, ly, ux, uy;
 82     int     i, j;
 83 
 84     if (edgerect == NULL)
 85         return;
 86 
 87     lx = edgerect->region->lx;
 88     ly = edgerect->region->ly;
 89     ux = edgerect->region->ux;
 90     uy = edgerect->region->uy;
 91 
 92     for (i = ly; i < uy; ++i)
 93         for (j = lx; j < ux; ++j)
 94         {
 95             Edgel  *edge = (Edgel *) IM_PTR(edgerect, i, j);
 96 
 97             if ((edge != NULL) && (mask == (int) NULL || type == (edge->type & mask)))
 98             {
 99                 edge_free(edge);
100                 IM_PTR(edgerect, i, j) = NULL;
101             }
102         }
103 }
104 
105 void    er_free(Imrect * edgerect)
106 {
107     er_apply_to_all_edges(edgerect, edge_free, NULL);
108     im_free(edgerect);
109 }
110 
111 Edgel  *er_get_edge(Imrect * edgerect, int i, int j)
112 {
113     if (edgerect == NULL || edgerect->vtype != ptr_v ||
114         !roi_inregion(edgerect->region, j, i))
115         return (NULL);
116 
117     return ((Edgel *) IM_PTR(edgerect, i, j));
118 }
119 
120 void    er_put_edge(Edgel * edge, Imrect * edgerect, int i, int j)
121 {
122     if (edgerect == NULL || edgerect->vtype != ptr_v ||
123         !roi_inregion(edgerect->region, j, i))
124         return;
125 
126     IM_PTR(edgerect, i, j) = edge;
127 }
128 
129 void   *er_closest(Imrect * edgerect, int r, int c, int maxsep, void *(*index_func) ( /* ??? */ ), void *data)
130 {
131     int     i, j, k;
132     void   *ptr;
133     void   *res;
134 
135     if (edgerect == NULL || edgerect->vtype != ptr_v)
136         return (NULL);
137 
138     if ((ptr = im_get_ptr(edgerect, r, c)) != NULL)
139     {
140         if (index_func == NULL)
141             return (ptr);
142         if ((res = index_func(ptr, data)))
143             return (res);
144     }
145     for (i = 1; i < maxsep; ++i)
146     {
147         for (j = -i; j <= i; ++j)
148         {
149             void   *ptr[4];
150 
151             ptr[0] = im_get_ptr(edgerect, r + j, c - i);
152             ptr[1] = im_get_ptr(edgerect, r + j, c + i);
153             ptr[2] = im_get_ptr(edgerect, r - i, c + j);
154             ptr[3] = im_get_ptr(edgerect, r + i, c + j);
155 
156             for (k = 0; k < 4; ++k)
157             {
158                 if (ptr[k] != NULL)
159                 {
160                     if (index_func == NULL)
161                         return (ptr[k]);
162                     if ((res = index_func(ptr[k], data)))
163                         return (res);
164                 }
165             }
166         }
167     }
168     return (NULL);
169 }
170 
171 int     er_add_edge(Imrect * edgerect, Edgel * edge)
172 {
173     int     i, j;
174 
175     if (edgerect == NULL || edge == NULL || edgerect->vtype != ptr_v)
176         return (0);
177 
178     j = (int)floor(vec2_x(edge->pos));
179     i = (int)floor(vec2_y(edge->pos));
180     if (!roi_inregion(edgerect->region, j, i))
181         return (0);
182     if (IM_PTR(edgerect, i, j) == NULL)
183     {
184         IM_PTR(edgerect, i, j) = (void *) edge;
185         return (1);
186     } else
187         return (0);
188 }
189 
190 /* row index allows rapid access to edges
191  * 
192  * column subscript stored in list type
193  * 
194  */
195 
196 void    er_set_row_index(Imrect * er)
197 /* edge rect */
198 {
199     Rindex *rx;
200     Rindex *rx_alloc();
201     List  **index;
202     int     lx, ly, ux, uy;
203     int     i, j;
204     void    rx_free_links();
205 
206     if (er == NULL)
207         return;
208 
209     lx = er->region->lx;
210     ly = er->region->ly;
211     ux = er->region->ux;
212     uy = er->region->uy;
213     rx = rx_alloc(er->region, EDGE);
214     index = (List **) rx->index;
215 
216     for (i = ly; i < uy; ++i)
217     {
218         for (j = lx; j < ux; ++j)
219             if (IM_PTR(er, i, j) != NULL)
220                 index[i] = ref_addtostart((List *) index[i], (void *) IM_PTR(er, i, j), j);
221         index[i] = list_reverse(index[i]);
222     }
223     er->props = proplist_addifnp(er->props, (void *) rx, ER_ROWS, rx_free_links, true);
224 }
225 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.