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

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

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