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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomSpline_strspline.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomSpline_strspline.c,v $
 27  * Date    :  $Date: 2005/01/23 19:10:21 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: geomSpline_strspline.c,v 1.2 2005/01/23 19:10:21 paul Exp $
 30  *
 31  * Notes :
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomSpline_strspline.h"
 38 
 39 #if HAVE_CONFIG_H
 40   #include <config.h>
 41 #endif
 42 
 43 #include <stdio.h>
 44 #include <math.h>
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/geometry/geomDef.h>
 50 #include <tina/geometry/geom_CurvePro.h>
 51 #include <tina/geometry/geom_SplineDef.h>
 52 #include <tina/geometry/geom_EdgePro.h>
 53 
 54 
 55 /*
 56 Return 8-neighbour connected edge string occupied by spline.
 57 Points returned are sub-pixel accuracy.
 58 */
 59 Tstring *str2_of_spline2(Spline2 * spline)
 60 {
 61     double t1 = 0.0, t2;
 62 
 63     if (spline == NULL)
 64         return (NULL);
 65 
 66     switch (spline->type)
 67     {
 68         case SPLINE_NATURAL:
 69         case SPLINE_TANGENT:
 70             t2 = spline->n - 1;
 71             break;
 72         case SPLINE_PERIODIC:
 73             t2 = spline->n;
 74             break;
 75         default:
 76             return(NULL);
 77     }
 78     return (str2_of_curve2(spline2_eval, spline, t1, t2, (void *) NULL));
 79 }
 80 
 81 /*
 82 Returns a spline interpolating an edge string at n evenly spaced points.
 83 */
 84 Spline2 *spline2_of_str2(Tstring * str, int n)
 85 {
 86     Spline2 *spline=NULL;
 87     Vec2 *p=NULL;
 88 
 89     if (str == NULL)
 90         return (NULL);
 91 
 92     switch (str->type)
 93     {
 94         case STRING:
 95             spline = spline2_make(SPLINE_NATURAL, n);
 96             break;
 97         case LOOP:
 98             spline = spline2_make(SPLINE_PERIODIC, n);
 99             break;
100     }
101     p = tvector_alloc(0, n, Vec2);
102     str2_get_interp_vec2_knots(str, n, p);
103     spline2_interpolate(spline, p);
104     tvector_free(p, 0, Vec2);
105     return (spline);
106 }
107 
108 /*
109 Returns a 2D-spline approximating an edge string to an
110 accuracy dmax. Can be fooled by shapes with symmetry,
111 since accuracy is checked only at knot-mid-points.
112 Recursive call is fairly expensive.
113 */
114 Spline2 *spline2_approx_str2(Tstring * str, int *pn, double dmax)
115 {
116     Spline2 *spline=NULL;
117     Vec2 *p=NULL;
118     double dist;
119     int i, n = *pn;
120 
121     if (str == NULL)
122         return (NULL);
123     switch (str->type)
124     {
125         case STRING:
126             spline = spline2_make(SPLINE_NATURAL, n);
127             break;
128         case LOOP:
129             spline = spline2_make(SPLINE_PERIODIC, n);
130             break;
131     }
132     p = tvector_alloc(0, 2*n, Vec2);
133     str2_get_interp_vec2_knots(str, n, p);
134     spline2_interpolate(spline, p);
135 
136     str2_get_interp_vec2_knots(str, 2*n, p);
137     dist = 0;
138     for(i = 0; i < n; i++)
139     {
140         double d = spline2_dist(spline, p[2*i+1]);
141         dist = MAX(dist, d);
142     }
143     tvector_free(p, 0, Vec2);
144     if(dist > dmax && *pn < 500)
145     {
146         spline2_free(spline);
147         *pn = 1.4142*n;
148         return(spline2_approx_str2(str, pn, dmax));
149     }
150     return (spline);
151 }
152 
153 
154 

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