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

Linux Cross Reference
Tina4/src/vision/curve2/conic2.c

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

  1 /**@(#)
  2 **/
  3 #include <tina/sys.h>
  4 #include <tina/sysfuncs.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 #include <tina/vision.h>
  8 #include <tina/visionfuncs.h>
  9 
 10 /**
 11 recover unbroken (in pixel sence) string of Vec2 from conic
 12 **/
 13 
 14 static Conic *conic;
 15 
 16 static List *conic2_chop(double t1, double t2, Vec2 v1, Vec2 v2)
 17 {
 18     int     x1, y1, x2, y2;
 19     double  t;
 20     Vec2    v = {Vec2_id};
 21 
 22     x1 = (int)floor(vec2_x(v1));
 23     y1 = (int)floor(vec2_y(v1));
 24     x2 = (int)floor(vec2_x(v2));
 25     y2 = (int)floor(vec2_y(v2));
 26     if (x1 == x2 && y1 == y2)   /* same pixel */
 27         return (NULL);
 28     if (abs(x1 - x2) <= 1 && abs(y1 - y2) <= 1) /* neighbours */
 29         return (dd_link_alloc((void *) vec2_make(v2), VEC2));
 30 
 31     t = (t1 + t2) * 0.5;
 32     v = conic_point(conic, t);
 33     return (dd_append(conic2_chop(t1, t, v1, v), conic2_chop(t, t2, v, v2)));
 34 }
 35 
 36 Tstring *conic2_string(Conic * c)
 37 {
 38     List *list;
 39     Tstring *str;
 40     double  t1, t2, tm;
 41     Vec2    v1 = {Vec2_id};
 42     Vec2    v2 = {Vec2_id};
 43     Vec2    vm = {Vec2_id};
 44     int     x1, x2, y1, y2;
 45 
 46     if (c == NULL)
 47         return (NULL);
 48 
 49     conic = c;
 50     t1 = c->t1;
 51     t2 = c->t2;
 52     tm = (t1 + t2) * 0.5;
 53     v1 = conic_point(c, t1);
 54     v2 = conic_point(c, t2);
 55     vm = conic_point(c, tm);
 56     list = dd_link_alloc((void *) vec2_make(v1), VEC2);
 57     list = dd_append(list, conic2_chop(t1, tm, v1, vm));
 58     list = dd_append(list, conic2_chop(tm, t2, vm, v2));
 59 
 60     str = str_make(STRING, list, dd_get_end(list));
 61     if (str == NULL || str->count <= 3)
 62         return (str);
 63 
 64     x1 = (int)floor(vec2_x(v1));
 65     x2 = (int)floor(vec2_x(v2));
 66     y1 = (int)floor(vec2_y(v1));
 67     y2 = (int)floor(vec2_y(v2));
 68     if (abs(x1 - x2) <= 1 && abs(y1 - y2) <= 1) /* neighbours */
 69     {
 70         if (x1 == x2 && y1 == y2)       /* in same pixel */
 71         {
 72             str->start = str->start->next;
 73             (void) dd_link_rm(list, rfree);     /* same as start */
 74         }
 75         str->type = LOOP;
 76         str->start->last = str->end;
 77         str->end->next = str->start;
 78     }
 79     return (str);
 80 }
 81 

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