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

Linux Cross Reference
Tina6/tina-libs/tina/geometry/geomLine_polyprox.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/geomLine_polyprox.c,v $
 27  * Date    :  $Date: 2002/12/09 11:51:23 $
 28  * Version :  $Revision: 1.1.1.1 $
 29  * CVS Id  :  $Id: geomLine_polyprox.c,v 1.1.1.1 2002/12/09 11:51:23 cvstina Exp $
 30  *
 31  * Notes :
 32  *
 33  *********
 34 */
 35 
 36 
 37 #include "geomLine_polyprox.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_LineDef.h>
 51 #include <tina/geometry/geom_LinePro.h>
 52 
 53 /* Accepts either edgel or vec2 List */
 54 List *poly_prox(List * start, List * end, double thres)
 55 {
 56     Vec2    p1 = {Vec2_id};
 57     Vec2    p2 = {Vec2_id};
 58     Vec2    v = {Vec2_id};
 59     List *dptr;
 60     List *dmax;
 61     double  length, perp, maxperp;
 62     Line2  *line2_between();
 63 
 64     if (start == NULL || end == NULL || start == end)
 65         return (NULL);
 66 
 67     DD_GET_POS2(start, p1);
 68     DD_GET_POS2(end, p2);
 69     length = vec2_mod(vec2_diff(p2,p1));
 70     v = vec2_unit(vec2_diff(p2, p1));
 71 
 72     dmax = NULL;
 73     maxperp = 0;
 74     for (dptr = start->next; dptr != end; dptr = dptr->next)
 75     {
 76         Vec2    p = {Vec2_id};
 77 
 78         DD_GET_POS2(dptr, p);
 79         perp = vec2_mod(vec2_projperp(vec2_diff(p, p1), v));
 80         if (perp > maxperp)
 81         {
 82             maxperp = perp;
 83             dmax = dptr;
 84         }
 85     }
 86 
 87     if (maxperp/length < thres)
 88         return (dd_link_alloc((void *) line2_between(start, end), LINE2));
 89 
 90     return (dd_append(poly_prox(start, dmax, thres), poly_prox(dmax, end, thres)));
 91 }
 92 
 93 Tstring *poly_string(Tstring * string, double thres)
 94 {
 95     List *poly;
 96 
 97     if (string == NULL)
 98         return (NULL);
 99 
100     poly = poly_prox(string->start, string->end, thres);
101 
102     if (poly == NULL)
103         return (NULL);
104 
105     return (str_make(STRING, poly, dd_get_end(poly)));
106 }
107 
108 List   *poly_strings(List * strings, double thres)
109 {
110     List   *sptr;
111     List   *splist = NULL;
112 
113     for (sptr = strings; sptr != NULL; sptr = sptr->next)
114     {
115         Tstring *string = poly_string((Tstring *) sptr->to, thres);
116 
117         splist = ref_addtostart((List *) splist, (void *) string, STRING);
118     }
119     return (splist);
120 }
121 

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