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

Linux Cross Reference
Tina4/src/vision/spline/strspline.c

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

  1 #include <values.h>
  2 #include <math.h>
  3 #include <tina/sys.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/vision.h>
  7 #include <tina/visionfuncs.h>
  8 #include <tina/splinefuncs.h>
  9 
 10 /*
 11 Return 8-neighbour connected edge string occupied by spline.
 12 Points returned are sub-pixel accuracy.
 13 */
 14 Tstring *str2_of_spline2(Spline2 * spline)
 15 {
 16     double t1 = 0.0, t2;
 17 
 18     if (spline == NULL)
 19         return (NULL);
 20 
 21     switch (spline->type)
 22     {
 23         case SPLINE_NATURAL:
 24         case SPLINE_TANGENT:
 25             t2 = spline->n - 1;
 26             break;
 27         case SPLINE_PERIODIC:
 28             t2 = spline->n;
 29             break;
 30         default:
 31             return(NULL);
 32     }
 33     return (str2_of_curve2(spline2_eval, spline, t1, t2, (void *) NULL));
 34 }
 35 
 36 /*
 37 Returns a spline interpolating an edge string at n evenly spaced points.
 38 */
 39 Spline2 *spline2_of_str2(Tstring * str, int n)
 40 {
 41     Spline2 *spline;
 42     Vec2 *p;
 43 
 44     if (str == NULL)
 45         return (NULL);
 46 
 47     switch (str->type)
 48     {
 49         case STRING:
 50             spline = spline2_make(SPLINE_NATURAL, n);
 51             break;
 52         case LOOP:
 53             spline = spline2_make(SPLINE_PERIODIC, n);
 54             break;
 55     }
 56     p = tvector_alloc(0, n, Vec2);
 57     str2_get_interp_vec2_knots(str, n, p);
 58     spline2_interpolate(spline, p);
 59     tvector_free((void *) p, 0, Vec2);
 60     return (spline);
 61 }
 62 
 63 /*
 64 Returns a 2D-spline approximating an edge string to an
 65 accuracy dmax. Can be fooled by shapes with symmetry,
 66 since accuracy is checked only at knot-mid-points.
 67 Recursive call is fairly expensive.
 68 */
 69 Spline2 *spline2_approx_str2(Tstring * str, int *pn, double dmax)
 70 {
 71     Spline2 *spline;
 72     Vec2 *p;
 73     double dist;
 74     int i, n = *pn;
 75 
 76     if (str == NULL)
 77         return (NULL);
 78     switch (str->type)
 79     {
 80         case STRING:
 81             spline = spline2_make(SPLINE_NATURAL, n);
 82             break;
 83         case LOOP:
 84             spline = spline2_make(SPLINE_PERIODIC, n);
 85             break;
 86     }
 87     p = tvector_alloc(0, 2*n, Vec2);
 88     str2_get_interp_vec2_knots(str, n, p);
 89     spline2_interpolate(spline, p);
 90 
 91     str2_get_interp_vec2_knots(str, 2*n, p);
 92     dist = 0;
 93     for(i = 0; i < n; i++)
 94     {
 95         double d = spline2_dist(spline, p[2*i+1]);
 96         dist = MAX(dist, d);
 97     }
 98     tvector_free((void *) p, 0, Vec2);
 99     if(dist > dmax && *pn < 500)
100     {
101         spline2_free(spline);
102         *pn = 1.4142*n;
103         return(spline2_approx_str2(str, pn, dmax));
104     }
105     return (spline);
106 }
107 
108 
109 

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