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

Linux Cross Reference
Tina6/tina-libs/tina/vision/visModel_match.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_match.c,v $
 27  * Date    :  $Date: 2003/10/06 12:29:48 $
 28  * Version :  $Revision: 1.3 $
 29  * CVS Id  :  $Id: visModel_match.c,v 1.3 2003/10/06 12:29:48 neil Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  * 
 35  * matchability module and functions
 36  * 
 37  *
 38  *********
 39 */
 40 
 41 #include "visModel_match.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 
 58 static Bool use_transf_thres = false;
 59 static float rotthres = (float)PI;
 60 static float dotthres = (float)1.0;
 61 static float posthres = (float)1000.0;
 62 static float low_lenratio = (float)0.75;
 63 static float up_lenratio = (float)1.33;
 64 static float low_conratio = (float)0.75;
 65 static float up_conratio = (float)1.33;
 66 
 67 void    matcher_set_length_ratio(double lenratio)
 68 {
 69     low_lenratio = (float)lenratio;
 70     up_lenratio = (float)(1.0 / lenratio);
 71     ORDER(float, low_lenratio, up_lenratio);
 72     low_conratio = low_lenratio;/* tempory measure */
 73     up_conratio = up_lenratio;
 74 }
 75 
 76 double  matcher_get_length_ratio(void)
 77 {
 78     return (low_lenratio);
 79 }
 80 
 81 void    matcher_set_max_rot(double rot)
 82 {
 83     rotthres = (float)rot;
 84     dotthres = (float)cos(rotthres);
 85 }
 86 
 87 double  matcher_get_max_rot(void)
 88 {
 89     return (rotthres);
 90 }
 91 
 92 void    matcher_set_max_trans(double pos)
 93 {
 94     posthres = (float)pos;
 95 }
 96 
 97 double  matcher_get_max_trans(void)
 98 {
 99     return (posthres);
100 }
101 
102 void    matcher_set_use_transf_thres(Bool use)
103 {
104     use_transf_thres = use;
105 }
106 
107 static Bool line3_good_match(Line3 * l1, Line3 * l2)
108 {
109     float   lenratio;
110 
111     if (l1 == NULL || l2 == NULL)
112         return (false);
113 
114     if (use_transf_thres == true)
115     {
116         if (vec3_dot(l1->v, l2->v) < dotthres)
117             return (false);
118     }
119     lenratio = l1->length / l2->length;
120     if (lenratio < low_lenratio || lenratio > up_lenratio)
121         return (false);
122 
123     return (true);
124 }
125 
126 static Bool conic3_matchable(Conic3 * c1, Conic3 * c2)
127 {
128     double  conratio;
129 
130     if (c1 == NULL || c2 == NULL)
131         return (false);
132 
133     if (use_transf_thres == true)
134     {
135         if (vec3_dot(c1->ez, c2->ez) < dotthres)
136             return (false);
137     }
138     conratio = c1->conic->alpha / c2->conic->alpha;
139     if (conratio < low_conratio || conratio > up_conratio)
140         return (false);
141     conratio = c1->conic->beta / c2->conic->beta;
142     if (conratio < low_conratio || conratio > up_conratio)
143         return (false);
144     return (true);
145 }
146 
147 Bool    smm_good_match(void *p1, void *p2, int type)
148 {
149     Bool    bool = false;
150 
151     switch (type)
152     {
153     case POINT3:
154         bool = (true);          /* always matchable */
155         break;
156     case LINE3:
157         bool = (line3_good_match((Line3 *) p1, (Line3 *) p2));
158         break;
159     case CONIC3:
160         bool = (conic3_matchable((Conic3 *) p1, (Conic3 *) p2));
161         break;
162     default:
163         bool = (false);
164         break;
165     }
166     return (bool);
167 }
168 
169 static Bool line3_reasonable_match(Line3 * l1, Line3 * l2)
170 {
171     if (l1 == NULL || l2 == NULL)
172         return (false);
173 
174     if (use_transf_thres == true)
175     {
176         if (vec3_dot(l1->v, l2->v) < dotthres)
177             return (false);
178     }
179     return (true);
180 }
181 
182 Bool    smm_reasonable_match(void *p1, void *p2, int type)
183 {
184     Bool    bool = false;
185 
186     switch (type)
187     {
188     case POINT3:
189         bool = (true);          /* always matchable */
190         break;
191     case LINE3:
192         bool = (line3_reasonable_match((Line3 *) p1, (Line3 *) p2));
193         break;
194     case CONIC3:
195         bool = (conic3_matchable((Conic3 *) p1, (Conic3 *) p2));
196         break;
197     default:
198         bool = (false);
199         break;
200     }
201     return (bool);
202 }
203 
204 
205 List   *smm_good_matches(void *p, int ptype, List * list)
206 {
207     List   *lptr;
208     List   *match_list = NULL;
209     Match  *match_make();
210     double  smm_match_strength(Match * match);
211 
212     for (lptr = list; lptr != NULL; lptr = lptr->next)
213         if (lptr->type == ptype && smm_good_match(p, lptr->to, ptype))
214         {
215             Match  *match = match_make(p, lptr->to, ptype);
216 
217             match->weight = (float)smm_match_strength(match);
218             match_list = ref_addtostart(match_list, (void *) match, MATCH);
219         }
220     return (list_reverse(match_list));
221 }
222 
223 double  smm_match_strength(Match * match)
224 {
225     if (match == NULL)
226         return (0.0);
227 
228     switch (match->type)
229     {
230     case LINE3:
231         {
232             Line3  *l1 = (Line3 *) match->to1;
233             Line3  *l2 = (Line3 *) match->to2;
234 
235             if (l1->length < l2->length)
236                 return (l1->length * l1->length / l2->length);
237             else
238                 return (l2->length * l2->length / l1->length);
239         }
240     case CONIC3:
241         {
242             Conic  *c1 = ((Conic3 *) match->to1)->conic;
243             Conic  *c2 = ((Conic3 *) match->to2)->conic;
244             double  len1, len2;
245 
246             len1 = conic_approx_length(c1, 3);
247             len2 = conic_approx_length(c2, 3);
248             if (len1 < len2)
249                 return (fabs(c1->t2 - c1->t1) * len1 / TWOPI);
250             else
251                 return (fabs(c2->t2 - c2->t1) * len2 / TWOPI);
252         }
253     case POINT3:
254         return (1.0);
255     default:
256         return (0.0);
257     }
258 }
259 
260 double  smm_mlist_goodness(List * mlist)
261 /* list of matches  */
262 {
263     float   goodness = (float) 0.0;
264     List   *con_list = NULL;
265     List   *lptr;
266     List   *cptr;
267 
268     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
269     {
270         Match  *m = (Match *) lptr->to;
271         float   con;
272         int     label;
273 
274         con = m->weight;
275         label = geom_label_get(m->to1, m->type);
276         cptr = link_get_by_type(con_list, label);
277 
278         if (cptr == NULL)
279         {
280             con_list = ref_addtostart(con_list, (void *) ralloc(sizeof(float)), label);
281             cptr = con_list;
282         } else if (*((float *) cptr->to) > con)
283             continue;
284 
285         *((float *) cptr->to) = con;
286     }
287 
288     for (cptr = con_list; cptr != NULL; cptr = cptr->next)
289         goodness += *((float *) cptr->to);
290     list_rm(con_list, (void (*) ()) NULL);
291     return (goodness);
292 }
293 

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