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

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

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