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

Linux Cross Reference
Tina4/src/vision/matcher/matcher.c

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

  1 /**@(#)
  2 **/
  3 /* matcher.c
  4  * 
  5  */
  6 
  7 #include <math.h>
  8 #include <tina/sys.h>
  9 #include <tina/sysfuncs.h>
 10 #include <tina/math.h>
 11 #include <tina/mathfuncs.h>
 12 #include <tina/vision.h>
 13 #include <tina/visionfuncs.h>
 14 
 15 static List *model;
 16 static Matrix *model_tbl;
 17 static List *scene;
 18 static Matrix *scene_tbl;
 19 
 20 static List *pot_cliques=NULL;
 21 static List *pw_cliques=NULL;
 22 
 23 double  smm_mlist_goodness();
 24 
 25 static Match_clique *clique_make(List * mlist, double strength, int csize)
 26 {
 27     Match_clique *c = ts_ralloc(Match_clique);
 28 
 29     c->strength = (float)strength;
 30     c->mlist = mlist;
 31     c->csize = csize;
 32     return (c);
 33 }
 34 
 35 static void clique_free(Match_clique * c)
 36 {
 37     if (c == NULL)
 38         return;
 39 
 40     list_rm(c->mlist, match_free);
 41     c->mlist = NULL;
 42     rfree((void *) c);
 43 }
 44 
 45 static double clique_neg_strength(Match_clique * c)
 46 {
 47     if (c == NULL)
 48         return (0.0);
 49     return (-(c->strength));
 50 }
 51 
 52 void    smm_set(List * list1, List * list2, Matrix * table1, Matrix * table2)
 53 {
 54     model = list1;
 55     scene = list2;
 56     model_tbl = table1;
 57     scene_tbl = table2;
 58     list_rm(pot_cliques, clique_free);
 59     pot_cliques = NULL;
 60 /*
 61     cross indexed freeing fixed NAT 22/12/99
 62 */
 63     list_rm_links(pw_cliques);
 64     pw_cliques = NULL;
 65 }
 66 
 67 Bool    smm_consistent_matches(Match * m1, Match * m2)
 68 {
 69     int     p11, p12, p21, p22;
 70     Pwrte  *pwrte1, *pwrte2;
 71 
 72     if (m1 == NULL || m2 == NULL)
 73         return (false);
 74 
 75     if (m1->to1 == m2->to1 || m1->to2 == m2->to2)
 76         return (false);
 77 
 78     p11 = (int) geom_prop_get(m1->to1, m1->type, PWR);
 79     p21 = (int) geom_prop_get(m1->to2, m1->type, PWR);
 80     p12 = (int) geom_prop_get(m2->to1, m2->type, PWR);
 81     p22 = (int) geom_prop_get(m2->to2, m2->type, PWR);
 82 
 83     pwrte1 = model_tbl->el.ptr_v[p11][p12];
 84     pwrte2 = scene_tbl->el.ptr_v[p21][p22];
 85 
 86     return (pwrte_compatible(pwrte1, pwrte2));
 87 }
 88 
 89 static List *clique_to_mlist(Match_clique * c)
 90 {
 91     return (c->mlist);
 92 }
 93 
 94 #if 0
 95 static List *smm_pot_clique_mlists(void)
 96 {
 97     return (list_copy(pot_cliques, (void *(*) ()) clique_to_mlist, NULL));
 98 }
 99 
100 #endif
101 
102 static List *smm_pw_clique_mlists(void)
103 {
104     return (list_copy(pw_cliques, (void *(*) ()) clique_to_mlist, NULL));
105 }
106 
107 static List *mutual_cliques(List * mlist, int csize)
108 {
109     List   *graph;
110     List   *gcliques;
111     List   *cliques = NULL;
112     List   *lptr;
113 
114     graph = graph_make_list(mlist);
115     graph_list_consistent(graph, smm_consistent_matches);
116     gcliques = cliques_get(graph, csize - 1);
117     for (lptr = gcliques; lptr != NULL; lptr = lptr->next)
118     {
119         List   *mlist = graph_recover_list((List *) lptr->to);
120         Match_clique *c;
121 
122         c = clique_make(mlist, smm_mlist_goodness(mlist), csize);
123         cliques = ref_addtostart(cliques, (void *) c, LIST);
124         list_rm_links((List *) lptr->to);
125     }
126     list_rm(graph, rfree);
127     return (cliques);
128 }
129 
130 static void smm_cliches_to_pot_cliques(List * match_cliches)
131 /* Match cliche list */
132 {
133     List   *cptr;
134 
135     for (cptr = match_cliches; cptr != NULL; cptr = cptr->next)
136     {
137         Match_cliche *mc = (Match_cliche *) cptr->to;
138         List   *mlist = NULL;
139         List   *group;
140         List   *clist;
141         List   *ptr;
142         int     fthres, gthres; /* focus and global clique sizes */
143 
144         fthres = mc->fthres;
145         gthres = mc->gthres;
146         group = mc->group;
147 
148         for (ptr = mc->focus; ptr != NULL; ptr = ptr->next)
149         {
150             List   *flist = smm_good_matches(ptr->to, ptr->type, scene);
151 
152             mlist = list_append(flist, mlist);
153         }
154 
155         clist = mutual_cliques(mlist, fthres);  /* a set of initial
156                                                  * cliques */
157 
158         for (ptr = clist; ptr != NULL; ptr = ptr->next)
159         {
160             Match_clique *clique = (Match_clique *) ptr->to;
161 
162             clique->mlist = smm_mats_con_with_mlist(group, scene, clique->mlist);
163 
164             clique->strength = (float)smm_mlist_goodness(clique->mlist);
165             clique->csize = gthres;
166         }
167         pot_cliques = list_append(clist, pot_cliques);
168     }
169     pot_cliques = sort_list(pot_cliques, clique_neg_strength, NULL);
170 }
171 
172 static void smm_mutual_cliques(void)
173 {
174     List   *lptr;
175 
176     for (lptr = pot_cliques; lptr != NULL; lptr = lptr->next)
177     {
178         Match_clique *mc = (Match_clique *) lptr->to;
179 
180         if (list_length(mc->mlist) > mc->csize)
181         {
182             List   *cliques = mutual_cliques(mc->mlist, mc->csize);
183 
184             pw_cliques = list_append(cliques, pw_cliques);
185         }
186     }
187     pw_cliques = sort_list(pw_cliques, clique_neg_strength, NULL);
188 }
189 
190 List   *smm_run(List * cliches)
191 {
192     List   *mlists;
193 
194     smm_cliches_to_pot_cliques(cliches);
195     smm_mutual_cliques();
196     mlists = smm_pw_clique_mlists();
197     return (mlists);
198 }
199 

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