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

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

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

  1 /**@(#)
  2 **/
  3 /* splines.c
  4  * 
  5  * functions to take strings of 2d positions and return various forms of
  6  * spline fit through them
  7  * 
  8  */
  9 
 10 #include <math.h>
 11 #include <tina/sys.h>
 12 #include <tina/sysfuncs.h>
 13 #include <tina/math.h>
 14 #include <tina/mathfuncs.h>
 15 #include <tina/vision.h>
 16 
 17 /* function to take a string of pos2 (referenced through the DD_GET_POS
 18  * macro) and return a string of Vec2 representation of the
 19  * interpolated conic spline */
 20 
 21 Tstring *str_ics2(Tstring * str, int knot_sample, double str_space, double *a, double *b)
 22 /* string of pos2 */
 23 /* sample of underlying spline */
 24 /* with respect to units of underlying string */
 25 /* end point derivetive conditions: NULL for natural */
 26 {
 27     List *ptr;
 28     List *start;
 29     List *end;
 30     int     i, nknots;
 31     float  *t, *x, *y, *x2, *y2;
 32     float   s, sum;
 33     Vec2    p = {Vec2_id};
 34     Vec2    p_last = {Vec2_id};
 35 
 36     if (str == NULL || str->start == str->end || str->start == NULL)
 37         return (NULL);
 38 
 39     nknots = str->count / knot_sample + 2;      /* maximum possible size */
 40     start = str->start;
 41     end = str->end;
 42 
 43     t = fvector_alloc(0, nknots);
 44     x = fvector_alloc(0, nknots);
 45     y = fvector_alloc(0, nknots);
 46     x2 = fvector_alloc(0, nknots);
 47     y2 = fvector_alloc(0, nknots);
 48 
 49     DD_GET_POS2(start, p_last);
 50     for (nknots=0, sum=(float)0.0, i=0, ptr=start;; ptr=ptr->next, i++)
 51     {
 52         if (i % knot_sample == 0 || ptr == end)
 53         {
 54             DD_GET_POS2(ptr, p);
 55             x[nknots] = vec2_x(p);
 56             y[nknots] = vec2_y(p);
 57             sum += (float) vec2_mod(vec2_diff(p, p_last));
 58             t[nknots] = sum;
 59             nknots++;
 60             p_last = p;
 61             if (ptr == end)
 62                 break;
 63         }
 64     }
 65 
 66     spl_ci_sbp(t, x, nknots, a, b, x2);
 67     spl_ci_sbp(t, y, nknots, a, b, y2);
 68 
 69     start = NULL;
 70     for (s = t[0]; s <= sum; s += (float)str_space)
 71     {
 72         vec2_x(p) = (float) spl_ci_val(t, x, x2, nknots, s);
 73         vec2_y(p) = (float) spl_ci_val(t, y, y2, nknots, s);
 74         start = dd_ref_addtostart(start, (void *) vec2_make(p), VEC2);
 75     }
 76 
 77     if (start == NULL)
 78         return (NULL);
 79 
 80     start = dd_list_reverse(start);
 81     end = dd_get_end(start);
 82 
 83     fvector_free((void *) t, 0);
 84     fvector_free((void *) x, 0);
 85     fvector_free((void *) y, 0);
 86     fvector_free((void *) x2, 0);
 87     fvector_free((void *) y2, 0);
 88 
 89     return (str_make(STRING, start, end));
 90 }
 91 

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