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

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

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