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/vision/visMatch_cindex.c,v $
23 * Date : $Date: 2004/08/04 15:07:47 $
24 * Version : $Revision: 1.4 $
25 * CVS Id : $Id: visMatch_cindex.c,v 1.4 2004/08/04 15:07:47 paul Exp $
26 *
27 * Author : Legacy TINA
28 *
29 * Notes :
30 *
31 *********
32 */
33
34 #include "visMatch_cindex.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/image/imgDef.h>
45 #include <tina/image/imgPro.h>
46 #include <tina/geometry/geomDef.h>
47 #include <tina/geometry/geomPro.h>
48
49
50 static Vec2 *(*locate) ();
51 static Imregion *er_rect_bounding_region(Imrect * er);
52
53
54 /* routine to construct a fast access index for edge structures stored
55 * in the Imrect er. The indexing scheme is positional using the
56 * location for each edge defined by the function locate_func. The
57 * resulting structure is put into the Imrects property list for later
58 * retrieval by the given type and then returned. */
59 Rindex *er_set_findex(Imrect * er, int type, Vec2 * (*locate_func) ( /* ??? */ ))
60 {
61 Rindex *fx;
62 Rindex *rx_alloc();
63 Imregion *index_region;
64 int lx, ly, ux, uy;
65 int i, j;
66 Vec2 *edge_pos(Edgel * edgel);
67 void rx_free_links();
68
69 if (er->vtype != ptr_v)
70 {
71 error("findex: passed non edge rect ", non_fatal);
72 return (NULL);
73 }
74 if (locate_func == NULL)
75 locate = edge_pos;
76 else
77 locate = locate_func;
78
79 index_region = er_rect_bounding_region(er);
80 if (index_region == NULL)
81 {
82 error("findex: nill region ", non_fatal);
83 return (NULL);
84 }
85 fx = rx_alloc(index_region, type);
86
87 lx = er->region->lx;
88 ly = er->region->ly;
89 ux = er->region->ux;
90 uy = er->region->uy;
91
92 for (i = ly; i < uy; ++i)
93 {
94 for (j = lx; j < ux; ++j)
95 {
96 Edgel *edge = (Edgel *) IM_PTR(er, i, j);
97
98 if (edge != NULL)
99 {
100 List *link_addtostart();
101 Vec2 *rect;
102 int ry;
103
104 if ((rect = locate(edge)) != NULL)
105 {
106 ry = (int)floor(rect->el[1]);
107 fx->index[ry] = link_addtostart((List *) fx->index[ry],
108 link_alloc((void *) edge, STRING));
109 }
110 }
111 }
112 }
113 er->props = proplist_addifnp(er->props, (void *) fx, type, rx_free_links, true);
114 return (fx);
115 }
116
117 Vec2 *edge_pos(Edgel * edgel)
118 {
119 return (&edgel->pos);
120 }
121
122 /* ARGSUSED quieten lint */
123 static void inc_region(Edgel * edge, int type, Imregion * roi)
124
125 /* not used */
126
127 {
128 int x, y;
129 Vec2 *rect;
130
131 if ((rect = locate(edge)) == NULL)
132 return;
133 x = (int)floor(rect->el[0]);
134 y = (int)floor(rect->el[1]);
135
136 if (roi->lx == LARGEST_INT)
137 {
138 roi->lx = roi->ux = x;
139 roi->ly = roi->uy = y;
140 return;
141 }
142 if (x < roi->lx)
143 roi->lx = x;
144 if (y < roi->ly)
145 roi->ly = y;
146 if (x > roi->ux)
147 roi->ux = x;
148 if (y > roi->uy)
149 roi->uy = y;
150 }
151
152 static Imregion *er_rect_bounding_region(Imrect * er)
153 {
154 Imregion *roi;
155
156 if (er == NULL || er->vtype != ptr_v)
157 return (NULL);
158
159 roi = roi_alloc(LARGEST_INT, LARGEST_INT, LARGEST_INT, LARGEST_INT);
160 er_apply_to_all_edges(er, (void (*) ()) inc_region, (void *) roi);
161 if (roi->lx == LARGEST_INT)
162 {
163 rfree((void *) roi);
164 return (NULL);
165 }
166 roi->ux += 1;
167 roi->uy += 1;
168 return (roi);
169 }
170
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.