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

Linux Cross Reference
Tina4/src/vision/line2/polyprox.c

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

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <stdio.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/mathfuncs.h>
  9 #include <tina/vision.h>
 10 
 11 /* Accepts either edgel or vec2 List */
 12 List *poly_prox(List * start, List * end, double thres)
 13 {
 14     Vec2    p1 = {Vec2_id};
 15     Vec2    p2 = {Vec2_id};
 16     Vec2    v = {Vec2_id};
 17     List *dptr;
 18     List *dmax;
 19     double  length, perp, maxperp;
 20     Line2  *line2_between();
 21 
 22     if (start == NULL || end == NULL || start == end)
 23         return (NULL);
 24 
 25     DD_GET_POS2(start, p1);
 26     DD_GET_POS2(end, p2);
 27     length = vec2_mod(vec2_diff(p2,p1));
 28     v = vec2_unit(vec2_diff(p2, p1));
 29 
 30     dmax = NULL;
 31     maxperp = 0;
 32     for (dptr = start->next; dptr != end; dptr = dptr->next)
 33     {
 34         Vec2    p = {Vec2_id};
 35 
 36         DD_GET_POS2(dptr, p);
 37         perp = vec2_mod(vec2_projperp(vec2_diff(p, p1), v));
 38         if (perp > maxperp)
 39         {
 40             maxperp = perp;
 41             dmax = dptr;
 42         }
 43     }
 44 
 45     if (maxperp/length < thres)
 46         return (dd_link_alloc((void *) line2_between(start, end), LINE2));
 47 
 48     return (dd_append(poly_prox(start, dmax, thres), poly_prox(dmax, end, thres)));
 49 }
 50 
 51 Tstring *poly_string(Tstring * string, double thres)
 52 {
 53     List *poly;
 54 
 55     if (string == NULL)
 56         return (NULL);
 57 
 58     poly = poly_prox(string->start, string->end, thres);
 59 
 60     if (poly == NULL)
 61         return (NULL);
 62 
 63     return (str_make(STRING, poly, dd_get_end(poly)));
 64 }
 65 
 66 List   *poly_strings(List * strings, double thres)
 67 {
 68     List   *sptr;
 69     List   *splist = NULL;
 70 
 71     for (sptr = strings; sptr != NULL; sptr = sptr->next)
 72     {
 73         Tstring *string = poly_string((Tstring *) sptr->to, thres);
 74 
 75         splist = ref_addtostart((List *) splist, (void *) string, STRING);
 76     }
 77     return (splist);
 78 }
 79 

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