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

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

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

  1 /**@(#)
  2 **/
  3 /* mat_match.c
  4  * 
  5  * matchability module and functions
  6  * 
  7  */
  8 
  9 #include <math.h>
 10 #include <tina/sys.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/math.h>
 13 #include <tina/mathfuncs.h>
 14 #include <tina/vision.h>
 15 #include <tina/visionfuncs.h>
 16 
 17 static Bool use_transf_thres = false;
 18 static float rotthres = (float)PI;
 19 static float dotthres = (float)1.0;
 20 static float posthres = (float)1000.0;
 21 static float low_lenratio = (float)0.75;
 22 static float up_lenratio = (float)1.33;
 23 static float low_conratio = (float)0.75;
 24 static float up_conratio = (float)1.33;
 25 
 26 void    matcher_set_length_ratio(double lenratio)
 27 {
 28     low_lenratio = (float)lenratio;
 29     up_lenratio = (float)(1.0 / lenratio);
 30     ORDER(float, low_lenratio, up_lenratio);
 31     low_conratio = low_lenratio;/* tempory measure */
 32     up_conratio = up_lenratio;
 33 }
 34 
 35 double  matcher_get_length_ratio(void)
 36 {
 37     return (low_lenratio);
 38 }
 39 
 40 void    matcher_set_max_rot(double rot)
 41 {
 42     rotthres = (float)rot;
 43     dotthres = (float)cos(rotthres);
 44 }
 45 
 46 double  matcher_get_max_rot(void)
 47 {
 48     return (rotthres);
 49 }
 50 
 51 void    matcher_set_max_trans(double pos)
 52 {
 53     posthres = (float)pos;
 54 }
 55 
 56 double  matcher_get_max_trans(void)
 57 {
 58     return (posthres);
 59 }
 60 
 61 void    matcher_set_use_transf_thres(Bool use)
 62 {
 63     use_transf_thres = use;
 64 }
 65 
 66 static Bool line3_good_match(Line3 * l1, Line3 * l2)
 67 {
 68     float   lenratio;
 69 
 70     if (l1 == NULL || l2 == NULL)
 71         return (false);
 72 
 73     if (use_transf_thres == true)
 74     {
 75         if (vec3_dot(l1->v, l2->v) < dotthres)
 76             return (false);
 77     }
 78     lenratio = l1->length / l2->length;
 79     if (lenratio < low_lenratio || lenratio > up_lenratio)
 80         return (false);
 81 
 82     return (true);
 83 }
 84 
 85 static Bool conic3_matchable(Conic3 * c1, Conic3 * c2)
 86 {
 87     double  conratio;
 88 
 89     if (c1 == NULL || c2 == NULL)
 90         return (false);
 91 
 92     if (use_transf_thres == true)
 93     {
 94         if (vec3_dot(c1->ez, c2->ez) < dotthres)
 95             return (false);
 96     }
 97     conratio = c1->conic->alpha / c2->conic->alpha;
 98     if (conratio < low_conratio || conratio > up_conratio)
 99         return (false);
100     conratio = c1->conic->beta / c2->conic->beta;
101     if (conratio < low_conratio || conratio > up_conratio)
102         return (false);
103     return (true);
104 }
105 
106 Bool    smm_good_match(void *p1, void *p2, int type)
107 {
108     Bool    bool = false;
109 
110     switch (type)
111     {
112     case POINT3:
113         bool = (true);          /* always matchable */
114         break;
115     case LINE3:
116         bool = (line3_good_match((Line3 *) p1, (Line3 *) p2));
117         break;
118     case CONIC3:
119         bool = (conic3_matchable((Conic3 *) p1, (Conic3 *) p2));
120         break;
121     default:
122         bool = (false);
123         break;
124     }
125     return (bool);
126 }
127 
128 static Bool line3_reasonable_match(Line3 * l1, Line3 * l2)
129 {
130     if (l1 == NULL || l2 == NULL)
131         return (false);
132 
133     if (use_transf_thres == true)
134     {
135         if (vec3_dot(l1->v, l2->v) < dotthres)
136             return (false);
137     }
138     return (true);
139 }
140 
141 Bool    smm_reasonable_match(void *p1, void *p2, int type)
142 {
143     Bool    bool = false;
144 
145     switch (type)
146     {
147     case POINT3:
148         bool = (true);          /* always matchable */
149         break;
150     case LINE3:
151         bool = (line3_reasonable_match((Line3 *) p1, (Line3 *) p2));
152         break;
153     case CONIC3:
154         bool = (conic3_matchable((Conic3 *) p1, (Conic3 *) p2));
155         break;
156     default:
157         bool = (false);
158         break;
159     }
160     return (bool);
161 }
162 
163 
164 List   *smm_good_matches(void *p, int ptype, List * list)
165 {
166     List   *lptr;
167     List   *match_list = NULL;
168     Match  *match_make();
169     double  smm_match_strength(Match * match);
170 
171     for (lptr = list; lptr != NULL; lptr = lptr->next)
172         if (lptr->type == ptype && smm_good_match(p, lptr->to, ptype))
173         {
174             Match  *match = match_make(p, lptr->to, ptype);
175 
176             match->weight = (float)smm_match_strength(match);
177             match_list = ref_addtostart(match_list, (void *) match, MATCH);
178         }
179     return (list_reverse(match_list));
180 }
181 
182 double  smm_match_strength(Match * match)
183 {
184     if (match == NULL)
185         return (0.0);
186 
187     switch (match->type)
188     {
189     case LINE3:
190         {
191             Line3  *l1 = (Line3 *) match->to1;
192             Line3  *l2 = (Line3 *) match->to2;
193 
194             if (l1->length < l2->length)
195                 return (l1->length * l1->length / l2->length);
196             else
197                 return (l2->length * l2->length / l1->length);
198         }
199     case CONIC3:
200         {
201             Conic  *c1 = ((Conic3 *) match->to1)->conic;
202             Conic  *c2 = ((Conic3 *) match->to2)->conic;
203             double  len1, len2;
204 
205             len1 = conic_approx_length(c1, 3);
206             len2 = conic_approx_length(c2, 3);
207             if (len1 < len2)
208                 return (fabs(c1->t2 - c1->t1) * len1 / TWOPI);
209             else
210                 return (fabs(c2->t2 - c2->t1) * len2 / TWOPI);
211         }
212     case POINT3:
213         return (1.0);
214     default:
215         return (0.0);
216     }
217 }
218 
219 double  smm_mlist_goodness(List * mlist)
220 /* list of matches  */
221 {
222     float   goodness = (float) 0.0;
223     List   *con_list = NULL;
224     List   *lptr;
225     List   *cptr;
226 
227     for (lptr = mlist; lptr != NULL; lptr = lptr->next)
228     {
229         Match  *m = (Match *) lptr->to;
230         float   con;
231         int     label;
232 
233         con = m->weight;
234         label = geom_label_get(m->to1, m->type);
235         cptr = link_get_by_type(con_list, label);
236 
237         if (cptr == NULL)
238         {
239             con_list = ref_addtostart(con_list, (void *) ralloc(sizeof(float)), label);
240             cptr = con_list;
241         } else if (*((float *) cptr->to) > con)
242             continue;
243 
244         *((float *) cptr->to) = con;
245     }
246 
247     for (cptr = con_list; cptr != NULL; cptr = cptr->next)
248         goodness += *((float *) cptr->to);
249     list_rm(con_list, (void (*) ()) NULL);
250     return (goodness);
251 }
252 

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