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

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

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