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

Linux Cross Reference
Tina5/tina-libs/tina/vision/visModel_cliches.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 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/visModel_cliches.c,v $
 23  * Date    :  $Date: 2008/10/02 11:53:05 $
 24  * Version :  $Revision: 1.4 $
 25  * CVS Id  :  $Id: visModel_cliches.c,v 1.4 2008/10/02 11:53:05 neil Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  *
 31  * simple isotropic error model for geometric data
 32  *
 33  *
 34  *********
 35 */
 36 
 37 #include "visModel_cliches.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <math.h>
 44 #include <tina/sys/sysDef.h>
 45 #include <tina/sys/sysPro.h>
 46 #include <tina/math/mathDef.h>
 47 #include <tina/math/mathPro.h>
 48 #include <tina/geometry/geomDef.h>
 49 #include <tina/geometry/geomPro.h>
 50 #include <tina/vision/vis_ModelDef.h>
 51 #include <tina/vision/vis_ModelPro.h>
 52 
 53 #define CLICHE_TAG 11111
 54 
 55 static List *model;
 56 static Matrix *model_tbl;
 57 static List *scene;
 58 static Matrix *scene_tbl;
 59 
 60 static List *pot_cliques=NULL;
 61 static List *pw_cliques=NULL;
 62 
 63 double  smm_mlist_goodness();
 64 
 65 
 66 Match_cliche *match_cliche_make(List * focus, int fthres, List * group, int gthres)
 67 {
 68     Match_cliche *mc = ts_ralloc(Match_cliche);
 69 
 70     mc->focus = focus;
 71     mc->fthres = fthres;
 72     mc->group = group;
 73     mc->gthres = gthres;
 74 
 75     return (mc);
 76 }
 77 
 78 void    match_cliche_free(Match_cliche * mc)
 79 {
 80     if (mc == NULL)
 81         return;
 82 
 83     list_rm_links(mc->group);
 84     rfree((void *) mc);
 85 }
 86 
 87 static Match_clique *clique_make(List * mlist, double strength, int csize)
 88 {
 89     Match_clique *c = ts_ralloc(Match_clique);
 90 
 91     c->strength = (float)strength;
 92     c->mlist = mlist;
 93     c->csize = csize;
 94     return (c);
 95 }
 96 
 97 static void clique_free(Match_clique * c)
 98 {
 99     if (c == NULL)
100         return;
101 
102     list_rm(c->mlist, match_free);
103     c->mlist = NULL;
104 
105     rfree((void *) c);
106 }
107 
108 static double clique_neg_strength(Match_clique * c)
109 {
110     if (c == NULL)
111         return (0.0);
112     return (-(c->strength));
113 }
114 
115 void    smm_set(List * list1, List * list2, Matrix * table1, Matrix * table2)
116 {
117     model = list1;
118     scene = list2;
119     model_tbl = table1;
120     scene_tbl = table2;
121     list_rm(pot_cliques, clique_free);
122     pot_cliques = NULL;
123 /*
124     cross indexed freeing fixed NAT 22/12/99
125 */
126     list_rm_links(pw_cliques);
127     pw_cliques = NULL;
128 }
129 
130 Bool    smm_consistent_matches(Match * m1, Match * m2)
131 {
132     int     p11, p12, p21, p22;
133     Pwrte  *pwrte1, *pwrte2;
134 
135     if (m1 == NULL || m2 == NULL)
136         return (false);
137 
138     if (m1->to1 == m2->to1 || m1->to2 == m2->to2)
139         return (false);
140 
141     p11 = (int) geom_prop_get(m1->to1, m1->type, PWR);
142     p21 = (int) geom_prop_get(m1->to2, m1->type, PWR);
143     p12 = (int) geom_prop_get(m2->to1, m2->type, PWR);
144     p22 = (int) geom_prop_get(m2->to2, m2->type, PWR);
145 
146     pwrte1 = model_tbl->el.ptr_v[p11][p12];
147     pwrte2 = scene_tbl->el.ptr_v[p21][p22];
148 
149     return (pwrte_compatible(pwrte1, pwrte2));
150 }
151 
152 static List *clique_to_mlist(Match_clique * c)
153 {
154     List *lptr, *lptr2, *cl_tag;
155 
156     lptr = c->mlist;
157 
158     cl_tag = c->cliche_tag;
159 
160 ////////printf("clid = %d\n", (int)cl_tag->to );
161 
162 
163     for ( lptr2 = lptr; lptr2 != NULL; lptr2 = lptr2->next )
164     {
165         Match *m = (Match *) lptr2->to;
166         m->props =  proplist_addifnp( m->props, cl_tag, CLICHE_TAG, NULL, false ); 
167     }
168     return (lptr);
169 }
170 
171 static List *smm_pw_clique_mlists(void)
172 {
173     return (list_copy(pw_cliques, (void *(*) ()) clique_to_mlist, NULL));
174 }
175 
176 static List *update_cliche_tags(List *cliques, List *memo)
177 {
178         List *lptr;     
179 
180         for (lptr = cliques; lptr != NULL; lptr = lptr->next)
181         {
182                 Match_clique *m_c = (Match_clique *)lptr->to;
183 
184                 m_c->cliche_tag = memo;
185         }
186         return ( cliques ); ///////////////// JUST ADDED 010307!!!!!!!!!!!!!!$%^&
187 }
188 
189 static List *mutual_cliques(List * mlist, int csize)
190 {
191     List   *graph;
192     List   *gcliques;
193     List   *cliques = NULL;
194     List   *lptr;
195 
196     graph = graph_make_list(mlist);
197     graph_list_consistent(graph, smm_consistent_matches);
198     gcliques = cliques_get(graph, csize - 1);
199     for (lptr = gcliques; lptr != NULL; lptr = lptr->next)
200     {
201         List   *mlist = graph_recover_list((List *) lptr->to);
202         Match_clique *c;
203 
204         c = clique_make(mlist, smm_mlist_goodness(mlist), csize);
205 
206         cliques = ref_addtostart(cliques, (void *) c, LIST);
207         list_rm_links((List *) lptr->to);
208     }
209     list_rm(graph, rfree);
210     return (cliques);
211 }
212 
213 static void smm_cliches_to_pot_cliques(List * match_cliches)
214 /* Match cliche list */
215 {
216     List   *cptr;
217 
218     for (cptr = match_cliches; cptr != NULL; cptr = cptr->next)
219     {
220         Match_cliche *mc = (Match_cliche *) cptr->to;
221         List   *mlist = NULL;
222         List   *group;
223         List   *clist;
224         List   *ptr;
225         int     fthres, gthres; /* focus and global clique sizes */
226         List   *cl_list;
227 
228         fthres = mc->fthres;
229         gthres = mc->gthres;
230         group = mc->group;
231         cl_list = mc->cliche_tag;
232 
233 /* set up an intial list of geometric features matching focus feature in model */
234         for (ptr = mc->focus; ptr != NULL; ptr = ptr->next)
235         {
236             List   *flist = smm_good_matches(ptr->to, ptr->type, scene);
237 
238             mlist = list_append(flist, mlist);
239         }
240 
241         clist = mutual_cliques(mlist, fthres);  /* a set of initial
242                                                  * cliques */
243 
244         for (ptr = clist; ptr != NULL; ptr = ptr->next)
245         {
246             Match_clique *clique = (Match_clique *) ptr->to;
247 
248             clique->mlist = smm_mats_con_with_mlist(group, scene,  clique->mlist);
249 
250             clique->strength = (float)smm_mlist_goodness(clique->mlist);
251             clique->csize = gthres;
252             clique->cliche_tag = cl_list;
253         }
254         pot_cliques = list_append(clist, pot_cliques);
255     }
256     pot_cliques = sort_list(pot_cliques, clique_neg_strength, NULL);
257 }
258 
259 static void smm_mutual_cliques(void)
260 {
261     List   *lptr, *memo;
262         
263 
264     for (lptr = pot_cliques; lptr != NULL; lptr = lptr->next)
265     {
266         Match_clique *mc = (Match_clique *) lptr->to;
267 
268         if (list_length(mc->mlist) > mc->csize)
269         {
270             List   *cliques = mutual_cliques(mc->mlist, mc->csize); 
271 
272             memo = mc->cliche_tag;
273 
274             cliques = update_cliche_tags(cliques, memo);
275 
276             pw_cliques = list_append(cliques, pw_cliques);
277         }
278     }
279     pw_cliques = sort_list(pw_cliques, clique_neg_strength, NULL);
280 }
281 
282 List   *smm_run(List * cliches)
283 {
284     List   *mlists;
285 
286     smm_cliches_to_pot_cliques(cliches);
287     smm_mutual_cliques();
288     mlists = smm_pw_clique_mlists();
289     return (mlists);
290 }
291 

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