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

Linux Cross Reference
Tina4/src/vision/stereo/match_str.c

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

  1 /**@(#)
  2 **/
  3 /* match_str.c
  4  * 
  5  * generic stereo functions for computing support between complete edge
  6  * strings
  7  * 
  8  * the strings must already be referenced through the property list of
  9  * each edge using the key STRING
 10  * 
 11  * this approach is used to compute the strict figural continuity support.
 12  * That is, the sum of support from valid matches that exist between a
 13  * pair of uniquely labled sub-strings. */
 14 
 15 #include <math.h>
 16 #include <tina/sys.h>
 17 #include <tina/sysfuncs.h>
 18 #include <tina/math.h>
 19 #include <tina/mathfuncs.h>
 20 #include <tina/vision.h>
 21 #include <tina/visionfuncs.h>
 22 
 23 /* make an example of a string match */
 24 String_match *sm_make(Tstring * s1, Tstring * s2, int s1_id, int s2_id)
 25 {
 26     String_match *sm = ts_ralloc(String_match);
 27 
 28     sm->s1 = s1;
 29     sm->s2 = s2;
 30     sm->s1_id = s1_id;
 31     sm->s2_id = s2_id;
 32     sm->support = 0;
 33     sm->r_low = sm->r_up = 0;
 34 
 35     return (sm);
 36 }
 37 
 38 /* free a list of string matches */
 39 void    sm_list_rm(List * sm_list)
 40 {
 41     list_rm(sm_list, rfree);
 42 }
 43 
 44 /* initialise values in a string match */
 45 static void sm_init_sup(String_match * sm)
 46 {
 47     if (sm == NULL)
 48         return;
 49 
 50     sm->support = 0;
 51 }
 52 
 53 
 54 /* search list of string matches for one with given pair of edge
 55  * sub-string identifiers
 56  * 
 57  * if no such string match exists return NULL */
 58 String_match *str_mat_from_list(List * mlist, int s1_id, int s2_id)
 59 {
 60     List   *ptr;
 61 
 62     for (ptr = mlist; ptr != NULL; ptr = ptr->next)
 63         if (s1_id == ptr->type && s2_id == ((String_match *) ptr->to)->s2_id)
 64             return ((String_match *) ptr->to);
 65     return (NULL);
 66 }
 67 
 68 /* initialise edge string match string lists */
 69 void    es_match_string_init(Tstring * es)
 70 {
 71     if (es == NULL)
 72         return;
 73     es->props = proplist_addifnp(es->props, NULL, MLIST,
 74                                  (void (*) ()) NULL, true);
 75 }
 76 
 77 /* accumulate matches and support for an individual edge contour string
 78  * into list of string matches of uniquely labled sub-parts add it to
 79  * the property list of the global string
 80  * 
 81  * uniquely labled sub-strings correspond to those string parts that cross
 82  * a set of epipolars/rasters only once (eg strings are implicitly
 83  * broken at turning points in the y direction). These labels are
 84  * indexed through the property luists of the epipolar sub-strings
 85  * using the key STRING.
 86  * 
 87  * examines the matches of the component epipolar sub-strings */
 88 /* ARGSUSED quieten lint */
 89 void    es_match_string(Tstring * es, int type, double (*cost_func) ( /* ??? */ ))
 90 
 91 /* unused */
 92 
 93 {
 94     List   *matches;            /* list of string matches */
 95     Tstring *ses;               /* string of sub strings */
 96     List *sptr;
 97     List *start;
 98     List *end;
 99     int     s1_id, s2_id;
100 
101     ses = string_of_sindex_strings(es);
102 
103     if (ses == NULL)
104         return;
105 
106     start = ses->start;
107     end = ses->end;
108 
109     matches = (List *) prop_get(es->props, MLIST);
110     list_apply_func(matches, sm_init_sup, NULL);
111 
112     for (sptr = start; sptr != end; sptr = sptr->next)
113     {
114         Tstring *s1;
115         List   *mlist;
116         List   *mptr;
117         int     r;
118         Vec2    v = {Vec2_id};
119 
120 
121         s1 = (Tstring *) sptr->to;
122         mlist = (List *) prop_get(s1->props, MLIST);
123         s1_id = (int) prop_get(s1->props, STRING);
124 
125         v = str2_centroid(s1);
126         r = (int)floor(vec2_y(v));
127 
128         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
129         {
130             Match  *m = (Match *) mptr->to;
131             Tstring *s2;
132             String_match *sm;
133 
134             s2 = (Tstring *) m->to2;
135             s2_id = (int) prop_get(s2->props, STRING);
136             if ((sm = str_mat_from_list(matches, s1_id, s2_id)) == NULL)
137             {
138                 Edgel  *edge = (Edgel *) s2->start->to;
139 
140                 sm = sm_make(es, (Tstring *) prop_get(edge->props, STRING), s1_id, s2_id);
141                 matches = ref_addtostart((List *) matches, (void *) sm, s1_id);
142                 sm->r_low = sm->r_up = r;
143             }
144             if (r < sm->r_low)
145                 sm->r_low = r;
146             if (r > sm->r_up)
147                 sm->r_up = r;
148 
149             if (cost_func == NULL)
150             {
151                 Support *s = (Support *) prop_get(m->props, MATCH_SUPPORT);
152 
153                 if (s == NULL || s->type <= BAD_MATCH)
154                     continue;
155                 sm->support += ((Match *) mptr->to)->weight;
156             } else
157                 sm->support += cost_func(m);
158         }
159         if (sptr == end)
160             break;
161     }
162     es->props = proplist_addifnp(es->props, (void *) matches, MLIST, sm_list_rm, false);
163     str_rm_links(ses);
164 }
165 
166 /* set the total string support for matches associated with epipolar
167  * sub-strings of an edge contour from the string matches of the edge
168  * string as a whole */
169 void    es_mlist_set_total_string_sup(Tstring * es)
170 {
171     List   *matches;            /* list of string matches */
172     Tstring *ses;               /* string of sub strings */
173     List *sptr;
174     List *start;
175     List *end;
176     int     s1_id, s2_id;
177 
178     ses = string_of_sindex_strings(es);
179 
180     if (ses == NULL)
181         return;
182 
183     start = ses->start;
184     end = ses->end;
185 
186     matches = (List *) prop_get(es->props, MLIST);
187 
188     for (sptr = start; sptr != end; sptr = sptr->next)
189     {
190         Tstring *s1;
191         List   *mlist;
192         List   *mptr;
193 
194         s1 = (Tstring *) sptr->to;
195         mlist = (List *) prop_get(s1->props, MLIST);
196         s1_id = (int) prop_get(s1->props, STRING);
197 
198         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
199         {
200             Match  *m = (Match *) mptr->to;
201             Support *sup;
202             Tstring *s2;
203             String_match *sm;
204 
205             s2 = (Tstring *) m->to2;
206             sup = (Support *) prop_get(m->props, MATCH_SUPPORT);
207             s2_id = (int) prop_get(s2->props, STRING);
208             sm = str_mat_from_list(matches, s1_id, s2_id);
209 
210             if (sm == NULL)
211                 continue;
212 
213             sup->total_string = (float)sm->support;
214         }
215         if (sptr == end)
216             break;
217     }
218     str_rm_links(ses);
219 }
220 
221 /* match string support value */
222 static double sm_support_neg(String_match * sm)
223 {
224     return (sm == NULL) ? 0.0 : -sm->support;
225 }
226 
227 /* choose matches that are consitent with the given string match */
228 static void sm_choose_matches(Tstring * ses, String_match * sm)
229 {
230     List *sptr;
231     List *start;
232     List *end;
233 
234     if (ses == NULL || sm == NULL)
235         return;
236 
237     start = ses->start;
238     end = ses->end;
239 
240     for (sptr = start; sptr != end; sptr = sptr->next)
241     {
242         Tstring *s1, *s2;
243         int     s1_id, s2_id;
244         List   *mlist;
245         List   *mptr;
246         Match  *match;
247         Support *msup = NULL;
248 
249         s1 = (Tstring *) sptr->to;
250         s1_id = (int) prop_get(s1->props, STRING);
251 
252         if (s1_id != sm->s1_id)
253             continue;
254 
255         mlist = (List *) prop_get(s1->props, MLIST);
256 
257         for (mptr = mlist; mptr != NULL; mptr = mptr->next)
258         {
259             match = (Match *) mptr->to;
260 
261             s2 = (Tstring *) ((Match *) mptr->to)->to2;
262             s2_id = (int) prop_get(s2->props, STRING);
263 
264             if (s2_id != sm->s2_id)
265                 continue;
266 
267             msup = (Support *) prop_get(match->props, MATCH_SUPPORT);
268             if (msup->type <= BAD_MATCH)        /* already rejected */
269                 mptr = NULL;
270 
271             break;
272         }
273 
274         if (mptr == NULL)
275             continue;           /* no appropriate match */
276 
277         mlist_set_supp_type(mlist, BAD_MATCH);
278         msup->type = GOOD_MATCH;
279     }
280 }
281 
282 /* choose matches at the string level */
283 void    es_choose_string_matches(Tstring * es, int type, double (*cost_func) ( /* ??? */ ))
284 
285 /* not used */
286 
287 {
288     List   *matches;
289     List   *mptr;
290     Tstring *ses;               /* string of sub-strings */
291 
292     ses = string_of_sindex_strings(es);
293 
294     es_match_string(es, type, cost_func);       /* first call to string
295                                                  * matcher */
296     matches = (List *) prop_get(es->props, MLIST);
297     matches = sort_list(matches, sm_support_neg, NULL);
298     for (mptr = matches; mptr != NULL; mptr = mptr->next)
299     {
300         String_match *sm = (String_match *) mptr->to;
301 
302         if (sm->support == 0.0)
303             break;
304 
305         sm_choose_matches(ses, sm);
306         /* es_match_string does not effect order of matches */
307         es_match_string(es, type, cost_func);
308         mptr->next = sort_list(mptr->next, sm_support_neg, NULL);
309     }
310     str_rm_links(ses);
311 }
312 

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