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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomEdge_rect.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  * 
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomEdge_rect.c,v $
 23  * Date    :  $Date: 2008/12/07 04:33:58 $
 24  * Version :  $Revision: 1.2 $
 25  * CVS Id  :  $Id: geomEdge_rect.c,v 1.2 2008/12/07 04:33:58 paul Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes : functions for manipulating Imrects that represent edgerects
 30  *
 31  *********
 32 */
 33 
 34 #include "geomEdge_rect.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <math.h>
 41 #include <tina/sys/sysDef.h>
 42 #include <tina/sys/sysPro.h>
 43 #include <tina/math/mathDef.h>
 44 #include <tina/math/mathPro.h>
 45 #include <tina/image/imgDef.h>
 46 #include <tina/image/imgPro.h>
 47 #include <tina/geometry/geom_IndxDef.h>
 48 #include <tina/geometry/geom_IndxPro.h>
 49 #include <tina/geometry/geom_EdgeDef.h>
 50 #include <tina/geometry/geom_EdgePro.h>
 51 
 52 void    er_apply_to_all_edges(Imrect * edgerect, void (*edgefunc) ( /* ??? */ ), void *data)
 53 {
 54     Rindex *row_index;
 55     int     lx, ly, ux, uy;
 56     int     i, j;
 57 
 58     if (edgerect == NULL)
 59         return;
 60 
 61     row_index = prop_get(edgerect->props, ER_ROWS);
 62 
 63     if (row_index != NULL)
 64     {
 65         List   *ptr;
 66         List  **index = (List **) row_index->index;
 67         Imregion *roi = row_index->region;
 68 
 69         ly = roi->ly;
 70         uy = roi->uy;
 71 
 72         for (i = ly; i < uy; ++i)
 73             for (ptr = index[i]; ptr != NULL; ptr = ptr->next)
 74                 edgefunc(ptr->to, EDGE, data, i, ptr->type);
 75         return;
 76     }
 77     lx = edgerect->region->lx;
 78     ly = edgerect->region->ly;
 79     ux = edgerect->region->ux;
 80     uy = edgerect->region->uy;
 81 
 82     for (i = ly; i < uy; ++i)
 83         for (j = lx; j < ux; ++j)
 84         {
 85             Edgel  *edge = (Edgel *) IM_PTR(edgerect, i, j);
 86 
 87             if (edge != NULL)
 88                 edgefunc(edge, EDGE, data, i, j);
 89         }
 90 }
 91 
 92 void    er_apply_to_all_strings(Imrect * er, void (*func) ( /* ??? */ ), void *data)
 93 {
 94     if (er == NULL)
 95         return;
 96     list_apply_func((List *) prop_get(er->props, STRING), func, data);
 97 }
 98 
 99 void    es_apply_to_all_edges(Imrect * er, void (*func) ( /* ??? */ ), void *data)
100 {
101     List   *strings;
102     List   *lptr;
103 
104     if (er == NULL)
105         return;
106 
107     strings = (List *) prop_get(er->props, STRING);
108 
109     for (lptr = strings; lptr != NULL; lptr = lptr->next)
110         str_apply_func((Tstring *) lptr->to, func, data);
111 }
112 
113 void    er_rm_edges(Imrect * edgerect, unsigned int mask, unsigned int type)    /* rm all edges of
114                                                                                  * specified type */
115 
116 
117 {
118     int     lx, ly, ux, uy;
119     int     i, j;
120 
121     if (edgerect == NULL)
122         return;
123 
124     lx = edgerect->region->lx;
125     ly = edgerect->region->ly;
126     ux = edgerect->region->ux;
127     uy = edgerect->region->uy;
128 
129     for (i = ly; i < uy; ++i)
130         for (j = lx; j < ux; ++j)
131         {
132             Edgel  *edge = (Edgel *) IM_PTR(edgerect, i, j);
133 
134             if ((edge != NULL) && (mask == 0 || type == (edge->type & mask)))
135             {
136                 edge_free(edge);
137                 IM_PTR(edgerect, i, j) = NULL;
138             }
139         }
140 }
141 
142 void    er_free(Imrect * edgerect)
143 {
144     er_apply_to_all_edges(edgerect, edge_free, NULL);
145     im_free(edgerect);
146 }
147 
148 Edgel  *er_get_edge(Imrect * edgerect, int i, int j)
149 {
150     if (edgerect == NULL || edgerect->vtype != ptr_v ||
151         !roi_inregion(edgerect->region, j, i))
152         return (NULL);
153 
154     return ((Edgel *) IM_PTR(edgerect, i, j));
155 }
156 
157 void    er_put_edge(Edgel * edge, Imrect * edgerect, int i, int j)
158 {
159     if (edgerect == NULL || edgerect->vtype != ptr_v ||
160         !roi_inregion(edgerect->region, j, i))
161         return;
162 
163     IM_PTR(edgerect, i, j) = edge;
164 }
165 
166 void   *er_closest(Imrect * edgerect, int r, int c, int maxsep, void *(*index_func) ( /* ??? */ ), void *data)
167 {
168     int     i, j, k;
169     void   *ptr;
170     void   *res;
171 
172     if (edgerect == NULL || edgerect->vtype != ptr_v)
173         return (NULL);
174 
175     if ((ptr = im_get_ptr(edgerect, r, c)) != NULL)
176     {
177         if (index_func == NULL)
178             return (ptr);
179         if ((res = index_func(ptr, data)))
180             return (res);
181     }
182     for (i = 1; i < maxsep; ++i)
183     {
184         for (j = -i; j <= i; ++j)
185         {
186             void   *ptr[4];
187 
188             ptr[0] = im_get_ptr(edgerect, r + j, c - i);
189             ptr[1] = im_get_ptr(edgerect, r + j, c + i);
190             ptr[2] = im_get_ptr(edgerect, r - i, c + j);
191             ptr[3] = im_get_ptr(edgerect, r + i, c + j);
192 
193             for (k = 0; k < 4; ++k)
194             {
195                 if (ptr[k] != NULL)
196                 {
197                     if (index_func == NULL)
198                         return (ptr[k]);
199                     if ((res = index_func(ptr[k], data)))
200                         return (res);
201                 }
202             }
203         }
204     }
205     return (NULL);
206 }
207 
208 int     er_add_edge(Imrect * edgerect, Edgel * edge)
209 {
210     int     i, j;
211 
212     if (edgerect == NULL || edge == NULL || edgerect->vtype != ptr_v)
213         return (0);
214 
215     j = (int)floor(vec2_x(edge->pos));
216     i = (int)floor(vec2_y(edge->pos));
217     if (!roi_inregion(edgerect->region, j, i))
218         return (0);
219     if (IM_PTR(edgerect, i, j) == NULL)
220     {
221         IM_PTR(edgerect, i, j) = (void *) edge;
222         return (1);
223     } else
224         return (0);
225 }
226 
227 /* row index allows rapid access to edges
228  * 
229  * column subscript stored in list type
230  * 
231  */
232 
233 void    er_set_row_index(Imrect * er)
234 /* edge rect */
235 {
236     Rindex *rx;
237     Rindex *rx_alloc();
238     List  **index;
239     int     lx, ly, ux, uy;
240     int     i, j;
241     void    rx_free_links();
242 
243     if (er == NULL)
244         return;
245 
246     lx = er->region->lx;
247     ly = er->region->ly;
248     ux = er->region->ux;
249     uy = er->region->uy;
250     rx = rx_alloc(er->region, EDGE);
251     index = (List **) rx->index;
252 
253     for (i = ly; i < uy; ++i)
254     {
255         for (j = lx; j < ux; ++j)
256             if (IM_PTR(er, i, j) != NULL)
257                 index[i] = ref_addtostart((List *) index[i], (void *) IM_PTR(er, i, j), j);
258         index[i] = list_reverse(index[i]);
259     }
260     er->props = proplist_addifnp(er->props, (void *) rx, ER_ROWS, rx_free_links, true);
261 }
262 

~ [ 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.