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

Linux Cross Reference
Tina5/tina-libs/tina/geometry/geomCurve_string2.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 Lesser 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 Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser 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  **********
 20  * 
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/geometry/geomCurve_string2.c,v $
 23  * Date    :  $Date: 2005/01/09 17:49:25 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: geomCurve_string2.c,v 1.3 2005/01/09 17:49:25 paul Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes : recover unbroken (in pixel sence) string of Vec2 from curve function
 30  *
 31  *********
 32 */
 33 
 34 #include "geomCurve_string2.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <math.h>
 41 #include <stdlib.h>
 42 #include <tina/sys/sysDef.h>
 43 #include <tina/sys/sysPro.h>
 44 #include <tina/math/mathDef.h>
 45 #include <tina/math/mathPro.h>
 46 
 47 
 48 static  Vec2(*curve_func) ();           /* static data! */
 49 static void *curve_data;                        /* static data! */
 50 static void *extra_data;                        /* static data! */
 51 
 52 static List *curve2_chop(double t1, double t2, Vec2 v1, Vec2 v2)
 53 {
 54     int     x1, y1, x2, y2;
 55     double  t;
 56     Vec2    v = {Vec2_id};
 57 
 58     x1 = (int)floor(vec2_x(v1));
 59     y1 = (int)floor(vec2_y(v1));
 60     x2 = (int)floor(vec2_x(v2));
 61     y2 = (int)floor(vec2_y(v2));
 62     if (x1 == x2 && y1 == y2)   /* same pixel */
 63         return (NULL);
 64     if (abs(x1 - x2) <= 1 && abs(y1 - y2) <= 1) /* neighbours */
 65         return (dd_link_alloc((void *) vec2_make(v2), VEC2));
 66 
 67     t = (t1 + t2) * 0.5;
 68     v = curve_func(curve_data, t, extra_data);
 69     return (dd_append(curve2_chop(t1, t, v1, v), curve2_chop(t, t2, v, v2)));
 70 }
 71 
 72 Tstring *str2_of_curve2(Vec2(*c_func) ( /* ??? */ ), void *c_data, double t1, double t2, void *e_data)
 73 {
 74     List *list;
 75     Tstring *str;
 76     double  tm;
 77     Vec2    v1 = {Vec2_id};
 78     Vec2    v2 = {Vec2_id};
 79     Vec2    vm = {Vec2_id};
 80     int     x1, x2, y1, y2;
 81 
 82     if (c_func == NULL)
 83         return (NULL);
 84 
 85     curve_func = c_func;
 86     curve_data = c_data;
 87     extra_data = e_data;
 88 
 89     tm = (t1 + t2) * 0.5;
 90     v1 = curve_func(curve_data, t1, extra_data);
 91     v2 = curve_func(curve_data, t2, extra_data);
 92     vm = curve_func(curve_data, tm, extra_data);
 93     list = dd_link_alloc((void *) vec2_make(v1), VEC2);
 94     list = dd_append(list, curve2_chop(t1, tm, v1, vm));
 95     list = dd_append(list, curve2_chop(tm, t2, vm, v2));
 96 
 97     str = str_make(STRING, list, dd_get_end(list));
 98     if (str == NULL || str->start == str->end)
 99         return (str);
100 
101     x1 = (int)floor(vec2_x(v1));
102     x2 = (int)floor(vec2_x(v2));
103     y1 = (int)floor(vec2_y(v1));
104     y2 = (int)floor(vec2_y(v2));
105     if (abs(x1 - x2) <= 1 && abs(y1 - y2) <= 1) /* neighbours */
106     {
107         if (x1 == x2 && y1 == y2)       /* in same pixel */
108         {
109             str->start = str->start->next;
110             (void) dd_link_rm(list, rfree);     /* same as start */
111         }
112         str->type = LOOP;
113         str->start->last = str->end;
114         str->end->next = str->start;
115     }
116     return (str);
117 }
118 

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